aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack
diff options
context:
space:
mode:
Diffstat (limited to 'ctrack')
-rw-r--r--ctrack/conftest.py22
-rw-r--r--ctrack/organisations/models.py7
-rw-r--r--ctrack/users/models.py9
-rw-r--r--ctrack/users/tests/test_models.py15
4 files changed, 40 insertions, 13 deletions
diff --git a/ctrack/conftest.py b/ctrack/conftest.py
index b0a5bce..6ae06c2 100644
--- a/ctrack/conftest.py
+++ b/ctrack/conftest.py
@@ -29,7 +29,22 @@ from ctrack.users.tests.factories import UserFactory
@pytest.fixture
-def submode():
+def user() -> User:
+ return UserFactory()
+
+
+@pytest.fixture
+def inspector1() -> User:
+ return UserFactory()
+
+
+@pytest.fixture
+def inspector2() -> User:
+ return UserFactory()
+
+
+@pytest.fixture
+def submode(inspector1, inspector2):
return Submode.objects.create(
descriptor="Light Rail", mode=Mode.objects.create(descriptor="Rail")
)
@@ -105,11 +120,6 @@ def cct_user_group() -> Group:
@pytest.fixture
-def user() -> User:
- return UserFactory()
-
-
-@pytest.fixture
def cct_user(cct_user_group) -> User:
# For testing views which require redirects to permission-controlled
# pages, we have to ensure our test user is has the requisite permissions here
diff --git a/ctrack/organisations/models.py b/ctrack/organisations/models.py
index 9baf672..dca590f 100644
--- a/ctrack/organisations/models.py
+++ b/ctrack/organisations/models.py
@@ -95,6 +95,7 @@ class Person(models.Model):
def get_single_datetime_events(self):
from ctrack.register.models import SingleDateTimeEvent
+
return SingleDateTimeEvent.objects.filter(participants__id=self.pk)
class Meta:
@@ -289,17 +290,17 @@ class IncidentReport(models.Model):
incident_stage = models.CharField(choices=INCIDENT_STAGE, max_length=20)
summary = models.TextField(
help_text="Please provide a summary of your understanding of the incident, including"
- " any impact to services and/or users."
+ " any impact to services and/or users."
)
mitigations = models.TextField(
verbose_name="Investigations or mitigations",
help_text="What investigations and/or mitigations have you or a third"
- " party performed or plan to perform?",
+ " party performed or plan to perform?",
)
others_informed = models.TextField(
verbose_name="Others parties informed",
help_text="Who else has been informed about this incident?"
- "(CSIRT, NCSC, NCA, etc)",
+ "(CSIRT, NCSC, NCA, etc)",
)
next_steps = models.TextField(
verbose_name="Planned next steps", help_text="What are your planned next steps?"
diff --git a/ctrack/users/models.py b/ctrack/users/models.py
index 052efd6..93c086a 100644
--- a/ctrack/users/models.py
+++ b/ctrack/users/models.py
@@ -3,11 +3,10 @@ from django.db import models
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
-from ctrack.organisations.models import Stakeholder
+from ctrack.organisations.models import Stakeholder, Submode, Organisation
class User(AbstractUser):
-
name = models.CharField(_("Name of User"), blank=True, max_length=255)
stakeholder = models.OneToOneField(
Stakeholder, on_delete=models.CASCADE, null=True, blank=True
@@ -26,3 +25,9 @@ class User(AbstractUser):
def get_organisation_name(self):
if self.is_stakeholder:
return self.stakeholder.person.organisation.name
+
+ def get_lead_inspector_organisations(self):
+ return Organisation.objects.filter(lead_inspector=self)
+
+ def get_deputy_lead_inspector_organisations(self):
+ return Organisation.objects.filter(deputy_lead_inspector=self)
diff --git a/ctrack/users/tests/test_models.py b/ctrack/users/tests/test_models.py
index 368be34..eff8b42 100644
--- a/ctrack/users/tests/test_models.py
+++ b/ctrack/users/tests/test_models.py
@@ -1,16 +1,27 @@
import pytest
-from ctrack.organisations.models import Stakeholder
+from ctrack.organisations.models import Stakeholder, Submode
pytestmark = pytest.mark.django_db
+def test_user_can_be_lead_inspector(inspector1, org):
+ org.lead_inspector = inspector1
+ org.save()
+ assert inspector1.get_lead_inspector_organisations().first() == org
+
+
+def test_user_can_be_deputy_lead_inspector(inspector1, org):
+ org.deputy_lead_inspector = inspector1
+ org.save()
+ assert inspector1.get_deputy_lead_inspector_organisations().first() == org
+
+
def test_user_get_absolute_url(user):
assert user.get_absolute_url() == f"/users/{user.username}/"
def test_user_is_person_object(user):
-
"""User comes from ctrack.conftest.
"""
assert user