|
@@ -1,57 +1,94 @@
|
1
|
1
|
# coding=utf-8
|
2
|
2
|
import pytest
|
|
3
|
+from sqlalchemy.exc import OperationalError
|
3
|
4
|
|
4
|
5
|
from tracim.tests import FunctionalTest
|
|
6
|
+from tracim.tests import FunctionalTestNoDB
|
5
|
7
|
|
6
|
8
|
|
7
|
9
|
class TestLogoutEndpoint(FunctionalTest):
|
8
|
10
|
|
9
|
|
- def test_logout(self):
|
|
11
|
+ def test_api__access_logout_get_enpoint__ok__nominal_case(self):
|
|
12
|
+ res = self.testapp.post_json('/api/v2/sessions/logout', status=204)
|
|
13
|
+
|
|
14
|
+ def test_api__access_logout_post_enpoint__ok__nominal_case(self):
|
10
|
15
|
res = self.testapp.get('/api/v2/sessions/logout', status=204)
|
11
|
16
|
|
12
|
17
|
|
|
18
|
+class TestLoginEndpointUnititedDB(FunctionalTestNoDB):
|
|
19
|
+
|
|
20
|
+ @pytest.mark.xfail(raises=OperationalError,
|
|
21
|
+ reason='Not supported yet by hapic')
|
|
22
|
+ def test_api__try_login_enpoint__err_500__no_inited_db(self):
|
|
23
|
+ params = {
|
|
24
|
+ 'email': 'admin@admin.admin',
|
|
25
|
+ 'password': 'admin@admin.admin',
|
|
26
|
+ }
|
|
27
|
+ res = self.testapp.post_json(
|
|
28
|
+ '/api/v2/sessions/login',
|
|
29
|
+ params=params,
|
|
30
|
+ status=500,
|
|
31
|
+ )
|
|
32
|
+ assert isinstance(res.json, dict)
|
|
33
|
+ assert 'code' in res.json.keys()
|
|
34
|
+ assert 'message' in res.json.keys()
|
|
35
|
+ assert 'details' in res.json.keys()
|
|
36
|
+
|
|
37
|
+
|
13
|
38
|
class TestLoginEndpoint(FunctionalTest):
|
14
|
39
|
|
15
|
|
- def test_login_ok(self):
|
|
40
|
+ def test_api__try_login_enpoint__ok_204__nominal_case(self):
|
16
|
41
|
params = {
|
17
|
42
|
'email': 'admin@admin.admin',
|
18
|
43
|
'password': 'admin@admin.admin',
|
19
|
44
|
}
|
20
|
|
- res = self.testapp.get(
|
|
45
|
+ res = self.testapp.post_json(
|
21
|
46
|
'/api/v2/sessions/login',
|
|
47
|
+ params=params,
|
22
|
48
|
status=204,
|
23
|
|
- params=params
|
24
|
49
|
)
|
25
|
50
|
|
26
|
|
- def test_bad_password(self):
|
|
51
|
+ def test_api__try_login_enpoint__err_400__bad_password(self):
|
27
|
52
|
params = {
|
28
|
53
|
'email': 'admin@admin.admin',
|
29
|
54
|
'password': 'bad_password',
|
30
|
55
|
}
|
31
|
|
- res = self.testapp.get(
|
|
56
|
+ res = self.testapp.post_json(
|
32
|
57
|
'/api/v2/sessions/login',
|
33
|
58
|
status=400,
|
34
|
59
|
params=params,
|
35
|
60
|
)
|
|
61
|
+ assert isinstance(res.json, dict)
|
|
62
|
+ assert 'code' in res.json.keys()
|
|
63
|
+ assert 'message' in res.json.keys()
|
|
64
|
+ assert 'details' in res.json.keys()
|
36
|
65
|
|
37
|
|
- def test_bad_user(self):
|
|
66
|
+ def test_api__try_login_enpoint__err_400__unregistered_user(self):
|
38
|
67
|
params = {
|
39
|
68
|
'email': 'unknown_user@unknown.unknown',
|
40
|
69
|
'password': 'bad_password',
|
41
|
70
|
}
|
42
|
|
- res = self.testapp.get(
|
|
71
|
+ res = self.testapp.post_json(
|
43
|
72
|
'/api/v2/sessions/login',
|
44
|
73
|
status=400,
|
45
|
74
|
params=params,
|
46
|
75
|
)
|
|
76
|
+ assert isinstance(res.json, dict)
|
|
77
|
+ assert 'code' in res.json.keys()
|
|
78
|
+ assert 'message' in res.json.keys()
|
|
79
|
+ assert 'details' in res.json.keys()
|
47
|
80
|
|
48
|
|
- def test_uncomplete(self):
|
49
|
|
- res = self.testapp.get('/api/v2/sessions/login', status=400)
|
|
81
|
+ def test_api__try_login_enpoint__err_400__no_json_body(self):
|
|
82
|
+ res = self.testapp.post_json('/api/v2/sessions/login', status=400)
|
|
83
|
+ assert isinstance(res.json, dict)
|
|
84
|
+ assert 'code' in res.json.keys()
|
|
85
|
+ assert 'message' in res.json.keys()
|
|
86
|
+ assert 'details' in res.json.keys()
|
50
|
87
|
|
51
|
88
|
|
52
|
89
|
class TestWhoamiEndpoint(FunctionalTest):
|
53
|
90
|
|
54
|
|
- def test_whoami_ok(self):
|
|
91
|
+ def test_api__try_whoami_enpoint__ok_200__nominal_case(self):
|
55
|
92
|
self.testapp.authorization = (
|
56
|
93
|
'Basic',
|
57
|
94
|
(
|
|
@@ -70,7 +107,7 @@ class TestWhoamiEndpoint(FunctionalTest):
|
70
|
107
|
assert res.json_body['caldav_url'] is None
|
71
|
108
|
assert res.json_body['avatar_url'] is None
|
72
|
109
|
|
73
|
|
- def test_unauthenticated(self):
|
|
110
|
+ def test_api__try_whoami_enpoint__err_401__unauthenticated(self):
|
74
|
111
|
self.testapp.authorization = (
|
75
|
112
|
'Basic',
|
76
|
113
|
(
|
|
@@ -79,3 +116,7 @@ class TestWhoamiEndpoint(FunctionalTest):
|
79
|
116
|
)
|
80
|
117
|
)
|
81
|
118
|
res = self.testapp.get('/api/v2/sessions/whoami', status=401)
|
|
119
|
+ assert isinstance(res.json, dict)
|
|
120
|
+ assert 'code' in res.json.keys()
|
|
121
|
+ assert 'message' in res.json.keys()
|
|
122
|
+ assert 'details' in res.json.keys()
|