aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ctrack/conftest.py36
-rw-r--r--ctrack/users/models.py7
-rw-r--r--ctrack/users/stakeholder.py7
-rw-r--r--ctrack/users/tests/test_models.py15
-rw-r--r--ctrack/users/tests/test_views.py3
5 files changed, 51 insertions, 17 deletions
diff --git a/ctrack/conftest.py b/ctrack/conftest.py
index 8c40fe4..60a177f 100644
--- a/ctrack/conftest.py
+++ b/ctrack/conftest.py
@@ -1,13 +1,21 @@
import pytest
from django.test import RequestFactory
-from ctrack.organisations.models import AddressType
-from ctrack.users.models import User
-from ctrack.organisations.models import Organisation, Address
-from ctrack.users.tests.factories import (
- UserFactory,
+from ctrack.organisations.models import (
+ Address,
+ AddressType,
+ Mode,
+ Organisation,
+ Submode,
+)
+from ctrack.organisations.tests.factories import (
+ AddressFactory,
+ OrganisationFactory,
+ PersonFactory,
+ RoleFactory,
)
-from ctrack.organisations.tests.factories import OrganisationFactory, AddressFactory
+from ctrack.users.models import User
+from ctrack.users.tests.factories import UserFactory
@pytest.fixture(autouse=True)
@@ -21,6 +29,22 @@ def user() -> User:
@pytest.fixture
+def person(user):
+ role = RoleFactory.create(name="Compliance Inspector")
+ mode = Mode.objects.create(descriptor="Rail")
+ submode = Submode.objects.create(descriptor="Light Rail", mode=mode)
+ org = OrganisationFactory.create(submode=submode)
+ person = PersonFactory.create(
+ role=role,
+ updated_by=user,
+ predecessor=None,
+ organisation__submode=submode,
+ organisation=org,
+ )
+ return person
+
+
+@pytest.fixture
def org() -> Organisation:
return OrganisationFactory()
diff --git a/ctrack/users/models.py b/ctrack/users/models.py
index 76dabf3..8f07b15 100644
--- a/ctrack/users/models.py
+++ b/ctrack/users/models.py
@@ -1,6 +1,5 @@
from django.contrib.auth.models import AbstractUser
-from django.db import models
-from django.db.models import BooleanField, CharField
+from django.db.models import CharField
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
@@ -13,7 +12,3 @@ class User(AbstractUser):
def get_absolute_url(self):
return reverse("users:detail", kwargs={"username": self.username})
-
-
-class UserProfile(models.Model):
- pass
diff --git a/ctrack/users/stakeholder.py b/ctrack/users/stakeholder.py
new file mode 100644
index 0000000..d15dd39
--- /dev/null
+++ b/ctrack/users/stakeholder.py
@@ -0,0 +1,7 @@
+from django.db import models
+
+from ctrack.organisations.models import Person
+
+
+class Stakeholder(models.Model):
+ person = models.ForeignKey(Person, on_delete=models.CASCADE)
diff --git a/ctrack/users/tests/test_models.py b/ctrack/users/tests/test_models.py
index c429b9c..2d45cca 100644
--- a/ctrack/users/tests/test_models.py
+++ b/ctrack/users/tests/test_models.py
@@ -1,16 +1,25 @@
import pytest
-from ctrack.users.models import User
+from ctrack.users.stakeholder import Stakeholder
pytestmark = pytest.mark.django_db
-def test_user_get_absolute_url(user: User):
+def test_user_get_absolute_url(user):
assert user.get_absolute_url() == f"/users/{user.username}/"
-def test_user_is_person_object(user: User):
+def test_user_is_person_object(user):
"""User comes from ctrack.conftest.
"""
assert user
+
+
+def test_stakeholder_model(person):
+ """
+ A stakeholder is someone who is part of the regime but also has user access to the
+ the system.
+ """
+ stakeholder = Stakeholder(person=person)
+ assert stakeholder
diff --git a/ctrack/users/tests/test_views.py b/ctrack/users/tests/test_views.py
index 561c540..3299cd6 100644
--- a/ctrack/users/tests/test_views.py
+++ b/ctrack/users/tests/test_views.py
@@ -2,7 +2,6 @@ import pytest
from django.contrib.auth import get_user_model
from django.test import RequestFactory
-from ctrack.organisations.tests.factories import OrganisationFactory
from ctrack.users.models import User
from ctrack.users.views import UserDetailView, UserRedirectView, UserUpdateView
@@ -64,4 +63,4 @@ def test_profile_view_contains_organisation_information():
response = UserDetailView.as_view()(request, username=user.username)
assert response.status_code == 200
# TODO - work out how we can attach an organisation to the User model
- assert response.context_data["object"]
+ assert False, "This does nothing yet"