Browse Source

Merge pull request #81 from tracim/fix/few_more_tests

Bastien Sevajol 6 years ago
parent
commit
9284ec4d44
No account linked to committer's email

+ 3 - 0
README.md View File

@@ -111,8 +111,11 @@ run wsgidav server:
111 111
 
112 112
     tracimcli webdav start
113 113
 
114
+
114 115
 ## Run Tests and others checks ##
115 116
 
117
+### Run Tests ###
118
+
116 119
 Before running some functional test related to email, you need a local working *MailHog*
117 120
 see here : https://github.com/mailhog/MailHog
118 121
 

+ 9 - 1
tests_configs.ini View File

@@ -5,6 +5,14 @@ depot_storage_dir = /tmp/test/depot
5 5
 user.auth_token.validity = 604800
6 6
 preview_cache_dir = /tmp/test/preview_cache
7 7
 
8
+[app:command_test]
9
+use = egg:tracim_backend
10
+sqlalchemy.url = sqlite:///tracim_test.sqlite
11
+depot_storage_name = test
12
+depot_storage_dir = /tmp/test/depot
13
+user.auth_token.validity = 604800
14
+preview_cache_dir = /tmp/test/preview_cache
15
+
8 16
 [mail_test]
9 17
 sqlalchemy.url = sqlite:///:memory:
10 18
 depot_storage_name = test
@@ -54,4 +62,4 @@ email.processing_mode = async
54 62
 email.notification.smtp.server = 127.0.0.1
55 63
 email.notification.smtp.port = 1025
56 64
 email.notification.smtp.user = test_user
57
-email.notification.smtp.password = just_a_password
65
+email.notification.smtp.password = just_a_password

+ 2 - 1
tracim/command/__init__.py View File

@@ -9,7 +9,7 @@ from cliff.commandmanager import CommandManager
9 9
 
10 10
 from pyramid.paster import bootstrap
11 11
 from pyramid.scripting import AppEnvironment
12
-from tracim.exceptions import CommandAbortedError
12
+from tracim.exceptions import BadCommandError
13 13
 from tracim.lib.utils.utils import DEFAULT_TRACIM_CONFIG_FILE
14 14
 
15 15
 
@@ -56,6 +56,7 @@ class AppContextCommand(Command):
56 56
                 with app_context['request'].tm:
57 57
                     self.take_app_action(parsed_args, app_context)
58 58
 
59
+
59 60
     def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
60 61
         parser = super(AppContextCommand, self).get_parser(prog_name)
61 62
 

+ 19 - 12
tracim/command/user.py View File

@@ -3,17 +3,15 @@ import argparse
3 3
 from pyramid.scripting import AppEnvironment
4 4
 import transaction
5 5
 from sqlalchemy.exc import IntegrityError
6
+from sqlalchemy.orm.exc import NoResultFound
6 7
 
7 8
 from tracim import CFG
8 9
 from tracim.command import AppContextCommand
9 10
 from tracim.command import Extender
10
-#from tracim.lib.auth.ldap import LDAPAuth
11
-#from tracim.lib.daemons import DaemonsManager
12
-#from tracim.lib.daemons import RadicaleDaemon
13
-#from tracim.lib.email import get_email_manager
14
-from tracim.exceptions import AlreadyExistError
11
+from tracim.exceptions import UserAlreadyExistError
12
+from tracim.exceptions import GroupDoesNotExist
15 13
 from tracim.exceptions import NotificationNotSend
16
-from tracim.exceptions import CommandAbortedError
14
+from tracim.exceptions import BadCommandError
17 15
 from tracim.lib.core.group import GroupApi
18 16
 from tracim.lib.core.user import UserApi
19 17
 from tracim.models import User
@@ -85,6 +83,14 @@ class UserCommand(AppContextCommand):
85 83
         return self._user_api.user_with_email_exists(login)
86 84
 
87 85
     def _get_group(self, name: str) -> Group:
86
+        groups_availables = [group.group_name
87
+                             for group in self._group_api.get_all()]
88
+        if name not in groups_availables:
89
+            msg = "Group '{}' does not exist, choose a group name in : ".format(name)  # nopep8
90
+            for group in groups_availables:
91
+                msg+= "'{}',".format(group)
92
+            self._session.rollback()
93
+            raise GroupDoesNotExist(msg)
88 94
         return self._group_api.get_one_with_name(name)
89 95
 
90 96
     def _add_user_to_named_group(
@@ -92,6 +98,7 @@ class UserCommand(AppContextCommand):
92 98
             user: str,
93 99
             group_name: str
94 100
     ) -> None:
101
+
95 102
         group = self._get_group(group_name)
96 103
         if user not in group.users:
97 104
             group.users.append(user)
@@ -116,7 +123,7 @@ class UserCommand(AppContextCommand):
116 123
     ) -> User:
117 124
         if not password:
118 125
             if self._password_required():
119
-                raise CommandAbortedError(
126
+                raise BadCommandError(
120 127
                     "You must provide -p/--password parameter"
121 128
                 )
122 129
             password = ''
@@ -135,7 +142,7 @@ class UserCommand(AppContextCommand):
135 142
             self._user_api.execute_created_user_actions(user)
136 143
         except IntegrityError:
137 144
             self._session.rollback()
138
-            raise AlreadyExistError()
145
+            raise UserAlreadyExistError()
139 146
         except NotificationNotSend as exception:
140 147
             self._session.rollback()
141 148
             raise exception
@@ -182,10 +189,10 @@ class UserCommand(AppContextCommand):
182 189
                     password=parsed_args.password,
183 190
                     do_notify=parsed_args.send_email,
184 191
                 )
185
-            except AlreadyExistError:
186
-                raise CommandAbortedError("Error: User already exist (use `user update` command instead)")
192
+            except UserAlreadyExistError:
193
+                raise UserAlreadyExistError("Error: User already exist (use `user update` command instead)")
187 194
             except NotificationNotSend:
188
-                raise CommandAbortedError("Error: Cannot send email notification, user not created.")
195
+                raise NotificationNotSend("Error: Cannot send email notification, user not created.")
189 196
             # TODO - G.M - 04-04-2018 - [Email] Check this code
190 197
             # if parsed_args.send_email:
191 198
             #     email_manager = get_email_manager()
@@ -243,5 +250,5 @@ class UpdateUserCommand(UserCommand):
243 250
     action = UserCommand.ACTION_UPDATE
244 251
 
245 252
 
246
-class LDAPUserUnknown(CommandAbortedError):
253
+class LDAPUserUnknown(BadCommandError):
247 254
     pass

+ 9 - 9
tracim/exceptions.py View File

@@ -25,15 +25,11 @@ class ConfigurationError(TracimError):
25 25
     pass
26 26
 
27 27
 
28
-class AlreadyExistError(TracimError):
28
+class UserAlreadyExistError(TracimError):
29 29
     pass
30 30
 
31 31
 
32
-class CommandError(TracimError):
33
-    pass
34
-
35
-
36
-class CommandAbortedError(CommandError):
32
+class BadCommandError(TracimError):
37 33
     pass
38 34
 
39 35
 
@@ -93,13 +89,17 @@ class WrongUserPassword(TracimException):
93 89
     pass
94 90
 
95 91
 
96
-class UserDoesNotExist(TracimException):
92
+class NotificationNotSend(TracimException):
97 93
     pass
98 94
 
99 95
 
100
-class UserNotFoundInTracimRequest(TracimException):
96
+class GroupDoesNotExist(TracimError):
101 97
     pass
102 98
 
103 99
 
104
-class NotificationNotSend(TracimException):
100
+class UserDoesNotExist(TracimException):
105 101
     pass
102
+
103
+
104
+class UserNotFoundInTracimRequest(TracimException):
105
+    pass

+ 17 - 2
tracim/lib/core/group.py View File

@@ -1,8 +1,12 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 import typing
3 3
 
4
+from sqlalchemy.orm.exc import NoResultFound
5
+
6
+from tracim.exceptions import GroupDoesNotExist
4 7
 from tracim import CFG
5 8
 
9
+
6 10
 __author__ = 'damien'
7 11
 
8 12
 from tracim.models.auth import Group, User
@@ -26,7 +30,18 @@ class GroupApi(object):
26 30
         return self._session.query(Group)
27 31
 
28 32
     def get_one(self, group_id) -> Group:
29
-        return self._base_query().filter(Group.group_id == group_id).one()
33
+        try:
34
+            group = self._base_query().filter(Group.group_id == group_id).one()
35
+            return group
36
+        except NoResultFound:
37
+            raise GroupDoesNotExist()
30 38
 
31 39
     def get_one_with_name(self, group_name) -> Group:
32
-        return self._base_query().filter(Group.group_name == group_name).one()
40
+        try:
41
+            group = self._base_query().filter(Group.group_name == group_name).one()
42
+            return group
43
+        except NoResultFound:
44
+            raise GroupDoesNotExist()
45
+
46
+    def get_all(self):
47
+        return self._base_query().order_by(Group.group_id).all()

+ 22 - 9
tracim/tests/__init__.py View File

@@ -35,8 +35,9 @@ class FunctionalTest(unittest.TestCase):
35 35
     sqlalchemy_url = 'sqlite:///tracim_test.sqlite'
36 36
 
37 37
     def setUp(self):
38
+        logger._logger.setLevel('WARNING')
38 39
         DepotManager._clear()
39
-        settings = {
40
+        self.settings = {
40 41
             'sqlalchemy.url': self.sqlalchemy_url,
41 42
             'user.auth_token.validity': '604800',
42 43
             'depot_storage_dir': '/tmp/test/depot',
@@ -45,19 +46,24 @@ class FunctionalTest(unittest.TestCase):
45 46
 
46 47
         }
47 48
         hapic.reset_context()
48
-        app = web({}, **settings)
49
-        self.init_database(settings)
49
+        self.engine = get_engine(self.settings)
50
+        DeclarativeBase.metadata.create_all(self.engine)
51
+        self.session_factory = get_session_factory(self.engine)
52
+        self.app_config = CFG(self.settings)
53
+        self.app_config.configure_filedepot()
54
+        self.init_database(self.settings)
55
+        DepotManager._clear()
56
+        self.run_app()
57
+
58
+    def run_app(self):
59
+        app = web({}, **self.settings)
50 60
         self.testapp = TestApp(app)
51 61
 
52 62
     def init_database(self, settings):
53
-        self.engine = get_engine(settings)
54
-        DeclarativeBase.metadata.create_all(self.engine)
55
-        session_factory = get_session_factory(self.engine)
56
-        app_config = CFG(settings)
57 63
         with transaction.manager:
58
-            dbsession = get_tm_session(session_factory, transaction.manager)
64
+            dbsession = get_tm_session(self.session_factory, transaction.manager)
59 65
             try:
60
-                fixtures_loader = FixturesLoader(dbsession, app_config)
66
+                fixtures_loader = FixturesLoader(dbsession, self.app_config)
61 67
                 fixtures_loader.loads(self.fixtures)
62 68
                 transaction.commit()
63 69
                 print("Database initialized.")
@@ -90,6 +96,12 @@ class FunctionalTestNoDB(FunctionalTest):
90 96
         self.engine = get_engine(settings)
91 97
 
92 98
 
99
+class CommandFunctionalTest(FunctionalTest):
100
+
101
+    def run_app(self):
102
+        self.session = get_tm_session(self.session_factory, transaction.manager)
103
+
104
+
93 105
 class BaseTest(unittest.TestCase):
94 106
     """
95 107
     Pyramid default test.
@@ -99,6 +111,7 @@ class BaseTest(unittest.TestCase):
99 111
     config_section = 'base_test'
100 112
 
101 113
     def setUp(self):
114
+        logger._logger.setLevel('WARNING')
102 115
         logger.debug(self, 'Setup Test...')
103 116
         self.settings = plaster.get_settings(
104 117
             self.config_uri,

+ 181 - 3
tracim/tests/commands/test_commands.py View File

@@ -1,12 +1,25 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 import os
3 3
 import subprocess
4
-
4
+import pytest
5 5
 import tracim
6
+from tracim.command import TracimCLI
7
+from tracim.exceptions import UserAlreadyExistError
8
+from tracim.exceptions import BadCommandError
9
+from tracim.exceptions import GroupDoesNotExist
10
+from tracim.exceptions import UserDoesNotExist
11
+from tracim.lib.core.user import UserApi
12
+from tracim.tests import CommandFunctionalTest
13
+
6 14
 
15
+class TestCommands(CommandFunctionalTest):
16
+    """
17
+    Test tracimcli command line ui.
18
+    """
7 19
 
8
-class TestCommands(object):
9
-    def test_commands(self):
20
+    config_section = 'app:command_test'
21
+
22
+    def test_func__check_commands_list__ok__nominal_case(self) -> None:
10 23
         """
11 24
         Test listing of tracimcli command: Tracim commands must be listed
12 25
         :return:
@@ -20,3 +33,168 @@ class TestCommands(object):
20 33
         assert output.find('user update') > 0
21 34
         assert output.find('db init') > 0
22 35
         assert output.find('db delete') > 0
36
+        assert output.find('webdav start') > 0
37
+
38
+    def test_func__user_create_command__ok__nominal_case(self) -> None:
39
+        """
40
+        Test User creation
41
+        """
42
+        api = UserApi(
43
+            current_user=None,
44
+            session=self.session,
45
+            config=self.app_config,
46
+        )
47
+        with pytest.raises(UserDoesNotExist):
48
+            api.get_one_by_email('command_test@user')
49
+        app = TracimCLI()
50
+        result = app.run([
51
+            'user', 'create',
52
+            '-c', 'tests_configs.ini#command_test',
53
+            '-l', 'command_test@user',
54
+            '-p', 'new_password',
55
+            '--debug',
56
+        ])
57
+        new_user = api.get_one_by_email('command_test@user')
58
+        assert new_user.email == 'command_test@user'
59
+        assert new_user.validate_password('new_password')
60
+        assert new_user.profile.name == 'users'
61
+
62
+    def test_func__user_create_command__ok__in_admin_group(self) -> None:
63
+        """
64
+        Test User creation with admin as group
65
+        """
66
+        api = UserApi(
67
+            current_user=None,
68
+            session=self.session,
69
+            config=self.app_config,
70
+        )
71
+        with pytest.raises(UserDoesNotExist):
72
+            api.get_one_by_email('command_test@user')
73
+        app = TracimCLI()
74
+        result = app.run([
75
+            'user', 'create',
76
+            '-c', 'tests_configs.ini#command_test',
77
+            '-l', 'command_test@user',
78
+            '-p', 'new_password',
79
+            '-g', 'administrators',
80
+            '--debug',
81
+        ])
82
+        new_user = api.get_one_by_email('command_test@user')
83
+        assert new_user.email == 'command_test@user'
84
+        assert new_user.validate_password('new_password')
85
+        assert new_user.profile.name == 'administrators'
86
+
87
+    def test_func__user_create_command__err__in_unknown_group(self) -> None:
88
+        """
89
+        Test User creation with an unknown group
90
+        """
91
+        api = UserApi(
92
+            current_user=None,
93
+            session=self.session,
94
+            config=self.app_config,
95
+        )
96
+        app = TracimCLI()
97
+        with pytest.raises(GroupDoesNotExist):
98
+            result = app.run([
99
+                'user', 'create',
100
+                '-c', 'tests_configs.ini#command_test',
101
+                '-l', 'command_test@user',
102
+                '-p', 'new_password',
103
+                '-g', 'unknown',
104
+                '--debug',
105
+            ])
106
+
107
+    def test_func__user_create_command__err_user_already_exist(self) -> None:
108
+        """
109
+        Test User creation with existing user login
110
+        """
111
+        api = UserApi(
112
+            current_user=None,
113
+            session=self.session,
114
+            config=self.app_config,
115
+        )
116
+        app = TracimCLI()
117
+        with pytest.raises(UserAlreadyExistError):
118
+            result = app.run([
119
+                '--debug',
120
+                'user', 'create',
121
+                '-c', 'tests_configs.ini#command_test',
122
+                '-l', 'admin@admin.admin',
123
+                '-p', 'new_password',
124
+                '--debug',
125
+            ])
126
+
127
+    def test_func__user_create_command__err__password_required(self) -> None:
128
+        """
129
+        Test User creation without filling password
130
+        """
131
+        api = UserApi(
132
+            current_user=None,
133
+            session=self.session,
134
+            config=self.app_config,
135
+        )
136
+        app = TracimCLI()
137
+        with pytest.raises(BadCommandError):
138
+            result = app.run([
139
+                '--debug',
140
+                'user', 'create',
141
+                '-c', 'tests_configs.ini#command_test',
142
+                '-l', 'admin@admin.admin',
143
+                '--debug',
144
+            ])
145
+
146
+    def test_func__user_update_command__ok__nominal_case(self) -> None:
147
+        """
148
+        Test user password update
149
+        """
150
+        api = UserApi(
151
+            current_user=None,
152
+            session=self.session,
153
+            config=self.app_config,
154
+        )
155
+        user = api.get_one_by_email('admin@admin.admin')
156
+        assert user.email == 'admin@admin.admin'
157
+        assert user.validate_password('admin@admin.admin')
158
+        assert not user.validate_password('new_password')
159
+
160
+        app = TracimCLI()
161
+        result = app.run([
162
+            'user', 'update',
163
+            '-c', 'tests_configs.ini#command_test',
164
+            '-l', 'admin@admin.admin',
165
+            '-p', 'new_password',
166
+            '--debug',
167
+        ])
168
+        new_user = api.get_one_by_email('admin@admin.admin')
169
+        assert new_user.email == 'admin@admin.admin'
170
+        assert new_user.validate_password('new_password')
171
+        assert not new_user.validate_password('admin@admin.admin')
172
+
173
+    def test_func__user_update_command__ok__remove_group(self) -> None:
174
+        """
175
+        Test user password update
176
+        """
177
+        api = UserApi(
178
+            current_user=None,
179
+            session=self.session,
180
+            config=self.app_config,
181
+        )
182
+        user = api.get_one_by_email('admin@admin.admin')
183
+        assert user.email == 'admin@admin.admin'
184
+        assert user.validate_password('admin@admin.admin')
185
+        assert not user.validate_password('new_password')
186
+        assert user.profile.name == 'administrators'
187
+        app = TracimCLI()
188
+        result = app.run([
189
+            'user', 'update',
190
+            '-c', 'tests_configs.ini#command_test',
191
+            '-l', 'admin@admin.admin',
192
+            '-p', 'new_password',
193
+            '-rmg', 'administrators',
194
+            '--debug',
195
+        ])
196
+        new_user = api.get_one_by_email('admin@admin.admin')
197
+        assert new_user.email == 'admin@admin.admin'
198
+        assert new_user.validate_password('new_password')
199
+        assert not new_user.validate_password('admin@admin.admin')
200
+        assert new_user.profile.name == 'managers'

+ 2 - 3
tracim/tests/library/test_content_api.py View File

@@ -213,14 +213,13 @@ class TestContentApi(DefaultTest):
213 213
         user = uapi.create_minimal_user(
214 214
             email='this.is@user',
215 215
             groups=groups,
216
-            save_now=True
216
+            save_now=True,
217 217
         )
218 218
         workspace_api = WorkspaceApi(
219 219
             current_user=user,
220 220
             session=self.session,
221
-            config=self.app_config
221
+            config=self.app_config,
222 222
         )
223
-
224 223
         workspace = workspace_api.create_workspace(
225 224
             'test workspace',
226 225
             save_now=True

+ 74 - 0
tracim/tests/library/test_group_api.py View File

@@ -0,0 +1,74 @@
1
+# coding=utf-8
2
+import pytest
3
+
4
+from tracim.exceptions import GroupDoesNotExist
5
+from tracim.lib.core.group import GroupApi
6
+from tracim.tests import DefaultTest
7
+from tracim.fixtures.users_and_groups import Base as BaseFixture
8
+from tracim.fixtures.content import Content as ContentFixture
9
+
10
+
11
+class TestGroupApi(DefaultTest):
12
+    fixtures = [BaseFixture, ContentFixture]
13
+
14
+    def test_unit__get_one__ok_nominal_case(self) -> None:
15
+        """
16
+        Get one group by id
17
+        """
18
+        api = GroupApi(
19
+            current_user=None,
20
+            session=self.session,
21
+            config=self.app_config,
22
+        )
23
+        group = api.get_one(1)
24
+        assert group.group_id == 1
25
+        assert group.group_name == 'users'
26
+
27
+    def test_unit__get_one__err__group_not_exist(self) -> None:
28
+        """
29
+        Get one group who does not exist by id
30
+        """
31
+        api = GroupApi(
32
+            current_user=None,
33
+            session=self.session,
34
+            config=self.app_config,
35
+        )
36
+        with pytest.raises(GroupDoesNotExist):
37
+            group = api.get_one(10)
38
+
39
+    def test_unit__get_one_group_with_name__nominal_case(self) -> None:
40
+        """
41
+        get one group by name
42
+        """
43
+        api = GroupApi(
44
+            current_user=None,
45
+            session=self.session,
46
+            config=self.app_config,
47
+        )
48
+        group = api.get_one_with_name('administrators')
49
+        assert group.group_id == 3
50
+        assert group.group_name == 'administrators'
51
+
52
+    def test_unit__get_one_with_name__err__group_not_exist(self) -> None:
53
+        """
54
+        get one group by name who does not exist
55
+        """
56
+        api = GroupApi(
57
+            current_user=None,
58
+            session=self.session,
59
+            config=self.app_config,
60
+        )
61
+        with pytest.raises(GroupDoesNotExist):
62
+            group = api.get_one_with_name('unknown_group')
63
+
64
+    def test_unit__get_all__ok__nominal_case(self):
65
+        """
66
+        get all groups
67
+        """
68
+        api = GroupApi(
69
+            current_user=None,
70
+            session=self.session,
71
+            config=self.app_config,
72
+        )
73
+        groups = api.get_all()
74
+        assert ['users', 'managers', 'administrators'] == [group.group_name for group in groups]  # nopep8

+ 16 - 0
tracim/tests/models/test_controller.py View File

@@ -0,0 +1,16 @@
1
+# coding=utf-8
2
+import pytest
3
+from pyramid.config import Configurator
4
+
5
+from tracim.views.controllers import Controller
6
+
7
+
8
+class TestControllerModel(object):
9
+    """
10
+    Test for Controller object
11
+    """
12
+    def test_unit__bind__err__not_implemented(self):
13
+        controller = Controller()
14
+        configurator = Configurator()
15
+        with pytest.raises(NotImplementedError):
16
+            controller.bind(configurator)

+ 51 - 0
tracim/tests/models/test_permission.py View File

@@ -0,0 +1,51 @@
1
+# coding=utf-8
2
+import transaction
3
+from tracim.tests import eq_
4
+from tracim.tests import BaseTest
5
+from tracim.models.auth import Permission
6
+
7
+
8
+class TestPermissionModel(BaseTest):
9
+    """
10
+    Test for permission model
11
+    """
12
+    def test_unit__create__ok__nominal_case(self):
13
+        self.session.flush()
14
+        transaction.commit()
15
+
16
+        name = 'my_permission'
17
+        description = 'my_perm_description'
18
+        permission = Permission()
19
+        permission.permission_name = name
20
+        permission.description = description
21
+
22
+        self.session.add(permission)
23
+        self.session.flush()
24
+        transaction.commit()
25
+
26
+        new_permission = self.session.query(Permission).filter(permission.permission_name == name).one()  # nopep8
27
+
28
+        assert new_permission.permission_name == name
29
+        assert new_permission.description == description
30
+        assert new_permission.permission_id
31
+        assert isinstance(new_permission.permission_id, int)
32
+        # TODO - G.M -24-05-2018 - Do test for groups
33
+
34
+    def test_unit__repr__ok__nominal_case(self):
35
+        name = 'my_permission'
36
+        description = 'my_perm_description'
37
+        permission = Permission()
38
+        permission.permission_name = name
39
+        permission.description = description
40
+
41
+        assert permission.__repr__() == "<Permission: name='my_permission'>"
42
+
43
+    def test_unit__unicode__ok__nominal_case(self):
44
+        name = 'my_permission'
45
+        description = 'my_perm_description'
46
+        permission = Permission()
47
+        permission.permission_name = name
48
+        permission.description = description
49
+
50
+        assert permission.__unicode__() == name
51
+

+ 92 - 11
tracim/tests/models/test_user.py View File

@@ -1,15 +1,15 @@
1 1
 # -*- coding: utf-8 -*-
2
-import transaction
3 2
 
4
-from tracim.tests import eq_
3
+import transaction
5 4
 from tracim.tests import BaseTest
6
-
7 5
 from tracim.models.auth import User
8 6
 
9 7
 
10 8
 class TestUserModel(BaseTest):
11
-
12
-    def test_create(self):
9
+    """
10
+    Test for User model
11
+    """
12
+    def test_unit__create__ok__nominal_case(self):
13 13
         self.session.flush()
14 14
         transaction.commit()
15 15
         name = 'Damien'
@@ -23,13 +23,49 @@ class TestUserModel(BaseTest):
23 23
         self.session.flush()
24 24
         transaction.commit()
25 25
 
26
-        new_user = self.session.query(User).filter(User.display_name==name).one()
26
+        new_user = self.session.query(User).filter(User.display_name == name).one()  # nopep8
27
+
28
+        assert new_user.display_name == name
29
+        assert new_user.email == email
30
+        assert new_user.email_address == email
31
+
32
+    def test_unit__password__ok__nominal_case(self):
33
+        """
34
+        Check if password can be set and hashed password
35
+        can be retrieve. Verify if hashed password is not
36
+        same as password.
37
+        """
38
+        name = 'Damien'
39
+        email = 'tracim@trac.im'
40
+        password = 'my_secure_password'
41
+
42
+        user = User()
43
+        user.display_name = name
44
+        user.email = email
45
+        assert user._password is None
46
+        user.password = password
47
+        assert user._password is not None
48
+        assert user._password != password
49
+        assert user.password == user._password
50
+
51
+    def test__unit__validate_password__ok__nominal_case(self):
52
+        """
53
+        Check if validate_password can correctly check if password i the correct
54
+        one
55
+        """
27 56
 
28
-        eq_(new_user.display_name, name)
29
-        eq_(new_user.email, email)
30
-        eq_(new_user.email_address, email)
57
+        name = 'Damien'
58
+        email = 'tracim@trac.im'
59
+        password = 'my_secure_password'
60
+
61
+        user = User()
62
+        user.display_name = name
63
+        user.email = email
64
+        user.password = password
65
+
66
+        assert user.validate_password(password) is True
31 67
 
32
-    def test_null_password(self):
68
+    def test_unit__validate_password__false__null_password(self):
33 69
         # Check bug #70 fixed
34 70
         # http://tracim.org/workspaces/4/folders/5/threads/70
35 71
 
@@ -40,4 +76,49 @@ class TestUserModel(BaseTest):
40 76
         user.display_name = name
41 77
         user.email = email
42 78
 
43
-        eq_(False, user.validate_password(None))
79
+        assert user.validate_password('') is False
80
+
81
+    def test_unit__validate_password__false__bad_password(self):
82
+        """
83
+        Check if validate_password can correctly check if password is
84
+        an uncorrect correct one
85
+        """
86
+        name = 'Damien'
87
+        email = 'tracim@trac.im'
88
+        password = 'my_secure_password'
89
+
90
+        user = User()
91
+        user.display_name = name
92
+        user.email = email
93
+        user.password = password
94
+
95
+        assert user.validate_password('uncorrect_password') is False
96
+
97
+    def test_unit__repr__ok__nominal_case(self):
98
+        name = 'Damien'
99
+        email = 'tracim@trac.im'
100
+
101
+        user = User()
102
+        user.display_name = name
103
+        user.email = email
104
+
105
+        assert user.__repr__() == "<User: email='tracim@trac.im', display='Damien'>"  # nopep8
106
+
107
+    def test_unit__unicode__ok__nominal_case(self):
108
+        name = 'Damien'
109
+        email = 'tracim@trac.im'
110
+
111
+        user = User()
112
+        user.display_name = name
113
+        user.email = email
114
+
115
+        assert user.__unicode__() == name
116
+
117
+    def test__unit__unicode__ok__no_display_name(self):
118
+
119
+        email = 'tracim@trac.im'
120
+
121
+        user = User()
122
+        user.email = email
123
+
124
+        assert user.__unicode__() == email