From 82270367bb00b3687a875ca397e99d3fc1a63d5a Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Wed, 18 May 2016 23:53:12 +0200 Subject: [PATCH] Refactored test_person_permissions to use the new faster backend.unittest, and include process permissions --- backend/tests/test_perms.py | 271 ++++++++++++---- public/tests/test_person_permissions.py | 412 ------------------------ 2 files changed, 211 insertions(+), 472 deletions(-) delete mode 100644 public/tests/test_person_permissions.py diff --git a/backend/tests/test_perms.py b/backend/tests/test_perms.py index 0700c68..e0af21e 100644 --- a/backend/tests/test_perms.py +++ b/backend/tests/test_perms.py @@ -74,7 +74,7 @@ class PatchDiff(object): elif change[0] == "-": self.removed.add(change[1:]) else: - raise RuntimeError("Changes {} contain {} that is nether an add nor a remove".format(changes, change)) + raise RuntimeError("Changes {} contain {} that is nether an add nor a remove".format(text, change)) def apply(self, cur): if cur is None: @@ -375,7 +375,6 @@ class TestVisitApplicant(PersonFixtureMixin, TestVisitPersonMixin, TestCase): expected.patch_advs("dm dm_ga", "-dm_ga") self.assertApplicantPermsAMApproved(expected) - # Final states self.persons.app.status = self.processes.app.applying_for self.persons.app.save(audit_skip=True) expected.patch_perms("fd dam app", "-edit_ldap -edit_agreements") @@ -408,7 +407,6 @@ class TestVisitApplicant(PersonFixtureMixin, TestVisitPersonMixin, TestCase): expected.patch_advs("fd dam dd_nu dd_u app dm dm_ga", "-dm_ga") self.assertApplicantPermsAMApproved(expected) - # Final states self.persons.app.status = self.processes.app.applying_for self.persons.app.save(audit_skip=True) expected.patch_perms("fd dam app", "-edit_ldap -edit_agreements") @@ -422,64 +420,217 @@ class TestVisitApplicant(PersonFixtureMixin, TestVisitPersonMixin, TestCase): self.persons.create("adv", status=const.STATUS_DD_NU) self.processes.create("app", person=self.persons.app, applying_for=const.STATUS_DM, progress=const.PROGRESS_APP_RCVD) - # States without advocates and AMs - for p in (const.PROGRESS_APP_NEW, const.PROGRESS_APP_RCVD, const.PROGRESS_APP_HOLD, const.PROGRESS_ADV_RCVD, const.PROGRESS_POLL_SENT): - self.processes.app.progress = p - self.processes.app.save() - self.assertApplicantPerms(ExpectedPerms({ - "fd dam app": "update_keycheck edit_bio edit_ldap view_person_audit_log see_agreements edit_agreements", - "adv dd_nu dd_u": "view_person_audit_log", - }, advs={ - "fd dam adv dd_nu dd_u": "dc_ga dm dd_u dd_nu", - "dm dm_ga": "dc_ga", - })) - - # States with advocates and no AMs + expected = ExpectedPerms({ + "fd dam app": "update_keycheck edit_bio edit_ldap view_person_audit_log see_agreements edit_agreements view_mbox", + "adv dd_nu dd_u": "view_person_audit_log", + }, advs={ + "fd dam adv dd_nu dd_u": "dc_ga dm dd_u dd_nu", + "dm dm_ga": "dc_ga", + }) + self.assertApplicantPermsInitialProcess(expected) + self.processes.app.advocates.add(self.persons.adv) - for p in (const.PROGRESS_APP_OK,): - self.processes.app.progress = p - self.processes.app.save() - self.assertApplicantPerms(ExpectedPerms({ - "fd dam app": "update_keycheck edit_bio edit_ldap view_person_audit_log see_agreements edit_agreements", - "adv": "update_keycheck edit_bio edit_ldap view_person_audit_log see_agreements", - "dd_nu dd_u": "view_person_audit_log", - }, advs={ - "fd dam dd_nu dd_u": "dc_ga dm dd_u dd_nu", - "adv": "dc_ga dd_u dd_nu", - "dm dm_ga": "dc_ga", - })) - - # States after the AM - for p in (const.PROGRESS_FD_HOLD, const.PROGRESS_FD_OK, const.PROGRESS_DAM_HOLD, const.PROGRESS_DAM_OK): - self.processes.app.progress = p - self.processes.app.save() - self.assertApplicantPerms(ExpectedPerms({ - "fd dam": "update_keycheck edit_bio edit_ldap view_person_audit_log see_agreements edit_agreements", - "app": "update_keycheck edit_bio view_person_audit_log see_agreements edit_agreements", - "adv dd_nu dd_u": "view_person_audit_log", - }, advs={ - "fd dam adv dd_nu dd_u": "dc_ga dd_u dd_nu", - "dm dm_ga": "dc_ga", - })) - - # Final states + expected.set_perms("adv", "update_keycheck edit_bio edit_ldap view_person_audit_log see_agreements view_mbox") + expected.patch_advs("adv", "-dm") + self.assertApplicantPermsHasAdvocate(expected) + + expected.patch_perms("app", "-edit_ldap") + expected.set_perms("adv", "view_person_audit_log view_mbox") + expected.patch_advs("fd dam dd_nu dd_u app dm dm_ga", "-dm") + self.assertApplicantPermsAMApproved(expected) + self.persons.app.status = self.processes.app.applying_for self.persons.app.save(audit_skip=True) - for p in (const.PROGRESS_DONE, const.PROGRESS_CANCELLED): - self.processes.app.progress = p - self.processes.app.is_active = False - self.processes.app.save() - self.assertApplicantPerms(ExpectedPerms({ - "fd dam app": "update_keycheck edit_bio edit_ldap view_person_audit_log see_agreements edit_agreements", - "adv dd_nu dd_u": "view_person_audit_log", - }, advs={ - "fd dam adv dd_nu dd_u": "dm_ga dd_u dd_nu", - "app dm dm_ga": "dm_ga", - })) - - #@classmethod - #def setUpClass(cls): - # super(TestVisitApplicant, cls).setUpClass() - # cls.persons.create("am", status=const.STATUS_DD_NU) - # cls.ams.create("am", person=cls.persons.am) + expected.patch_perms("app", "+edit_ldap") + expected.patch_advs("fd dam dd_nu dd_u app adv dm dm_ga", "-dc_ga +dm_ga") + self.assertApplicantPermsFinal(expected) + + def test_dc_ddnu(self): + """ + Test all visit combinations for an applicant from dc to dd_nu, with a dd advocate + """ + self.persons.create("app", status=const.STATUS_DC) + self.persons.create("adv", status=const.STATUS_DD_NU) + self.processes.create("app", person=self.persons.app, applying_for=const.STATUS_DD_NU, progress=const.PROGRESS_APP_RCVD) + + expected = ExpectedPerms({ + "fd dam app": "update_keycheck edit_bio edit_ldap view_person_audit_log see_agreements edit_agreements view_mbox", + "adv dd_nu dd_u": "view_person_audit_log", + }, advs={ + "fd dam adv dd_nu dd_u": "dc_ga dm dd_u dd_nu", + "dm dm_ga": "dc_ga", + }) + self.assertApplicantPermsInitialProcess(expected) + self.processes.app.advocates.add(self.persons.adv) + expected.set_perms("adv", "update_keycheck edit_bio edit_ldap view_person_audit_log see_agreements view_mbox") + expected.patch_advs("adv", "-dd_nu -dd_u") + self.assertApplicantPermsHasAdvocate(expected) + + expected.patch_perms("app", "-edit_ldap") + expected.set_perms("adv", "view_person_audit_log view_mbox") + expected.patch_advs("fd dam dd_nu dd_u app dm dm_ga", "-dd_nu -dd_u") + self.assertApplicantPermsAMApproved(expected) + + self.persons.app.status = self.processes.app.applying_for + self.persons.app.save(audit_skip=True) + expected.patch_perms("fd dam app", "-edit_ldap -edit_agreements") + expected.patch_advs("fd dam dd_nu dd_u app dm dm_ga adv", "-dc_ga -dm") + self.assertApplicantPermsFinal(expected) + + def test_dcga_ddnu(self): + """ + Test all visit combinations for an applicant from dc_ga to dd_nu, with a dd advocate + """ + self.persons.create("app", status=const.STATUS_DC_GA) + self.persons.create("adv", status=const.STATUS_DD_NU) + self.processes.create("app", person=self.persons.app, applying_for=const.STATUS_DD_NU, progress=const.PROGRESS_APP_RCVD) + + expected = ExpectedPerms({ + "fd dam app": "update_keycheck edit_bio view_person_audit_log see_agreements view_mbox", + "adv dd_nu dd_u": "view_person_audit_log", + }, advs={ + "fd dam adv dd_nu dd_u": "dm_ga dd_u dd_nu", + }) + self.assertApplicantPermsInitialProcess(expected) + + self.processes.app.advocates.add(self.persons.adv) + expected.set_perms("adv", "update_keycheck edit_bio view_person_audit_log see_agreements view_mbox") + expected.patch_advs("adv", "-dd_nu -dd_u") + self.assertApplicantPermsHasAdvocate(expected) + + expected.patch_perms("app", "-edit_ldap") + expected.set_perms("adv", "view_person_audit_log view_mbox") + expected.patch_advs("fd dam dd_nu dd_u app dm dm_ga", "-dd_nu -dd_u") + self.assertApplicantPermsAMApproved(expected) + + self.persons.app.status = self.processes.app.applying_for + self.persons.app.save(audit_skip=True) + expected.patch_advs("fd dam dd_nu dd_u app dm dm_ga adv", "-dm_ga") + self.assertApplicantPermsFinal(expected) + + def test_dc_ddu(self): + """ + Test all visit combinations for an applicant from dc to dd_u, with a dd advocate + """ + self.persons.create("app", status=const.STATUS_DC) + self.persons.create("adv", status=const.STATUS_DD_NU) + self.processes.create("app", person=self.persons.app, applying_for=const.STATUS_DD_U, progress=const.PROGRESS_APP_RCVD) + + expected = ExpectedPerms({ + "fd dam app": "update_keycheck edit_bio edit_ldap view_person_audit_log see_agreements edit_agreements view_mbox", + "adv dd_nu dd_u": "view_person_audit_log", + }, advs={ + "fd dam adv dd_nu dd_u": "dc_ga dm dd_u dd_nu", + "dm dm_ga": "dc_ga", + }) + self.assertApplicantPermsInitialProcess(expected) + + self.processes.app.advocates.add(self.persons.adv) + expected.set_perms("adv", "update_keycheck edit_bio edit_ldap view_person_audit_log see_agreements view_mbox") + expected.patch_advs("adv", "-dd_nu -dd_u") + self.assertApplicantPermsHasAdvocate(expected) + + expected.patch_perms("app", "-edit_ldap") + expected.set_perms("adv", "view_person_audit_log view_mbox") + expected.patch_advs("fd dam dd_nu dd_u app dm dm_ga", "-dd_nu -dd_u") + self.assertApplicantPermsAMApproved(expected) + + self.persons.app.status = self.processes.app.applying_for + self.persons.app.save(audit_skip=True) + expected.patch_perms("fd dam app", "-edit_ldap -edit_agreements") + expected.patch_advs("fd dam dd_nu dd_u app dm dm_ga adv", "-dc_ga -dm") + self.assertApplicantPermsFinal(expected) + + def test_dcga_ddu(self): + """ + Test all visit combinations for an applicant from dc_ga to dd_u, with a dd advocate + """ + self.persons.create("app", status=const.STATUS_DC_GA) + self.persons.create("adv", status=const.STATUS_DD_NU) + self.processes.create("app", person=self.persons.app, applying_for=const.STATUS_DD_U, progress=const.PROGRESS_APP_RCVD) + + expected = ExpectedPerms({ + "fd dam app": "update_keycheck edit_bio view_person_audit_log see_agreements view_mbox", + "adv dd_nu dd_u": "view_person_audit_log", + }, advs={ + "fd dam adv dd_nu dd_u": "dm_ga dd_u dd_nu", + }) + self.assertApplicantPermsInitialProcess(expected) + + self.processes.app.advocates.add(self.persons.adv) + expected.set_perms("adv", "update_keycheck edit_bio view_person_audit_log see_agreements view_mbox") + expected.patch_advs("adv", "-dd_nu -dd_u") + self.assertApplicantPermsHasAdvocate(expected) + + expected.patch_perms("app", "-edit_ldap") + expected.set_perms("adv", "view_person_audit_log view_mbox") + expected.patch_advs("fd dam dd_nu dd_u app dm dm_ga", "-dd_nu -dd_u") + self.assertApplicantPermsAMApproved(expected) + + self.persons.app.status = self.processes.app.applying_for + self.persons.app.save(audit_skip=True) + expected.patch_advs("fd dam dd_nu dd_u app dm dm_ga adv", "-dm_ga") + self.assertApplicantPermsFinal(expected) + + def test_dm_ddu(self): + """ + Test all visit combinations for an applicant from dm to dd_u, with a dd advocate + """ + self.persons.create("app", status=const.STATUS_DM) + self.persons.create("adv", status=const.STATUS_DD_NU) + self.processes.create("app", person=self.persons.app, applying_for=const.STATUS_DD_U, progress=const.PROGRESS_APP_RCVD) + + expected = ExpectedPerms({ + "fd dam app": "update_keycheck edit_bio edit_ldap view_person_audit_log see_agreements edit_agreements view_mbox", + "adv dd_nu dd_u": "view_person_audit_log", + }, advs={ + "fd dam adv dd_nu dd_u": "dm_ga dd_u dd_nu", + "dm dm_ga app": "dm_ga", + }) + self.assertApplicantPermsInitialProcess(expected) + + self.processes.app.advocates.add(self.persons.adv) + expected.set_perms("adv", "update_keycheck edit_bio edit_ldap view_person_audit_log see_agreements view_mbox") + expected.patch_advs("adv", "-dd_nu -dd_u") + self.assertApplicantPermsHasAdvocate(expected) + + expected.patch_perms("app", "-edit_ldap") + expected.set_perms("adv", "view_person_audit_log view_mbox") + expected.patch_advs("fd dam dd_nu dd_u app dm dm_ga", "-dd_nu -dd_u") + self.assertApplicantPermsAMApproved(expected) + + self.persons.app.status = self.processes.app.applying_for + self.persons.app.save(audit_skip=True) + expected.patch_perms("fd dam adv app", "-edit_ldap -edit_agreements") + expected.patch_advs("fd dam dd_nu dd_u app dm dm_ga adv", "-dm_ga") + self.assertApplicantPermsFinal(expected) + + def test_dmga_ddu(self): + """ + Test all visit combinations for an applicant from dm to dd_u, with a dd advocate + """ + self.persons.create("app", status=const.STATUS_DM_GA) + self.persons.create("adv", status=const.STATUS_DD_NU) + self.processes.create("app", person=self.persons.app, applying_for=const.STATUS_DD_U, progress=const.PROGRESS_APP_RCVD) + + expected = ExpectedPerms({ + "fd dam app": "update_keycheck edit_bio view_person_audit_log see_agreements view_mbox", + "adv dd_nu dd_u": "view_person_audit_log", + }, advs={ + "fd dam adv dd_nu dd_u": "dd_u dd_nu", + }) + self.assertApplicantPermsInitialProcess(expected) + + self.processes.app.advocates.add(self.persons.adv) + expected.set_perms("adv", "update_keycheck edit_bio view_person_audit_log see_agreements view_mbox") + expected.patch_advs("adv", "-dd_nu -dd_u") + self.assertApplicantPermsHasAdvocate(expected) + + expected.set_perms("adv", "view_person_audit_log view_mbox") + expected.patch_advs("fd dam dd_nu dd_u app dm dm_ga", "-dd_nu -dd_u") + self.assertApplicantPermsAMApproved(expected) + + self.persons.app.status = self.processes.app.applying_for + self.persons.app.save(audit_skip=True) + self.assertApplicantPermsFinal(expected) diff --git a/public/tests/test_person_permissions.py b/public/tests/test_person_permissions.py deleted file mode 100644 index f9b592c..0000000 --- a/public/tests/test_person_permissions.py +++ /dev/null @@ -1,412 +0,0 @@ -# coding: utf8 -""" -Test permissions -""" -from __future__ import print_function -from __future__ import absolute_import -from __future__ import division -from __future__ import unicode_literals -from django.test import TestCase -from backend import const -from backend.test_common import * - -class WhenView(NMTestUtilsWhen): - def setUp(self, fixture): - super(WhenView, self).setUp(fixture) - self.url = reverse("person", kwargs={ "key": self.args["person"].lookup_key }) - -class ThenPerms(ThenSuccess): - def __init__(self, perms): - self.perms_expected = frozenset(perms.split() if perms else ()) - def __call__(self, fixture, response, when, test_client): - super(ThenPerms, self).__call__(fixture, response, when, test_client) - perms = response.context["vperms"].perms - if perms != self.perms_expected: - fixture.fail("{} got permissions ({}) instead of ({}) when {}".format( - when.user, ", ".join(sorted(perms)), ", ".join(sorted(self.perms_expected)), when)) - -class ThenCanAdv(ThenSuccess): - def __init__(self, adv): - self.adv_expected = frozenset(adv.split() if adv else ()) - def __call__(self, fixture, response, when, test_client): - super(ThenCanAdv, self).__call__(fixture, response, when, test_client) - adv = frozenset(response.context["vperms"].advocate_targets) - if adv != self.adv_expected: - fixture.fail("{} can advocate for ({}) instead of ({}) when {}".format( - when.user, ", ".join(sorted(adv)), ", ".join(sorted(self.adv_expected)), when)) - -class visit_base(object): - def __init__(self, fixture, person, other_perms="", other_advs=""): - self.fixture = fixture - self.visitors_perms_seen = set() - self.visitors_advs_seen = set() - self.other_perms = other_perms - self.other_advs = other_advs - self.person = fixture.users[person] - - def __enter__(self): - self.fixture.visit = self - return self - - def _check_other_perms(self): - "Test all other users not tested in the previous loop" - if None not in self.visitors_perms_seen: - self.fixture.assertVisit(WhenView(person=self.person), ThenPerms(self.other_perms)) - for u in self.fixture.users.viewkeys() - self.visitors_perms_seen: - self.fixture.assertVisit(WhenView(person=self.person, user=self.fixture.users[u]), ThenPerms(self.other_perms)) - - def _check_other_advs(self): - "Test all other users not tested in the previous loop" - if None not in self.visitors_advs_seen: - self.fixture.assertVisit(WhenView(person=self.person), ThenCanAdv(self.other_advs)) - for u in self.fixture.users.viewkeys() - self.visitors_advs_seen: - self.fixture.assertVisit(WhenView(person=self.person, user=self.fixture.users[u]), ThenCanAdv(self.other_advs)) - -class visit(visit_base): - def __exit__(self, type, value, traceback): - if type is not None: return - self._check_other_perms() - self._check_other_advs() - self.fixture.visit = None - -class visit_perms(visit_base): - def __exit__(self, type, value, traceback): - if type is not None: return - self._check_other_perms() - self.fixture.visit = None - -class visit_advs(visit_base): - def __exit__(self, type, value, traceback): - if type is not None: return - self._check_other_advs() - self.fixture.visit = None - -class PersonTestMixin(NMBasicFixtureMixin, NMTestUtilsMixin): - def assertPerms(self, who, perms=""): - # Go through all combinations of visitors and expected results - for u in who.split(): - if u is None: - self.assertVisit(WhenView(person=self.visit.person), ThenPerms(perms)) - else: - self.assertVisit(WhenView(person=self.visit.person, user=self.users[u]), ThenPerms(perms)) - self.visit.visitors_perms_seen.add(u) - - def assertAdvs(self, who, adv): - # Go through all combinations of visitors and expected results - for u in who.split(): - if u is None: - self.assertVisit(WhenView(person=self.visit.person), ThenCanAdv(adv)) - else: - self.assertVisit(WhenView(person=self.visit.person, user=self.users[u]), ThenCanAdv(adv)) - self.visit.visitors_advs_seen.add(u) - - -class ProcTestMixin(PersonTestMixin): - applying_as = None - applying_for = None - advocate_status = const.STATUS_DD_NU - - def setUp(self): - super(ProcTestMixin, self).setUp() - self.app = self.make_user("app", self.applying_as, alioth=True) - self.adv = self.make_user("adv", self.advocate_status) - self.am = self.make_user("am", const.STATUS_DD_NU) - self.am_am = bmodels.AM.objects.create(person=self.am) - self.proc = self.make_process(self.app, self.applying_for, const.PROGRESS_APP_RCVD) - - def assertAdvsInitial(self): self.fail("Not implemented") - def assertAdvsAdv(self): self.fail("Not implemented") - def assertAdvsAdvAM(self): self.fail("Not implemented") - def assertAdvsFDDAM(self): self.fail("Not implemented") - def assertAdvsDone(self): self.fail("Not implemented") - - def test_advs(self): - self.proc.advocates.clear() - self.proc.manager = None - self.proc.save() - - # States without advocates and AMs - for p in (const.PROGRESS_APP_NEW, const.PROGRESS_APP_RCVD, const.PROGRESS_APP_HOLD, const.PROGRESS_ADV_RCVD, const.PROGRESS_POLL_SENT): - self.proc.progress = p - self.proc.save() - with visit_advs(self, "app"): - self.assertAdvsInitial() - - # States with advocates and no AMs - self.proc.advocates.add(self.adv) - for p in (const.PROGRESS_APP_OK,): - self.proc.progress = p - self.proc.save() - with visit_advs(self, "app"): - self.assertAdvsAdv() - - # States with advocates and AMs - self.proc.manager = self.am_am - for p in (const.PROGRESS_AM_RCVD, const.PROGRESS_AM, const.PROGRESS_AM_HOLD): - self.proc.progress = p - self.proc.save() - with visit_advs(self, "app"): - self.assertAdvsAdvAM() - - # States after the AM - for p in (const.PROGRESS_AM_OK, const.PROGRESS_FD_HOLD, const.PROGRESS_FD_OK, const.PROGRESS_DAM_HOLD, const.PROGRESS_DAM_OK): - self.proc.progress = p - self.proc.save() - - with visit_advs(self, "app"): - self.assertAdvsFDDAM() - - # Final states - self.app.status = self.applying_for - self.app.save(audit_skip=True) - for p in (const.PROGRESS_DONE, const.PROGRESS_CANCELLED): - self.proc.progress = p - self.proc.is_active = False - self.proc.save() - - with visit_advs(self, "app"): - self.assertAdvsDone() - - # Standard behaviour - def assertPermsInitial(self): - self.assertPerms("fd dam app", "update_keycheck edit_bio edit_ldap view_person_audit_log") - self.assertPerms("adv dd_nu dd_u am", "view_person_audit_log") - def assertPermsAdv(self): - self.assertPerms("fd dam adv app", "update_keycheck edit_bio edit_ldap view_person_audit_log") - self.assertPerms("dd_nu dd_u am", "view_person_audit_log") - def assertPermsAdvAM(self): - self.assertPerms("fd dam adv am app", "update_keycheck edit_bio edit_ldap view_person_audit_log") - self.assertPerms("dd_nu dd_u", "view_person_audit_log") - def assertPermsFDDAM(self): - self.assertPerms("fd dam", "update_keycheck edit_bio edit_ldap view_person_audit_log") - self.assertPerms("app", "update_keycheck edit_bio view_person_audit_log") - self.assertPerms("adv dd_nu dd_u am", "view_person_audit_log") - def assertPermsDone(self): - self.assertPerms("fd dam app", "update_keycheck edit_bio view_person_audit_log") - self.assertPerms("adv dd_nu dd_u am", "view_person_audit_log") - - def test_perms(self): - self.proc.advocates.clear() - self.proc.manager = None - self.proc.save() - - # States without advocates and AMs - for p in (const.PROGRESS_APP_NEW, const.PROGRESS_APP_RCVD, const.PROGRESS_APP_HOLD, const.PROGRESS_ADV_RCVD, const.PROGRESS_POLL_SENT): - self.proc.progress = p - self.proc.save() - with visit_perms(self, "app"): - self.assertPermsInitial() - - # States with advocates and no AMs - self.proc.advocates.add(self.adv) - for p in (const.PROGRESS_APP_OK,): - self.proc.progress = p - self.proc.save() - with visit_perms(self, "app"): - self.assertPermsAdv() - - # States with advocates and AMs - self.proc.manager = self.am_am - for p in (const.PROGRESS_AM_RCVD, const.PROGRESS_AM, const.PROGRESS_AM_HOLD): - self.proc.progress = p - self.proc.save() - with visit_perms(self, "app"): - self.assertPermsAdvAM() - - # States after the AM - for p in (const.PROGRESS_AM_OK, const.PROGRESS_FD_HOLD, const.PROGRESS_FD_OK, const.PROGRESS_DAM_HOLD, const.PROGRESS_DAM_OK): - self.proc.progress = p - self.proc.save() - - with visit_perms(self, "app"): - self.assertPermsFDDAM() - - # Final states - self.app.status = self.applying_for - self.app.save(audit_skip=True) - for p in (const.PROGRESS_DONE, const.PROGRESS_CANCELLED): - self.proc.progress = p - self.proc.is_active = False - self.proc.save() - - with visit_perms(self, "app"): - self.assertPermsDone() - - -class ProcDcDdnuTestCase(ProcTestMixin, TestCase): - """ - Test all visit combinations for an applicant from dc to dd_nu, with dd_nu advocate - """ - applying_as = const.STATUS_DC - applying_for = const.STATUS_DD_NU - advocate_status = const.STATUS_DD_NU - - def assertAdvsInitial(self): - self.assertAdvs("fd dam adv am dd_nu dd_u", "dc_ga dm dd_u dd_nu") - self.assertAdvs("dm dm_ga", "dc_ga") - def assertAdvsAdv(self): - self.assertAdvs("fd dam am dd_nu dd_u", "dc_ga dm dd_u dd_nu") - self.assertAdvs("dm dm_ga", "dc_ga") - self.assertAdvs("adv", "dc_ga dm") - def assertAdvsAdvAM(self): - self.assertAdvs("fd dam dd_nu dd_u", "dc_ga dm dd_u dd_nu") - self.assertAdvs("dm dm_ga", "dc_ga") - self.assertAdvs("adv am", "dc_ga dm") - def assertAdvsFDDAM(self): - self.assertAdvs("fd dam adv am dd_nu dd_u", "dc_ga dm") - self.assertAdvs("dm dm_ga", "dc_ga") - def assertAdvsDone(self): - pass - -class ProcDcgaDdnuTestCase(ProcTestMixin, TestCase): - """ - Test all visit combinations for an applicant from dc to dc_ga, with a dm advocate - """ - applying_as = const.STATUS_DC_GA - applying_for = const.STATUS_DD_NU - advocate_status = const.STATUS_DD_NU - - def assertAdvsInitial(self): - self.assertAdvs("fd dam adv am dd_nu dd_u", "dm_ga dd_u dd_nu") - def assertAdvsAdv(self): - self.assertAdvs("fd dam am dd_nu dd_u", "dm_ga dd_u dd_nu") - self.assertAdvs("adv", "dm_ga") - def assertAdvsAdvAM(self): - self.assertAdvs("fd dam dd_nu dd_u", "dm_ga dd_u dd_nu") - self.assertAdvs("adv am", "dm_ga") - def assertAdvsFDDAM(self): - self.assertAdvs("fd dam adv am dd_nu dd_u", "dm_ga") - def assertAdvsDone(self): - pass - - def assertPermsInitial(self): - self.assertPerms("fd dam app", "update_keycheck edit_bio view_person_audit_log") - self.assertPerms("adv dd_nu dd_u am", "view_person_audit_log") - def assertPermsAdv(self): - self.assertPerms("fd dam adv app", "update_keycheck edit_bio view_person_audit_log") - self.assertPerms("dd_nu dd_u am", "view_person_audit_log") - def assertPermsAdvAM(self): - self.assertPerms("fd dam adv am app", "update_keycheck edit_bio view_person_audit_log") - self.assertPerms("dd_nu dd_u", "view_person_audit_log") - def assertPermsFDDAM(self): - self.assertPerms("fd dam", "update_keycheck edit_bio view_person_audit_log") - self.assertPerms("app", "update_keycheck edit_bio view_person_audit_log") - self.assertPerms("adv dd_nu dd_u am", "view_person_audit_log") - -class ProcDcDduTestCase(ProcTestMixin, TestCase): - """ - Test all visit combinations for an applicant from dc to dc_ga, with a dm advocate - """ - applying_as = const.STATUS_DC - applying_for = const.STATUS_DD_U - advocate_status = const.STATUS_DD_U - - def assertAdvsInitial(self): - self.assertAdvs("fd dam adv am dd_nu dd_u", "dc_ga dm dd_u dd_nu") - self.assertAdvs("dm dm_ga", "dc_ga") - def assertAdvsAdv(self): - self.assertAdvs("fd dam am dd_nu dd_u", "dc_ga dm dd_u dd_nu") - self.assertAdvs("dm dm_ga", "dc_ga") - self.assertAdvs("adv", "dc_ga dm") - def assertAdvsAdvAM(self): - self.assertAdvs("fd dam dd_nu dd_u", "dc_ga dm dd_u dd_nu") - self.assertAdvs("dm dm_ga", "dc_ga") - self.assertAdvs("adv am", "dc_ga dm") - def assertAdvsFDDAM(self): - self.assertAdvs("fd dam adv am dd_nu dd_u", "dc_ga dm") - self.assertAdvs("dm dm_ga", "dc_ga") - def assertAdvsDone(self): - pass - -class ProcDcgaDduTestCase(ProcTestMixin, TestCase): - """ - Test all visit combinations for an applicant from dc to dc_ga, with a dm advocate - """ - applying_as = const.STATUS_DC_GA - applying_for = const.STATUS_DD_U - advocate_status = const.STATUS_DD_U - - def assertAdvsInitial(self): - self.assertAdvs("fd dam adv am dd_nu dd_u", "dm_ga dd_u dd_nu") - def assertAdvsAdv(self): - self.assertAdvs("fd dam am dd_nu dd_u", "dm_ga dd_u dd_nu") - self.assertAdvs("adv", "dm_ga") - def assertAdvsAdvAM(self): - self.assertAdvs("fd dam dd_nu dd_u", "dm_ga dd_u dd_nu") - self.assertAdvs("adv am", "dm_ga") - def assertAdvsFDDAM(self): - self.assertAdvs("fd dam adv am dd_nu dd_u", "dm_ga") - def assertAdvsDone(self): - pass - - def assertPermsInitial(self): - self.assertPerms("fd dam app", "update_keycheck edit_bio view_person_audit_log") - self.assertPerms("adv dd_nu dd_u am", "view_person_audit_log") - def assertPermsAdv(self): - self.assertPerms("fd dam adv app", "update_keycheck edit_bio view_person_audit_log") - self.assertPerms("dd_nu dd_u am", "view_person_audit_log") - def assertPermsAdvAM(self): - self.assertPerms("fd dam adv am app", "update_keycheck edit_bio view_person_audit_log") - self.assertPerms("dd_nu dd_u", "view_person_audit_log") - def assertPermsFDDAM(self): - self.assertPerms("fd dam", "update_keycheck edit_bio view_person_audit_log") - self.assertPerms("app", "update_keycheck edit_bio view_person_audit_log") - self.assertPerms("adv dd_nu dd_u am", "view_person_audit_log") - -class ProcDmDduTestCase(ProcTestMixin, TestCase): - """ - Test all visit combinations for an applicant from dc to dc_ga, with a dm advocate - """ - applying_as = const.STATUS_DM - applying_for = const.STATUS_DD_U - advocate_status = const.STATUS_DD_U - - def assertAdvsInitial(self): - self.assertAdvs("fd dam adv am dd_nu dd_u", "dm_ga dd_u dd_nu") - self.assertAdvs("app dm dm_ga", "dm_ga") - def assertAdvsAdv(self): - self.assertAdvs("fd dam am dd_nu dd_u", "dm_ga dd_u dd_nu") - self.assertAdvs("adv app dm dm_ga", "dm_ga") - def assertAdvsAdvAM(self): - self.assertAdvs("fd dam dd_nu dd_u", "dm_ga dd_u dd_nu") - self.assertAdvs("adv am app dm dm_ga", "dm_ga") - def assertAdvsFDDAM(self): - self.assertAdvs("fd dam dd_nu dd_u adv am app dm dm_ga", "dm_ga") - def assertAdvsDone(self): - pass - -class ProcDmgaDduTestCase(ProcTestMixin, TestCase): - """ - Test all visit combinations for an applicant from dm_ga to dd_u, with a dd_u advocate - """ - applying_as = const.STATUS_DM_GA - applying_for = const.STATUS_DD_U - advocate_status = const.STATUS_DD_U - - def assertAdvsInitial(self): - self.assertAdvs("fd dam adv am dd_nu dd_u", "dd_u dd_nu") - def assertAdvsAdv(self): - self.assertAdvs("fd dam am dd_nu dd_u", "dd_u dd_nu") - def assertAdvsAdvAM(self): - self.assertAdvs("fd dam dd_nu dd_u", "dd_u dd_nu") - def assertAdvsFDDAM(self): - pass - def assertAdvsDone(self): - pass - - def assertPermsInitial(self): - self.assertPerms("fd dam app", "update_keycheck edit_bio view_person_audit_log") - self.assertPerms("adv dd_nu dd_u am", "view_person_audit_log") - def assertPermsAdv(self): - self.assertPerms("fd dam adv app", "update_keycheck edit_bio view_person_audit_log") - self.assertPerms("dd_nu dd_u am", "view_person_audit_log") - def assertPermsAdvAM(self): - self.assertPerms("fd dam adv am app", "update_keycheck edit_bio view_person_audit_log") - self.assertPerms("dd_nu dd_u", "view_person_audit_log") - def assertPermsFDDAM(self): - self.assertPerms("fd dam", "update_keycheck edit_bio view_person_audit_log") - self.assertPerms("app", "update_keycheck edit_bio view_person_audit_log") - self.assertPerms("adv dd_nu dd_u am", "view_person_audit_log") - def assertPermsDone(self): - self.assertPerms("fd dam app", "update_keycheck edit_bio view_person_audit_log") - self.assertPerms("adv dd_nu dd_u am", "view_person_audit_log") -- GitLab