Fix failing tests

This commit is contained in:
Seamus Johnston 2022-11-28 13:02:19 -06:00
parent 758c645943
commit 54b6b525b5
No known key found for this signature in database
GPG key ID: 2F21225985069105
6 changed files with 37 additions and 14 deletions

View file

@ -4,7 +4,7 @@ from django.contrib.contenttypes.models import ContentType
from django.http.response import HttpResponseRedirect
from django.urls import reverse
from .models import User, UserProfile, DomainApplication, Website
from . import models
class AuditedAdmin(admin.ModelAdmin):
@ -26,7 +26,7 @@ class UserProfileInline(admin.StackedInline):
"""Edit a user's profile on the user page."""
model = UserProfile
model = models.UserProfile
class MyUserAdmin(UserAdmin):
@ -36,6 +36,24 @@ class MyUserAdmin(UserAdmin):
inlines = [UserProfileInline]
admin.site.register(User, MyUserAdmin)
admin.site.register(DomainApplication, AuditedAdmin)
admin.site.register(Website, AuditedAdmin)
class HostIPInline(admin.StackedInline):
"""Edit an ip address on the host page."""
model = models.HostIP
class MyHostAdmin(AuditedAdmin):
"""Custom host admin class to use our inlines."""
inlines = [HostIPInline]
admin.site.register(models.User, MyUserAdmin)
admin.site.register(models.Contact, AuditedAdmin)
admin.site.register(models.DomainApplication, AuditedAdmin)
admin.site.register(models.Domain, AuditedAdmin)
admin.site.register(models.Host, MyHostAdmin)
admin.site.register(models.Nameserver, MyHostAdmin)
admin.site.register(models.Website, AuditedAdmin)

View file

@ -1,4 +1,4 @@
# Generated by Django 4.1.3 on 2022-11-17 13:46
# Generated by Django 4.1.3 on 2022-11-28 19:07
from django.conf import settings
import django.core.validators
@ -43,7 +43,6 @@ class Migration(migrations.Migration):
default=False,
help_text="Domain is live in the registry",
max_length=50,
protected=True,
),
),
("owners", models.ManyToManyField(to=settings.AUTH_USER_MODEL)),
@ -77,6 +76,7 @@ class Migration(migrations.Migration):
models.ForeignKey(
help_text="Domain to which this host belongs",
on_delete=django.db.models.deletion.PROTECT,
related_name="host",
to="registrar.domain",
),
),
@ -133,6 +133,7 @@ class Migration(migrations.Migration):
models.ForeignKey(
help_text="Host to which this IP address belongs",
on_delete=django.db.models.deletion.PROTECT,
related_name="ip",
to="registrar.host",
),
),

View file

@ -224,7 +224,8 @@ class Domain(TimeStampedModel):
(False, "No"),
],
default=False,
protected=True,
# TODO: how to edit models in Django admin if protected = True
protected=False,
help_text="Domain is live in the registry",
)

View file

@ -211,8 +211,8 @@ class DomainApplication(TimeStampedModel):
def __str__(self):
try:
if self.requested_domain and self.requested_domain.website:
return self.requested_domain.website
if self.requested_domain and self.requested_domain.name:
return self.requested_domain.name
else:
return f"{self.status} application created by {self.creator}"
except Exception:

View file

@ -32,7 +32,7 @@
<tbody>
{% for application in domain_applications %}
<tr>
<th>{{ application.requested_domain.website }}</th>
<th>{{ application.requested_domain.name }}</th>
<td>{{ application.status }}</td>
</tr>
{% endfor %}

View file

@ -5,9 +5,11 @@ from django.contrib.auth import get_user_model
from django_webtest import WebTest # type: ignore
from registrar.models import DomainApplication, Website
from registrar.models import DomainApplication, Domain
from registrar.forms.application_wizard import TITLES
from .common import less_console_noise
class TestViews(TestCase):
def setUp(self):
@ -58,7 +60,7 @@ class LoggedInTests(TestWithUser):
def test_home_lists_domain_applications(self):
response = self.client.get("/")
self.assertNotContains(response, "igorville.gov")
site = Website.objects.create(website="igorville.gov")
site = Domain.objects.create(name="igorville.gov")
application = DomainApplication.objects.create(
creator=self.user, requested_domain=site
)
@ -307,6 +309,7 @@ class FormTests(TestWithUser, WebTest):
# following this redirect is a GET request, so include the cookie
# here too.
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
with less_console_noise():
final_result = review_result.follow()
self.assertContains(final_result, "Thank you for your domain request")