Skip to content

Commit 95cf73a

Browse files
Merge pull request #86 from minos-framework/restyled/issue-78-redis-not-saving-data
Restyle Issue 78 redis not saving data
2 parents 930e016 + af91b8d commit 95cf73a

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

minos/api_gateway/discovery/database/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class OrdersMinosApiRouter(MinosApiRouter):
1616
import logging
1717
from typing import (
1818
Any,
19-
Optional
19+
Optional,
2020
)
2121

2222
import aioredis
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import random
22
import socket
33
import struct
4-
from uuid import uuid4
4+
from uuid import (
5+
uuid4,
6+
)
57

68

79
def generate_random_microservice_names(quantity: int):
@@ -11,21 +13,27 @@ def generate_random_microservice_names(quantity: int):
1113

1214

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

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

2025
return record
2126

2227

2328
def generate_record_old(x):
24-
ip = socket.inet_ntoa(struct.pack('>I', random.randint(1, 0xffffffff)))
29+
ip = socket.inet_ntoa(struct.pack(">I", random.randint(1, 0xFFFFFFFF)))
2530
port = random.randint(1, 9999)
2631
name = f"microservice_{x}"
2732

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

3139
return name, record

tests/test_api_gateway/test_discovery/test_views/test_microservice.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
AioHTTPTestCase,
55
unittest_run_loop,
66
)
7+
78
from minos.api_gateway.common import (
89
MinosConfig,
910
)
1011
from minos.api_gateway.discovery import (
1112
DiscoveryService,
1213
)
13-
from tests.test_api_gateway.test_discovery.dataset import generate_record, generate_random_microservice_names, \
14-
generate_record_old
14+
from tests.test_api_gateway.test_discovery.dataset import (
15+
generate_random_microservice_names,
16+
generate_record,
17+
generate_record_old,
18+
)
1519
from tests.utils import (
1620
BASE_PATH,
1721
)
@@ -70,15 +74,16 @@ async def test_bulk_update(self):
7074
# Check updated records are correct
7175
for record in expected:
7276
response = await self.client.get(
73-
f"/microservices?verb={record['body']['endpoints'][0][0]}&path={record['body']['endpoints'][0][1]}")
77+
f"/microservices?verb={record['body']['endpoints'][0][0]}&path={record['body']['endpoints'][0][1]}"
78+
)
7479

7580
self.assertEqual(200, response.status)
7681

7782
body = await response.json()
7883

79-
self.assertEqual(record['body']['address'], body["address"])
80-
self.assertEqual(record['body']['port'], int(body["port"]))
81-
self.assertEqual(record['name'], body["name"])
84+
self.assertEqual(record["body"]["address"], body["address"])
85+
self.assertEqual(record["body"]["port"], int(body["port"]))
86+
self.assertEqual(record["name"], body["name"])
8287

8388
async def test_bulk_update_2(self):
8489
expected = list()
@@ -106,15 +111,16 @@ async def test_bulk_update_2(self):
106111

107112
for record in expected:
108113
response = await self.client.get(
109-
f"/microservices?verb={record['body']['endpoints'][0][0]}&path={record['body']['endpoints'][0][1]}")
114+
f"/microservices?verb={record['body']['endpoints'][0][0]}&path={record['body']['endpoints'][0][1]}"
115+
)
110116

111117
self.assertEqual(200, response.status)
112118

113119
body = await response.json()
114120

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"])
121+
self.assertEqual(record["body"]["address"], body["address"])
122+
self.assertEqual(int(record["body"]["port"]), int(body["port"]))
123+
self.assertEqual(record["name"], body["name"])
118124

119125
@unittest_run_loop
120126
async def test_post_missing_param(self):

0 commit comments

Comments
 (0)