Coverage for tests/test_20_users10.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Test the users.
3## Domain
5* Users as in `conftest`, under *players*
6* Clean slate, see `starters`
7* The user table
9## Acts
11Getting to know all users.
13`test_users`
14: **office** checks whether all users in the database have a corresponding
15 client fixture.
17`test_identity`
18: We check whether all users work as their own identity.
19 This is a test on the web-app as well a test on the mechanics of the test
20 framework.
22`test_readEmail`
23: All users try to read the email address of **auth**, but only some succeed
24"""
26import pytest
28import magic # noqa
29from control.utils import E, serverprint
30from conftest import USER_LIST, NAMED_USERS, POWER_USERS
31from example import AUTH, AUTH_EMAIL, EMAIL, PUBLIC, USER
32from helpers import viewField
33from starters import start
34from subtest import assertFieldValue, assertStatus
36startInfo = {}
39@pytest.mark.usefixtures("db")
40def test_start(clientOffice):
41 startInfo.update(start(clientOffice=clientOffice, users=True))
44def test_users(clientOffice):
45 assert len(USER_LIST) == 11
46 valueTables = startInfo["valueTables"]
48 users = valueTables[USER]
49 for user in USER_LIST:
50 if user == PUBLIC:
51 assert user not in users
52 else:
53 assert user in users
56def test_identity(clients):
57 for (user, cl) in clients.items():
58 response = cl.get("/whoami")
59 actualUser = response.get_data(as_text=True)
60 serverprint(f"{user} says: I am {actualUser}")
61 assert user == actualUser
64def test_login(clients, clientPublic):
65 for user in sorted(NAMED_USERS) + [E, PUBLIC, "xxxxxx"]:
66 isNamed = user in NAMED_USERS
67 expect = 302 if isNamed else 303
68 serverprint(f"LOGIN {user}")
69 assertStatus(clientPublic, f"/login?eppn={user}", expect)
70 serverprint(f"LOGOUT {user}")
71 if user in clients:
72 assertStatus(clients[user], "/logout", expect)
75def test_readEmail(clients):
76 valueTables = startInfo["valueTables"]
78 eid = valueTables[USER][AUTH]
79 for (user, client) in clients.items():
80 (text, fields) = viewField(client, USER, eid, EMAIL)
81 if user in POWER_USERS:
82 assertFieldValue(fields, EMAIL, AUTH_EMAIL)
83 else:
84 assertFieldValue(fields, EMAIL, None)