aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/core/tests
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-10-20 15:01:20 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-10-20 15:01:20 +0100
commite4c95417112ffe8ba684b4f1d7bd957f87b2f2ed (patch)
tree9b61947660b28196dc7f33df42c82dc1c7ffd979 /ctrack/core/tests
parent4ea13b2ed79e95d2cf710c8d2d6e95fb454e054a (diff)
func to group lead inspectors by submode
Diffstat (limited to 'ctrack/core/tests')
-rw-r--r--ctrack/core/tests/test_views.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/ctrack/core/tests/test_views.py b/ctrack/core/tests/test_views.py
new file mode 100644
index 0000000..53dc1da
--- /dev/null
+++ b/ctrack/core/tests/test_views.py
@@ -0,0 +1,41 @@
+import pytest
+
+from ctrack.organisations.models import Organisation, Submode, Mode
+from ctrack.organisations.views import inspectors_for_each_mode
+from ctrack.organisations.tests.factories import OrganisationFactory
+
+pytestmark = pytest.mark.django_db
+
+
+def test_group_lead_inspector_by_submode(
+ submode, mode, org, org_with_people, inspector1, inspector2
+):
+ # because I can't be bothered making another fixture
+ submode1 = submode # this is Light Rail by the way
+ submode2 = Submode.objects.create(
+ descriptor="Metro Rail", mode=Mode.objects.create(descriptor="Rail"))
+
+ org1 = OrganisationFactory(submode=submode1, lead_inspector=inspector1)
+ org2 = OrganisationFactory(submode=submode1, lead_inspector=inspector1)
+ org3 = OrganisationFactory(submode=submode1, lead_inspector=inspector1)
+ org4 = OrganisationFactory(submode=submode1, lead_inspector=inspector1)
+
+ org5 = OrganisationFactory(submode=submode2, lead_inspector=inspector2)
+ org6 = OrganisationFactory(submode=submode2, lead_inspector=inspector2)
+ org7 = OrganisationFactory(submode=submode2, lead_inspector=inspector2)
+ org8 = OrganisationFactory(submode=submode2, lead_inspector=inspector2)
+
+ # We have two lead inspectors for submode1!
+ org8 = OrganisationFactory(submode=submode1, lead_inspector=inspector2)
+
+ orgs = Organisation.objects.filter(submode=submode)
+ leads = [org.lead_inspector for org in orgs]
+ for lead in leads[:3]:
+ assert lead.first_name == "Cyril"
+
+ for lead in leads[4:]:
+ assert lead.first_name == "Ogilvie"
+
+ inspector_dict = inspectors_for_each_mode(lead_type="lead_inspector")
+ assert inspector_dict["Light Rail"] == [inspector1, inspector2]
+ assert inspector_dict["Metro Rail"] == [inspector2]