Skip to content

Commit d866eea

Browse files
Restyled by black
1 parent 930e016 commit d866eea

File tree

3 files changed

+32
-34
lines changed

3 files changed

+32
-34
lines changed

minos/api_gateway/discovery/database/client.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,12 @@ class OrdersMinosApiRouter(MinosApiRouter):
1414

1515
import json
1616
import logging
17-
from typing import (
18-
Any,
19-
Optional
20-
)
17+
from typing import Any, Optional
2118

2219
import aioredis
2320

24-
from minos.api_gateway.common import (
25-
MinosConfig,
26-
)
27-
from minos.api_gateway.discovery.domain.microservice import (
28-
MICROSERVICE_KEY_PREFIX,
29-
)
21+
from minos.api_gateway.common import MinosConfig
22+
from minos.api_gateway.discovery.domain.microservice import MICROSERVICE_KEY_PREFIX
3023

3124
log = logging.getLogger(__name__)
3225

tests/test_api_gateway/test_discovery/dataset.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,27 @@ def generate_random_microservice_names(quantity: int):
1111

1212

1313
def generate_record(name):
14-
ip = socket.inet_ntoa(struct.pack('>I', random.randint(1, 0xffffffff)))
14+
ip = socket.inet_ntoa(struct.pack(">I", random.randint(1, 0xFFFFFFFF)))
1515
port = random.randint(1, 9999)
1616

17-
record = {"address": f"{ip}", "port": port,
18-
"endpoints": [["GET", f"test_endpoint_{name}"], ["POST", f"test_endpoint_{name}"]]}
17+
record = {
18+
"address": f"{ip}",
19+
"port": port,
20+
"endpoints": [["GET", f"test_endpoint_{name}"], ["POST", f"test_endpoint_{name}"]],
21+
}
1922

2023
return record
2124

2225

2326
def generate_record_old(x):
24-
ip = socket.inet_ntoa(struct.pack('>I', random.randint(1, 0xffffffff)))
27+
ip = socket.inet_ntoa(struct.pack(">I", random.randint(1, 0xFFFFFFFF)))
2528
port = random.randint(1, 9999)
2629
name = f"microservice_{x}"
2730

28-
record = {"address": f"{ip}", "port": port,
29-
"endpoints": [["GET", f"test_endpoint_{name}"], ["POST", f"test_endpoint_{name}"]]}
31+
record = {
32+
"address": f"{ip}",
33+
"port": port,
34+
"endpoints": [["GET", f"test_endpoint_{name}"], ["POST", f"test_endpoint_{name}"]],
35+
}
3036

3137
return name, record

tests/test_api_gateway/test_discovery/test_views/test_microservice.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@
44
AioHTTPTestCase,
55
unittest_run_loop,
66
)
7-
from minos.api_gateway.common import (
8-
MinosConfig,
9-
)
10-
from minos.api_gateway.discovery import (
11-
DiscoveryService,
12-
)
13-
from tests.test_api_gateway.test_discovery.dataset import generate_record, generate_random_microservice_names, \
14-
generate_record_old
15-
from tests.utils import (
16-
BASE_PATH,
7+
from minos.api_gateway.common import MinosConfig
8+
from minos.api_gateway.discovery import DiscoveryService
9+
from tests.test_api_gateway.test_discovery.dataset import (
10+
generate_record,
11+
generate_random_microservice_names,
12+
generate_record_old,
1713
)
14+
from tests.utils import BASE_PATH
1815

1916

2017
class TestMicroserviceEndpoints(AioHTTPTestCase):
@@ -70,15 +67,16 @@ async def test_bulk_update(self):
7067
# Check updated records are correct
7168
for record in expected:
7269
response = await self.client.get(
73-
f"/microservices?verb={record['body']['endpoints'][0][0]}&path={record['body']['endpoints'][0][1]}")
70+
f"/microservices?verb={record['body']['endpoints'][0][0]}&path={record['body']['endpoints'][0][1]}"
71+
)
7472

7573
self.assertEqual(200, response.status)
7674

7775
body = await response.json()
7876

79-
self.assertEqual(record['body']['address'], body["address"])
80-
self.assertEqual(record['body']['port'], int(body["port"]))
81-
self.assertEqual(record['name'], body["name"])
77+
self.assertEqual(record["body"]["address"], body["address"])
78+
self.assertEqual(record["body"]["port"], int(body["port"]))
79+
self.assertEqual(record["name"], body["name"])
8280

8381
async def test_bulk_update_2(self):
8482
expected = list()
@@ -106,15 +104,16 @@ async def test_bulk_update_2(self):
106104

107105
for record in expected:
108106
response = await self.client.get(
109-
f"/microservices?verb={record['body']['endpoints'][0][0]}&path={record['body']['endpoints'][0][1]}")
107+
f"/microservices?verb={record['body']['endpoints'][0][0]}&path={record['body']['endpoints'][0][1]}"
108+
)
110109

111110
self.assertEqual(200, response.status)
112111

113112
body = await response.json()
114113

115-
self.assertEqual(record['body']['address'], body["address"])
116-
self.assertEqual(int(record['body']['port']), int(body["port"]))
117-
self.assertEqual(record['name'], body["name"])
114+
self.assertEqual(record["body"]["address"], body["address"])
115+
self.assertEqual(int(record["body"]["port"]), int(body["port"]))
116+
self.assertEqual(record["name"], body["name"])
118117

119118
@unittest_run_loop
120119
async def test_post_missing_param(self):

0 commit comments

Comments
 (0)