Skip to content

Commit

Permalink
Add testcase to test deletion; fixes #44
Browse files Browse the repository at this point in the history
  • Loading branch information
maikelpoot committed Nov 15, 2024
1 parent e8f3b98 commit 1291448
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/test_provider_octodns_transip.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ def make_mock_empty():
return mock


def make_domainmock_existing():
mock = Mock()

api_entries = []
api_entries.append(DNSEntry("@", 300, "A", "1.2.3.4"))
api_entries.append(DNSEntry("@", 300, "A", "1.2.3.5"))
api_entries.append(DNSEntry("delete-me", 3600, "A", "1.1.1.1"))
api_entries.append(DNSEntry("delete-me-too", 3600, "CNAME", "unit.tests."))

mock.dns.list.return_value = api_entries
mock.nameservers.list.return_value = make_mock_nameservers()

return mock


def make_mock_nameservers():
nameservers = []
for value in [
Expand Down Expand Up @@ -663,6 +678,31 @@ def test_apply_nameservers_fail(self, client_mock):
with self.assertRaises(TransipSaveNameserverException):
provider.apply(plan)

@patch("octodns_transip.TransIP")
def test_apply_deletions(self, client_mock):
domain_mock = make_domainmock_existing()
client_mock.return_value.domains.get.return_value = domain_mock
domain_mock.nameservers.list.return_value = []
provider = TransipProvider(
"test", "unittest", self.bogus_key, strict_supports=False
)

plan = provider.plan(make_expected())

self.assertIsNotNone(plan)
self.assertEqual(21, plan.change_counts["Create"])
self.assertEqual(0, plan.change_counts["Update"])
self.assertEqual(2, plan.change_counts["Delete"])

provider.apply(plan)

for e in domain_mock.dns.replace.mock_calls[0][1][0]:
self.assertNotRegex(
e.name,
r'^delete-me.*$',
"This record should be deleted, and be seen within the api call",
)

@patch("octodns_transip.TransIP")
def test_apply_unsupported(self, client_mock):
# This triggers the if supported statement to give 100% code coverage
Expand Down

0 comments on commit 1291448

Please sign in to comment.