1+ from playwright .sync_api import Page , expect
2+ from e2e_tests .helpers import login , logout
3+
4+
5+ def test_teacher_list_access_rights (page : Page ):
6+
7+ page .goto ("http://localhost:8000/?hl=en" )
8+ if page .get_by_test_id ('user-menu' ).is_visible ():
9+ logout (page )
10+ page .goto ("http://localhost:8000/accounts/teachers" )
11+
12+ alert = page .get_by_role ("alert" )
13+ message = "Unfortunately, you are not permitted to view this content"
14+
15+ expect (alert ).to_be_visible ()
16+ expect (alert ).to_contain_text (message )
17+
18+ login (page , "student" , "student" )
19+ page .goto ("http://localhost:8000/accounts/teachers" )
20+ expect (alert ).to_be_visible ()
21+ expect (alert ).to_contain_text (message )
22+
23+ logout (page )
24+ login (page , "teacher" , "teacher" )
25+ page .goto ("http://localhost:8000/accounts/teachers" )
26+ expect (alert ).to_be_visible ()
27+ expect (alert ).to_contain_text (message )
28+
29+ logout (page )
30+ login (page , "admin" , "admin" )
31+ page .goto ("http://localhost:8000/accounts/teachers" )
32+ expect (alert ).not_to_be_visible ()
33+ expect (page ).to_have_title ("Teacher list | A+" )
34+
35+
36+ def test_teacher_list_content (page : Page ):
37+
38+ page .goto ("http://localhost:8000/?hl=en" )
39+ login (page , "admin" , "admin" )
40+ page .goto ("http://localhost:8000/accounts/teachers" )
41+
42+ table = page .get_by_role ("table" )
43+ expect (table ).to_be_visible ()
44+
45+ rows = table .locator ("tbody tr" )
46+ expect (rows ).to_have_count (3 )
47+
48+ expected_first_three_cols = [ #there are 5 columns in total, validate first 3
49+ [
50+ "Terry Teacher" ,
51+ "teacher@localhost.invalid" ,
52+ "aplus-manual Aplus Manual: Main" ,
53+ ],
54+ [
55+ "Terry Teacher" ,
56+ "teacher@localhost.invalid" ,
57+ "test-course Test Course: Master" ,
58+ ],
59+ [
60+ "Terry Teacher" ,
61+ "teacher@localhost.invalid" ,
62+ "DEF000 Def. Course: Current" ,
63+ ],
64+ ]
65+
66+ for i , expected_cells in enumerate (expected_first_three_cols ):
67+ row_cells = rows .nth (i ).locator ("td" )
68+ expect (row_cells ).to_have_count (5 )
69+
70+ for j , expected_text in enumerate (expected_cells ):
71+ expect (row_cells .nth (j )).to_contain_text (expected_text )
72+ expect (row_cells .nth (j )).to_contain_text (expected_text )
0 commit comments