|
1
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
|
|
2
|
|
|
import pytest |
|
|
|
|
|
|
3
|
|
|
from sqlalchemy.orm.exc import NoResultFound |
|
4
|
|
|
|
|
5
|
|
|
import transaction |
|
6
|
|
|
|
|
7
|
|
|
from tracim.lib.core.user import UserApi |
|
8
|
|
|
from tracim.tests import DefaultTest |
|
9
|
|
|
from tracim.tests import eq_ |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class TestUserApi(DefaultTest): |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
def test_create_and_update_user(self): |
|
|
|
|
|
|
15
|
|
|
api = UserApi( |
|
16
|
|
|
current_user=None, |
|
17
|
|
|
session=self.session, |
|
18
|
|
|
config=self.config, |
|
19
|
|
|
) |
|
20
|
|
|
u = api.create_user() |
|
|
|
|
|
|
21
|
|
|
api.update(u, 'bob', 'bob@bob', True) |
|
22
|
|
|
|
|
23
|
|
|
nu = api.get_one_by_email('bob@bob') |
|
|
|
|
|
|
24
|
|
|
assert nu != None |
|
25
|
|
|
eq_('bob@bob', nu.email) |
|
26
|
|
|
eq_('bob', nu.display_name) |
|
27
|
|
|
|
|
28
|
|
|
def test_user_with_email_exists(self): |
|
|
|
|
|
|
29
|
|
|
api = UserApi( |
|
30
|
|
|
current_user=None, |
|
31
|
|
|
session=self.session, |
|
32
|
|
|
config=self.config, |
|
33
|
|
|
) |
|
34
|
|
|
u = api.create_user() |
|
|
|
|
|
|
35
|
|
|
api.update(u, 'bibi', 'bibi@bibi', True) |
|
36
|
|
|
transaction.commit() |
|
37
|
|
|
|
|
38
|
|
|
eq_(True, api.user_with_email_exists('bibi@bibi')) |
|
39
|
|
|
eq_(False, api.user_with_email_exists('unknown')) |
|
40
|
|
|
|
|
41
|
|
|
def test_get_one_by_email(self): |
|
|
|
|
|
|
42
|
|
|
api = UserApi( |
|
43
|
|
|
current_user=None, |
|
44
|
|
|
session=self.session, |
|
45
|
|
|
config=self.config, |
|
46
|
|
|
) |
|
47
|
|
|
u = api.create_user() |
|
|
|
|
|
|
48
|
|
|
api.update(u, 'bibi', 'bibi@bibi', True) |
|
49
|
|
|
uid = u.user_id |
|
50
|
|
|
transaction.commit() |
|
51
|
|
|
|
|
52
|
|
|
eq_(uid, api.get_one_by_email('bibi@bibi').user_id) |
|
53
|
|
|
|
|
54
|
|
|
def test_get_one_by_email_exception(self): |
|
|
|
|
|
|
55
|
|
|
api = UserApi( |
|
56
|
|
|
current_user=None, |
|
57
|
|
|
session=self.session, |
|
58
|
|
|
config=self.config, |
|
59
|
|
|
) |
|
60
|
|
|
with pytest.raises(NoResultFound): |
|
61
|
|
|
api.get_one_by_email('unknown') |
|
62
|
|
|
|
|
63
|
|
|
def test_get_all(self): |
|
|
|
|
|
|
64
|
|
|
# TODO - G.M - 29-03-2018 Check why this method is not enabled |
|
|
|
|
|
|
65
|
|
|
api = UserApi( |
|
|
|
|
|
|
66
|
|
|
current_user=None, |
|
67
|
|
|
session=self.session, |
|
68
|
|
|
config=self.config, |
|
69
|
|
|
) |
|
70
|
|
|
# u1 = api.create_user(True) |
|
71
|
|
|
# u2 = api.create_user(True) |
|
72
|
|
|
|
|
73
|
|
|
# users = api.get_all() |
|
74
|
|
|
# ok_(2==len(users)) |
|
75
|
|
|
|
|
76
|
|
|
def test_get_one(self): |
|
|
|
|
|
|
77
|
|
|
api = UserApi( |
|
78
|
|
|
current_user=None, |
|
79
|
|
|
session=self.session, |
|
80
|
|
|
config=self.config, |
|
81
|
|
|
) |
|
82
|
|
|
u = api.create_user() |
|
|
|
|
|
|
83
|
|
|
api.update(u, 'titi', 'titi@titi', True) |
|
84
|
|
|
one = api.get_one(u.user_id) |
|
85
|
|
|
eq_(u.user_id, one.user_id) |
|
86
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.