[PATCH 2 of 5 seda] [test/security] Add test about some relation from ConceptScheme

Philippe Pepiot philippe.pepiot at logilab.fr
Tue Apr 11 15:13:07 CEST 2017


On 04/10/2017 05:48 PM, Sylvain Thenault wrote:
> # HG changeset patch
> # User Sylvain Thénault <sylvain.thenault at logilab.fr>
> # Date 1491831763 -7200
> #      Mon Apr 10 15:42:43 2017 +0200
> # Node ID 07350ed1e41071babe8e698f5435378704e96550
> # Parent  8f62b2d83afd4a325178ae4aa6908d9b8567c408
> [test/security] Add test about some relation from ConceptScheme
>
> * scheme_relation_type / scheme_entity_type (reserved to managers)
> * code_keyword_type (users friendly)
>
> diff --git a/test/test_schema.py b/test/test_schema.py
> --- a/test/test_schema.py
> +++ b/test/test_schema.py
> @@ -367,10 +367,35 @@ class SecurityTC(CubicWebTC):
>              cnx.commit()
>              cloned.cw_clear_all_caches()
>
>              self.assertTrue(cloned.first_level_choice.content_sequence)
>
> +    def test_scheme_type(self):
> +        with self.new_access('alice').repo_cnx() as cnx:


For consistency you could use cnx() instead of repo_cnx()


> +            scheme = cnx.create_entity('ConceptScheme', title=u'Some vocabulary')
> +            cnx.commit()
> +
> +            with self.assertUnauthorized(cnx):
> +                scheme.cw_set(scheme_entity_type=cnx.find('CWEType', name=u'CWEType').one())
> +            with self.assertUnauthorized(cnx):
> +                scheme.cw_set(scheme_relation_type=cnx.find('CWRType', name=u'name').one())
> +


It's not clear to me that cnx.find() can or cannot raise Unauthorized.
Either add an assertion on the exception message or move the cnx.find() 
outside of the context manager.


> +    def test_scheme_code_keyword_type(self):
> +        with self.admin_access.cnx() as cnx:
> +            admin_scheme = testutils.scheme_for_type(cnx, u'seda_keyword_type_to', None,
> +                                                     u'type1')
> +            cnx.commit()
> +            type_concept = admin_scheme.reverse_in_scheme[0]
> +
> +        with self.new_access('alice').repo_cnx() as cnx:
> +            # ensure code_keyword_type is editable by standard user
> +            scheme = cnx.create_entity('ConceptScheme', title=u'Some vocabulary',
> +                                       code_keyword_type=type_concept)
> +            cnx.commit()
> +            scheme.cw_set(code_keyword_type=None)
> +            cnx.commit()
> +
>
>  class SchemaIteratorTC(CubicWebTC):
>
>      def test_iter_all_rdefs(self):
>          values = {str(rdef) for rdef, role in iter_all_rdefs(self.schema, 'SEDABinaryDataObject')}
>



More information about the saem-devel mailing list