1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00

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.
This commit is contained in:
mintopia
2020-10-16 17:53:07 +01:00
parent 00254f957f
commit e89f309179
2 changed files with 52 additions and 1 deletions

View File

@@ -178,7 +178,7 @@ class ConstellixClient(object):
def pool(self, pool_type, pool_name): def pool(self, pool_type, pool_name):
pools = self.pools(pool_type) pools = self.pools(pool_type)
for pool in pools: for pool in pools:
if pool['name'] == pool_name: if pool['name'] == pool_name and pool['type'] == pool_type:
return pool return pool
return None return None

View File

@@ -521,3 +521,54 @@ class TestConstellixProvider(TestCase):
self.assertIsNone(provider._client.pool_by_id('A', 1)) self.assertIsNone(provider._client.pool_by_id('A', 1))
self.assertIsNone(provider._client.pool('A', 'foobar')) 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'])