-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathtest_user_endpoint.py
More file actions
49 lines (39 loc) · 1.34 KB
/
test_user_endpoint.py
File metadata and controls
49 lines (39 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import pytest
import json
@pytest.fixture
def post_body_share_user():
return json.dumps({
'data': {
'type': 'ShareUser',
'attributes': {
'username': 'TestUser'
}
}
})
@pytest.mark.django_db
class TestSourcesGet:
endpoint = '/api/v2/user/'
def test_logged_in(self, client, share_user):
resp = client.get(self.endpoint, HTTP_AUTHORIZATION=share_user.authorization())
assert resp.status_code == 200
assert resp.json()['meta']['pagination']['count'] == 1
def test_not_logged_in(self, client):
resp = client.get(self.endpoint)
assert resp.status_code == 200
assert resp.json()['meta']['pagination']['count'] == 0
@pytest.mark.django_db
class TestSourcesPost:
endpoint = '/api/v2/user/'
def test_unauthorized_post(self, client, post_body_share_user):
assert client.post(
self.endpoint,
post_body_share_user,
content_type='application/vnd.api+json'
).status_code == 401
def test_authorized_post(self, client, share_user, post_body_share_user):
assert client.post(
self.endpoint,
post_body_share_user,
content_type='application/vnd.api+json',
HTTP_AUTHORIZATION=share_user.authorization(),
).status_code == 405