Skip to content

Commit 9357f22

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent c5eb9ed commit 9357f22

File tree

5 files changed

+61
-17
lines changed

5 files changed

+61
-17
lines changed

UnleashClient/api/async_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import asyncio
2+
import json
23
from typing import Any, Mapping, Optional, Tuple
4+
35
import aiohttp
46

5-
import json
67
from UnleashClient.api.packet_building import build_registration_packet
78
from UnleashClient.constants import (
89
APPLICATION_HEADERS,
910
FEATURES_URL,
10-
REGISTER_URL,
1111
METRICS_URL,
12+
REGISTER_URL,
1213
)
1314
from UnleashClient.utils import LOGGER
1415

15-
1616
_TRANSIENT_ERROR_CODES = {500, 502, 504}
1717

1818

UnleashClient/api/packet_building.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from datetime import datetime, timezone
22
from platform import python_implementation, python_version
3+
34
import yggdrasil_engine
5+
46
from UnleashClient.constants import (
57
CLIENT_SPEC_VERSION,
68
SDK_NAME,

tests/unit_tests/api/test_async_feature.py

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
23
import pytest
34
from aioresponses import aioresponses
45

@@ -20,54 +21,93 @@
2021
MOCK_FEATURE_RESPONSE = {"version": 1, "features": []}
2122
PROJECT_URL = f"{FULL_FEATURE_URL}?project={PROJECT_NAME}"
2223

24+
2325
@pytest.mark.asyncio
2426
async def test_get_feature_toggles_success():
2527
with aioresponses() as m:
26-
m.get(FULL_FEATURE_URL, status=200, payload=MOCK_FEATURE_RESPONSE, headers={"etag": ETAG_VALUE})
28+
m.get(
29+
FULL_FEATURE_URL,
30+
status=200,
31+
payload=MOCK_FEATURE_RESPONSE,
32+
headers={"etag": ETAG_VALUE},
33+
)
2734

2835
body, etag = await get_feature_toggles_async(
29-
URL, APP_NAME, INSTANCE_ID, CUSTOM_HEADERS, CUSTOM_OPTIONS,
30-
REQUEST_TIMEOUT, REQUEST_RETRIES
36+
URL,
37+
APP_NAME,
38+
INSTANCE_ID,
39+
CUSTOM_HEADERS,
40+
CUSTOM_OPTIONS,
41+
REQUEST_TIMEOUT,
42+
REQUEST_RETRIES,
3143
)
3244

3345
assert json.loads(body)["version"] == 1
3446
assert etag == ETAG_VALUE
3547

48+
3649
@pytest.mark.asyncio
3750
async def test_get_feature_toggles_project_and_etag_present():
3851
with aioresponses() as m:
3952
m.get(PROJECT_URL, status=304, headers={"etag": ETAG_VALUE})
4053

4154
body, etag = await get_feature_toggles_async(
42-
URL, APP_NAME, INSTANCE_ID, CUSTOM_HEADERS, CUSTOM_OPTIONS,
43-
REQUEST_TIMEOUT, REQUEST_RETRIES, project=PROJECT_NAME, cached_etag=ETAG_VALUE
55+
URL,
56+
APP_NAME,
57+
INSTANCE_ID,
58+
CUSTOM_HEADERS,
59+
CUSTOM_OPTIONS,
60+
REQUEST_TIMEOUT,
61+
REQUEST_RETRIES,
62+
project=PROJECT_NAME,
63+
cached_etag=ETAG_VALUE,
4464
)
4565

4666
assert body is None
4767
assert etag == ETAG_VALUE
4868

69+
4970
@pytest.mark.asyncio
5071
async def test_get_feature_toggles_retries_then_success():
5172
with aioresponses() as m:
5273
m.get(PROJECT_URL, status=500) # first attempt
53-
m.get(PROJECT_URL, status=200, payload=MOCK_FEATURE_RESPONSE, headers={"etag": ETAG_VALUE})
74+
m.get(
75+
PROJECT_URL,
76+
status=200,
77+
payload=MOCK_FEATURE_RESPONSE,
78+
headers={"etag": ETAG_VALUE},
79+
)
5480

5581
body, etag = await get_feature_toggles_async(
56-
URL, APP_NAME, INSTANCE_ID, CUSTOM_HEADERS, CUSTOM_OPTIONS,
57-
REQUEST_TIMEOUT, request_retries=1, project=PROJECT_NAME, cached_etag=ETAG_VALUE
82+
URL,
83+
APP_NAME,
84+
INSTANCE_ID,
85+
CUSTOM_HEADERS,
86+
CUSTOM_OPTIONS,
87+
REQUEST_TIMEOUT,
88+
request_retries=1,
89+
project=PROJECT_NAME,
90+
cached_etag=ETAG_VALUE,
5891
)
5992

6093
assert json.loads(body)["version"] == 1
6194
assert etag == ETAG_VALUE
6295

96+
6397
@pytest.mark.asyncio
6498
async def test_get_feature_toggles_failure_after_retries():
6599
with aioresponses() as m:
66100
m.get(PROJECT_URL, status=500)
67101
m.get(PROJECT_URL, status=500)
68102
body, etag = await get_feature_toggles_async(
69-
URL, APP_NAME, INSTANCE_ID, CUSTOM_HEADERS, CUSTOM_OPTIONS,
70-
REQUEST_TIMEOUT, request_retries=1, project=PROJECT_NAME
103+
URL,
104+
APP_NAME,
105+
INSTANCE_ID,
106+
CUSTOM_HEADERS,
107+
CUSTOM_OPTIONS,
108+
REQUEST_TIMEOUT,
109+
request_retries=1,
110+
project=PROJECT_NAME,
71111
)
72112
assert body is None
73113
assert etag == ""

tests/unit_tests/api/test_async_metrics.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import json
2+
23
import pytest
3-
from aioresponses import aioresponses
44
from aiohttp import ClientConnectionError
5+
from aioresponses import aioresponses
56
from yarl import URL as YURL
67

78
from UnleashClient.api.async_api import send_metrics_async
@@ -51,4 +52,4 @@ async def test_send_metrics_async(status, inject_exception, expected):
5152
assert ("POST", YURL(FULL_METRICS_URL)) in m.requests
5253
call = m.requests[("POST", YURL(FULL_METRICS_URL))][0]
5354
sent = json.loads(call.kwargs["data"])
54-
assert sent["connectionId"] == MOCK_METRICS_REQUEST["connectionId"]
55+
assert sent["connectionId"] == MOCK_METRICS_REQUEST["connectionId"]

tests/unit_tests/api/test_async_register.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import json
2+
23
import pytest
3-
from aioresponses import aioresponses
44
from aiohttp import ClientConnectionError
5+
from aioresponses import aioresponses
56
from yarl import URL as YURL
67

78
from UnleashClient.api.async_api import register_client_async
8-
from UnleashClient.constants import REGISTER_URL, CLIENT_SPEC_VERSION
9+
from UnleashClient.constants import CLIENT_SPEC_VERSION, REGISTER_URL
910

1011
BASE_URL = "https://example.com"
1112
FULL_REGISTER_URL = BASE_URL + REGISTER_URL

0 commit comments

Comments
 (0)