-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathtest_aggregate_and_send_metrics.py
69 lines (55 loc) · 1.55 KB
/
test_aggregate_and_send_metrics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import json
import responses
from yggdrasil_engine.engine import UnleashEngine
from tests.utilities.testing_constants import (
APP_NAME,
CONNECTION_ID,
CUSTOM_HEADERS,
CUSTOM_OPTIONS,
INSTANCE_ID,
REQUEST_TIMEOUT,
URL,
)
from UnleashClient.constants import (
CLIENT_SPEC_VERSION,
METRICS_URL,
)
from UnleashClient.periodic_tasks import aggregate_and_send_metrics
FULL_METRICS_URL = URL + METRICS_URL
print(FULL_METRICS_URL)
@responses.activate
def test_no_metrics():
responses.add(responses.POST, FULL_METRICS_URL, json={}, status=200)
engine = UnleashEngine()
aggregate_and_send_metrics(
URL,
APP_NAME,
INSTANCE_ID,
CONNECTION_ID,
CUSTOM_HEADERS,
CUSTOM_OPTIONS,
REQUEST_TIMEOUT,
engine,
)
assert len(responses.calls) == 0
@responses.activate
def test_metrics_metadata_is_sent():
responses.add(responses.POST, FULL_METRICS_URL, json={}, status=200)
engine = UnleashEngine()
engine.count_toggle("something-to-make-sure-metrics-get-sent", True)
aggregate_and_send_metrics(
URL,
APP_NAME,
INSTANCE_ID,
CONNECTION_ID,
CUSTOM_HEADERS,
CUSTOM_OPTIONS,
REQUEST_TIMEOUT,
engine,
)
assert len(responses.calls) == 1
request = json.loads(responses.calls[0].request.body)
assert request["yggdrasilVersion"] is not None
assert request["specVersion"] == CLIENT_SPEC_VERSION
assert request["platformName"] is not None
assert request["platformVersion"] is not None