1 |
1 |
import os
|
2 |
2 |
import json
|
|
3 |
import uuid
|
3 |
4 |
|
4 |
5 |
import pytest
|
5 |
6 |
import mock
|
... | ... | |
34 |
35 |
mocked_get_app_settings.return_value = Archimed
|
35 |
36 |
mocked_requests_post.side_effect = MOCKED_RESPONSES_LIST
|
36 |
37 |
|
37 |
|
user = create_user(username='kevin', password='kevin')
|
|
38 |
user_uuid = uuid.uuid4().hex
|
|
39 |
|
|
40 |
user = create_user(username=user_uuid[:30], password='kevin')
|
38 |
41 |
|
39 |
42 |
# test with invalid username
|
40 |
43 |
client = Client()
|
41 |
|
client.login(username='kevin', password='kevin')
|
|
44 |
client.login(username=user_uuid[:30], password='kevin')
|
42 |
45 |
response = client.get('/_mandaye/ws/account/whatever/')
|
43 |
46 |
assert response.status_code == 404
|
44 |
47 |
assert json.loads(response.content)['err_desc'] == 'User whatever does not exist'
|
45 |
48 |
assert json.loads(response.content)['err'] == 1
|
46 |
49 |
|
47 |
50 |
# test with unlinked user
|
48 |
|
client = Client()
|
49 |
|
client.login(username='kevin', password='kevin')
|
50 |
|
response = client.get('/_mandaye/ws/account/kevin/')
|
|
51 |
response = client.get('/_mandaye/ws/account/%s/' % user_uuid)
|
51 |
52 |
assert response.status_code == 404
|
52 |
|
assert json.loads(response.content)['err_desc'] == 'User kevin is not associated'
|
|
53 |
assert json.loads(response.content)['err_desc'] == 'User %s is not associated' % user_uuid[:30]
|
53 |
54 |
assert json.loads(response.content)['err'] == 1
|
54 |
55 |
|
55 |
56 |
create_credentials(user, {'carte': 'kevin', 'code': 'whatever'})
|
56 |
57 |
# test with wrong credentials
|
57 |
|
client = Client()
|
58 |
|
client.login(username='kevin', password='kevin')
|
59 |
|
response = client.get('/_mandaye/ws/account/kevin/')
|
|
58 |
response = client.get('/_mandaye/ws/account/%s/' % user_uuid)
|
60 |
59 |
assert response.status_code == 401
|
61 |
60 |
assert json.loads(response.content)['err_desc'] == 'Authentication failed'
|
62 |
61 |
assert json.loads(response.content)['err'] == 1
|
63 |
62 |
|
64 |
63 |
# test with good credentials
|
65 |
|
client.login(username='kevin', password='kevin')
|
66 |
|
response = client.get('/_mandaye/ws/account/kevin/')
|
|
64 |
response = client.get('/_mandaye/ws/account/%s/' % user_uuid)
|
67 |
65 |
assert response.status_code == 200
|
68 |
66 |
assert json.loads(response.content)['data']['message'] == 'Whatever is whatever'
|
69 |
67 |
assert json.loads(response.content)['data']['success'] is True
|
archimed: truncate sent uuid when over 30 characters (#19149)