This commit is contained in:
Rachid Mrad 2023-09-06 15:25:17 -04:00
parent 5fd84b534d
commit 0568928f1a
No known key found for this signature in database
GPG key ID: EF38E4CEC4A8F3CF
3 changed files with 58 additions and 57 deletions

View file

@ -614,8 +614,8 @@ class DomainApplication(TimeStampedModel):
def reject(self):
"""Reject an application that has been submitted.
As a side effect this will delete the domain and domain_information
(will cascade), and send an email notification"""
As side effects this will delete the domain and domain_information
(will cascade), and send an email notification."""
if self.status == self.APPROVED:
self.approved_domain.delete_request()
@ -641,7 +641,7 @@ class DomainApplication(TimeStampedModel):
any existing domains/applications and from submitting new aplications.
We do this by setting an ineligible status on the user, which the
permissions classes test against. This will also delete the domain
and domain_information (will cascade)"""
and domain_information (will cascade) when they exist."""
if self.status == self.APPROVED:
self.approved_domain.delete_request()

View file

@ -1,6 +1,5 @@
from django.test import TestCase, RequestFactory, Client
from django.contrib.admin.sites import AdminSite
from unittest.mock import patch
from contextlib import ExitStack
from django.contrib import messages
@ -457,8 +456,8 @@ class TestDomainApplicationAdmin(TestCase):
# Use ExitStack to combine patch contexts
with ExitStack() as stack:
# Patch Domain.is_active and django.contrib.messages.error simultaneously
stack.enter_context(patch.object(Domain, 'is_active', custom_is_active))
stack.enter_context(patch.object(messages, 'error'))
stack.enter_context(patch.object(Domain, "is_active", custom_is_active))
stack.enter_context(patch.object(messages, "error"))
# Simulate saving the model
application.status = DomainApplication.REJECTED
@ -467,15 +466,16 @@ class TestDomainApplicationAdmin(TestCase):
# Assert that the error message was called with the correct argument
messages.error.assert_called_once_with(
request,
"This action is not permitted, the domain "
+ "is already active.",
"This action is not permitted, the domain " + "is already active.",
)
def test_side_effects_when_saving_approved_to_rejected(self):
# Create an instance of the model
application = completed_application(status=DomainApplication.APPROVED)
domain = Domain.objects.create(name=application.requested_domain.name)
domain_information = DomainInformation.objects.create(creator=self.superuser, domain=domain)
domain_information = DomainInformation.objects.create(
creator=self.superuser, domain=domain
)
application.approved_domain = domain
application.save()
@ -492,8 +492,8 @@ class TestDomainApplicationAdmin(TestCase):
# Use ExitStack to combine patch contexts
with ExitStack() as stack:
# Patch Domain.is_active and django.contrib.messages.error simultaneously
stack.enter_context(patch.object(Domain, 'is_active', custom_is_active))
stack.enter_context(patch.object(messages, 'error'))
stack.enter_context(patch.object(Domain, "is_active", custom_is_active))
stack.enter_context(patch.object(messages, "error"))
# Simulate saving the model
application.status = DomainApplication.REJECTED
@ -532,8 +532,8 @@ class TestDomainApplicationAdmin(TestCase):
# Use ExitStack to combine patch contexts
with ExitStack() as stack:
# Patch Domain.is_active and django.contrib.messages.error simultaneously
stack.enter_context(patch.object(Domain, 'is_active', custom_is_active))
stack.enter_context(patch.object(messages, 'error'))
stack.enter_context(patch.object(Domain, "is_active", custom_is_active))
stack.enter_context(patch.object(messages, "error"))
# Simulate saving the model
application.status = DomainApplication.INELIGIBLE
@ -542,15 +542,16 @@ class TestDomainApplicationAdmin(TestCase):
# Assert that the error message was called with the correct argument
messages.error.assert_called_once_with(
request,
"This action is not permitted, the domain "
+ "is already active.",
"This action is not permitted, the domain " + "is already active.",
)
def test_side_effects_when_saving_approved_to_ineligible(self):
# Create an instance of the model
application = completed_application(status=DomainApplication.APPROVED)
domain = Domain.objects.create(name=application.requested_domain.name)
domain_information = DomainInformation.objects.create(creator=self.superuser, domain=domain)
domain_information = DomainInformation.objects.create(
creator=self.superuser, domain=domain
)
application.approved_domain = domain
application.save()
@ -567,8 +568,8 @@ class TestDomainApplicationAdmin(TestCase):
# Use ExitStack to combine patch contexts
with ExitStack() as stack:
# Patch Domain.is_active and django.contrib.messages.error simultaneously
stack.enter_context(patch.object(Domain, 'is_active', custom_is_active))
stack.enter_context(patch.object(messages, 'error'))
stack.enter_context(patch.object(Domain, "is_active", custom_is_active))
stack.enter_context(patch.object(messages, "error"))
# Simulate saving the model
application.status = DomainApplication.INELIGIBLE

View file

@ -456,7 +456,7 @@ class TestDomainApplication(TestCase):
return True # Override to return True
# Use patch to temporarily replace is_active with the custom implementation
with patch.object(Domain, 'is_active', custom_is_active):
with patch.object(Domain, "is_active", custom_is_active):
# Now, when you call is_active on Domain, it will return True
with self.assertRaises(TransitionNotAllowed):
application.reject()
@ -529,7 +529,7 @@ class TestDomainApplication(TestCase):
return True # Override to return True
# Use patch to temporarily replace is_active with the custom implementation
with patch.object(Domain, 'is_active', custom_is_active):
with patch.object(Domain, "is_active", custom_is_active):
# Now, when you call is_active on Domain, it will return True
with self.assertRaises(TransitionNotAllowed):
application.reject_with_prejudice()