mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-17 10:07:04 +02:00
removed data calculation from renew_domain dja function
This commit is contained in:
parent
2ec954ff1d
commit
d0d4fbdb5f
5 changed files with 4 additions and 61 deletions
|
@ -13,7 +13,6 @@ from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
||||||
from django.contrib.auth.models import Group
|
from django.contrib.auth.models import Group
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from dateutil.relativedelta import relativedelta # type: ignore
|
|
||||||
from epplibwrapper.errors import ErrorCode, RegistryError
|
from epplibwrapper.errors import ErrorCode, RegistryError
|
||||||
from registrar.models.user_domain_role import UserDomainRole
|
from registrar.models.user_domain_role import UserDomainRole
|
||||||
from waffle.admin import FlagAdmin
|
from waffle.admin import FlagAdmin
|
||||||
|
@ -2196,24 +2195,8 @@ class DomainAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
extra_context["state_help_message"] = Domain.State.get_admin_help_text(domain.state)
|
extra_context["state_help_message"] = Domain.State.get_admin_help_text(domain.state)
|
||||||
extra_context["domain_state"] = domain.get_state_display()
|
extra_context["domain_state"] = domain.get_state_display()
|
||||||
|
|
||||||
# Pass in what the an extended expiration date would be for the expiration date modal
|
|
||||||
self._set_expiration_date_context(domain, extra_context)
|
|
||||||
|
|
||||||
return super().changeform_view(request, object_id, form_url, extra_context)
|
return super().changeform_view(request, object_id, form_url, extra_context)
|
||||||
|
|
||||||
def _set_expiration_date_context(self, domain, extra_context):
|
|
||||||
"""Given a domain, calculate the an extended expiration date
|
|
||||||
from the current registry expiration date."""
|
|
||||||
years_to_extend_by = self._get_calculated_years_for_exp_date(domain)
|
|
||||||
try:
|
|
||||||
curr_exp_date = domain.registry_expiration_date
|
|
||||||
except KeyError:
|
|
||||||
# No expiration date was found. Return none.
|
|
||||||
extra_context["extended_expiration_date"] = None
|
|
||||||
else:
|
|
||||||
new_date = curr_exp_date + relativedelta(years=years_to_extend_by)
|
|
||||||
extra_context["extended_expiration_date"] = new_date
|
|
||||||
|
|
||||||
def response_change(self, request, obj):
|
def response_change(self, request, obj):
|
||||||
# Create dictionary of action functions
|
# Create dictionary of action functions
|
||||||
ACTION_FUNCTIONS = {
|
ACTION_FUNCTIONS = {
|
||||||
|
@ -2241,11 +2224,9 @@ class DomainAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
self.message_user(request, "Object is not of type Domain.", messages.ERROR)
|
self.message_user(request, "Object is not of type Domain.", messages.ERROR)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
years = self._get_calculated_years_for_exp_date(obj)
|
|
||||||
|
|
||||||
# Renew the domain.
|
# Renew the domain.
|
||||||
try:
|
try:
|
||||||
obj.renew_domain(length=years)
|
obj.renew_domain()
|
||||||
self.message_user(
|
self.message_user(
|
||||||
request,
|
request,
|
||||||
"Successfully extended the expiration date.",
|
"Successfully extended the expiration date.",
|
||||||
|
@ -2270,37 +2251,6 @@ class DomainAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
|
|
||||||
return HttpResponseRedirect(".")
|
return HttpResponseRedirect(".")
|
||||||
|
|
||||||
def _get_calculated_years_for_exp_date(self, obj, extension_period: int = 1):
|
|
||||||
"""Given the current date, an extension period, and a registry_expiration_date
|
|
||||||
on the domain object, calculate the number of years needed to extend the
|
|
||||||
current expiration date by the extension period.
|
|
||||||
"""
|
|
||||||
# Get the date we want to update to
|
|
||||||
desired_date = self._get_current_date() + relativedelta(years=extension_period)
|
|
||||||
|
|
||||||
# Grab the current expiration date
|
|
||||||
try:
|
|
||||||
exp_date = obj.registry_expiration_date
|
|
||||||
except KeyError:
|
|
||||||
# if no expiration date from registry, set it to today
|
|
||||||
logger.warning("current expiration date not set; setting to today")
|
|
||||||
exp_date = self._get_current_date()
|
|
||||||
|
|
||||||
# If the expiration date is super old (2020, for example), we need to
|
|
||||||
# "catch up" to the current year, so we add the difference.
|
|
||||||
# If both years match, then lets just proceed as normal.
|
|
||||||
calculated_exp_date = exp_date + relativedelta(years=extension_period)
|
|
||||||
|
|
||||||
year_difference = desired_date.year - exp_date.year
|
|
||||||
|
|
||||||
years = extension_period
|
|
||||||
if desired_date > calculated_exp_date:
|
|
||||||
# Max probably isn't needed here (no code flow), but it guards against negative and 0.
|
|
||||||
# In both of those cases, we just want to extend by the extension_period.
|
|
||||||
years = max(extension_period, year_difference)
|
|
||||||
|
|
||||||
return years
|
|
||||||
|
|
||||||
# Workaround for unit tests, as we cannot mock date directly.
|
# Workaround for unit tests, as we cannot mock date directly.
|
||||||
# it is immutable. Rather than dealing with a convoluted workaround,
|
# it is immutable. Rather than dealing with a convoluted workaround,
|
||||||
# lets wrap this in a function.
|
# lets wrap this in a function.
|
||||||
|
|
|
@ -69,16 +69,13 @@
|
||||||
</h2>
|
</h2>
|
||||||
<div class="usa-prose">
|
<div class="usa-prose">
|
||||||
<p>
|
<p>
|
||||||
This will extend the expiration date by one year.
|
This will extend the expiration date by one year from today.
|
||||||
{# Acts as a <br> #}
|
{# Acts as a <br> #}
|
||||||
<div class="display-inline"></div>
|
<div class="display-inline"></div>
|
||||||
This action cannot be undone.
|
This action cannot be undone.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Domain: <b>{{ original.name }}</b>
|
Domain: <b>{{ original.name }}</b>
|
||||||
{# Acts as a <br> #}
|
|
||||||
<div class="display-inline"></div>
|
|
||||||
New expiration date: <b>{{ extended_expiration_date }}</b>
|
|
||||||
{{test}}
|
{{test}}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1543,8 +1543,6 @@ class MockEppLib(TestCase):
|
||||||
def mockInfoDomainCommands(self, _request, cleaned):
|
def mockInfoDomainCommands(self, _request, cleaned):
|
||||||
request_name = getattr(_request, "name", None).lower()
|
request_name = getattr(_request, "name", None).lower()
|
||||||
|
|
||||||
print(request_name)
|
|
||||||
|
|
||||||
# Define a dictionary to map request names to data and extension values
|
# Define a dictionary to map request names to data and extension values
|
||||||
request_mappings = {
|
request_mappings = {
|
||||||
"security.gov": (self.infoDomainNoContact, None),
|
"security.gov": (self.infoDomainNoContact, None),
|
||||||
|
|
|
@ -374,9 +374,9 @@ class TestDomainAdmin(MockEppLib, WebTest):
|
||||||
|
|
||||||
# Create a ready domain with a preset expiration date
|
# Create a ready domain with a preset expiration date
|
||||||
domain, _ = Domain.objects.get_or_create(name="fake.gov", state=Domain.State.READY)
|
domain, _ = Domain.objects.get_or_create(name="fake.gov", state=Domain.State.READY)
|
||||||
|
|
||||||
response = self.app.get(reverse("admin:registrar_domain_change", args=[domain.pk]))
|
response = self.app.get(reverse("admin:registrar_domain_change", args=[domain.pk]))
|
||||||
|
# load expiration date into cache and registrar with below command
|
||||||
|
domain.registry_expiration_date
|
||||||
# Make sure the ex date is what we expect it to be
|
# Make sure the ex date is what we expect it to be
|
||||||
domain_ex_date = Domain.objects.get(id=domain.id).expiration_date
|
domain_ex_date = Domain.objects.get(id=domain.id).expiration_date
|
||||||
self.assertEqual(domain_ex_date, date(2023, 5, 25))
|
self.assertEqual(domain_ex_date, date(2023, 5, 25))
|
||||||
|
@ -400,7 +400,6 @@ class TestDomainAdmin(MockEppLib, WebTest):
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertContains(response, domain.name)
|
self.assertContains(response, domain.name)
|
||||||
self.assertContains(response, "Extend expiration date")
|
self.assertContains(response, "Extend expiration date")
|
||||||
self.assertContains(response, "New expiration date: <b>May 25, 2025</b>")
|
|
||||||
|
|
||||||
# Ensure the message we recieve is in line with what we expect
|
# Ensure the message we recieve is in line with what we expect
|
||||||
expected_message = "Successfully extended the expiration date."
|
expected_message = "Successfully extended the expiration date."
|
||||||
|
|
|
@ -735,7 +735,6 @@ class ExportDataTest(MockDb, MockEppLib):
|
||||||
csv_file.seek(0)
|
csv_file.seek(0)
|
||||||
# Read the content into a variable
|
# Read the content into a variable
|
||||||
csv_content = csv_file.read()
|
csv_content = csv_file.read()
|
||||||
print(csv_content)
|
|
||||||
self.maxDiff = None
|
self.maxDiff = None
|
||||||
expected_content = (
|
expected_content = (
|
||||||
# Header
|
# Header
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue