summaryrefslogtreecommitdiff
path: root/tests/test_profile.py
diff options
context:
space:
mode:
authorpennae <github@quasiparticle.net>2022-07-18 17:12:52 +0200
committerpennae <github@quasiparticle.net>2022-07-18 17:12:52 +0200
commita89158377f829720a98342cf434a18b962006ee7 (patch)
tree680e35a2e8e3311d832da336df8cf625c7bf07a7 /tests/test_profile.py
parenta4a929218528920c4ae525e2510562dd209f6b3a (diff)
downloadminor-skulk-a89158377f829720a98342cf434a18b962006ee7.tar.gz
minor-skulk-a89158377f829720a98342cf434a18b962006ee7.tar.xz
minor-skulk-a89158377f829720a98342cf434a18b962006ee7.zip
speed up test suite
mostly by grouping tests that can reuse the same account (which is expensive to create) into classes and scoping accounts to classes.
Diffstat (limited to 'tests/test_profile.py')
-rw-r--r--tests/test_profile.py235
1 files changed, 118 insertions, 117 deletions
diff --git a/tests/test_profile.py b/tests/test_profile.py
index 1e21ecc..13dc8b4 100644
--- a/tests/test_profile.py
+++ b/tests/test_profile.py
@@ -7,128 +7,129 @@ from api import *
def profile(account):
return account.profile()
-def test_profile_noauth(profile):
- with pytest.raises(ClientError) as e:
- profile.get("/profile")
- assert e.value.details == {
- 'code': 403,
- 'errno': 100,
- 'error': 'Forbidden',
- 'message': 'unauthorized'
- }
+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(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_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(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_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(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_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(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_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(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_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(account, profile):
- resp = profile.get_a("/avatar")
- assert resp == {
- 'avatar': f'http://localhost:{API_PORT}/avatars/00000000000000000000000000000000',
- 'avatarDefault': True,
- 'id': '00000000000000000000000000000000'
- }
+ 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(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_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(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': None,
- 'email': account.email,
- 'locale': None,
- 'subscriptions': None,
- 'twoFactorAuthentication': False,
- 'uid': account.props['uid']
- }
+ 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']
+ }