test case written

This commit is contained in:
David Kennedy 2024-03-21 15:09:02 -04:00
parent 1179a6a6b7
commit 100e3cf300
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
2 changed files with 15 additions and 1 deletions

View file

@ -665,6 +665,20 @@ class TestDomainManagers(TestDomainOverview):
with self.assertRaises(DomainInvitation.DoesNotExist):
DomainInvitation.objects.get(id=invitation.id)
def test_domain_invitation_cancel_retrieved_invitation(self):
"""Posting to the delete view when invitation retrieved returns an error message"""
email_address = "mayor@igorville.gov"
invitation, _ = DomainInvitation.objects.get_or_create(domain=self.domain, email=email_address, status=DomainInvitation.DomainInvitationStatus.RETRIEVED)
with less_console_noise():
response = self.client.post(reverse("invitation-delete", kwargs={"pk": invitation.id}), follow=True)
# Assert that an error message is displayed to the user
self.assertContains(response, f"Invitation to {email_address} has already been retrieved.")
# Assert that the Cancel link is not displayed
self.assertNotContains(response, "Cancel")
# Assert that the DomainInvitation is not deleted
self.assertTrue(DomainInvitation.objects.filter(id=invitation.id).exists())
DomainInvitation.objects.filter(email=email_address).delete()
def test_domain_invitation_cancel_no_permissions(self):
"""Posting to the delete view as a different user should fail."""
email_address = "mayor@igorville.gov"

View file

@ -831,7 +831,7 @@ class DomainInvitationDeleteView(SuccessMessageMixin, DomainInvitationPermission
return self.form_valid(form)
else:
# Produce an error message if the domain invatation status is RETRIEVED
messages.error(request, f"Invitation to {self.object.email} has already been retrieved")
messages.error(request, f"Invitation to {self.object.email} has already been retrieved.")
return HttpResponseRedirect(self.get_success_url())
def get_success_url(self):