Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 1ba1ca5

Browse files
committed
lint found minor stuff
1 parent dbec555 commit 1ba1ca5

16 files changed

+145
-34
lines changed

CloudFlare/tests/test_add.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
cf = None
1313

1414
def test_cloudflare(debug=False):
15+
""" test_cloudflare """
1516
global cf
1617
cf = CloudFlare.CloudFlare(debug=debug)
1718
assert isinstance(cf, CloudFlare.CloudFlare)
1819

1920
def test_app_invalid():
21+
""" test_app_invalid """
2022
"""add API commands"""
2123
cf.add('OPEN', 'invalid')
2224
try:
@@ -60,4 +62,3 @@ def test_app_invalid_with_dash():
6062
test_app_invalid()
6163
test_app_invalid_with_underscore()
6264
test_app_invalid_with_dash()
63-

CloudFlare/tests/test_api_dump.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
OPENAPI_URL = "https://github.com/cloudflare/api-schemas/raw/main/openapi.json"
1616

1717
def test_cloudflare(debug=False):
18+
""" test_cloudflare """
1819
global cf
1920
cf = CloudFlare.CloudFlare(debug=debug)
2021
assert isinstance(cf, CloudFlare.CloudFlare)
2122

22-
verb_only = re.compile('^[a-zA-Z0-9][a-zA-Z0-9_\-]*[a-zA-Z0-9]$')
23+
verb_only = re.compile('^[a-zA-Z0-9][-a-zA-Z0-9_]*[a-zA-Z0-9]$')
2324

2425
def check_cmd_syntax(cmd):
26+
""" check_cmd_syntax """
2527
assert '/' == cmd[0]
2628
for verb in cmd[1:].split('/'):
2729
if verb[0] == '@':
@@ -35,6 +37,7 @@ def check_cmd_syntax(cmd):
3537
assert bool(verb_only.match(verb))
3638

3739
def check_method_syntax(method):
40+
""" check_method_syntax """
3841
assert method in ['GET', 'POST', 'PATCH', 'PUT', 'DELETE']
3942

4043
def test_api_list():

CloudFlare/tests/test_certificates.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
cf = None
1414

1515
def test_cloudflare(debug=False):
16+
""" test_cloudflare """
1617
global cf
1718
cf = CloudFlare.CloudFlare(debug=debug)
1819
assert isinstance(cf, CloudFlare.CloudFlare)
@@ -21,6 +22,7 @@ def test_cloudflare(debug=False):
2122
zone_id = None
2223

2324
def test_find_zone(domain_name=None):
25+
""" test_find_zone """
2426
global zone_name, zone_id
2527
# grab a random zone identifier from the first 10 zones
2628
if domain_name:
@@ -31,7 +33,7 @@ def test_find_zone(domain_name=None):
3133
zones = cf.zones.get(params=params)
3234
except CloudFlare.exceptions.CloudFlareAPIError as e:
3335
print('%s: Error %d=%s' % (domain_name, int(e), str(e)), file=sys.stderr)
34-
exit(0)
36+
assert False
3537
assert len(zones) > 0 and len(zones) <= 10
3638
n = random.randrange(len(zones))
3739
zone_name = zones[n]['name']
@@ -40,12 +42,13 @@ def test_find_zone(domain_name=None):
4042
print('zone: %s %s' % (zone_id, zone_name), file=sys.stderr)
4143

4244
def test_certificates():
45+
""" test_certificates """
4346
params = {'zone_id':zone_id}
4447
try:
4548
certificates = cf.certificates(params=params)
4649
except CloudFlare.exceptions.CloudFlareAPIError as e:
4750
print('%s: Error %d=%s - can not run this test on this domain - no worries - skipping' % (zone_name, int(e), str(e)), file=sys.stderr)
48-
exit(0)
51+
return
4952

5053
assert isinstance(certificates, list)
5154
if len(certificates) == 0:

CloudFlare/tests/test_cloudflare.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,74 +7,88 @@
77
sys.path.insert(0, os.path.abspath('..'))
88
import CloudFlare
99

10-
global cf
10+
cf = None
1111

1212
def test_cloudflare(debug=False):
13+
""" test_cloudflare """
1314
global cf
1415
cf = CloudFlare.CloudFlare(debug=debug)
1516
assert isinstance(cf, CloudFlare.CloudFlare)
1617

1718
def test_ips1():
19+
""" test_ips1 """
1820
ips = cf.ips()
1921
assert isinstance(ips, dict)
2022
assert len(ips) > 0
2123

2224
def test_cloudflare_with_global_request_timeout(debug=False):
25+
""" test_cloudflare_with_global_request_timeout """
2326
global cf
2427
cf = CloudFlare.CloudFlare(debug=debug, global_request_timeout=10)
2528
assert isinstance(cf, CloudFlare.CloudFlare)
2629

2730
def test_ips2():
31+
""" test_ips2 """
2832
ips = cf.ips()
2933
assert isinstance(ips, dict)
3034
assert len(ips) > 0
3135

3236
def test_cloudflare_with_max_request_retries(debug=False):
37+
""" test_cloudflare_with_max_request_retries """
3338
global cf
3439
cf = CloudFlare.CloudFlare(debug=debug, max_request_retries=2)
3540
assert isinstance(cf, CloudFlare.CloudFlare)
3641

3742
def test_ips3():
43+
""" test_ips3 """
3844
ips = cf.ips()
3945
assert isinstance(ips, dict)
4046
assert len(ips) > 0
4147

4248
def test_cloudflare_with_global_request_timeout_and_max_request_retries(debug=False):
49+
""" test_cloudflare_with_global_request_timeout_and_max_request_retries """
4350
global cf
4451
cf = CloudFlare.CloudFlare(debug=debug, global_request_timeout=10, max_request_retries=2)
4552
assert isinstance(cf, CloudFlare.CloudFlare)
4653

4754
def test_ips4():
55+
""" test_ips4 """
4856
ips = cf.ips()
4957
assert isinstance(ips, dict)
5058
assert len(ips) > 0
5159

5260
def test_cloudflare_with_global_request_timeout_invalid(debug=False):
61+
""" test_cloudflare_with_global_request_timeout_invalid """
5362
global cf
5463
cf = CloudFlare.CloudFlare(debug=debug, global_request_timeout='STRING')
5564
assert isinstance(cf, CloudFlare.CloudFlare)
5665

5766
def test_ips5():
67+
""" test_ips5 """
5868
ips = cf.ips()
5969
assert isinstance(ips, dict)
6070
assert len(ips) > 0
6171

6272
def test_cloudflare_with_max_request_retries_invalid(debug=False):
73+
""" test_cloudflare_with_max_request_retries_invalid """
6374
global cf
6475
cf = CloudFlare.CloudFlare(debug=debug, max_request_retries='STRING')
6576
assert isinstance(cf, CloudFlare.CloudFlare)
6677

6778
def test_ips6():
79+
""" test_ips6 """
6880
ips = cf.ips()
6981
assert isinstance(ips, dict)
7082
assert len(ips) > 0
7183

7284
def test_cloudflare_with_global_request_timeout_and_max_request_retries_invalid(debug=False):
85+
""" test_cloudflare_with_global_request_timeout_and_max_request_retries_invalid """
7386
global cf
7487
cf = CloudFlare.CloudFlare(debug=debug, global_request_timeout='STRING', max_request_retries='STRING')
7588
assert isinstance(cf, CloudFlare.CloudFlare)
7689

7790
def test_ips7():
91+
""" test_ips7 """
7892
ips = cf.ips()
7993
assert isinstance(ips, dict)
8094
assert len(ips) > 0
@@ -94,4 +108,3 @@ def test_ips7():
94108
test_ips6()
95109
test_cloudflare_with_global_request_timeout_and_max_request_retries_invalid(debug=True)
96110
test_ips7()
97-

CloudFlare/tests/test_dns_import_export.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
cf = None
1717

1818
def test_cloudflare():
19+
""" test_cloudflare """
1920
global cf
2021
cf = CloudFlare.CloudFlare()
2122
assert isinstance(cf, CloudFlare.CloudFlare)
@@ -24,6 +25,7 @@ def test_cloudflare():
2425
zone_id = None
2526

2627
def test_find_zone(domain_name=None):
28+
""" test_find_zone """
2729
global zone_name, zone_id
2830
# grab a random zone identifier from the first 10 zones
2931
if domain_name:
@@ -34,7 +36,7 @@ def test_find_zone(domain_name=None):
3436
zones = cf.zones.get(params=params)
3537
except CloudFlare.exceptions.CloudFlareAPIError as e:
3638
print('%s: Error %d=%s' % (domain_name, int(e), str(e)), file=sys.stderr)
37-
exit(0)
39+
assert False
3840
assert len(zones) > 0 and len(zones) <= 10
3941
n = random.randrange(len(zones))
4042
zone_name = zones[n]['name']
@@ -43,6 +45,7 @@ def test_find_zone(domain_name=None):
4345
print('zone: %s %s' % (zone_id, zone_name), file=sys.stderr)
4446

4547
def test_dns_import():
48+
""" test_dns_import """
4649
# IMPORT
4750
# create a zero length file
4851
fp = tempfile.TemporaryFile(mode='w+b')
@@ -62,6 +65,7 @@ def test_dns_import():
6265
assert results['total_records_parsed'] == 0
6366

6467
def test_dns_export():
68+
""" test_dns_export """
6569
# EXPORT
6670
dns_records = cf.zones.dns_records.export.get(zone_id)
6771
assert len(dns_records) > 0
@@ -70,11 +74,13 @@ def test_dns_export():
7074
assert 'NS' in dns_records
7175

7276
def test_cloudflare_with_debug():
77+
""" test_cloudflare_with_debug """
7378
global cf
7479
cf = CloudFlare.CloudFlare(debug=True)
7580
assert isinstance(cf, CloudFlare.CloudFlare)
7681

7782
def test_dns_import_with_debug():
83+
""" test_dns_import_with_debug """
7884
# IMPORT
7985
# create a zero length file
8086
fp = tempfile.TemporaryFile(mode='w+b')
@@ -94,6 +100,7 @@ def test_dns_import_with_debug():
94100
assert results['total_records_parsed'] == 0
95101

96102
def test_dns_export_with_debug():
103+
""" test_dns_export_with_debug """
97104
# EXPORT
98105
dns_records = cf.zones.dns_records.export.get(zone_id)
99106
assert len(dns_records) > 0

CloudFlare/tests/test_dns_records.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
cf = None
1515

1616
def test_cloudflare(debug=False):
17+
""" test_cloudflare """
1718
global cf
1819
cf = CloudFlare.CloudFlare(debug=debug)
1920
assert isinstance(cf, CloudFlare.CloudFlare)
@@ -22,6 +23,7 @@ def test_cloudflare(debug=False):
2223
zone_id = None
2324

2425
def test_find_zone(domain_name=None):
26+
""" test_find_zone """
2527
global zone_name, zone_id
2628
# grab a random zone identifier from the first 10 zones
2729
if domain_name:
@@ -47,6 +49,7 @@ def test_find_zone(domain_name=None):
4749
dns_content3 = None
4850

4951
def test_dns_records_create_values():
52+
""" test_dns_records_create_values """
5053
global dns_name, dns_type, dns_content1, dns_content2, dns_content3
5154
dns_name = str(uuid.uuid1())
5255
dns_type = 'TXT'
@@ -56,6 +59,7 @@ def test_dns_records_create_values():
5659
print('dns_record: %s' % (dns_name), file=sys.stderr)
5760

5861
def test_dns_records_port_invalid():
62+
""" test_dns_records_port_invalid """
5963
# create an invalid DNS record - i.e. txt value for A record IP address
6064
dns_record = {'name':dns_name, 'type':'A', 'content':'NOT-A-VALID-IP-ADDRESS'}
6165
try:
@@ -70,6 +74,7 @@ def test_dns_records_port_invalid():
7074
assert True
7175

7276
def test_dns_records_get1():
77+
""" test_dns_records_get1 """
7378
# GET
7479
params = {'name':dns_name + '.' + zone_name, 'match':'all', 'type':dns_type}
7580
dns_results = cf.zones.dns_records.get(zone_id, params=params)
@@ -78,6 +83,7 @@ def test_dns_records_get1():
7883
dns_id = None
7984

8085
def test_dns_records_post():
86+
""" test_dns_records_post """
8187
global dns_id
8288
# POST
8389
dns_record = {'name':dns_name, 'type':dns_type, 'content':dns_content1}
@@ -91,6 +97,7 @@ def test_dns_records_post():
9197
print('dns_record: %s %s' % (dns_name, dns_id), file=sys.stderr)
9298

9399
def test_dns_records_get2():
100+
""" test_dns_records_get2 """
94101
# GET
95102
params = {'name':dns_name + '.' + zone_name, 'match':'all', 'type':dns_type}
96103
dns_results = cf.zones.dns_records.get(zone_id, params=params)
@@ -100,13 +107,15 @@ def test_dns_records_get2():
100107
assert dns_results[0]['content'] == dns_content1
101108

102109
def test_dns_records_get3():
110+
""" test_dns_records_get3 """
103111
# GET
104112
dns_result = cf.zones.dns_records.get(zone_id, dns_id)
105113
assert dns_result['name'] == dns_name + '.' + zone_name
106114
assert dns_result['type'] == dns_type
107115
assert dns_result['content'] == dns_content1
108116

109117
def test_dns_records_patch():
118+
""" test_dns_records_patch """
110119
# PATCH
111120
dns_record = {'content':dns_content2}
112121
dns_result = cf.zones.dns_records.patch(zone_id, dns_id, data=dns_record)
@@ -115,6 +124,7 @@ def test_dns_records_patch():
115124
assert dns_result['content'] == dns_content2
116125

117126
def test_dns_records_put():
127+
""" test_dns_records_put """
118128
# PUT
119129
dns_record = {'name':dns_name, 'type':dns_type, 'content':dns_content3}
120130
dns_result = cf.zones.dns_records.put(zone_id, dns_id, data=dns_record)
@@ -123,18 +133,21 @@ def test_dns_records_put():
123133
assert dns_result['content'] == dns_content3
124134

125135
def test_dns_records_get4():
136+
""" test_dns_records_get4 """
126137
# GET
127138
dns_result = cf.zones.dns_records.get(zone_id, dns_id)
128139
assert dns_result['name'] == dns_name + '.' + zone_name
129140
assert dns_result['type'] == dns_type
130141
assert dns_result['content'] == dns_content3
131142

132143
def test_dns_records_delete():
144+
""" test_dns_records_delete """
133145
# DELETE
134146
dns_result = cf.zones.dns_records.delete(zone_id, dns_id)
135147
assert dns_result['id'] == dns_id
136148

137149
def test_dns_records_get5():
150+
""" test_dns_records_get5 """
138151
# GET
139152
params = {'name':dns_name + '.' + zone_name, 'match':'all', 'type':dns_type}
140153
dns_results = cf.zones.dns_records.get(zone_id, params=params)

CloudFlare/tests/test_graphql.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
cf = None
1818

1919
def test_cloudflare(debug=False):
20+
""" test_cloudflare """
2021
global cf
2122
cf = CloudFlare.CloudFlare(debug=debug)
2223
assert isinstance(cf, CloudFlare.CloudFlare)
@@ -25,6 +26,7 @@ def test_cloudflare(debug=False):
2526
zone_id = None
2627

2728
def test_find_zone(domain_name=None):
29+
""" test_find_zone """
2830
global zone_name, zone_id
2931
# grab a random zone identifier from the first 10 zones
3032
if domain_name:
@@ -35,7 +37,7 @@ def test_find_zone(domain_name=None):
3537
zones = cf.zones.get(params=params)
3638
except CloudFlare.exceptions.CloudFlareAPIError as e:
3739
print('%s: Error %d=%s' % (domain_name, int(e), str(e)), file=sys.stderr)
38-
exit(0)
40+
assert False
3941
assert len(zones) > 0 and len(zones) <= 10
4042
n = random.randrange(len(zones))
4143
zone_name = zones[n]['name']
@@ -75,14 +77,15 @@ def test_graphql():
7577
try:
7678
r = cf.graphql.post(data={'query':query})
7779
except CloudFlare.exceptions.CloudFlareAPIError as e:
78-
exit('/graphql.post %d %s - api call failed' % (e, e))
80+
print('%s: Error %d=%s' % ('/graphql.post', int(e), str(e)), file=sys.stderr)
81+
assert False
7982

8083
# success - lets confirm it's graphql results as-per query above
8184

8285
# basic graphql results
8386
assert 'data' in r
8487
assert 'errors' in r
85-
assert r['errors'] == None
88+
assert r['errors'] is None
8689

8790
# viewer and zones from above
8891
assert 'viewer' in r['data']

0 commit comments

Comments
 (0)