mirror of
https://github.com/github/octodns.git
synced 2024-05-11 05:55:00 +00:00
f-strings for the rest of the tests
This commit is contained in:
@@ -129,7 +129,7 @@ class TestOwnershipProcessor(TestCase):
|
||||
# two delete changes.
|
||||
the_a = records['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, {
|
||||
'ttl': 30,
|
||||
'type': 'TXT',
|
||||
|
||||
@@ -157,36 +157,31 @@ class TestCloudflareProvider(TestCase):
|
||||
|
||||
# zones
|
||||
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:
|
||||
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,
|
||||
'per_page': 0}})
|
||||
|
||||
base = '{}/234234243423aaabb334342aaa343435'.format(base)
|
||||
base = f'{base}/234234243423aaabb334342aaa343435'
|
||||
|
||||
# pagerules/URLFWD
|
||||
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())
|
||||
|
||||
# records
|
||||
base = '{}/dns_records'.format(base)
|
||||
base = f'{base}/dns_records'
|
||||
with open('tests/fixtures/cloudflare-dns_records-'
|
||||
'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-'
|
||||
'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-'
|
||||
'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.', [])
|
||||
provider.populate(zone)
|
||||
|
||||
@@ -192,17 +192,13 @@ class TestConstellixProvider(TestCase):
|
||||
with requests_mock() as mock:
|
||||
base = 'https://api.dns.constellix.com/v1'
|
||||
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:
|
||||
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:
|
||||
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:
|
||||
mock.get('{}{}'.format(base, '/geoFilters'),
|
||||
text=fh.read())
|
||||
mock.get(f'{base}/geoFilters', text=fh.read())
|
||||
|
||||
zone = Zone('unit.tests.', [])
|
||||
provider.populate(zone)
|
||||
|
||||
@@ -79,9 +79,9 @@ class TestDnsimpleProvider(TestCase):
|
||||
base = 'https://api.dnsimple.com/v2/42/zones/unit.tests/' \
|
||||
'records?page='
|
||||
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:
|
||||
mock.get('{}{}'.format(base, 2), text=fh.read())
|
||||
mock.get(f'{base}2', text=fh.read())
|
||||
|
||||
zone = Zone('unit.tests.', [])
|
||||
provider.populate(zone)
|
||||
|
||||
@@ -95,10 +95,9 @@ class TestDnsMadeEasyProvider(TestCase):
|
||||
with requests_mock() as mock:
|
||||
base = 'https://api.dnsmadeeasy.com/V2.0/dns/managed'
|
||||
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:
|
||||
mock.get('{}{}'.format(base, '/123123/records'),
|
||||
text=fh.read())
|
||||
mock.get(f'{base}/123123/records', text=fh.read())
|
||||
|
||||
zone = Zone('unit.tests.', [])
|
||||
provider.populate(zone)
|
||||
|
||||
@@ -195,7 +195,7 @@ class TestGCoreProvider(TestCase):
|
||||
str(ctx.exception).startswith(
|
||||
"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):
|
||||
|
||||
@@ -156,8 +156,7 @@ class DummyResourceRecordSet:
|
||||
return False
|
||||
|
||||
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):
|
||||
return hash(repr(self))
|
||||
@@ -419,7 +418,7 @@ class TestGoogleCloudProvider(TestCase):
|
||||
dummy_gcloud_zone = DummyGoogleCloudZone("unit.tests")
|
||||
for octo_record in octo_records:
|
||||
_rrset_func = getattr(
|
||||
provider, '_rrset_for_{}'.format(octo_record._type))
|
||||
provider, f'_rrset_for_{octo_record._type}')
|
||||
self.assertEqual(
|
||||
_rrset_func(dummy_gcloud_zone, octo_record).record_type,
|
||||
octo_record._type
|
||||
|
||||
@@ -68,9 +68,9 @@ class TestHetznerProvider(TestCase):
|
||||
with requests_mock() as mock:
|
||||
base = provider._client.BASE_URL
|
||||
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:
|
||||
mock.get('{}/records'.format(base), text=fh.read())
|
||||
mock.get(f'{base}/records', text=fh.read())
|
||||
|
||||
zone = Zone('unit.tests.', [])
|
||||
provider.populate(zone)
|
||||
|
||||
@@ -1653,7 +1653,7 @@ class TestNs1ProviderDynamic(TestCase):
|
||||
'meta': {
|
||||
'priority': 1,
|
||||
'weight': 12,
|
||||
'note': 'from:{}'.format(catchall_pool_name),
|
||||
'note': f'from:{catchall_pool_name}',
|
||||
},
|
||||
'region': catchall_pool_name,
|
||||
}, {
|
||||
@@ -1774,8 +1774,7 @@ class TestNs1ProviderDynamic(TestCase):
|
||||
partial_oc_cntry_list
|
||||
data4 = provider._data_for_A('A', ns1_record)
|
||||
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
|
||||
# 1. Full list of countries should return 'NA' in geos
|
||||
@@ -1792,8 +1791,7 @@ class TestNs1ProviderDynamic(TestCase):
|
||||
partial_na_cntry_list
|
||||
data6 = provider._data_for_A('A', ns1_record)
|
||||
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
|
||||
ns1_record = {
|
||||
@@ -1919,7 +1917,7 @@ class TestNs1ProviderDynamic(TestCase):
|
||||
'meta': {
|
||||
'priority': 1,
|
||||
'weight': 12,
|
||||
'note': 'from:{}'.format(catchall_pool_name),
|
||||
'note': f'from:{catchall_pool_name}',
|
||||
},
|
||||
'region': catchall_pool_name,
|
||||
}, {
|
||||
|
||||
@@ -45,8 +45,7 @@ class MockDomainService(object):
|
||||
_dns_entries = []
|
||||
for record in records:
|
||||
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
|
||||
name = record.name
|
||||
|
||||
@@ -41,7 +41,7 @@ class TestUltraProvider(TestCase):
|
||||
|
||||
# Bad Auth
|
||||
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}')
|
||||
with self.assertRaises(Exception) as ctx:
|
||||
UltraProvider('test', 'account', 'user', 'wrongpass')
|
||||
@@ -50,7 +50,7 @@ class TestUltraProvider(TestCase):
|
||||
# Good Auth
|
||||
with requests_mock() as mock:
|
||||
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,
|
||||
text='{"token type": "Bearer", "refresh_token": "abc", '
|
||||
'"access_token":"123", "expires_in": "3600"}')
|
||||
@@ -67,7 +67,7 @@ class TestUltraProvider(TestCase):
|
||||
|
||||
# Test authorization issue
|
||||
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,
|
||||
"errorMessage": "Authorization Header required"})
|
||||
with self.assertRaises(HTTPError) as ctx:
|
||||
@@ -76,7 +76,7 @@ class TestUltraProvider(TestCase):
|
||||
|
||||
# Test no zones exist error
|
||||
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'},
|
||||
json=self.empty_body)
|
||||
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'},
|
||||
json=payload)
|
||||
zones = provider.zones
|
||||
@@ -120,14 +120,14 @@ class TestUltraProvider(TestCase):
|
||||
# Test different paging behavior
|
||||
provider._zones = None
|
||||
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,
|
||||
"offset": 0,
|
||||
"returnedCount": 10},
|
||||
"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,
|
||||
"offset": 10,
|
||||
"returnedCount": 5},
|
||||
@@ -141,7 +141,7 @@ class TestUltraProvider(TestCase):
|
||||
payload = {'a': 1}
|
||||
|
||||
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={})
|
||||
with self.assertRaises(Exception) as ctx:
|
||||
provider._get(path)
|
||||
@@ -149,37 +149,37 @@ class TestUltraProvider(TestCase):
|
||||
|
||||
# Test all GET patterns
|
||||
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'},
|
||||
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'})
|
||||
provider._get(path, params=payload, json_response=False)
|
||||
|
||||
# Test all POST patterns
|
||||
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'},
|
||||
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'},
|
||||
text="{'a':1}")
|
||||
provider._post(path, data=payload, json_response=False)
|
||||
|
||||
# Test all PUT patterns
|
||||
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'},
|
||||
json=payload)
|
||||
provider._put(path, json=payload)
|
||||
|
||||
# Test all DELETE patterns
|
||||
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'})
|
||||
provider._delete(path, json_response=False)
|
||||
|
||||
@@ -221,10 +221,9 @@ class TestUltraProvider(TestCase):
|
||||
zone_path = '/v2/zones'
|
||||
rec_path = '/v2/zones/octodns1.test./rrsets'
|
||||
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)
|
||||
|
||||
zone = Zone('octodns1.test.', [])
|
||||
@@ -257,21 +256,18 @@ class TestUltraProvider(TestCase):
|
||||
path = '/v2/zones'
|
||||
with requests_mock() as mock:
|
||||
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:
|
||||
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:
|
||||
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())
|
||||
with open('tests/fixtures/ultra-records-page-2.json') as fh:
|
||||
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())
|
||||
|
||||
zone = Zone('octodns1.test.', [])
|
||||
|
||||
@@ -14,7 +14,7 @@ class TestEnvVarSource(TestCase):
|
||||
source = EnvVarSource('testid', envvar, 'recordname', ttl=120)
|
||||
with self.assertRaises(EnvironmentVariableNotFoundException) as ctx:
|
||||
source._read_variable()
|
||||
msg = 'Unknown environment variable {}'.format(envvar)
|
||||
msg = f'Unknown environment variable {envvar}'
|
||||
self.assertEquals(msg, text_type(ctx.exception))
|
||||
|
||||
with patch.dict('os.environ', {envvar: 'testvalue'}):
|
||||
@@ -35,7 +35,7 @@ class TestEnvVarSource(TestCase):
|
||||
self.assertEquals(1, len(zone.records))
|
||||
record = list(zone.records)[0]
|
||||
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(1, len(record.values))
|
||||
self.assertEquals(value, record.values[0])
|
||||
|
||||
Reference in New Issue
Block a user