diff options
Diffstat (limited to 'ctrack')
-rw-r--r-- | ctrack/core/tests/test_views.py | 27 | ||||
-rw-r--r-- | ctrack/organisations/views.py | 7 |
2 files changed, 20 insertions, 14 deletions
diff --git a/ctrack/core/tests/test_views.py b/ctrack/core/tests/test_views.py index 53dc1da..9f7d292 100644 --- a/ctrack/core/tests/test_views.py +++ b/ctrack/core/tests/test_views.py @@ -15,18 +15,18 @@ def test_group_lead_inspector_by_submode( 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) + OrganisationFactory(submode=submode1, lead_inspector=inspector1, deputy_lead_inspector=inspector2) + OrganisationFactory(submode=submode1, lead_inspector=inspector1, deputy_lead_inspector=inspector2) + OrganisationFactory(submode=submode1, lead_inspector=inspector1, deputy_lead_inspector=inspector2) + OrganisationFactory(submode=submode1, lead_inspector=inspector1, deputy_lead_inspector=inspector2) - 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) + OrganisationFactory(submode=submode2, lead_inspector=inspector2, deputy_lead_inspector=inspector1) + OrganisationFactory(submode=submode2, lead_inspector=inspector2, deputy_lead_inspector=inspector1) + OrganisationFactory(submode=submode2, lead_inspector=inspector2, deputy_lead_inspector=inspector1) + OrganisationFactory(submode=submode2, lead_inspector=inspector2, deputy_lead_inspector=inspector1) # We have two lead inspectors for submode1! - org8 = OrganisationFactory(submode=submode1, lead_inspector=inspector2) + org8 = OrganisationFactory(submode=submode1, lead_inspector=inspector2, deputy_lead_inspector=inspector1) orgs = Organisation.objects.filter(submode=submode) leads = [org.lead_inspector for org in orgs] @@ -36,6 +36,9 @@ def test_group_lead_inspector_by_submode( 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] + lead_inspectors = inspectors_for_each_mode(lead_type="lead_inspector") + deputy_lead_inspectors = inspectors_for_each_mode(lead_type="deputy_lead_inspector") + assert lead_inspectors["Light Rail"] == {inspector1, inspector2} + assert lead_inspectors["Metro Rail"] == {inspector2} + assert deputy_lead_inspectors["Light Rail"] == {inspector2, inspector1} + assert deputy_lead_inspectors["Metro Rail"] == {inspector1} diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py index 45a86bb..82347e6 100644 --- a/ctrack/organisations/views.py +++ b/ctrack/organisations/views.py @@ -145,7 +145,10 @@ class IncidentReportCreateView(FormView): return HttpResponseRedirect(reverse("core:home")) -def inspectors_for_each_mode(lead_type="lead_inspector") -> Dict[str, List[str]]: +def inspectors_for_each_mode(lead_type="lead_inspector") -> Dict[str, Set[str]]: + """ + We want to be able to group lead inspectors by submode. + """ if lead_type not in ["lead_inspector", "deputy_lead_inspector"]: raise ValueError("Can only query for lead_inspector and deputy_lead_inspector attributes.") submodes = Submode.objects.all() @@ -155,6 +158,6 @@ def inspectors_for_each_mode(lead_type="lead_inspector") -> Dict[str, List[str]] orgs = sm.organisation_set.all() for org in orgs: insp.add(getattr(org, lead_type)) - out[sm.descriptor] = list(insp) + out[sm.descriptor] = insp del insp return out |