From 0acff67faa4c38ca36a13f164ed6903c504a64fc Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Sat, 5 Oct 2019 14:38:58 -0700 Subject: [PATCH] Ns1Provider python3 --- octodns/provider/ns1.py | 5 ++--- tests/test_octodns_provider_ns1.py | 13 +++++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/octodns/provider/ns1.py b/octodns/provider/ns1.py index d3faf21..b4fd850 100644 --- a/octodns/provider/ns1.py +++ b/octodns/provider/ns1.py @@ -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: diff --git a/tests/test_octodns_provider_ns1.py b/tests/test_octodns_provider_ns1.py index 178ce53..91d1a3f 100644 --- a/tests/test_octodns_provider_ns1.py +++ b/tests/test_octodns_provider_ns1.py @@ -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')