Hide keyboard shortcuts

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. 

2 

3## Domain 

4 

5* Users as in `conftest`, under *players* 

6* Clean slate, see `starters` 

7* The user table 

8 

9## Acts 

10 

11Getting to know all users. 

12 

13`test_users` 

14: **office** checks whether all users in the database have a corresponding 

15 client fixture. 

16 

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. 

21 

22`test_readEmail` 

23: All users try to read the email address of **auth**, but only some succeed 

24""" 

25 

26import pytest 

27 

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 

35 

36startInfo = {} 

37 

38 

39@pytest.mark.usefixtures("db") 

40def test_start(clientOffice): 

41 startInfo.update(start(clientOffice=clientOffice, users=True)) 

42 

43 

44def test_users(clientOffice): 

45 assert len(USER_LIST) == 11 

46 valueTables = startInfo["valueTables"] 

47 

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 

54 

55 

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 

62 

63 

64def test_login(clients, clientPublic): 

65 for user in sorted(NAMED_USERS) + [E, PUBLIC, f"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], f"/logout", expect) 

73 

74 

75def test_readEmail(clients): 

76 valueTables = startInfo["valueTables"] 

77 

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)