Apply consistent Python and Django coding standards

This commit is contained in:
parkel committed 2026-11-21 02:12:32 +01:00
1 parent 1d0b5adeee
commit d7314fa927
61 files changed
+1829 -603

No files matched your search

+44 -15
View File
@@ -42,11 +42,15 @@ class DnsPublicationTests(TestCase):
self.url = reverse("panel:dns_zone_publish", args=[self.zone.pk])
self.detail = self.account.get_absolute_url()
def test_queued_snapshot_survives_edits_and_the_new_revision_can_publish_next(self):
def test_queued_snapshot_survives_edits_and_next_revision_can_publish(
self,
):
self.assertContains(self.client.get(self.detail), "Publish zone")
self.assertEqual(self.client.get(self.url).status_code, 405)
for _ in range(2):
self.assertRedirects(self.client.post(self.url, {"serial": 1}), self.detail)
self.assertRedirects(
self.client.post(self.url, {"serial": 1}), self.detail
)
publication = DnsPublication.objects.get(zone=self.zone)
self.assertContains(self.client.get(self.detail), "Queued serial 1")
with patch.object(publish_dns_zone, "apply_async") as send:
@@ -71,7 +75,9 @@ class DnsPublicationTests(TestCase):
)
self.zone.refresh_from_db()
self.assertEqual(self.zone.serial, 2)
self.assertEqual(self.client.post(self.url, {"serial": 1}).status_code, 409)
self.assertEqual(
self.client.post(self.url, {"serial": 1}).status_code, 409
)
self.client.post(self.url, {"serial": 2})
publication.refresh_from_db()
self.assertEqual(publication.serial, 1)
@@ -85,7 +91,9 @@ class DnsPublicationTests(TestCase):
self.assertContains(detail, "Published SOA serial 1")
self.assertContains(detail, "Publish zone")
self.assertRedirects(self.client.post(self.url, {"serial": 2}), self.detail)
self.assertRedirects(
self.client.post(self.url, {"serial": 2}), self.detail
)
publication.refresh_from_db()
self.assertEqual(publication.published_serial, 1)
self.assertEqual(publication.serial, 2)
@@ -98,13 +106,19 @@ class DnsPublicationTests(TestCase):
self.assertContains(detail, "Published SOA serial 1")
self.assertContains(detail, "Publishing failed for serial 2")
self.assertContains(detail, "Retry publishing")
self.assertRedirects(self.client.post(self.url, {"serial": 2}), self.detail)
self.assertRedirects(
self.client.post(self.url, {"serial": 2}), self.detail
)
with patch("coulobre.hosting.tasks.publish_local_zone") as apply:
publish_dns_zone.run(publication.pk)
apply.assert_called_once_with(self.zone.spec)
self.assertContains(self.client.get(self.detail), "Published SOA serial 2")
self.assertContains(
self.client.get(self.detail), "Published SOA serial 2"
)
def test_customer_and_operator_without_publish_permission_cannot_queue(self):
def test_customer_and_operator_without_publish_permission_cannot_queue(
self,
):
viewer = get_user_model().objects.create_user("viewer")
viewer.user_permissions.add(
*Permission.objects.filter(
@@ -114,7 +128,9 @@ class DnsPublicationTests(TestCase):
for user in (self.customer, viewer):
with self.subTest(user=user):
self.client.force_login(user)
self.assertNotContains(self.client.get(self.detail), "Publish zone")
self.assertNotContains(
self.client.get(self.detail), "Publish zone"
)
self.assertEqual(
self.client.post(self.url, {"serial": 1}).status_code, 403
)
@@ -123,7 +139,9 @@ class DnsPublicationTests(TestCase):
@override_settings(LOCAL_DNS_PUBLISHING=False)
def test_disabled_publishing_keeps_manifest_downloads_available(self):
self.assertNotContains(self.client.get(self.detail), "Publish zone")
self.assertEqual(self.client.post(self.url, {"serial": 1}).status_code, 404)
self.assertEqual(
self.client.post(self.url, {"serial": 1}).status_code, 404
)
manifest_url = reverse("panel:dns_zone_manifest", args=[self.zone.pk])
self.assertEqual(
self.client.get(manifest_url).json(), self.zone.spec.manifest()
@@ -133,9 +151,15 @@ class DnsPublicationTests(TestCase):
class DnsPublicationSocketTests(SimpleTestCase):
def test_receipt_must_identify_the_exact_soa_serial(self):
zone = DnsZone(
"site.example", 1, ("ns.provider.example",), "hostmaster.site.example"
"site.example",
1,
("ns.provider.example",),
"hostmaster.site.example",
)
reply = zone.manifest_identity() | {"state": "configured", "problem": None}
reply = zone.manifest_identity() | {
"state": "configured",
"problem": None,
}
with patch("coulobre.hosting.node_client.socket.socket") as socket:
connection = socket.return_value.__enter__.return_value
read = connection.makefile.return_value.__enter__
@@ -144,9 +168,14 @@ class DnsPublicationSocketTests(SimpleTestCase):
BytesIO(json.dumps(reply | {"serial": True}).encode()),
)
publish_local_zone(zone)
connection.connect.assert_called_once_with("/run/coulobre-dns-apply.sock")
self.assertEqual(
json.loads(connection.sendall.call_args.args[0]), zone.manifest()
connection.connect.assert_called_once_with(
"/run/coulobre-dns-apply.sock"
)
with self.assertRaisesMessage(ValueError, "invalid response for this zone"):
self.assertEqual(
json.loads(connection.sendall.call_args.args[0]),
zone.manifest(),
)
with self.assertRaisesMessage(
ValueError, "invalid response for this zone"
):
publish_local_zone(zone)