[test] Add a test for user registration unicity constraint on email
authorDenis Laxalde <denis.laxalde@logilab.fr>
Thu, 23 Jun 2016 11:30:10 +0200
changeset 11369 3c8d345d0f3a
parent 11368 a32209aba682
child 11370 ec858780b6b7
[test] Add a test for user registration unicity constraint on email
cubicweb/sobjects/test/unittest_register_user.py
--- a/cubicweb/sobjects/test/unittest_register_user.py	Thu Jun 23 11:27:43 2016 +0200
+++ b/cubicweb/sobjects/test/unittest_register_user.py	Thu Jun 23 11:30:10 2016 +0200
@@ -30,7 +30,7 @@
                               login=u'foo2', password=u'bar2',
                               email=u'foo2@bar2.com', firstname=u'Foo2', surname=u'Bar2')
 
-    def test_register_user_service_unique(self):
+    def test_register_user_service_unique_login(self):
         with self.admin_access.cnx() as cnx:
             cnx.call_service('register_user', login=u'foo3',
                              password=u'bar3', email=u'foo3@bar3.com',
@@ -40,6 +40,19 @@
                 cnx.call_service('register_user', login=u'foo3',
                                  password=u'bar3')
 
+    def test_register_user_service_unique_email(self):
+        with self.admin_access.cnx() as cnx:
+            cnx.call_service('register_user', login=u'foo3',
+                             password=u'bar3', email=u'foo3@bar3.com',
+                             firstname=u'Foo3', surname=u'Bar3')
+            with self.assertRaises(ValidationError) as cm:
+                cnx.call_service('register_user', login=u'foo3@bar3.com',
+                                 password=u'bar3')
+            expected_errors = {
+                'login-subject': u'the value "foo3@bar3.com" is already used, use another one',
+            }
+            self.assertEqual(cm.exception.errors, expected_errors)
+
     def test_register_user_attributes(self):
         with self.admin_access.cnx() as cnx:
             cnx.call_service('register_user', login=u'foo3',