minor formatting and linting changes

This commit is contained in:
Alysia Broddrick 2023-06-15 08:11:33 -07:00
parent 5398a81d24
commit 7e18f7f8d1
No known key found for this signature in database
GPG key ID: 03917052CD0F06B7
3 changed files with 73 additions and 66 deletions

View file

@ -49,7 +49,6 @@ class Domain(TimeStampedModel, DomainHelper):
self._cache = {} self._cache = {}
super(Domain, self).__init__(*args, **kwargs) super(Domain, self).__init__(*args, **kwargs)
class Status(models.TextChoices): class Status(models.TextChoices):
""" """
The status codes we can receive from the registry. The status codes we can receive from the registry.
@ -103,7 +102,6 @@ class Domain(TimeStampedModel, DomainHelper):
PENDING_TRANSFER = "pendingTransfer" PENDING_TRANSFER = "pendingTransfer"
PENDING_UPDATE = "pendingUpdate" PENDING_UPDATE = "pendingUpdate"
class State(models.TextChoices): class State(models.TextChoices):
"""These capture (some of) the states a domain object can be in.""" """These capture (some of) the states a domain object can be in."""
@ -116,7 +114,6 @@ class Domain(TimeStampedModel, DomainHelper):
# the state is indeterminate # the state is indeterminate
UNKNOWN = "unknown" UNKNOWN = "unknown"
class Cache(property): class Cache(property):
""" """
Python descriptor to turn class methods into properties. Python descriptor to turn class methods into properties.
@ -149,7 +146,6 @@ class Domain(TimeStampedModel, DomainHelper):
"""Called during delete. Example: `del domain.registrant`.""" """Called during delete. Example: `del domain.registrant`."""
super().__delete__(obj) super().__delete__(obj)
@classmethod @classmethod
def available(cls, domain: str) -> bool: def available(cls, domain: str) -> bool:
"""Check if a domain is available.""" """Check if a domain is available."""
@ -541,7 +537,9 @@ class Domain(TimeStampedModel, DomainHelper):
"tr_date": getattr(data, "tr_date", ...), "tr_date": getattr(data, "tr_date", ...),
"up_date": getattr(data, "up_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 # replace the prior cache with new data
self._cache = cleaned self._cache = cleaned

View file

@ -2,26 +2,33 @@ from django.test import TestCase
from django.db.utils import IntegrityError from django.db.utils import IntegrityError
from unittest.mock import patch, MagicMock from unittest.mock import patch, MagicMock
import datetime import datetime
from registrar.models import ( from registrar.models import DomainApplication, User, Domain
DomainApplication,
User,
Domain
)
from unittest import skip from unittest import skip
from epplibwrapper import commands from epplibwrapper import commands
class TestDomain(TestCase): class TestDomain(TestCase):
class fakedEppObject(object): class fakedEppObject(object):
"""""" """"""
def __init__(self, auth_info=..., cr_date=..., contacts=..., hosts=...): def __init__(self, auth_info=..., cr_date=..., contacts=..., hosts=...):
self.auth_info = auth_info self.auth_info = auth_info
self.cr_date = cr_date self.cr_date = cr_date
self.contacts = contacts self.contacts = contacts
self.hosts = hosts self.hosts = hosts
mockDataInfoDomain=fakedEppObject("fakepw",cr_date= datetime.datetime(2023, 5, 25, 19, 45, 35), contacts=["123"], hosts=["fake.host.com"]) mockDataInfoDomain = fakedEppObject(
mockDataInfoContact=fakedEppObject("anotherPw", cr_date=datetime.datetime(2023, 7, 25, 19, 45, 35)) "fakepw",
mockDataInfoHosts=fakedEppObject("lastPw", cr_date=datetime.datetime(2023, 8, 25, 19, 45, 35)) 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): def mockSend(self, _request, cleaned):
"""""" """"""
@ -56,9 +63,10 @@ class TestDomain(TestCase):
"""Cache should be set on getter and reset on setter calls""" """Cache should be set on getter and reset on setter calls"""
domain, _ = Domain.objects.get_or_create(name="igorville.gov") domain, _ = Domain.objects.get_or_create(name="igorville.gov")
# trigger getter # 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["auth_info"], self.mockDataInfoDomain.auth_info)
self.assertEquals(domain._cache["cr_date"], self.mockDataInfoDomain.cr_date) self.assertEquals(domain._cache["cr_date"], self.mockDataInfoDomain.cr_date)
self.assertFalse("avail" in domain._cache.keys()) 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 # send was only called once & not on the second getter call
self.mock_foo.assert_called_once() self.mock_foo.assert_called_once()
def test_cache_nested_elements(self): def test_cache_nested_elements(self):
"""Cache works correctly with the nested objects cache and hosts""" """Cache works correctly with the nested objects cache and hosts"""
domain, _ = Domain.objects.get_or_create(name="igorville.gov") domain, _ = Domain.objects.get_or_create(name="igorville.gov")
# the cached contacts and hosts should be dictionaries of what is passed to them # the cached contacts and hosts should be dictionaries of what is passed to them
expectedContactsDict={'id':self.mockDataInfoDomain.contacts[0], expectedContactsDict = {
'auth_info':self.mockDataInfoContact.auth_info, "id": self.mockDataInfoDomain.contacts[0],
'cr_date':self.mockDataInfoContact.cr_date "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 # this can be changed when the getter for contacts is implemented
domain._get_property("contacts") domain._get_property("contacts")

View file

@ -137,7 +137,6 @@ class DomainNameserversView(DomainPermissionView, FormMixin):
domain = self.get_object() domain = self.get_object()
return [{"server": name} for name, *ip in domain.nameservers] return [{"server": name} for name, *ip in domain.nameservers]
def get_success_url(self): def get_success_url(self):
"""Redirect to the nameservers page for the domain.""" """Redirect to the nameservers page for the domain."""
return reverse("domain-nameservers", kwargs={"pk": self.object.pk}) return reverse("domain-nameservers", kwargs={"pk": self.object.pk})