From eda5e9751b4e636c34c9ff2a550ed1b7df8c7bec Mon Sep 17 00:00:00 2001 From: Seamus Johnston Date: Thu, 17 Nov 2022 08:26:41 -0600 Subject: [PATCH] Fix lint errors --- src/epp/mock_epp.py | 8 ++++---- src/registrar/forms/application_wizard.py | 6 +++--- ...2_domain_host_nameserver_hostip_and_more.py | 2 +- src/registrar/models/domain.py | 18 ++++++++++-------- src/registrar/models/host.py | 6 ++++-- src/registrar/models/host_ip.py | 3 ++- src/registrar/models/nameserver.py | 4 +++- src/registrar/tests/common.py | 2 -- src/registrar/tests/test_models.py | 1 - 9 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/epp/mock_epp.py b/src/epp/mock_epp.py index 8d3121d83..7d1d1d84e 100644 --- a/src/epp/mock_epp.py +++ b/src/epp/mock_epp.py @@ -4,12 +4,14 @@ communication with the registry until that integration is implemented. """ from datetime import datetime + def domain_check(_): - """ Is domain available for registration? """ + """Is domain available for registration?""" return True + def domain_info(domain): - """ What does the registry know about this domain? """ + """What does the registry know about this domain?""" return { "name": domain, "roid": "EXAMPLE1-REP", @@ -36,5 +38,3 @@ def domain_info(domain): "expiration_date": datetime.today(), "last_transfer_date": datetime.today(), } - - diff --git a/src/registrar/forms/application_wizard.py b/src/registrar/forms/application_wizard.py index 90ef2c958..0cf0eb6e0 100644 --- a/src/registrar/forms/application_wizard.py +++ b/src/registrar/forms/application_wizard.py @@ -9,7 +9,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin from formtools.wizard.views import NamedUrlSessionWizardView # type: ignore -from registrar.models import DomainApplication, Website +from registrar.models import DomainApplication, Domain logger = logging.getLogger(__name__) @@ -134,8 +134,8 @@ class ApplicationWizard(LoginRequiredMixin, NamedUrlSessionWizardView): # This isn't really the requested_domain field # but we need something in this field to make the form submittable - requested_site, _ = Website.objects.get_or_create( - website=contact_data["organization_name"] + ".gov" + requested_site, _ = Domain.objects.get_or_create( + name=contact_data["organization_name"] + ".gov" ) application.requested_domain = requested_site return application diff --git a/src/registrar/migrations/0002_domain_host_nameserver_hostip_and_more.py b/src/registrar/migrations/0002_domain_host_nameserver_hostip_and_more.py index b41c5908d..fb00d0a22 100644 --- a/src/registrar/migrations/0002_domain_host_nameserver_hostip_and_more.py +++ b/src/registrar/migrations/0002_domain_host_nameserver_hostip_and_more.py @@ -4,7 +4,7 @@ from django.conf import settings import django.core.validators from django.db import migrations, models import django.db.models.deletion -import django_fsm +import django_fsm # type: ignore class Migration(migrations.Migration): diff --git a/src/registrar/models/domain.py b/src/registrar/models/domain.py index ab0ecaa28..b5a2255c7 100644 --- a/src/registrar/models/domain.py +++ b/src/registrar/models/domain.py @@ -23,19 +23,21 @@ class Domain(TimeStampedModel): 2. To allow a new registrant to draft DNS entries before their application is approved """ + class Meta: constraints = [ # draft domains may share the same name, but # once approved, they must be globally unique models.UniqueConstraint( - fields=['name'], + fields=["name"], condition=models.Q(is_active=True), - name='unique_domain_name_in_registry' + name="unique_domain_name_in_registry", ), ] class Status(models.TextChoices): """The status codes we can receive from the registry.""" + # Requests to delete the object MUST be rejected. CLIENT_DELETE_PROHIBITED = "clientDeleteProhibited" SERVER_DELETE_PROHIBITED = "serverDeleteProhibited" @@ -81,7 +83,6 @@ class Domain(TimeStampedModel): PENDING_TRANSFER = "pendingTransfer" PENDING_UPDATE = "pendingUpdate" - # a domain name is alphanumeric or hyphen, up to 63 characters, doesn't # begin or end with a hyphen, followed by a TLD of 2-6 alphabetic characters DOMAIN_REGEX = re.compile(r"^(?!-)[A-Za-z0-9-]{1,63}(? bool: - """Check if a domain is available. Not implemented. """ + """Check if a domain is available. Not implemented.""" return domain_check(domain) def transfer(self): - """ Going somewhere. Not implemented. """ + """Going somewhere. Not implemented.""" pass def renew(self): - """ Time to renew. Not implemented. """ + """Time to renew. Not implemented.""" pass def _get_property(self, property): """Get some info about a domain.""" - if not self.is_active: return None + if not self.is_active: + return None if not hasattr(self, "info"): try: # get info from registry @@ -194,7 +196,7 @@ class Domain(TimeStampedModel): def last_transfer_date(self): return self._get_property("last_transfer_date") - name = models.CharField( + name = models.CharField( max_length=253, blank=False, default=None, # prevent saving without a value diff --git a/src/registrar/models/host.py b/src/registrar/models/host.py index 0e4133a71..132e72792 100644 --- a/src/registrar/models/host.py +++ b/src/registrar/models/host.py @@ -3,10 +3,11 @@ from django.db import models from .utility.time_stamped_model import TimeStampedModel from .domain import Domain + class Host(TimeStampedModel): """ Hosts are internet-connected computers. - + They may handle email, serve websites, or perform other tasks. The registry is the source of truth for this data. @@ -14,7 +15,8 @@ class Host(TimeStampedModel): This model exists ONLY to allow a new registrant to draft DNS entries before their application is approved. """ - name = models.CharField( + + name = models.CharField( max_length=253, null=False, blank=False, diff --git a/src/registrar/models/host_ip.py b/src/registrar/models/host_ip.py index 87feca14f..c6aa1a3c8 100644 --- a/src/registrar/models/host_ip.py +++ b/src/registrar/models/host_ip.py @@ -4,6 +4,7 @@ from django.core.validators import validate_ipv46_address from .utility.time_stamped_model import TimeStampedModel from .host import Host + class HostIP(TimeStampedModel): """ Hosts may have one or more IP addresses. @@ -13,6 +14,7 @@ class HostIP(TimeStampedModel): This model exists ONLY to allow a new registrant to draft DNS entries before their application is approved. """ + address = models.CharField( max_length=46, null=False, @@ -27,4 +29,3 @@ class HostIP(TimeStampedModel): on_delete=models.PROTECT, help_text="Host to which this IP address belongs", ) - diff --git a/src/registrar/models/nameserver.py b/src/registrar/models/nameserver.py index 8716c0383..913b3ab03 100644 --- a/src/registrar/models/nameserver.py +++ b/src/registrar/models/nameserver.py @@ -1,5 +1,6 @@ from .host import Host + class Nameserver(Host): """ A nameserver is a host which has been delegated to respond to DNS queries. @@ -9,4 +10,5 @@ class Nameserver(Host): This model exists ONLY to allow a new registrant to draft DNS entries before their application is approved. """ - pass \ No newline at end of file + + pass diff --git a/src/registrar/tests/common.py b/src/registrar/tests/common.py index 8bda74b4e..b6c7c01d8 100644 --- a/src/registrar/tests/common.py +++ b/src/registrar/tests/common.py @@ -73,5 +73,3 @@ class MockUserLogin: response = self.get_response(request) return response - - diff --git a/src/registrar/tests/test_models.py b/src/registrar/tests/test_models.py index a77a4a935..78d4cb196 100644 --- a/src/registrar/tests/test_models.py +++ b/src/registrar/tests/test_models.py @@ -85,7 +85,6 @@ class TestDomain(TestCase): domain.save() self.assertIn("ok", domain.status) - def test_fsm_activate_fail_unique(self): # can't activate domain if name is not unique d1, _ = Domain.objects.get_or_create(name="igorville.gov")