Browse Source

Ns1Provider python3

pull/384/head
Ross McFarland 6 years ago
parent
commit
0acff67faa
No known key found for this signature in database GPG Key ID: 61C10C4FC8FE4A89
2 changed files with 11 additions and 7 deletions
  1. +2
    -3
      octodns/provider/ns1.py
  2. +9
    -4
      tests/test_octodns_provider_ns1.py

+ 2
- 3
octodns/provider/ns1.py View File

@ -10,7 +10,7 @@ from itertools import chain
from collections import OrderedDict, defaultdict
from nsone import NSONE
from nsone.rest.errors import RateLimitException, ResourceException
from incf.countryutils import transformations
from pycountry_convert import country_alpha2_to_continent_code
from time import sleep
from six import text_type
@ -62,8 +62,7 @@ class Ns1Provider(BaseProvider):
us_state = meta.get('us_state', [])
ca_province = meta.get('ca_province', [])
for cntry in country:
cn = transformations.cc_to_cn(cntry)
con = transformations.cn_to_ctca2(cn)
con = country_alpha2_to_continent_code(cntry)
key = '{}-{}'.format(con, cntry)
geo[key].extend(answer['answer'])
for state in us_state:


+ 9
- 4
tests/test_octodns_provider_ns1.py View File

@ -5,6 +5,7 @@
from __future__ import absolute_import, division, print_function, \
unicode_literals
from collections import defaultdict
from mock import Mock, call, patch
from nsone.rest.errors import AuthException, RateLimitException, \
ResourceException
@ -373,8 +374,12 @@ class TestNs1Provider(TestCase):
load_mock.side_effect = [nsone_zone, nsone_zone]
plan = provider.plan(desired)
self.assertEquals(3, len(plan.changes))
self.assertIsInstance(plan.changes[0], Update)
self.assertIsInstance(plan.changes[2], Delete)
# Shouldn't rely on order so just count classes
classes = defaultdict(lambda: 0)
for change in plan.changes:
classes[change.__class__] += 1
self.assertEquals(1, classes[Delete])
self.assertEquals(2, classes[Update])
# ugh, we need a mock record that can be returned from loadRecord for
# the update and delete targets, we can add our side effects to that to
# trigger rate limit handling
@ -397,7 +402,7 @@ class TestNs1Provider(TestCase):
call('unit.tests', u'A'),
call('geo', u'A'),
call('delete-me', u'A'),
])
], any_order=True)
mock_record.assert_has_calls([
call.update(answers=[{'answer': [u'1.2.3.4'], 'meta': {}}],
filters=[],
@ -424,7 +429,7 @@ class TestNs1Provider(TestCase):
ttl=34),
call.delete(),
call.delete()
])
], any_order=True)
def test_escaping(self):
provider = Ns1Provider('test', 'api-key')


Loading…
Cancel
Save