Simplify test cases further, linting

This commit is contained in:
zandercymatics 2024-02-26 15:02:54 -07:00
parent 3b4e470f0c
commit 3d6f638462
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
3 changed files with 33 additions and 91 deletions

View file

@ -849,7 +849,7 @@ class DomainApplicationAdminForm(forms.ModelForm):
DomainApplication.ApplicationStatus.IN_REVIEW,
DomainApplication.ApplicationStatus.ACTION_NEEDED,
DomainApplication.ApplicationStatus.REJECTED,
DomainApplication.ApplicationStatus.INELIGIBLE
DomainApplication.ApplicationStatus.INELIGIBLE,
]
# If a status change occured, check for validity

View file

@ -731,7 +731,7 @@ class DomainApplication(TimeStampedModel):
ApplicationStatus.REJECTED,
],
target=ApplicationStatus.APPROVED,
conditions=[investigator_exists_and_is_staff]
conditions=[investigator_exists_and_is_staff],
)
def approve(self, send_email=True):
"""Approve an application that has been submitted.

View file

@ -249,6 +249,19 @@ class TestDomainApplication(TestCase):
# Call the method
method()
def assert_fsm_transition_does_not_raise_error(self, test_cases, method_to_run):
"""Given a list of test cases, ensure that none of them throw transition errors"""
with boto3_mocking.clients.handler_for("sesv2", self.mock_client), less_console_noise():
for application, exception_type in test_cases:
with self.subTest(application=application, exception_type=exception_type):
try:
# Retrieve the method by name from the application object and call it
method = getattr(application, method_to_run)
# Call the method
method()
except exception_type:
self.fail(f"{exception_type} was raised, but it was not expected.")
def test_submit_transition_allowed_with_no_investigator(self):
"""
Tests for attempting to transition without an investigator.
@ -263,13 +276,7 @@ class TestDomainApplication(TestCase):
# Set all investigators to none
set_applications_investigators(self.all_applications, None)
with boto3_mocking.clients.handler_for("sesv2", self.mock_client), less_console_noise():
for application, exception_type in test_cases:
with self.subTest(application=application, exception_type=exception_type):
try:
application.submit()
except TransitionNotAllowed:
self.fail("TransitionNotAllowed was raised, but it was not expected.")
self.assert_fsm_transition_does_not_raise_error(test_cases, "submit")
def test_submit_transition_allowed_with_investigator_not_staff(self):
"""
@ -286,13 +293,7 @@ class TestDomainApplication(TestCase):
user, _ = User.objects.get_or_create(username="pancakesyrup", is_staff=False)
set_applications_investigators(self.all_applications, user)
with boto3_mocking.clients.handler_for("sesv2", self.mock_client), less_console_noise():
for application, exception_type in test_cases:
with self.subTest(application=application, exception_type=exception_type):
try:
application.submit()
except TransitionNotAllowed:
self.fail("TransitionNotAllowed was raised, but it was not expected.")
self.assert_fsm_transition_does_not_raise_error(test_cases, "submit")
def test_submit_transition_allowed(self):
"""
@ -305,14 +306,7 @@ class TestDomainApplication(TestCase):
(self.withdrawn_application, TransitionNotAllowed),
]
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
with less_console_noise():
for application, exception_type in test_cases:
with self.subTest(application=application, exception_type=exception_type):
try:
application.submit()
except TransitionNotAllowed:
self.fail("TransitionNotAllowed was raised, but it was not expected.")
self.assert_fsm_transition_does_not_raise_error(test_cases, "submit")
def test_submit_transition_allowed_twice(self):
"""
@ -359,14 +353,7 @@ class TestDomainApplication(TestCase):
(self.ineligible_application, TransitionNotAllowed),
]
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
with less_console_noise():
for application, exception_type in test_cases:
with self.subTest(application=application, exception_type=exception_type):
try:
application.in_review()
except TransitionNotAllowed:
self.fail("TransitionNotAllowed was raised, but it was not expected.")
self.assert_fsm_transition_does_not_raise_error(test_cases, "in_review")
def test_in_review_transition_not_allowed_with_no_investigator(self):
"""
@ -426,13 +413,8 @@ class TestDomainApplication(TestCase):
(self.rejected_application, TransitionNotAllowed),
(self.ineligible_application, TransitionNotAllowed),
]
with less_console_noise():
for application, exception_type in test_cases:
with self.subTest(application=application, exception_type=exception_type):
try:
application.action_needed()
except TransitionNotAllowed:
self.fail("TransitionNotAllowed was raised, but it was not expected.")
self.assert_fsm_transition_does_not_raise_error(test_cases, "action_needed")
def test_action_needed_transition_not_allowed_with_no_investigator(self):
"""
@ -493,14 +475,7 @@ class TestDomainApplication(TestCase):
(self.rejected_application, TransitionNotAllowed),
]
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
with less_console_noise():
for application, exception_type in test_cases:
with self.subTest(application=application, exception_type=exception_type):
try:
application.approve()
except TransitionNotAllowed:
self.fail("TransitionNotAllowed was raised, but it was not expected.")
self.assert_fsm_transition_does_not_raise_error(test_cases, "approve")
def test_approved_transition_not_allowed_with_no_investigator(self):
"""
@ -570,14 +545,7 @@ class TestDomainApplication(TestCase):
(self.action_needed_application, TransitionNotAllowed),
]
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
with less_console_noise():
for application, exception_type in test_cases:
with self.subTest(application=application, exception_type=exception_type):
try:
application.withdraw()
except TransitionNotAllowed:
self.fail("TransitionNotAllowed was raised, but it was not expected.")
self.assert_fsm_transition_does_not_raise_error(test_cases, "withdraw")
def test_withdraw_transition_allowed_with_no_investigator(self):
"""
@ -594,13 +562,7 @@ class TestDomainApplication(TestCase):
# Set all investigators to none
set_applications_investigators(self.all_applications, None)
with boto3_mocking.clients.handler_for("sesv2", self.mock_client), less_console_noise():
for application, exception_type in test_cases:
with self.subTest(application=application, exception_type=exception_type):
try:
application.withdraw()
except TransitionNotAllowed:
self.fail("TransitionNotAllowed was raised, but it was not expected.")
self.assert_fsm_transition_does_not_raise_error(test_cases, "withdraw")
def test_withdraw_transition_allowed_with_investigator_not_staff(self):
"""
@ -618,13 +580,7 @@ class TestDomainApplication(TestCase):
user, _ = User.objects.get_or_create(username="pancakesyrup", is_staff=False)
set_applications_investigators(self.all_applications, user)
with boto3_mocking.clients.handler_for("sesv2", self.mock_client), less_console_noise():
for application, exception_type in test_cases:
with self.subTest(application=application, exception_type=exception_type):
try:
application.withdraw()
except TransitionNotAllowed:
self.fail("TransitionNotAllowed was raised, but it was not expected.")
self.assert_fsm_transition_does_not_raise_error(test_cases, "withdraw")
def test_withdraw_transition_not_allowed(self):
"""
@ -650,14 +606,7 @@ class TestDomainApplication(TestCase):
(self.approved_application, TransitionNotAllowed),
]
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
with less_console_noise():
for application, exception_type in test_cases:
with self.subTest(application=application, exception_type=exception_type):
try:
application.reject()
except TransitionNotAllowed:
self.fail("TransitionNotAllowed was raised, but it was not expected.")
self.assert_fsm_transition_does_not_raise_error(test_cases, "reject")
def test_reject_transition_not_allowed_with_no_investigator(self):
"""
@ -717,14 +666,7 @@ class TestDomainApplication(TestCase):
(self.rejected_application, TransitionNotAllowed),
]
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
with less_console_noise():
for application, exception_type in test_cases:
with self.subTest(application=application, exception_type=exception_type):
try:
application.reject_with_prejudice()
except TransitionNotAllowed:
self.fail("TransitionNotAllowed was raised, but it was not expected.")
self.assert_fsm_transition_does_not_raise_error(test_cases, "reject_with_prejudice")
def test_reject_with_prejudice_transition_not_allowed_with_no_investigator(self):
"""