From e89f309179bab3c81b21e6bdf2f0f3999efb6493 Mon Sep 17 00:00:00 2001 From: mintopia Date: Fri, 16 Oct 2020 17:53:07 +0100 Subject: [PATCH] Ensure pool caching works for Constellix Provider The caching of pools for the Constellix provider will now cache based on the type of pool and the name. Previously it was caching based on the name only. --- octodns/provider/constellix.py | 2 +- tests/test_octodns_provider_constellix.py | 51 +++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/octodns/provider/constellix.py b/octodns/provider/constellix.py index cb2a53f..67f7a6d 100644 --- a/octodns/provider/constellix.py +++ b/octodns/provider/constellix.py @@ -178,7 +178,7 @@ class ConstellixClient(object): def pool(self, pool_type, pool_name): pools = self.pools(pool_type) for pool in pools: - if pool['name'] == pool_name: + if pool['name'] == pool_name and pool['type'] == pool_type: return pool return None diff --git a/tests/test_octodns_provider_constellix.py b/tests/test_octodns_provider_constellix.py index d54d1fe..1ca3179 100644 --- a/tests/test_octodns_provider_constellix.py +++ b/tests/test_octodns_provider_constellix.py @@ -521,3 +521,54 @@ class TestConstellixProvider(TestCase): self.assertIsNone(provider._client.pool_by_id('A', 1)) self.assertIsNone(provider._client.pool('A', 'foobar')) + + def test_pools_are_cached_correctly(self): + provider = ConstellixProvider('test', 'api', 'secret') + + provider._client.pools = Mock(return_value=[{ + "id": 1808521, + "name": "unit.tests.:www.dynamic:A:two", + "type": "A", + "values": [ + { + "value": "1.2.3.4", + "weight": 1 + } + ] + }]) + + found = provider._client.pool('A', 'unit.tests.:www.dynamic:A:two') + self.assertIsNotNone(found) + + not_found = provider._client.pool('AAAA', + 'unit.tests.:www.dynamic:A:two') + self.assertIsNone(not_found) + + provider._client.pools = Mock(return_value=[{ + "id": 42, + "name": "unit.tests.:www.dynamic:A:two", + "type": "A", + "values": [ + { + "value": "1.2.3.4", + "weight": 1 + } + ] + }, { + "id": 451, + "name": "unit.tests.:www.dynamic:A:two", + "type": "AAAA", + "values": [ + { + "value": "1.2.3.4", + "weight": 1 + } + ] + }]) + + a_pool = provider._client.pool('A', 'unit.tests.:www.dynamic:A:two') + self.assertEquals(42, a_pool['id']) + + aaaa_pool = provider._client.pool('AAAA', + 'unit.tests.:www.dynamic:A:two') + self.assertEquals(451, aaaa_pool['id'])