Browse Source

fix tests + force email in create_minimal_user method

Guénaël Muller 6 years ago
parent
commit
682682f5f1

+ 2 - 3
tracim/lib/core/user.py View File

@@ -97,15 +97,14 @@ class UserApi(object):
97 97
 
98 98
     def create_minimal_user(
99 99
             self,
100
-            email=None,
100
+            email,
101 101
             groups=[],
102 102
             save_now=False
103 103
     ) -> User:
104 104
         """Previous create_user method"""
105 105
         user = User()
106 106
 
107
-        if email:
108
-            user.email = email
107
+        user.email = email
109 108
 
110 109
         for group in groups:
111 110
             user.groups.append(group)

+ 6 - 12
tracim/tests/library/test_content_api.py View File

@@ -1116,8 +1116,7 @@ class TestContentApi(DefaultTest):
1116 1116
         
1117 1117
         wid = workspace.workspace_id
1118 1118
 
1119
-        user2 = uapi.create_minimal_user()
1120
-        user2.email = 'this.is@another.user'
1119
+        user2 = uapi.create_minimal_user('this.is@another.user')
1121 1120
         uapi.save(user2)
1122 1121
 
1123 1122
         RoleApi(
@@ -1237,8 +1236,7 @@ class TestContentApi(DefaultTest):
1237 1236
             save_now=True
1238 1237
         )
1239 1238
 
1240
-        user2 = uapi.create_minimal_user()
1241
-        user2.email = 'this.is@another.user'
1239
+        user2 = uapi.create_minimal_user('this.is@another.user')
1242 1240
         uapi.save(user2)
1243 1241
 
1244 1242
         RoleApi(
@@ -1314,8 +1312,7 @@ class TestContentApi(DefaultTest):
1314 1312
         )
1315 1313
         wid = workspace.workspace_id
1316 1314
 
1317
-        user2 = uapi.create_minimal_user()
1318
-        user2.email = 'this.is@another.user'
1315
+        user2 = uapi.create_minimal_user('this.is@another.user')
1319 1316
         uapi.save(user2)
1320 1317
 
1321 1318
         RoleApi(
@@ -1427,8 +1424,7 @@ class TestContentApi(DefaultTest):
1427 1424
             save_now=True
1428 1425
         )
1429 1426
 
1430
-        user2 = uapi.create_minimal_user()
1431
-        user2.email = 'this.is@another.user'
1427
+        user2 = uapi.create_minimal_user('this.is@another.user')
1432 1428
         uapi.save(user2)
1433 1429
 
1434 1430
         RoleApi(
@@ -1508,8 +1504,7 @@ class TestContentApi(DefaultTest):
1508 1504
         )
1509 1505
         wid = workspace.workspace_id
1510 1506
 
1511
-        user2 = uapi.create_minimal_user()
1512
-        user2.email = 'this.is@another.user'
1507
+        user2 = uapi.create_minimal_user('this.is@another.user')
1513 1508
         uapi.save(user2)
1514 1509
 
1515 1510
         RoleApi(
@@ -1657,8 +1652,7 @@ class TestContentApi(DefaultTest):
1657 1652
         )
1658 1653
         wid = workspace.workspace_id
1659 1654
 
1660
-        user2 = uapi.create_minimal_user()
1661
-        user2.email = 'this.is@another.user'
1655
+        user2 = uapi.create_minimal_user('this.is@another.user')
1662 1656
         uapi.save(user2)
1663 1657
 
1664 1658
         RoleApi(

+ 28 - 18
tracim/tests/library/test_user_api.py View File

@@ -5,34 +5,45 @@ from sqlalchemy.orm.exc import NoResultFound
5 5
 import transaction
6 6
 
7 7
 from tracim.lib.core.user import UserApi
8
+from tracim.models import User
8 9
 from tracim.tests import DefaultTest
9 10
 from tracim.tests import eq_
10 11
 
11 12
 
12 13
 class TestUserApi(DefaultTest):
13 14
 
14
-    def test_create_and_update_user(self):
15
+    def test_unit__create_minimal_user__ok__nominal_case(self):
15 16
         api = UserApi(
16 17
             current_user=None,
17 18
             session=self.session,
18 19
             config=self.config,
19 20
         )
20
-        u = api.create_minimal_user()
21
-        api.update(u, 'bob', 'bob@bob', True)
21
+        u = api.create_minimal_user('bob@bob')
22
+        assert u.email == 'bob@bob'
23
+        assert u.display_name is None
22 24
 
25
+    def test_unit__create_minimal_user_and_update__ok__nominal_case(self):
26
+        api = UserApi(
27
+            current_user=None,
28
+            session=self.session,
29
+            config=self.config,
30
+        )
31
+        u = api.create_minimal_user('bob@bob')
32
+        api.update(u, 'bob', 'bob@bob', 'pass', do_save=True)
23 33
         nu = api.get_one_by_email('bob@bob')
24
-        assert nu != None
25
-        eq_('bob@bob', nu.email)
26
-        eq_('bob', nu.display_name)
34
+        assert nu is not None
35
+        assert nu.email == 'bob@bob'
36
+        assert nu.display_name == 'bob'
37
+        assert nu.validate_password('pass')
27 38
 
28
-    def test_user_with_email_exists(self):
39
+    def test_unit__user_with_email_exists__ok__nominal_case(self):
29 40
         api = UserApi(
30 41
             current_user=None,
31 42
             session=self.session,
32 43
             config=self.config,
33 44
         )
34
-        u = api.create_minimal_user()
35
-        api.update(u, 'bibi', 'bibi@bibi', True)
45
+        u = api.create_minimal_user('bibi@bibi')
46
+        api.update(u, 'bibi', 'bibi@bibi', 'pass', do_save=True)
36 47
         transaction.commit()
37 48
 
38 49
         eq_(True, api.user_with_email_exists('bibi@bibi'))
@@ -44,9 +55,9 @@ class TestUserApi(DefaultTest):
44 55
             session=self.session,
45 56
             config=self.config,
46 57
         )
47
-        u = api.create_minimal_user()
58
+        u = api.create_minimal_user('bibi@bibi')
48 59
         self.session.flush()
49
-        api.update(u, 'bibi', 'bibi@bibi', True)
60
+        api.update(u, 'bibi', 'bibi@bibi', 'pass', do_save=True)
50 61
         uid = u.user_id
51 62
         transaction.commit()
52 63
 
@@ -62,17 +73,16 @@ class TestUserApi(DefaultTest):
62 73
             api.get_one_by_email('unknown')
63 74
 
64 75
     def test_get_all(self):
65
-        # TODO - G.M - 29-03-2018 Check why this method is not enabled
66 76
         api = UserApi(
67 77
             current_user=None,
68 78
             session=self.session,
69 79
             config=self.config,
70 80
         )
71
-        # u1 = api.create_minimal_user(True)
72
-        # u2 = api.create_minimal_user(True)
81
+        u1 = api.create_minimal_user('bibi@bibi')
73 82
 
74
-        # users = api.get_all()
75
-        # ok_(2==len(users))
83
+        users = api.get_all()
84
+        # u1 + Admin user from BaseFixture
85
+        assert 2 == len(users)
76 86
 
77 87
     def test_get_one(self):
78 88
         api = UserApi(
@@ -80,7 +90,7 @@ class TestUserApi(DefaultTest):
80 90
             session=self.session,
81 91
             config=self.config,
82 92
         )
83
-        u = api.create_minimal_user()
84
-        api.update(u, 'titi', 'titi@titi', True)
93
+        u = api.create_minimal_user('titi@titi')
94
+        api.update(u, 'titi', 'titi@titi', 'pass', do_save=True)
85 95
         one = api.get_one(u.user_id)
86 96
         eq_(u.user_id, one.user_id)