Browse Source

f-strings for the rest of the tests

pull/768/head
Ross McFarland 4 years ago
parent
commit
775917f4b9
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
12 changed files with 55 additions and 73 deletions
  1. +1
    -1
      tests/test_octodns_processor_ownership.py
  2. +9
    -14
      tests/test_octodns_provider_cloudflare.py
  3. +4
    -8
      tests/test_octodns_provider_constellix.py
  4. +2
    -2
      tests/test_octodns_provider_dnsimple.py
  5. +2
    -3
      tests/test_octodns_provider_dnsmadeeasy.py
  6. +1
    -1
      tests/test_octodns_provider_gcore.py
  7. +2
    -3
      tests/test_octodns_provider_googlecloud.py
  8. +2
    -2
      tests/test_octodns_provider_hetzner.py
  9. +4
    -6
      tests/test_octodns_provider_ns1.py
  10. +1
    -2
      tests/test_octodns_provider_transip.py
  11. +25
    -29
      tests/test_octodns_provider_ultra.py
  12. +2
    -2
      tests/test_octodns_source_envvar.py

+ 1
- 1
tests/test_octodns_processor_ownership.py View File

@ -129,7 +129,7 @@ class TestOwnershipProcessor(TestCase):
# two delete changes. # two delete changes.
the_a = records['the-a'] the_a = records['the-a']
plan.existing.add_record(the_a) plan.existing.add_record(the_a)
name = '{}.a.the-a'.format(ownership.txt_name)
name = f'{ownership.txt_name}.a.the-a'
the_a_ownership = Record.new(zone, name, { the_a_ownership = Record.new(zone, name, {
'ttl': 30, 'ttl': 30,
'type': 'TXT', 'type': 'TXT',


+ 9
- 14
tests/test_octodns_provider_cloudflare.py View File

@ -157,36 +157,31 @@ class TestCloudflareProvider(TestCase):
# zones # zones
with open('tests/fixtures/cloudflare-zones-page-1.json') as fh: with open('tests/fixtures/cloudflare-zones-page-1.json') as fh:
mock.get('{}?page=1'.format(base), status_code=200,
text=fh.read())
mock.get(f'{base}?page=1', status_code=200, text=fh.read())
with open('tests/fixtures/cloudflare-zones-page-2.json') as fh: with open('tests/fixtures/cloudflare-zones-page-2.json') as fh:
mock.get('{}?page=2'.format(base), status_code=200,
text=fh.read())
mock.get('{}?page=3'.format(base), status_code=200,
mock.get(f'{base}?page=2', status_code=200, text=fh.read())
mock.get(f'{base}?page=3', status_code=200,
json={'result': [], 'result_info': {'count': 0, json={'result': [], 'result_info': {'count': 0,
'per_page': 0}}) 'per_page': 0}})
base = '{}/234234243423aaabb334342aaa343435'.format(base)
base = f'{base}/234234243423aaabb334342aaa343435'
# pagerules/URLFWD # pagerules/URLFWD
with open('tests/fixtures/cloudflare-pagerules.json') as fh: with open('tests/fixtures/cloudflare-pagerules.json') as fh:
mock.get('{}/pagerules?status=active'.format(base),
mock.get(f'{base}/pagerules?status=active',
status_code=200, text=fh.read()) status_code=200, text=fh.read())
# records # records
base = '{}/dns_records'.format(base)
base = f'{base}/dns_records'
with open('tests/fixtures/cloudflare-dns_records-' with open('tests/fixtures/cloudflare-dns_records-'
'page-1.json') as fh: 'page-1.json') as fh:
mock.get('{}?page=1'.format(base), status_code=200,
text=fh.read())
mock.get(f'{base}?page=1', status_code=200, text=fh.read())
with open('tests/fixtures/cloudflare-dns_records-' with open('tests/fixtures/cloudflare-dns_records-'
'page-2.json') as fh: 'page-2.json') as fh:
mock.get('{}?page=2'.format(base), status_code=200,
text=fh.read())
mock.get(f'{base}?page=2', status_code=200, text=fh.read())
with open('tests/fixtures/cloudflare-dns_records-' with open('tests/fixtures/cloudflare-dns_records-'
'page-3.json') as fh: 'page-3.json') as fh:
mock.get('{}?page=3'.format(base), status_code=200,
text=fh.read())
mock.get(f'{base}?page=3', status_code=200, text=fh.read())
zone = Zone('unit.tests.', []) zone = Zone('unit.tests.', [])
provider.populate(zone) provider.populate(zone)


+ 4
- 8
tests/test_octodns_provider_constellix.py View File

@ -192,17 +192,13 @@ class TestConstellixProvider(TestCase):
with requests_mock() as mock: with requests_mock() as mock:
base = 'https://api.dns.constellix.com/v1' base = 'https://api.dns.constellix.com/v1'
with open('tests/fixtures/constellix-domains.json') as fh: with open('tests/fixtures/constellix-domains.json') as fh:
mock.get('{}{}'.format(base, '/domains'),
text=fh.read())
mock.get(f'{base}/domains', text=fh.read())
with open('tests/fixtures/constellix-records.json') as fh: with open('tests/fixtures/constellix-records.json') as fh:
mock.get('{}{}'.format(base, '/domains/123123/records'),
text=fh.read())
mock.get(f'{base}/domains/123123/records', text=fh.read())
with open('tests/fixtures/constellix-pools.json') as fh: with open('tests/fixtures/constellix-pools.json') as fh:
mock.get('{}{}'.format(base, '/pools/A'),
text=fh.read())
mock.get(f'{base}/pools/A', text=fh.read())
with open('tests/fixtures/constellix-geofilters.json') as fh: with open('tests/fixtures/constellix-geofilters.json') as fh:
mock.get('{}{}'.format(base, '/geoFilters'),
text=fh.read())
mock.get(f'{base}/geoFilters', text=fh.read())
zone = Zone('unit.tests.', []) zone = Zone('unit.tests.', [])
provider.populate(zone) provider.populate(zone)


+ 2
- 2
tests/test_octodns_provider_dnsimple.py View File

@ -79,9 +79,9 @@ class TestDnsimpleProvider(TestCase):
base = 'https://api.dnsimple.com/v2/42/zones/unit.tests/' \ base = 'https://api.dnsimple.com/v2/42/zones/unit.tests/' \
'records?page=' 'records?page='
with open('tests/fixtures/dnsimple-page-1.json') as fh: with open('tests/fixtures/dnsimple-page-1.json') as fh:
mock.get('{}{}'.format(base, 1), text=fh.read())
mock.get(f'{base}1', text=fh.read())
with open('tests/fixtures/dnsimple-page-2.json') as fh: with open('tests/fixtures/dnsimple-page-2.json') as fh:
mock.get('{}{}'.format(base, 2), text=fh.read())
mock.get(f'{base}2', text=fh.read())
zone = Zone('unit.tests.', []) zone = Zone('unit.tests.', [])
provider.populate(zone) provider.populate(zone)


+ 2
- 3
tests/test_octodns_provider_dnsmadeeasy.py View File

@ -95,10 +95,9 @@ class TestDnsMadeEasyProvider(TestCase):
with requests_mock() as mock: with requests_mock() as mock:
base = 'https://api.dnsmadeeasy.com/V2.0/dns/managed' base = 'https://api.dnsmadeeasy.com/V2.0/dns/managed'
with open('tests/fixtures/dnsmadeeasy-domains.json') as fh: with open('tests/fixtures/dnsmadeeasy-domains.json') as fh:
mock.get('{}{}'.format(base, '/'), text=fh.read())
mock.get(f'{base}/', text=fh.read())
with open('tests/fixtures/dnsmadeeasy-records.json') as fh: with open('tests/fixtures/dnsmadeeasy-records.json') as fh:
mock.get('{}{}'.format(base, '/123123/records'),
text=fh.read())
mock.get(f'{base}/123123/records', text=fh.read())
zone = Zone('unit.tests.', []) zone = Zone('unit.tests.', [])
provider.populate(zone) provider.populate(zone)


+ 1
- 1
tests/test_octodns_provider_gcore.py View File

@ -195,7 +195,7 @@ class TestGCoreProvider(TestCase):
str(ctx.exception).startswith( str(ctx.exception).startswith(
"filter is enabled, but no pools where built for" "filter is enabled, but no pools where built for"
), ),
"{} - is not start from desired text".format(ctx.exception),
f"{ctx.exception} - is not start from desired text",
) )
def test_apply(self): def test_apply(self):


+ 2
- 3
tests/test_octodns_provider_googlecloud.py View File

@ -156,8 +156,7 @@ class DummyResourceRecordSet:
return False return False
def __repr__(self): def __repr__(self):
return "{} {} {} {!s}"\
.format(self.name, self.record_type, self.ttl, self.rrdatas)
return f"{self.name} {self.record_type} {self.ttl} {self.rrdatas}"
def __hash__(self): def __hash__(self):
return hash(repr(self)) return hash(repr(self))
@ -419,7 +418,7 @@ class TestGoogleCloudProvider(TestCase):
dummy_gcloud_zone = DummyGoogleCloudZone("unit.tests") dummy_gcloud_zone = DummyGoogleCloudZone("unit.tests")
for octo_record in octo_records: for octo_record in octo_records:
_rrset_func = getattr( _rrset_func = getattr(
provider, '_rrset_for_{}'.format(octo_record._type))
provider, f'_rrset_for_{octo_record._type}')
self.assertEqual( self.assertEqual(
_rrset_func(dummy_gcloud_zone, octo_record).record_type, _rrset_func(dummy_gcloud_zone, octo_record).record_type,
octo_record._type octo_record._type


+ 2
- 2
tests/test_octodns_provider_hetzner.py View File

@ -68,9 +68,9 @@ class TestHetznerProvider(TestCase):
with requests_mock() as mock: with requests_mock() as mock:
base = provider._client.BASE_URL base = provider._client.BASE_URL
with open('tests/fixtures/hetzner-zones.json') as fh: with open('tests/fixtures/hetzner-zones.json') as fh:
mock.get('{}/zones'.format(base), text=fh.read())
mock.get(f'{base}/zones', text=fh.read())
with open('tests/fixtures/hetzner-records.json') as fh: with open('tests/fixtures/hetzner-records.json') as fh:
mock.get('{}/records'.format(base), text=fh.read())
mock.get(f'{base}/records', text=fh.read())
zone = Zone('unit.tests.', []) zone = Zone('unit.tests.', [])
provider.populate(zone) provider.populate(zone)


+ 4
- 6
tests/test_octodns_provider_ns1.py View File

@ -1653,7 +1653,7 @@ class TestNs1ProviderDynamic(TestCase):
'meta': { 'meta': {
'priority': 1, 'priority': 1,
'weight': 12, 'weight': 12,
'note': 'from:{}'.format(catchall_pool_name),
'note': f'from:{catchall_pool_name}',
}, },
'region': catchall_pool_name, 'region': catchall_pool_name,
}, { }, {
@ -1774,8 +1774,7 @@ class TestNs1ProviderDynamic(TestCase):
partial_oc_cntry_list partial_oc_cntry_list
data4 = provider._data_for_A('A', ns1_record) data4 = provider._data_for_A('A', ns1_record)
for c in partial_oc_cntry_list: for c in partial_oc_cntry_list:
self.assertTrue(
'OC-{}'.format(c) in data4['dynamic']['rules'][0]['geos'])
self.assertTrue(f'OC-{c}' in data4['dynamic']['rules'][0]['geos'])
# NA test cases # NA test cases
# 1. Full list of countries should return 'NA' in geos # 1. Full list of countries should return 'NA' in geos
@ -1792,8 +1791,7 @@ class TestNs1ProviderDynamic(TestCase):
partial_na_cntry_list partial_na_cntry_list
data6 = provider._data_for_A('A', ns1_record) data6 = provider._data_for_A('A', ns1_record)
for c in partial_na_cntry_list: for c in partial_na_cntry_list:
self.assertTrue(
'NA-{}'.format(c) in data6['dynamic']['rules'][0]['geos'])
self.assertTrue(f'NA-{c}' in data6['dynamic']['rules'][0]['geos'])
# Test out fallback only pools and new-style notes # Test out fallback only pools and new-style notes
ns1_record = { ns1_record = {
@ -1919,7 +1917,7 @@ class TestNs1ProviderDynamic(TestCase):
'meta': { 'meta': {
'priority': 1, 'priority': 1,
'weight': 12, 'weight': 12,
'note': 'from:{}'.format(catchall_pool_name),
'note': f'from:{catchall_pool_name}',
}, },
'region': catchall_pool_name, 'region': catchall_pool_name,
}, { }, {


+ 1
- 2
tests/test_octodns_provider_transip.py View File

@ -45,8 +45,7 @@ class MockDomainService(object):
_dns_entries = [] _dns_entries = []
for record in records: for record in records:
if record._type in provider.SUPPORTS: if record._type in provider.SUPPORTS:
entries_for = getattr(provider,
'_entries_for_{}'.format(record._type))
entries_for = getattr(provider, f'_entries_for_{record._type}')
# Root records have '@' as name # Root records have '@' as name
name = record.name name = record.name


+ 25
- 29
tests/test_octodns_provider_ultra.py View File

@ -41,7 +41,7 @@ class TestUltraProvider(TestCase):
# Bad Auth # Bad Auth
with requests_mock() as mock: with requests_mock() as mock:
mock.post('{}{}'.format(self.host, path), status_code=401,
mock.post(f'{self.host}{path}', status_code=401,
text='{"errorCode": 60001}') text='{"errorCode": 60001}')
with self.assertRaises(Exception) as ctx: with self.assertRaises(Exception) as ctx:
UltraProvider('test', 'account', 'user', 'wrongpass') UltraProvider('test', 'account', 'user', 'wrongpass')
@ -50,7 +50,7 @@ class TestUltraProvider(TestCase):
# Good Auth # Good Auth
with requests_mock() as mock: with requests_mock() as mock:
headers = {'Content-Type': 'application/x-www-form-urlencoded'} headers = {'Content-Type': 'application/x-www-form-urlencoded'}
mock.post('{}{}'.format(self.host, path), status_code=200,
mock.post(f'{self.host}{path}', status_code=200,
request_headers=headers, request_headers=headers,
text='{"token type": "Bearer", "refresh_token": "abc", ' text='{"token type": "Bearer", "refresh_token": "abc", '
'"access_token":"123", "expires_in": "3600"}') '"access_token":"123", "expires_in": "3600"}')
@ -67,7 +67,7 @@ class TestUltraProvider(TestCase):
# Test authorization issue # Test authorization issue
with requests_mock() as mock: with requests_mock() as mock:
mock.get('{}{}'.format(self.host, path), status_code=400,
mock.get(f'{self.host}{path}', status_code=400,
json={"errorCode": 60004, json={"errorCode": 60004,
"errorMessage": "Authorization Header required"}) "errorMessage": "Authorization Header required"})
with self.assertRaises(HTTPError) as ctx: with self.assertRaises(HTTPError) as ctx:
@ -76,7 +76,7 @@ class TestUltraProvider(TestCase):
# Test no zones exist error # Test no zones exist error
with requests_mock() as mock: with requests_mock() as mock:
mock.get('{}{}'.format(self.host, path), status_code=404,
mock.get(f'{self.host}{path}', status_code=404,
headers={'Authorization': 'Bearer 123'}, headers={'Authorization': 'Bearer 123'},
json=self.empty_body) json=self.empty_body)
zones = provider.zones zones = provider.zones
@ -109,7 +109,7 @@ class TestUltraProvider(TestCase):
] ]
} }
mock.get('{}{}'.format(self.host, path), status_code=200,
mock.get(f'{self.host}{path}', status_code=200,
headers={'Authorization': 'Bearer 123'}, headers={'Authorization': 'Bearer 123'},
json=payload) json=payload)
zones = provider.zones zones = provider.zones
@ -120,14 +120,14 @@ class TestUltraProvider(TestCase):
# Test different paging behavior # Test different paging behavior
provider._zones = None provider._zones = None
with requests_mock() as mock: with requests_mock() as mock:
mock.get('{}{}?limit=100&q=zone_type%3APRIMARY&offset=0'
.format(self.host, path), status_code=200,
mock.get(f'{self.host}{path}?limit=100&q=zone_type%3APRIMARY&'
'offset=0', status_code=200,
json={"resultInfo": {"totalCount": 15, json={"resultInfo": {"totalCount": 15,
"offset": 0, "offset": 0,
"returnedCount": 10}, "returnedCount": 10},
"zones": []}) "zones": []})
mock.get('{}{}?limit=100&q=zone_type%3APRIMARY&offset=10'
.format(self.host, path), status_code=200,
mock.get(f'{self.host}{path}?limit=100&q=zone_type%3APRIMARY'
'&offset=10', status_code=200,
json={"resultInfo": {"totalCount": 15, json={"resultInfo": {"totalCount": 15,
"offset": 10, "offset": 10,
"returnedCount": 5}, "returnedCount": 5},
@ -141,7 +141,7 @@ class TestUltraProvider(TestCase):
payload = {'a': 1} payload = {'a': 1}
with requests_mock() as mock: with requests_mock() as mock:
mock.get('{}{}'.format(self.host, path), status_code=401,
mock.get(f'{self.host}{path}', status_code=401,
headers={'Authorization': 'Bearer 123'}, json={}) headers={'Authorization': 'Bearer 123'}, json={})
with self.assertRaises(Exception) as ctx: with self.assertRaises(Exception) as ctx:
provider._get(path) provider._get(path)
@ -149,37 +149,37 @@ class TestUltraProvider(TestCase):
# Test all GET patterns # Test all GET patterns
with requests_mock() as mock: with requests_mock() as mock:
mock.get('{}{}'.format(self.host, path), status_code=200,
mock.get(f'{self.host}{path}', status_code=200,
headers={'Authorization': 'Bearer 123'}, headers={'Authorization': 'Bearer 123'},
json=payload) json=payload)
provider._get(path, json=payload) provider._get(path, json=payload)
mock.get('{}{}?a=1'.format(self.host, path), status_code=200,
mock.get(f'{self.host}{path}?a=1', status_code=200,
headers={'Authorization': 'Bearer 123'}) headers={'Authorization': 'Bearer 123'})
provider._get(path, params=payload, json_response=False) provider._get(path, params=payload, json_response=False)
# Test all POST patterns # Test all POST patterns
with requests_mock() as mock: with requests_mock() as mock:
mock.post('{}{}'.format(self.host, path), status_code=200,
mock.post(f'{self.host}{path}', status_code=200,
headers={'Authorization': 'Bearer 123'}, headers={'Authorization': 'Bearer 123'},
json=payload) json=payload)
provider._post(path, json=payload) provider._post(path, json=payload)
mock.post('{}{}'.format(self.host, path), status_code=200,
mock.post(f'{self.host}{path}', status_code=200,
headers={'Authorization': 'Bearer 123'}, headers={'Authorization': 'Bearer 123'},
text="{'a':1}") text="{'a':1}")
provider._post(path, data=payload, json_response=False) provider._post(path, data=payload, json_response=False)
# Test all PUT patterns # Test all PUT patterns
with requests_mock() as mock: with requests_mock() as mock:
mock.put('{}{}'.format(self.host, path), status_code=200,
mock.put(f'{self.host}{path}', status_code=200,
headers={'Authorization': 'Bearer 123'}, headers={'Authorization': 'Bearer 123'},
json=payload) json=payload)
provider._put(path, json=payload) provider._put(path, json=payload)
# Test all DELETE patterns # Test all DELETE patterns
with requests_mock() as mock: with requests_mock() as mock:
mock.delete('{}{}'.format(self.host, path), status_code=200,
mock.delete(f'{self.host}{path}', status_code=200,
headers={'Authorization': 'Bearer 123'}) headers={'Authorization': 'Bearer 123'})
provider._delete(path, json_response=False) provider._delete(path, json_response=False)
@ -221,10 +221,9 @@ class TestUltraProvider(TestCase):
zone_path = '/v2/zones' zone_path = '/v2/zones'
rec_path = '/v2/zones/octodns1.test./rrsets' rec_path = '/v2/zones/octodns1.test./rrsets'
with requests_mock() as mock: with requests_mock() as mock:
mock.get('{}{}?limit=100&q=zone_type%3APRIMARY&offset=0'
.format(self.host, zone_path),
status_code=200, json=zone_payload)
mock.get('{}{}?offset=0&limit=100'.format(self.host, rec_path),
mock.get(f'{self.host}{zone_path}?limit=100&q=zone_type%3APRIMARY&'
'offset=0', status_code=200, json=zone_payload)
mock.get(f'{self.host}{rec_path}?offset=0&limit=100',
status_code=200, json=records_payload) status_code=200, json=records_payload)
zone = Zone('octodns1.test.', []) zone = Zone('octodns1.test.', [])
@ -257,21 +256,18 @@ class TestUltraProvider(TestCase):
path = '/v2/zones' path = '/v2/zones'
with requests_mock() as mock: with requests_mock() as mock:
with open('tests/fixtures/ultra-zones-page-1.json') as fh: with open('tests/fixtures/ultra-zones-page-1.json') as fh:
mock.get('{}{}?limit=100&q=zone_type%3APRIMARY&offset=0'
.format(self.host, path),
status_code=200, text=fh.read())
mock.get(f'{self.host}{path}?limit=100&q=zone_type%3APRIMARY&'
'offset=0', status_code=200, text=fh.read())
with open('tests/fixtures/ultra-zones-page-2.json') as fh: with open('tests/fixtures/ultra-zones-page-2.json') as fh:
mock.get('{}{}?limit=100&q=zone_type%3APRIMARY&offset=10'
.format(self.host, path),
status_code=200, text=fh.read())
mock.get(f'{self.host}{path}?limit=100&q=zone_type%3APRIMARY&'
'offset=10', status_code=200, text=fh.read())
with open('tests/fixtures/ultra-records-page-1.json') as fh: with open('tests/fixtures/ultra-records-page-1.json') as fh:
rec_path = '/v2/zones/octodns1.test./rrsets' rec_path = '/v2/zones/octodns1.test./rrsets'
mock.get('{}{}?offset=0&limit=100'.format(self.host, rec_path),
mock.get(f'{self.host}{rec_path}?offset=0&limit=100',
status_code=200, text=fh.read()) status_code=200, text=fh.read())
with open('tests/fixtures/ultra-records-page-2.json') as fh: with open('tests/fixtures/ultra-records-page-2.json') as fh:
rec_path = '/v2/zones/octodns1.test./rrsets' rec_path = '/v2/zones/octodns1.test./rrsets'
mock.get('{}{}?offset=10&limit=100'
.format(self.host, rec_path),
mock.get(f'{self.host}{rec_path}?offset=10&limit=100',
status_code=200, text=fh.read()) status_code=200, text=fh.read())
zone = Zone('octodns1.test.', []) zone = Zone('octodns1.test.', [])


+ 2
- 2
tests/test_octodns_source_envvar.py View File

@ -14,7 +14,7 @@ class TestEnvVarSource(TestCase):
source = EnvVarSource('testid', envvar, 'recordname', ttl=120) source = EnvVarSource('testid', envvar, 'recordname', ttl=120)
with self.assertRaises(EnvironmentVariableNotFoundException) as ctx: with self.assertRaises(EnvironmentVariableNotFoundException) as ctx:
source._read_variable() source._read_variable()
msg = 'Unknown environment variable {}'.format(envvar)
msg = f'Unknown environment variable {envvar}'
self.assertEquals(msg, text_type(ctx.exception)) self.assertEquals(msg, text_type(ctx.exception))
with patch.dict('os.environ', {envvar: 'testvalue'}): with patch.dict('os.environ', {envvar: 'testvalue'}):
@ -35,7 +35,7 @@ class TestEnvVarSource(TestCase):
self.assertEquals(1, len(zone.records)) self.assertEquals(1, len(zone.records))
record = list(zone.records)[0] record = list(zone.records)[0]
self.assertEquals(name, record.name) self.assertEquals(name, record.name)
self.assertEquals('{}.{}'.format(name, zone_name), record.fqdn)
self.assertEquals(f'{name}.{zone_name}', record.fqdn)
self.assertEquals('TXT', record._type) self.assertEquals('TXT', record._type)
self.assertEquals(1, len(record.values)) self.assertEquals(1, len(record.values))
self.assertEquals(value, record.values[0]) self.assertEquals(value, record.values[0])

Loading…
Cancel
Save