From 3cc0fac817023e8d22f1d69146ccfe8bea00f5d4 Mon Sep 17 00:00:00 2001 From: blanariu Date: Thu, 24 Jun 2021 12:39:56 +0300 Subject: [PATCH 1/5] Fix bug in Manager when using Python 2.7 In Python 2.7 the if statement would catch both cases from the test test_populate_lenient_fallback, so the test was failing. These are the error strings differences between Python 2 and 3: Python 2: NoLenient: populate() got an unexpected keyword argument 'lenient' NoZone: populate() got multiple values for keyword argument 'lenient' Python 3: NoLenient: populate() got an unexpected keyword argument 'lenient' NoZone: populate() got multiple values for argument 'lenient' --- octodns/manager.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/octodns/manager.py b/octodns/manager.py index 9b10196..dcae0a7 100644 --- a/octodns/manager.py +++ b/octodns/manager.py @@ -243,7 +243,8 @@ class Manager(object): try: source.populate(zone, lenient=lenient) except TypeError as e: - if "keyword argument 'lenient'" not in text_type(e): + if ("unexpected keyword argument 'lenient'" + not in text_type(e)): raise self.log.warn(': provider %s does not accept lenient ' 'param', source.__class__.__name__) From 749f0bd90fae302f23c9d0951c5447b279782fd6 Mon Sep 17 00:00:00 2001 From: blanariu Date: Thu, 24 Jun 2021 12:45:22 +0300 Subject: [PATCH 2/5] Fix bug in envvar source tests when run in Python 2.7 Due to an import error the envvar source tests would not run in Python 2.7 --- tests/test_octodns_source_envvar.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_octodns_source_envvar.py b/tests/test_octodns_source_envvar.py index 0714883..38b63dd 100644 --- a/tests/test_octodns_source_envvar.py +++ b/tests/test_octodns_source_envvar.py @@ -1,6 +1,12 @@ from six import text_type from unittest import TestCase -from unittest.mock import patch + +try: + # Python 3 + from unittest.mock import patch +except ImportError: + # Python 2 + from mock import patch from octodns.source.envvar import EnvVarSource from octodns.source.envvar import EnvironmentVariableNotFoundException From e934ea0423b25c656420948a73f1922db2d61b41 Mon Sep 17 00:00:00 2001 From: blanariu Date: Thu, 24 Jun 2021 12:51:45 +0300 Subject: [PATCH 3/5] Fix bug in ultra provider tests when run in Python 2.7 The test_login test from TestUltraProvider would fail in Python 2.7 due to the dictionary insertion order not being preserved in 2.7 and early 3.x versions. Comparing the dictionaries containing the query parameters solves this. Snippet from test failure: - username=user&password=rightpass&grant_type=password + grant_type=password&username=user&password=rightpass --- tests/test_octodns_provider_ultra.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/test_octodns_provider_ultra.py b/tests/test_octodns_provider_ultra.py index 52e0307..0597d85 100644 --- a/tests/test_octodns_provider_ultra.py +++ b/tests/test_octodns_provider_ultra.py @@ -1,3 +1,12 @@ +from __future__ import unicode_literals + +try: + # Python 3 + from urllib.parse import parse_qs +except ImportError: + # Python 2 + from urlparse import parse_qs + from mock import Mock, call from os.path import dirname, join from requests import HTTPError @@ -55,7 +64,8 @@ class TestUltraProvider(TestCase): self.assertEquals(1, mock.call_count) expected_payload = "grant_type=password&username=user&"\ "password=rightpass" - self.assertEquals(mock.last_request.text, expected_payload) + self.assertEquals(parse_qs(mock.last_request.text), + parse_qs(expected_payload)) def test_get_zones(self): provider = _get_provider() From efc4d99d8dc5409ae870ecd41e20729498019ba3 Mon Sep 17 00:00:00 2001 From: blanariu Date: Thu, 24 Jun 2021 19:17:09 +0300 Subject: [PATCH 4/5] Replaced conditional imports with six --- tests/test_octodns_provider_ultra.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/tests/test_octodns_provider_ultra.py b/tests/test_octodns_provider_ultra.py index 0597d85..a22a489 100644 --- a/tests/test_octodns_provider_ultra.py +++ b/tests/test_octodns_provider_ultra.py @@ -1,17 +1,11 @@ from __future__ import unicode_literals -try: - # Python 3 - from urllib.parse import parse_qs -except ImportError: - # Python 2 - from urlparse import parse_qs - from mock import Mock, call from os.path import dirname, join from requests import HTTPError from requests_mock import ANY, mock as requests_mock from six import text_type +from six.moves.urllib import parse from unittest import TestCase from json import load as json_load @@ -64,8 +58,8 @@ class TestUltraProvider(TestCase): self.assertEquals(1, mock.call_count) expected_payload = "grant_type=password&username=user&"\ "password=rightpass" - self.assertEquals(parse_qs(mock.last_request.text), - parse_qs(expected_payload)) + self.assertEquals(parse.parse_qs(mock.last_request.text), + parse.parse_qs(expected_payload)) def test_get_zones(self): provider = _get_provider() From 29532302e28fd16886d782b5eb9544f62b02ea46 Mon Sep 17 00:00:00 2001 From: blanariu Date: Thu, 24 Jun 2021 19:28:53 +0300 Subject: [PATCH 5/5] Leave just importing from mock --- tests/test_octodns_source_envvar.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/test_octodns_source_envvar.py b/tests/test_octodns_source_envvar.py index 38b63dd..ac66a22 100644 --- a/tests/test_octodns_source_envvar.py +++ b/tests/test_octodns_source_envvar.py @@ -1,13 +1,7 @@ +from mock import patch from six import text_type from unittest import TestCase -try: - # Python 3 - from unittest.mock import patch -except ImportError: - # Python 2 - from mock import patch - from octodns.source.envvar import EnvVarSource from octodns.source.envvar import EnvironmentVariableNotFoundException from octodns.zone import Zone