[PATCH 1 of 1 saem_ref V3] [test] Activate automatic tests

Sylvain Thenault sylvain.thenault at logilab.fr
Fri Mar 17 08:19:44 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1425043439 -3600
#      Fri Feb 27 14:23:59 2015 +0100
# Node ID 3368e672919eaf2411a85386d82c136d381b8412
# Parent  591c71cd3ca3d858f45af1c9d0b018da0bb81765
[test] Activate automatic tests

we need some fixes in underlying cubes to get it green, but no fixes in this
cube.

diff --git a/dev-requirements.txt b/dev-requirements.txt
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -1,5 +1,7 @@
 pytest
 webtest
 http://hg.logilab.org/review/cubes/eac/archive/tip.tar.bz2#egg=cubicweb-eac
 http://hg.logilab.org/review/cubes/compound/archive/tip.tar.bz2#egg=cubicweb-compound
+http://hg.logilab.org/review/cubes/seda/archive/55d886119a5a.tar.bz2#egg=cubicweb-seda
 http://hg.logilab.org/master/cubes/relationwidget/archive/tip.tar.bz2#egg=cubicweb-relationwidget
+http://hg.logilab.org/master/cubes/skos/archive/tip.tar.bz2#egg=cubicweb-skos
diff --git a/test/test_saem_ref.py b/test/test_saem_ref.py
--- a/test/test_saem_ref.py
+++ b/test/test_saem_ref.py
@@ -11,39 +11,18 @@
 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 # details.
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with this program. If not, see <http://www.gnu.org/licenses/>.
-
-"""cubicweb-saem-ref automatic tests
-
-
-uncomment code below if you want to activate automatic test for your cube:
-
-.. sourcecode:: python
-
-    from cubicweb.devtools.testlib import AutomaticWebTest
-
-    class AutomaticWebTest(AutomaticWebTest):
-        '''provides `to_test_etypes` and/or `list_startup_views` implementation
-        to limit test scope
-        '''
-
-        def to_test_etypes(self):
-            '''only test views for entities of the returned types'''
-            return set(('My', 'Cube', 'Entity', 'Types'))
-
-        def list_startup_views(self):
-            '''only test startup views of the returned identifiers'''
-            return ('some', 'startup', 'views')
-"""
+"""cubicweb-saem-ref automatic tests"""
 
 from functools import partial
 from unittest import TestCase
 from logilab.common import attrdict
 
 from cubicweb.devtools import testlib
+from cubicweb.schema import SCHEMA_TYPES
 
 from cubicweb_saem_ref import cwuri_url
 
 import testutils
 
@@ -100,8 +79,102 @@ class ArkURLTC(testlib.CubicWebTC):
                 ark_etypes.remove(etype)
         if ark_etypes:
             self.fail('entity types not checked {}'.format(ark_etypes))
 
 
+class AutomaticWebTest(testlib.AutomaticWebTest):
+    test_ten_each_config = None  # deactivate attempt to auto populate
+    skip_views = set([
+        'calendar',
+        'csvexport',
+        'ecsvexport',
+        'ejsonexport',
+        'filetree',
+        'hcal',
+        'jsonexport',
+        'n3rdf',
+        'oneweekcal',
+        'onemonthcal',
+        'owlabox',
+        'rsetxml',
+        'rss',
+        'security',
+        'treeview',
+        'xbel',
+        'skos.source-sync',
+    ])
+
+    @property
+    def no_auto_populate(self):
+        seda_types_to_skip = [eschema.type for eschema in self.schema.entities()
+                              if eschema.type.startswith('SEDA')
+                              and eschema not in ('SEDAArchiveTransfer',
+                                                  'SEDAArchiveUnit',
+                                                  'SEDABinaryDataObject')]
+        eac_types_to_skip = ['EACResourceRelation',
+                             'HierarchicalRelation',
+                             'ChronologicalRelation',
+                             'AssociationRelation']
+        cw_types_to_skip = [etype for etype in SCHEMA_TYPES
+                            if etype not in ('CWEType', 'CWRType')]
+        return seda_types_to_skip + eac_types_to_skip + cw_types_to_skip
+
+    @property
+    def ignored_relations(self):
+        seda_types_to_skip = [rschema.type for rschema in self.schema.relations()
+                              if rschema.type.startswith('seda_')
+                              and rschema not in ('seda_archive_unit',
+                                                  'seda_binary_data_object')]
+        ext_types_to_skip = [rschema.type for rschema in self.schema.relations()
+                             if 'ExternalUri' in rschema.objects()
+                             or 'ExternalUril' in rschema.subjects()]
+
+        return set(seda_types_to_skip + ext_types_to_skip + ['use_email'])
+
+    def post_populate(self, cnx):
+        unit = cnx.find('SEDAArchiveUnit').one()
+        alt = cnx.create_entity('SEDAAltArchiveUnitArchiveUnitRefId',
+                                reverse_seda_alt_archive_unit_archive_unit_ref_id=unit)
+        alt_seq = cnx.create_entity(
+            'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement',
+            reverse_seda_seq_alt_archive_unit_archive_unit_ref_id_management=alt)
+        cnx.create_entity('SEDATitle', seda_title=alt_seq, title=u'h&')
+
+        bdo = cnx.find('SEDABinaryDataObject').one()
+        choice = cnx.create_entity('SEDAAltBinaryDataObjectAttachment',
+                                   reverse_seda_alt_binary_data_object_attachment=bdo)
+        cnx.create_entity('SEDAAttachment', seda_attachment=choice)
+        cnx.create_entity('SEDADataObjectReference', user_cardinality=u'0..n',
+                          seda_data_object_reference=alt_seq,
+                          seda_data_object_reference_id=bdo)
+
+        cnx.execute('SET L kind "preferred" WHERE NOT EXISTS (L label_of X, L kind "preferred")')
+
+    def to_test_etypes(self):
+        '''only test views for entities of the returned types'''
+        no_auto_populate = self.no_auto_populate
+        # skip email address as well because we drop its alias attribute which makes standard views
+        # crashing, while it's only a second class citizen here so it's not actually a problem
+        etypes = [eschema.type for eschema in self.schema.entities()
+                  if not (eschema.final
+                          or eschema.type in no_auto_populate
+                          or eschema == 'EmailAddress')]
+        return etypes
+
+    def list_views_for(self, rset):
+        for view in super(AutomaticWebTest, self).list_views_for(rset):
+            if view.__regid__ in self.skip_views:
+                continue
+            yield view
+
+    # XXX needed until 3.25 is released
+    def list_boxes_for(self, rset):
+        """returns the list of boxes that can be applied on `rset`"""
+        req = rset.req
+        for box in self.vreg['ctxcomponents'].possible_objects(req, rset=rset,
+                                                               view=None):
+            yield box
+
+
 if __name__ == '__main__':
     import unittest
     unittest.main()


More information about the saem-devel mailing list