[test] Move assertUnauthorized to testutils
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 31 Mar 2017 14:53:32 +0200
changeset 2589 694ba9fce008
parent 2570 1269e5d31ecd
child 2590 54ded6ab2e4f
[test] Move assertUnauthorized to testutils so it's importable and reusable from client libs.
cubicweb_seda/testutils.py
test/test_schema.py
--- a/cubicweb_seda/testutils.py	Fri Mar 31 11:11:56 2017 +0200
+++ b/cubicweb_seda/testutils.py	Fri Mar 31 14:53:32 2017 +0200
@@ -15,9 +15,20 @@
 # 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
 
 
+@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')
--- a/test/test_schema.py	Fri Mar 31 11:11:56 2017 +0200
+++ b/test/test_schema.py	Fri Mar 31 14:53:32 2017 +0200
@@ -15,9 +15,7 @@
 # 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
 
@@ -269,12 +267,7 @@
 
 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: