diff options
Diffstat (limited to '')
-rw-r--r-- | ctrack/users/models.py | 9 | ||||
-rw-r--r-- | ctrack/users/tests/test_models.py | 15 |
2 files changed, 20 insertions, 4 deletions
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 |