mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-13 04:59:59 +02:00
minor formatting and linting changes
This commit is contained in:
parent
5398a81d24
commit
7e18f7f8d1
3 changed files with 73 additions and 66 deletions
|
@ -49,7 +49,6 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
self._cache = {}
|
||||
super(Domain, self).__init__(*args, **kwargs)
|
||||
|
||||
|
||||
class Status(models.TextChoices):
|
||||
"""
|
||||
The status codes we can receive from the registry.
|
||||
|
@ -103,7 +102,6 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
PENDING_TRANSFER = "pendingTransfer"
|
||||
PENDING_UPDATE = "pendingUpdate"
|
||||
|
||||
|
||||
class State(models.TextChoices):
|
||||
"""These capture (some of) the states a domain object can be in."""
|
||||
|
||||
|
@ -116,7 +114,6 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
# the state is indeterminate
|
||||
UNKNOWN = "unknown"
|
||||
|
||||
|
||||
class Cache(property):
|
||||
"""
|
||||
Python descriptor to turn class methods into properties.
|
||||
|
@ -149,7 +146,6 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
"""Called during delete. Example: `del domain.registrant`."""
|
||||
super().__delete__(obj)
|
||||
|
||||
|
||||
@classmethod
|
||||
def available(cls, domain: str) -> bool:
|
||||
"""Check if a domain is available."""
|
||||
|
@ -541,7 +537,9 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
"tr_date": getattr(data, "tr_date", ...),
|
||||
"up_date": getattr(data, "up_date", ...),
|
||||
}
|
||||
cleaned["hosts"].append({k: v for k, v in host.items() if v is not ...})
|
||||
cleaned["hosts"].append(
|
||||
{k: v for k, v in host.items() if v is not ...}
|
||||
)
|
||||
|
||||
# replace the prior cache with new data
|
||||
self._cache = cleaned
|
||||
|
|
|
@ -2,26 +2,33 @@ from django.test import TestCase
|
|||
from django.db.utils import IntegrityError
|
||||
from unittest.mock import patch, MagicMock
|
||||
import datetime
|
||||
from registrar.models import (
|
||||
DomainApplication,
|
||||
User,
|
||||
Domain
|
||||
)
|
||||
from registrar.models import DomainApplication, User, Domain
|
||||
from unittest import skip
|
||||
from epplibwrapper import commands
|
||||
|
||||
|
||||
class TestDomain(TestCase):
|
||||
class fakedEppObject(object):
|
||||
""""""
|
||||
|
||||
def __init__(self, auth_info=..., cr_date=..., contacts=..., hosts=...):
|
||||
self.auth_info = auth_info
|
||||
self.cr_date = cr_date
|
||||
self.contacts = contacts
|
||||
self.hosts = hosts
|
||||
|
||||
mockDataInfoDomain=fakedEppObject("fakepw",cr_date= datetime.datetime(2023, 5, 25, 19, 45, 35), contacts=["123"], hosts=["fake.host.com"])
|
||||
mockDataInfoContact=fakedEppObject("anotherPw", cr_date=datetime.datetime(2023, 7, 25, 19, 45, 35))
|
||||
mockDataInfoHosts=fakedEppObject("lastPw", cr_date=datetime.datetime(2023, 8, 25, 19, 45, 35))
|
||||
mockDataInfoDomain = fakedEppObject(
|
||||
"fakepw",
|
||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||
contacts=["123"],
|
||||
hosts=["fake.host.com"],
|
||||
)
|
||||
mockDataInfoContact = fakedEppObject(
|
||||
"anotherPw", cr_date=datetime.datetime(2023, 7, 25, 19, 45, 35)
|
||||
)
|
||||
mockDataInfoHosts = fakedEppObject(
|
||||
"lastPw", cr_date=datetime.datetime(2023, 8, 25, 19, 45, 35)
|
||||
)
|
||||
|
||||
def mockSend(self, _request, cleaned):
|
||||
""""""
|
||||
|
@ -56,9 +63,10 @@ class TestDomain(TestCase):
|
|||
"""Cache should be set on getter and reset on setter calls"""
|
||||
domain, _ = Domain.objects.get_or_create(name="igorville.gov")
|
||||
# trigger getter
|
||||
_val=domain.creation_date
|
||||
_ = domain.creation_date
|
||||
|
||||
#getter should set the domain cache with a InfoDomain object (see InfoDomainResult)
|
||||
# getter should set the domain cache with a InfoDomain object
|
||||
# (see InfoDomainResult)
|
||||
self.assertEquals(domain._cache["auth_info"], self.mockDataInfoDomain.auth_info)
|
||||
self.assertEquals(domain._cache["cr_date"], self.mockDataInfoDomain.cr_date)
|
||||
self.assertFalse("avail" in domain._cache.keys())
|
||||
|
@ -85,18 +93,20 @@ class TestDomain(TestCase):
|
|||
# send was only called once & not on the second getter call
|
||||
self.mock_foo.assert_called_once()
|
||||
|
||||
|
||||
def test_cache_nested_elements(self):
|
||||
"""Cache works correctly with the nested objects cache and hosts"""
|
||||
domain, _ = Domain.objects.get_or_create(name="igorville.gov")
|
||||
|
||||
# the cached contacts and hosts should be dictionaries of what is passed to them
|
||||
expectedContactsDict={'id':self.mockDataInfoDomain.contacts[0],
|
||||
'auth_info':self.mockDataInfoContact.auth_info,
|
||||
'cr_date':self.mockDataInfoContact.cr_date
|
||||
expectedContactsDict = {
|
||||
"id": self.mockDataInfoDomain.contacts[0],
|
||||
"auth_info": self.mockDataInfoContact.auth_info,
|
||||
"cr_date": self.mockDataInfoContact.cr_date,
|
||||
}
|
||||
expectedHostsDict = {
|
||||
"name": self.mockDataInfoDomain.hosts[0],
|
||||
"cr_date": self.mockDataInfoHosts.cr_date,
|
||||
}
|
||||
expectedHostsDict={'name':self.mockDataInfoDomain.hosts[0],
|
||||
'cr_date':self.mockDataInfoHosts.cr_date}
|
||||
|
||||
# this can be changed when the getter for contacts is implemented
|
||||
domain._get_property("contacts")
|
||||
|
|
|
@ -137,7 +137,6 @@ class DomainNameserversView(DomainPermissionView, FormMixin):
|
|||
domain = self.get_object()
|
||||
return [{"server": name} for name, *ip in domain.nameservers]
|
||||
|
||||
|
||||
def get_success_url(self):
|
||||
"""Redirect to the nameservers page for the domain."""
|
||||
return reverse("domain-nameservers", kwargs={"pk": self.object.pk})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue