aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ctrack/conftest.py11
-rw-r--r--ctrack/organisations/models.py4
-rw-r--r--ctrack/organisations/tests/test_views.py13
-rw-r--r--ctrack/organisations/urls.py12
-rw-r--r--ctrack/organisations/views.py7
-rw-r--r--ctrack/templates/pages/stakeholder_home.html2
-rw-r--r--ctrack/users/tests/test_functional.py40
7 files changed, 57 insertions, 32 deletions
diff --git a/ctrack/conftest.py b/ctrack/conftest.py
index 37a4a6c..58fabd0 100644
--- a/ctrack/conftest.py
+++ b/ctrack/conftest.py
@@ -62,9 +62,12 @@ def addr() -> Address:
@pytest.fixture
-def stakeholder(person):
- s = Stakeholder.objects.create(person=person)
- return s
+def stakeholder_user(person):
+ user = User.objects.create_user(username="toss", password="knob")
+ stakeholder = Stakeholder.objects.create(person=person)
+ user.stakeholder = stakeholder
+ user.save()
+ return user
@pytest.fixture
@@ -72,7 +75,7 @@ def request_factory() -> RequestFactory:
return RequestFactory()
-@pytest.fixture(scope="module")
+@pytest.fixture
def browser(request):
"Provide selenium webdriver instance."
os.environ["PATH"] += os.pathsep + os.getcwd()
diff --git a/ctrack/organisations/models.py b/ctrack/organisations/models.py
index 6a1b4ac..00e4db6 100644
--- a/ctrack/organisations/models.py
+++ b/ctrack/organisations/models.py
@@ -181,3 +181,7 @@ class Stakeholder(models.Model):
def __str__(self):
return f"{self.person.first_name} {self.person.last_name}"
+
+
+class IncidentReport(models.Model):
+ pass
diff --git a/ctrack/organisations/tests/test_views.py b/ctrack/organisations/tests/test_views.py
index 2111410..1e2476d 100644
--- a/ctrack/organisations/tests/test_views.py
+++ b/ctrack/organisations/tests/test_views.py
@@ -3,6 +3,7 @@ from django.contrib.auth import get_user_model
from django.test import RequestFactory
from ctrack.organisations.tests.factories import OrganisationFactory
+from ctrack.organisations.views import IncidentReportCreateView
from ..views import OrganisationListView
@@ -25,3 +26,15 @@ def test_organisation_list_view():
response = OrganisationListView.as_view()(request)
assert response.status_code == 200
assert len(response.context_data["organisation_list"]) == 3
+
+
+def test_incident_report_create_view():
+ user = get_user_model().objects.create_user(
+ username="testy", email="testy@test.com", password="test1020"
+ )
+ org = OrganisationFactory.create()
+ factory = RequestFactory()
+ request = factory.get(f"{org.name}/create-incident-report")
+ request.user = user
+ response = IncidentReportCreateView.as_view()(request)
+ assert response.status_code == 200
diff --git a/ctrack/organisations/urls.py b/ctrack/organisations/urls.py
index 09743af..5ccfca0 100644
--- a/ctrack/organisations/urls.py
+++ b/ctrack/organisations/urls.py
@@ -1,11 +1,21 @@
from django.urls import path
-from ctrack.organisations.views import OrganisationDetailView, OrganisationListView, OrganisationCreate
+from ctrack.organisations.views import (
+ IncidentReportCreateView,
+ OrganisationCreate,
+ OrganisationDetailView,
+ OrganisationListView,
+)
app_name = "organisations"
urlpatterns = [
path("<slug:slug>/", view=OrganisationDetailView.as_view(), name="detail"),
+ path(
+ "<slug:slug>/create-incident-report/",
+ view=IncidentReportCreateView.as_view(),
+ name="create_incident_report",
+ ),
path("", view=OrganisationListView.as_view(), name="list"),
path("create", view=OrganisationCreate.as_view(), name="create")
# path("create", view=OrganisationCreate.as_view(), name="create")
diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py
index b929de4..3363a33 100644
--- a/ctrack/organisations/views.py
+++ b/ctrack/organisations/views.py
@@ -10,7 +10,7 @@ from django.urls import reverse_lazy
from django.views.generic import CreateView, DetailView, ListView
from .forms import AddressInlineFormSet, OrganisationCreateForm
-from .models import Organisation
+from .models import IncidentReport, Organisation
class OrganisationCreate(LoginRequiredMixin, CreateView):
@@ -71,3 +71,8 @@ class OrganisationDetailView(LoginRequiredMixin, DetailView):
applicable_systems = org.applicablesystem_set.all()
context["applicable_systems"] = applicable_systems
return context
+
+
+class IncidentReportCreateView(LoginRequiredMixin, CreateView):
+ model = IncidentReport
+ fields = "__all__"
diff --git a/ctrack/templates/pages/stakeholder_home.html b/ctrack/templates/pages/stakeholder_home.html
index bcd5ecf..7070d71 100644
--- a/ctrack/templates/pages/stakeholder_home.html
+++ b/ctrack/templates/pages/stakeholder_home.html
@@ -64,7 +64,7 @@
<td><strong><span class="badge badge-success">RESOLVED</span></strong></td>
</tr>
</table>
- <a class="btn btn-primary" id="id_submit_incident_button">Report a NIS incident</a>
+ <a class="btn btn-primary" id="id_submit_incident_button" href="{% url "organisations:create_incident_report" org.slug %}">Report a NIS incident</a>
</div>
</div>
<hr>
diff --git a/ctrack/users/tests/test_functional.py b/ctrack/users/tests/test_functional.py
index 6ea818f..882c974 100644
--- a/ctrack/users/tests/test_functional.py
+++ b/ctrack/users/tests/test_functional.py
@@ -34,13 +34,12 @@ def test_regular_user_can_log_in(browser, live_server):
]
-def test_stakeholder_can_log_in_and_see_their_home(browser, live_server, stakeholder):
+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 = User.objects.create_user(username="toss", password="knob")
- user.stakeholder = stakeholder
- org = user.stakeholder.person.get_organisation_name()
- user.save()
+ 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")
@@ -52,19 +51,16 @@ def test_stakeholder_can_log_in_and_see_their_home(browser, live_server, stakeho
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 org in [m.text for m in h2_tags]
+
assert (
- f"{user.stakeholder.person.first_name} {user.stakeholder.person.last_name}"
- in [m.text for m in p_tags]
+ 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
+ browser, live_server, stakeholder_user
):
- user = User.objects.create_user(username="toss", password="knob")
- user.stakeholder = stakeholder
- 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")
@@ -78,10 +74,9 @@ def test_stakeholder_can_log_in_but_receieved_permisson_denied_when_off_piste(
def test_stakeholder_user_with_permissions_can_view_page(
- browser, live_server, stakeholder
+ browser, live_server, stakeholder_user
):
- user = User.objects.create_user(username="toss", password="knob")
- user.stakeholder = stakeholder
+ 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
@@ -101,11 +96,8 @@ def test_stakeholder_user_with_permissions_can_view_page(
def test_stakeholder_user_can_see_requisite_subtitles_on_home_page(
- browser, live_server, stakeholder
+ browser, live_server, stakeholder_user
):
- user = User.objects.create_user(username="toss", password="knob")
- user.stakeholder = stakeholder
- 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")
@@ -119,24 +111,22 @@ def test_stakeholder_user_can_see_requisite_subtitles_on_home_page(
h2 = browser.find_elements_by_tag_name("h2")
assert "Incident Reporting" in [x.text for x in h2]
- assert "Audits and Inspections" 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
+ browser, live_server, stakeholder_user
):
- user = User.objects.create_user(username="toss", password="knob")
- user.stakeholder = stakeholder
- user.save()
+ 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
- browser.get(current_url)
+ assert current_url == live_server + "/"
# Clicks the Report a NIS incident button
browser.find_element_by_id("id_submit_incident_button").submit()