summaryrefslogtreecommitdiff
path: root/tests/test_profile.py
blob: 13dc8b4b7a63f13c73900be77ec8107fc9c2211b (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import pytest
from fxa.errors import ClientError

from api import *

@pytest.fixture
def profile(account):
    return account.profile()

class TestProfile:
    def test_profile_noauth(self, profile):
        with pytest.raises(ClientError) as e:
            profile.get("/profile")
        assert e.value.details == {
            'code': 403,
            'errno': 100,
            'error': 'Forbidden',
            'message': 'unauthorized'
        }

    def test_display_name_noauth(self, profile):
        with pytest.raises(ClientError) as e:
            profile.post("/display_name", {'displayName': 'foo'})
        assert e.value.details == {
            'code': 403,
            'errno': 100,
            'error': 'Forbidden',
            'message': 'unauthorized'
        }

    def test_avatar_upload_noauth(self, profile):
        with pytest.raises(ClientError) as e:
            profile.post("/avatar/upload", "foo", headers={'content-type': 'image/png'})
        assert e.value.details == {
            'code': 403,
            'errno': 100,
            'error': 'Forbidden',
            'message': 'unauthorized'
        }

    def test_avatar_delete_noauth(self, profile):
        with pytest.raises(ClientError) as e:
            profile.delete("/avatar/00000000000000000000000000000000")
        assert e.value.details == {
            'code': 403,
            'errno': 100,
            'error': 'Forbidden',
            'message': 'unauthorized'
        }

    def test_profile(self, account, profile):
        resp = profile.get_a("/profile")
        assert resp == {
            'amrValues': None,
            'avatar': f'http://localhost:{API_PORT}/avatars/00000000000000000000000000000000',
            'avatarDefault': True,
            'displayName': None,
            'email': account.email,
            'locale': None,
            'subscriptions': None,
            'twoFactorAuthentication': False,
            'uid': account.props['uid']
        }

    def test_display_name(self, account, profile):
        resp = profile.get_a("/profile")
        assert resp == {
            'amrValues': None,
            'avatar': f'http://localhost:{API_PORT}/avatars/00000000000000000000000000000000',
            'avatarDefault': True,
            'displayName': None,
            'email': account.email,
            'locale': None,
            'subscriptions': None,
            'twoFactorAuthentication': False,
            'uid': account.props['uid']
        }
        profile.post_a("/display_name", {'displayName': 'foo'})
        resp = profile.get_a("/profile")
        assert resp == {
            'amrValues': None,
            'avatar': f'http://localhost:{API_PORT}/avatars/00000000000000000000000000000000',
            'avatarDefault': True,
            'displayName': 'foo',
            'email': account.email,
            'locale': None,
            'subscriptions': None,
            'twoFactorAuthentication': False,
            'uid': account.props['uid']
        }

    def test_avatar(self, account, profile):
        resp = profile.get_a("/avatar")
        assert resp == {
            'avatar': f'http://localhost:{API_PORT}/avatars/00000000000000000000000000000000',
            'avatarDefault': True,
            'id': '00000000000000000000000000000000'
        }

    def test_avatar_upload(self, account, profile):
        # server does not parse the bytes
        profile.post_a("/avatar/upload", "foo", headers={'content-type': 'image/png'})
        resp = profile.get_a("/avatar")
        new_id = resp['id']
        assert resp['avatar'] != f'http://localhost:{API_PORT}/avatars/00000000000000000000000000000000'
        assert not resp['avatarDefault']
        assert resp['id'] != '00000000000000000000000000000000'
        resp = profile.get_a("/profile")
        assert resp['avatar'] != f'http://localhost:{API_PORT}/avatars/00000000000000000000000000000000'
        assert not resp['avatarDefault']

    def test_avatar_delete(self, account, profile):
        # server does not parse the bytes
        profile.post_a("/avatar/upload", "foo", headers={'content-type': 'image/png'})
        resp = profile.get_a("/avatar")
        new_id = resp['id']
        profile.delete_a(f"/avatar/{new_id}")
        resp = profile.get_a("/avatar")
        assert resp == {
            'avatar': f'http://localhost:{API_PORT}/avatars/00000000000000000000000000000000',
            'avatarDefault': True,
            'id': '00000000000000000000000000000000'
        }
        resp = profile.get_a("/profile")
        assert resp == {
            'amrValues': None,
            'avatar': f'http://localhost:{API_PORT}/avatars/00000000000000000000000000000000',
            'avatarDefault': True,
            'displayName': resp['displayName'], # ignore this field
            'email': account.email,
            'locale': None,
            'subscriptions': None,
            'twoFactorAuthentication': False,
            'uid': account.props['uid']
        }