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
136
137
138
139
140
141
142
143
144
145
146
|
"""
Functional tests. Are probably SLOW thanks to using Selenium to load a browser instance.
The use case being tested here is related to a user being able to log in and hit
the correct page, containing their details. Those details depend on whether they are
a regular user or a stakeholder user.
"""
import time
import pytest
from django.contrib.auth.models import Permission
from ctrack.users.models import User
pytestmark = pytest.mark.django_db
def test_regular_user_can_log_in(browser, live_server):
# Toss McBride is an OES user. He logs into the system...
User.objects.create_user(username="toss", password="knob")
browser.get(live_server + "/accounts/login")
browser.find_element_by_id("id_login").send_keys("toss")
browser.find_element_by_id("id_password").send_keys("knob")
browser.find_element_by_id("sign_in_button").submit()
time.sleep(1)
current_url = browser.current_url
assert current_url == live_server + "/"
type_user_message = browser.find_elements_by_tag_name("p")
assert "THIS IS A TEMPLATE FOR A REGULAR USER" in [
m.text for m in type_user_message
]
def test_stakeholder_can_log_in_and_see_their_home(
browser, live_server, stakeholder_user
):
# Toss McBride is an OES user. He logs into the system...
user = stakeholder_user
browser.get(live_server + "/accounts/login")
browser.find_element_by_id("id_login").send_keys("toss")
browser.find_element_by_id("id_password").send_keys("knob")
browser.find_element_by_id("sign_in_button").submit()
time.sleep(1)
current_url = browser.current_url
assert current_url == live_server + "/"
p_tags = browser.find_elements_by_tag_name("p")
h2_tags = browser.find_elements_by_tag_name("h2")
assert "THIS IS A TEMPLATE FOR A STAKEHOLDER USER" in [m.text for m in p_tags]
assert (
f"{user.stakeholder.person.get_organisation_name()} {user.stakeholder.person.organisation.submode}"
in [m.text for m in h2_tags]
)
def test_stakeholder_can_log_in_but_receieved_permisson_denied_when_off_piste(
browser, live_server, stakeholder_user
):
browser.get(live_server + "/accounts/login")
browser.find_element_by_id("id_login").send_keys("toss")
browser.find_element_by_id("id_password").send_keys("knob")
browser.find_element_by_id("sign_in_button").submit()
time.sleep(1)
# Try to browser to Organisations list
browser.get(live_server + "/organisations")
assert "Sorry. You do not have permission to view this page." in [
x.text for x in browser.find_elements_by_tag_name("p")
]
def test_stakeholder_user_with_permissions_can_view_page(
browser, live_server, stakeholder_user
):
user = stakeholder_user
org_list_permission = Permission.objects.get(name="Can view organisation")
# Add the permission to view an Organisation, which is set on OrganisationListView
assert user.user_permissions.count() == 0
user.user_permissions.add(org_list_permission)
assert user.user_permissions.count() == 1
user.save()
browser.get(live_server + "/accounts/login")
browser.find_element_by_id("id_login").send_keys("toss")
browser.find_element_by_id("id_password").send_keys("knob")
browser.find_element_by_id("sign_in_button").submit()
time.sleep(1)
# Try to browser to Organisations list
browser.get(live_server + "/organisations")
assert "Organisations" in browser.title
def test_stakeholder_user_can_see_requisite_subtitles_on_home_page(
browser, live_server, stakeholder_user
):
browser.get(live_server + "/accounts/login")
browser.find_element_by_id("id_login").send_keys("toss")
browser.find_element_by_id("id_password").send_keys("knob")
browser.find_element_by_id("sign_in_button").submit()
time.sleep(1)
current_url = browser.current_url
assert current_url == live_server + "/"
# On the other side, he sees some basic details about himself.
assert "ctrack - Department for Transport" in browser.title
h2 = browser.find_elements_by_tag_name("h2")
assert "Incident Reporting" in [x.text for x in h2]
assert "Compliance Events" in [x.text for x in h2]
assert "NIS systems" in [x.text for x in h2]
assert "DfT Engagement" in [x.text for x in h2]
def test_stakeholder_logs_into_system_and_submits_incident_form(
browser, live_server, stakeholder_user
):
user = stakeholder_user
browser.get(live_server + "/accounts/login")
browser.find_element_by_id("id_login").send_keys("toss")
browser.find_element_by_id("id_password").send_keys("knob")
browser.find_element_by_id("sign_in_button").submit()
time.sleep(1)
current_url = browser.current_url
assert current_url == live_server + "/"
time.sleep(1)
browser.get(current_url)
# Clicks the Report a NIS incident button
# browser.find_element_by_id("id_submit_incident_button").submit()
button = browser.find_element_by_xpath('//*[@id="id_submit_incident_button"]')
button.click()
time.sleep(1)
current_url = browser.current_url
browser.get(current_url)
# Gets to the correct page
assert "Submit a new NIS Incident Report to DfT" in browser.title
|