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

Denis Laxalde denis.laxalde at logilab.fr
Thu Mar 16 13:33:35 CET 2017


Sylvain Thenault a écrit :
> # 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 7b205b1c0c0e6bd6d5026c49a69d52feaa8b2702
> # 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/master/cubes/seda/archive/tip.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,85 @@ 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
> +
> +    @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
> +        etypes = [eschema.type for eschema in self.schema.entities()
> +                  if not (eschema.final
> +                          or eschema.type in no_auto_populate
> +                          or eschema == 'EmailAddress')]

Could you add a comment explaining why EmailAddress is special here?

> +        return etypes
> +
> +    def list_views_for(self, rset):
> +        for view in super(AutomaticWebTest, self).list_views_for(rset):
> +            if view.__regid__ in ('calendar', 'csvexport', 'ecsvexport', 'ejsonexport',
> +                                  'filetree', 'hcal', 'jsonexport', 'n3rdf',
> +                                  'oneweekcal', 'onemonthcal', 'owlabox',
> +                                  'rsetxml', 'rss', 'security', 'treeview', 'xbel',
> +                                  'skos.source-sync',):

Might be better to have this list as a class attribute "ignored_views",
formatted with only one item per line.

> +                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