Skip to content

Commit 6fb204c

Browse files
authored
Merge pull request #92 from akx/blacken
Blacken codebase style
2 parents d0ea6d3 + e908399 commit 6fb204c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+602
-506
lines changed

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[tool.black]
2+
line-length = 99
3+
target-version = ['py36']
4+
skip-string-normalization = true

requirements-dev.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
black~=21.4b1; platform_python_implementation != "PyPy"
12
flake8
23
flake8-docstrings
34
hacking

requirements-dev.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
#
55
# pip-compile requirements-dev.in
66
#
7+
appdirs==1.4.4
8+
# via black
79
attrs==20.3.0
810
# via pytest
11+
black==21.4b1 ; platform_python_implementation != "PyPy"
12+
# via -r requirements-dev.in
913
certifi==2020.12.5
1014
# via requests
1115
chardet==4.0.0
1216
# via requests
1317
click==7.1.2
1418
# via
19+
# black
1520
# pip-tools
1621
# safety
1722
dparse==0.5.1
@@ -33,11 +38,15 @@ mccabe==0.6.1
3338
# via flake8
3439
mock==4.0.3
3540
# via -r requirements-dev.in
41+
mypy-extensions==0.4.3
42+
# via black
3643
packaging==20.9
3744
# via
3845
# dparse
3946
# pytest
4047
# safety
48+
pathspec==0.8.1
49+
# via black
4150
pep517==0.10.0
4251
# via pip-tools
4352
pip-tools==6.1.0
@@ -58,6 +67,8 @@ pytest==6.2.3
5867
# via -r requirements-dev.in
5968
pyyaml==5.4.1
6069
# via dparse
70+
regex==2021.4.4
71+
# via black
6172
requests==2.25.1
6273
# via
6374
# responses
@@ -72,6 +83,7 @@ snowballstemmer==2.1.0
7283
# via pydocstyle
7384
toml==0.10.2
7485
# via
86+
# black
7587
# dparse
7688
# pep517
7789
# pytest

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ def get_version(rel_path):
2424
long_description = f.read()
2525

2626
if __name__ == "__main__":
27-
setup(version=get_version('upcloud_api/__init__.py'))
27+
setup(version=get_version('upcloud_api/__init__.py'))

test/conftest.py

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ def pytest_addoption(parser):
1717
@pytest.fixture(scope='module')
1818
def manager():
1919
import upcloud_api
20+
2021
return upcloud_api.CloudManager("testuser", "mock-api-password")
2122

2223

2324
def read_from_file(filename):
2425
filename = filename.replace("/", "_")
2526
cwd = os.path.dirname(__file__)
26-
f = open(cwd + '/json_data/'+filename)
27+
f = open(cwd + '/json_data/' + filename)
2728
return f.read()
2829

2930

@@ -40,14 +41,19 @@ def mock_get(target, response_file=None):
4041
response_file = target + '.json'
4142

4243
data = Mock.read_from_file(response_file)
43-
responses.add(responses.GET, Mock.base_url + '/' + target,
44-
body=data,
45-
status=200,
46-
content_type='application/json')
44+
responses.add(
45+
responses.GET,
46+
Mock.base_url + '/' + target,
47+
body=data,
48+
status=200,
49+
content_type='application/json',
50+
)
4751
return data
4852

4953
@staticmethod
50-
def __put_patch_post_callback(request, target, data, ignore_data_field=False, empty_payload=False):
54+
def __put_patch_post_callback(
55+
request, target, data, ignore_data_field=False, empty_payload=False
56+
):
5157
data_field = target.split("/")[0]
5258

5359
if not empty_payload:
@@ -57,61 +63,74 @@ def __put_patch_post_callback(request, target, data, ignore_data_field=False, em
5763
for field in data[data_field]:
5864
if field in payload[data_field]:
5965
data[data_field][field] = payload[data_field][field]
60-
return(200, {}, json.dumps(data))
66+
return (200, {}, json.dumps(data))
6167

6268
@staticmethod
6369
def mock_post(target, empty_content=False, ignore_data_field=False, empty_payload=False):
64-
6570
def callback(request):
6671
if not empty_content:
6772
data = json.loads(Mock.read_from_file(target + '_post.json'))
68-
return Mock.__put_patch_post_callback(request, target, data, ignore_data_field, empty_payload)
73+
return Mock.__put_patch_post_callback(
74+
request, target, data, ignore_data_field, empty_payload
75+
)
6976
else:
70-
return(200, {}, '{}')
77+
return (200, {}, '{}')
7178

72-
responses.add_callback(responses.POST, Mock.base_url + '/' + target,
73-
callback=callback,
74-
content_type='application/json')
79+
responses.add_callback(
80+
responses.POST,
81+
Mock.base_url + '/' + target,
82+
callback=callback,
83+
content_type='application/json',
84+
)
7585

7686
@staticmethod
7787
def mock_put(target, ignore_data_field=False, empty_payload=False, call_api=True):
7888
data = json.loads(Mock.read_from_file(target + '.json'))
7989

8090
def callback(request):
81-
return Mock.__put_patch_post_callback(request, target, data, ignore_data_field, empty_payload)
91+
return Mock.__put_patch_post_callback(
92+
request, target, data, ignore_data_field, empty_payload
93+
)
8294

8395
url = Mock.base_url + '/' + target if call_api else target
84-
responses.add_callback(responses.PUT, url,
85-
callback=callback,
86-
content_type='application/json')
96+
responses.add_callback(
97+
responses.PUT, url, callback=callback, content_type='application/json'
98+
)
8799

88100
@staticmethod
89101
def mock_patch(target, ignore_data_field=False, empty_payload=False, call_api=True):
90102
data = json.loads(Mock.read_from_file(target + '.json'))
91103

92104
def callback(request):
93-
return Mock.__put_patch_post_callback(request, target, data, ignore_data_field, empty_payload)
105+
return Mock.__put_patch_post_callback(
106+
request, target, data, ignore_data_field, empty_payload
107+
)
94108

95109
url = Mock.base_url + '/' + target if call_api else target
96-
responses.add_callback(responses.PATCH, url,
97-
callback=callback,
98-
content_type='application/json')
110+
responses.add_callback(
111+
responses.PATCH, url, callback=callback, content_type='application/json'
112+
)
99113

100114
@staticmethod
101115
def mock_delete(target):
102-
responses.add(responses.DELETE, Mock.base_url + '/' + target,
103-
status=204)
116+
responses.add(responses.DELETE, Mock.base_url + '/' + target, status=204)
104117

105118
@staticmethod
106119
def mock_server_operation(target):
107120
# drop third (last) part of a string divided by two slashes ("/"); e.g "this/is/string" -> "this/is"
108121
targetsplit = target.split('/')
109-
targetfile = '/'.join( targetsplit[:2] )
122+
targetfile = '/'.join(targetsplit[:2])
110123

111-
data = json.loads( Mock.read_from_file(targetfile + '.json') )
124+
data = json.loads(Mock.read_from_file(targetfile + '.json'))
112125

113126
# API will always respond state: "started", see: Server.stop, Server.start, Server,restart
114127
data['server']['state'] = 'started'
115128

116-
data = json.dumps( data )
117-
responses.add(responses.POST, Mock.base_url + "/" + target, status=200, body = data, content_type='application/json')
129+
data = json.dumps(data)
130+
responses.add(
131+
responses.POST,
132+
Mock.base_url + "/" + target,
133+
status=200,
134+
body=data,
135+
content_type='application/json',
136+
)

test/helpers/infra.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
password_delivery='none',
1212
storage_devices=[
1313
Storage(os='01000000-0000-4000-8000-000030060200', size=10),
14-
Storage(size=10, tier='maxiops')
15-
]),
16-
14+
Storage(size=10, tier='maxiops'),
15+
],
16+
),
1717
'web2': Server(
1818
core_number=1,
1919
memory_amount=1024,
@@ -24,10 +24,8 @@
2424
Storage(os='01000000-0000-4000-8000-000030060200', size=10),
2525
Storage(size=10, tier='maxiops'),
2626
],
27-
ip_addresses=[
28-
IPAddress(family='IPv6', access='public')
29-
]),
30-
27+
ip_addresses=[IPAddress(family='IPv6', access='public')],
28+
),
3129
'db': Server(
3230
core_number=1,
3331
memory_amount=1024,
@@ -38,20 +36,20 @@
3836
Storage(os='01000000-0000-4000-8000-000050010300', size=10),
3937
Storage(size=10),
4038
],
41-
login_user=login_user_block('testuser', ['ssh-rsa AAAAB3NzaC1yc2EAA[...]ptshi44x user@some.host'], True),
39+
login_user=login_user_block(
40+
'testuser', ['ssh-rsa AAAAB3NzaC1yc2EAA[...]ptshi44x user@some.host'], True
4241
),
43-
44-
42+
),
4543
'lb': Server(
46-
plan= '1xCPU-1GB',
44+
plan='1xCPU-1GB',
4745
hostname='balancer.example.com',
4846
zone='uk-lon1',
4947
password_delivery='none',
50-
storage_devices=[
51-
Storage(os='Debian 10.0', size=30)
52-
],
53-
login_user=login_user_block('testuser', ['ssh-rsa AAAAB3NzaC1yc2EAA[...]ptshi44x user@some.host'], True),
54-
)
48+
storage_devices=[Storage(os='Debian 10.0', size=30)],
49+
login_user=login_user_block(
50+
'testuser', ['ssh-rsa AAAAB3NzaC1yc2EAA[...]ptshi44x user@some.host'], True
51+
),
52+
),
5553
}
5654

5755

@@ -65,7 +63,7 @@
6563
source_address_end='192.168.1.255',
6664
destination_port_start='22',
6765
destination_port_end='22',
68-
action='accept'
66+
action='accept',
6967
),
7068
FirewallRule(
7169
position='2',
@@ -76,13 +74,9 @@
7674
source_address_end='192.168.1.255',
7775
destination_port_start='21',
7876
destination_port_end='21',
79-
action='accept'
80-
)
77+
action='accept',
78+
),
8179
]
8280

8381

84-
TAGS = [
85-
Tag('testlb'),
86-
Tag('testdb'),
87-
Tag('testweb')
88-
]
82+
TAGS = [Tag('testlb'), Tag('testdb'), Tag('testweb')]

test/helpers/infra_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def server_test(manager, server):
5252

5353
server.start()
5454

55-
#sync new info from API and assert the changes from above have happened
55+
# sync new info from API and assert the changes from above have happened
5656
server.populate()
5757
assert server.core_number == '3'
5858
assert server.memory_amount == '1024'
@@ -70,7 +70,7 @@ def tag_servers_test(manager, tags, cluster):
7070

7171
cluster['web1'].add_tags(['testweb'])
7272
cluster['web2'].add_tags(['testweb'])
73-
cluster['lb'].add_tags([tags[1]]) # tags[1] is 'db'
73+
cluster['lb'].add_tags([tags[1]]) # tags[1] is 'db'
7474
cluster['db'].add_tags(['testlb'])
7575

7676
fetched_servers = manager.get_servers(tags_has_one=['testlb'])

test/test_apidoc/test_10_ip_addresses.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import json
44
import responses
55

6-
class TestIP:
76

7+
class TestIP:
88
def test_ip_in_server_creation(self):
99
"""IPAddress in server creation.
1010
@@ -21,11 +21,7 @@ def test_ip_in_server_details(self):
2121
https://www.upcloud.com/api/8-servers/#get-server-details
2222
"""
2323
ip = IPAddress(access='private', address='10.0.0.0', family='IPv4')
24-
assert ip.to_dict() == {
25-
'access': 'private',
26-
'address': '10.0.0.0',
27-
'family' : 'IPv4'
28-
}
24+
assert ip.to_dict() == {'access': 'private', 'address': '10.0.0.0', 'family': 'IPv4'}
2925

3026
data = read_from_file('server_00798b85-efdc-41ca-8021-f6ef457b8531.json')
3127
s = Server(**json.loads(data))
@@ -44,5 +40,5 @@ def test_ip_details(self):
4440
'family': 'IPv4',
4541
'part_of_plan': 'yes',
4642
'ptr_record': 'a.ptr.record',
47-
'server': '008c365d-d307-4501-8efc-cd6d3bb0e494'
43+
'server': '008c365d-d307-4501-8efc-cd6d3bb0e494',
4844
}

0 commit comments

Comments
 (0)