diff options
Diffstat (limited to 'ctrack/core')
-rw-r--r-- | ctrack/core/tests/test_views.py | 41 | ||||
-rw-r--r-- | ctrack/core/views.py | 5 |
2 files changed, 44 insertions, 2 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] diff --git a/ctrack/core/views.py b/ctrack/core/views.py index 254fb86..499aedd 100644 --- a/ctrack/core/views.py +++ b/ctrack/core/views.py @@ -1,9 +1,8 @@ from django.contrib.auth import get_user_model -from django.contrib.auth.decorators import login_required from django.shortcuts import render from ctrack.caf.models import EssentialService, CAF, ApplicableSystem -from ctrack.organisations.models import IncidentReport, Organisation, Person +from ctrack.organisations.models import IncidentReport, Organisation, Person, Submode from ctrack.register.models import EngagementEvent @@ -33,6 +32,7 @@ def home_page(request): no_cafs = CAF.objects.count() no_essential_services = EssentialService.objects.count() no_systems = ApplicableSystem.objects.count() + submodes = Submode.objects.all().order_by("descriptor") context = { "no_orgs": no_orgs, "no_people": no_people, @@ -40,5 +40,6 @@ def home_page(request): "no_essential_services": no_essential_services, "no_systems": no_systems, "caf_users": caf_users, + "submodes": submodes, } return render(request, "pages/home.html", context) |