[PATCH 4 of 6 seda] [test] Move assertUnauthorized to testutils

Sylvain Thenault sylvain.thenault at logilab.fr
Fri Mar 31 17:08:46 CEST 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1490964812 -7200
#      Fri Mar 31 14:53:32 2017 +0200
# Node ID 33a6b739e71f2a04ef7c3065e50895db03932fe6
# Parent  71250602be5574f1def04cdcd6d3c71106de0f55
[test] Move assertUnauthorized to testutils

so it's importable and reusable from client libs.

diff --git a/cubicweb_seda/testutils.py b/cubicweb_seda/testutils.py
--- a/cubicweb_seda/testutils.py
+++ b/cubicweb_seda/testutils.py
@@ -13,13 +13,24 @@
 #
 # 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/>.
 """Miscellaneous test utilities."""
 
+from contextlib import contextmanager
+
+from cubicweb import Unauthorized
 from cubicweb.rset import NoResultError
 
 
+ at contextmanager
+def assertUnauthorized(self, cnx):
+    with self.assertRaises(Unauthorized) as cm:
+        yield cm
+        cnx.commit()
+    cnx.rollback()
+
+
 def create_transfer_to_bdo(cnx):
     """Create minimal ArchiveTransfer down to a BinaryDataObject and return the later."""
     transfer = cnx.create_entity('SEDAArchiveTransfer', title=u'test profile')
     bdo = create_data_object(transfer)
     # commit and clear cache to allow access to container relation
diff --git a/test/test_schema.py b/test/test_schema.py
--- a/test/test_schema.py
+++ b/test/test_schema.py
@@ -13,13 +13,11 @@
 #
 # 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-seda unit tests for schema"""
 
-from contextlib import contextmanager
-
-from cubicweb import ValidationError, Unauthorized
+from cubicweb import ValidationError
 from cubicweb.devtools.testlib import CubicWebTC
 from cubicweb.schema import ERQLExpression, RRQLExpression
 
 from cubicweb_seda import iter_all_rdefs
 
@@ -267,16 +265,11 @@ class SchemaTC(CubicWebTC):
                                                 'read': ('managers', 'users', 'guests')})
 
 
 class SecurityTC(CubicWebTC):
 
-    @contextmanager
-    def assertUnauthorized(self, cnx):
-        with self.assertRaises(Unauthorized) as cm:
-            yield cm
-            cnx.commit()
-        cnx.rollback()
+    assertUnauthorized = testutils.assertUnauthorized
 
     def test_profile(self):
         with self.admin_access.repo_cnx() as cnx:
             self.create_user(cnx, login='alice')
             self.create_user(cnx, login='bob')


More information about the saem-devel mailing list