Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 24, 2023
1 parent 9c00f9c commit f1abf3b
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 22 deletions.
12 changes: 9 additions & 3 deletions UnleashClient/__init__.py
Expand Up @@ -13,7 +13,13 @@
from apscheduler.triggers.interval import IntervalTrigger

from UnleashClient.api import register_client
from UnleashClient.constants import DISABLED_VARIATION, ETAG, METRIC_LAST_SENT_TIME, REQUEST_TIMEOUT, REQUEST_RETRIES
from UnleashClient.constants import (
DISABLED_VARIATION,
ETAG,
METRIC_LAST_SENT_TIME,
REQUEST_RETRIES,
REQUEST_TIMEOUT,
)
from UnleashClient.events import UnleashEvent, UnleashEventType
from UnleashClient.features import Feature
from UnleashClient.loader import load_features
Expand Down Expand Up @@ -230,7 +236,7 @@ def initialize_client(self, fetch_toggles: bool = True) -> None:
"custom_options": self.unleash_custom_options,
"features": self.features,
"cache": self.cache,
"request_timeout": self.unleash_request_timeout
"request_timeout": self.unleash_request_timeout,
}

# Register app
Expand All @@ -243,7 +249,7 @@ def initialize_client(self, fetch_toggles: bool = True) -> None:
self.unleash_custom_headers,
self.unleash_custom_options,
self.strategy_mapping,
self.unleash_request_timeout
self.unleash_request_timeout,
)

if fetch_toggles:
Expand Down
6 changes: 4 additions & 2 deletions UnleashClient/periodic_tasks/send_metrics.py
Expand Up @@ -15,7 +15,7 @@ def aggregate_and_send_metrics(
custom_options: dict,
features: dict,
cache: BaseCache,
request_timeout: int
request_timeout: int,
) -> None:
feature_stats_list = []

Expand Down Expand Up @@ -45,7 +45,9 @@ def aggregate_and_send_metrics(
}

if feature_stats_list:
send_metrics(url, metrics_request, custom_headers, custom_options, request_timeout)
send_metrics(
url, metrics_request, custom_headers, custom_options, request_timeout
)
cache.set(METRIC_LAST_SENT_TIME, datetime.now(timezone.utc))
else:
LOGGER.debug("No feature flags with metrics, skipping metrics submission.")
30 changes: 25 additions & 5 deletions tests/unit_tests/api/test_feature.py
Expand Up @@ -13,9 +13,9 @@
INSTANCE_ID,
PROJECT_NAME,
PROJECT_URL,
URL,
REQUEST_RETRIES,
REQUEST_TIMEOUT,
REQUEST_RETRIES
URL,
)
from UnleashClient.api import get_feature_toggles
from UnleashClient.constants import FEATURES_URL
Expand Down Expand Up @@ -48,7 +48,13 @@ def test_get_feature_toggle(response, status, calls, expected):
)

(result, etag) = get_feature_toggles(
URL, APP_NAME, INSTANCE_ID, CUSTOM_HEADERS, CUSTOM_OPTIONS, REQUEST_TIMEOUT, REQUEST_RETRIES
URL,
APP_NAME,
INSTANCE_ID,
CUSTOM_HEADERS,
CUSTOM_OPTIONS,
REQUEST_TIMEOUT,
REQUEST_RETRIES,
)

assert len(responses.calls) == calls
Expand All @@ -66,7 +72,14 @@ def test_get_feature_toggle_project():
)

(result, etag) = get_feature_toggles(
URL, APP_NAME, INSTANCE_ID, CUSTOM_HEADERS, CUSTOM_OPTIONS, REQUEST_TIMEOUT, REQUEST_RETRIES, PROJECT_NAME
URL,
APP_NAME,
INSTANCE_ID,
CUSTOM_HEADERS,
CUSTOM_OPTIONS,
REQUEST_TIMEOUT,
REQUEST_RETRIES,
PROJECT_NAME,
)

assert len(responses.calls) == 1
Expand All @@ -81,7 +94,14 @@ def test_get_feature_toggle_failed_etag():
)

(result, etag) = get_feature_toggles(
URL, APP_NAME, INSTANCE_ID, CUSTOM_HEADERS, CUSTOM_OPTIONS, REQUEST_TIMEOUT, REQUEST_RETRIES, PROJECT_NAME,
URL,
APP_NAME,
INSTANCE_ID,
CUSTOM_HEADERS,
CUSTOM_OPTIONS,
REQUEST_TIMEOUT,
REQUEST_RETRIES,
PROJECT_NAME,
)

assert len(responses.calls) == 4
Expand Down
11 changes: 9 additions & 2 deletions tests/unit_tests/api/test_metrics.py
Expand Up @@ -3,7 +3,12 @@
from requests import ConnectionError

from tests.utilities.mocks.mock_metrics import MOCK_METRICS_REQUEST
from tests.utilities.testing_constants import CUSTOM_HEADERS, CUSTOM_OPTIONS, URL, REQUEST_TIMEOUT
from tests.utilities.testing_constants import (
CUSTOM_HEADERS,
CUSTOM_OPTIONS,
REQUEST_TIMEOUT,
URL,
)
from UnleashClient.api import send_metrics
from UnleashClient.constants import METRICS_URL

Expand All @@ -27,7 +32,9 @@
def test_send_metrics(payload, status, expected):
responses.add(responses.POST, FULL_METRICS_URL, **payload, status=status)

result = send_metrics(URL, MOCK_METRICS_REQUEST, CUSTOM_HEADERS, CUSTOM_OPTIONS, REQUEST_TIMEOUT)
result = send_metrics(
URL, MOCK_METRICS_REQUEST, CUSTOM_HEADERS, CUSTOM_OPTIONS, REQUEST_TIMEOUT
)

assert len(responses.calls) == 1
assert expected(result)
4 changes: 2 additions & 2 deletions tests/unit_tests/api/test_register.py
Expand Up @@ -9,8 +9,8 @@
DEFAULT_STRATEGY_MAPPING,
INSTANCE_ID,
METRICS_INTERVAL,
REQUEST_TIMEOUT,
URL,
REQUEST_TIMEOUT
)
from UnleashClient.api import register_client
from UnleashClient.constants import REGISTER_URL
Expand Down Expand Up @@ -43,7 +43,7 @@ def test_register_client(payload, status, expected):
CUSTOM_HEADERS,
CUSTOM_OPTIONS,
DEFAULT_STRATEGY_MAPPING,
REQUEST_TIMEOUT
REQUEST_TIMEOUT,
)

assert len(responses.calls) == 1
Expand Down
20 changes: 17 additions & 3 deletions tests/unit_tests/periodic/test_aggregate_and_send_metrics.py
Expand Up @@ -10,8 +10,8 @@
CUSTOM_OPTIONS,
INSTANCE_ID,
IP_LIST,
REQUEST_TIMEOUT,
URL,
REQUEST_TIMEOUT
)
from UnleashClient.cache import FileCache
from UnleashClient.constants import METRIC_LAST_SENT_TIME, METRICS_URL
Expand Down Expand Up @@ -56,7 +56,14 @@ def test_aggregate_and_send_metrics():
features = {"My Feature1": my_feature1, "My Feature 2": my_feature2}

aggregate_and_send_metrics(
URL, APP_NAME, INSTANCE_ID, CUSTOM_HEADERS, CUSTOM_OPTIONS, features, cache, REQUEST_TIMEOUT
URL,
APP_NAME,
INSTANCE_ID,
CUSTOM_HEADERS,
CUSTOM_OPTIONS,
features,
cache,
REQUEST_TIMEOUT,
)

assert len(responses.calls) == 1
Expand Down Expand Up @@ -89,7 +96,14 @@ def test_no_metrics():
features = {"My Feature1": my_feature1}

aggregate_and_send_metrics(
URL, APP_NAME, INSTANCE_ID, CUSTOM_HEADERS, CUSTOM_OPTIONS, features, cache, REQUEST_TIMEOUT
URL,
APP_NAME,
INSTANCE_ID,
CUSTOM_HEADERS,
CUSTOM_OPTIONS,
features,
cache,
REQUEST_TIMEOUT,
)

assert len(responses.calls) == 0
4 changes: 2 additions & 2 deletions tests/unit_tests/periodic/test_fetch_and_load.py
Expand Up @@ -13,9 +13,9 @@
INSTANCE_ID,
PROJECT_NAME,
PROJECT_URL,
URL,
REQUEST_RETRIES,
REQUEST_TIMEOUT,
REQUEST_RETRIES
URL,
)
from UnleashClient.constants import ETAG, FEATURES_URL
from UnleashClient.features import Feature
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/test_client.py
Expand Up @@ -31,9 +31,9 @@
PROJECT_URL,
REFRESH_INTERVAL,
REFRESH_JITTER,
URL,
REQUEST_RETRIES,
REQUEST_TIMEOUT,
REQUEST_RETRIES
URL,
)
from UnleashClient import INSTANCES, UnleashClient
from UnleashClient.cache import FileCache
Expand Down Expand Up @@ -163,7 +163,7 @@ def test_UC_initialize_full():
CUSTOM_HEADERS,
CUSTOM_OPTIONS,
REQUEST_TIMEOUT,
REQUEST_RETRIES
REQUEST_RETRIES,
)
assert client.unleash_instance_id == INSTANCE_ID
assert client.unleash_refresh_interval == REFRESH_INTERVAL
Expand Down

0 comments on commit f1abf3b

Please sign in to comment.