-
Notifications
You must be signed in to change notification settings - Fork 57
/
test_register.py
50 lines (44 loc) 路 1.17 KB
/
test_register.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
import responses
from pytest import mark, param
from requests import ConnectionError
from tests.utilities.testing_constants import (
APP_NAME,
CUSTOM_HEADERS,
CUSTOM_OPTIONS,
DEFAULT_STRATEGY_MAPPING,
INSTANCE_ID,
METRICS_INTERVAL,
REQUEST_TIMEOUT,
URL,
)
from UnleashClient.api import register_client
from UnleashClient.constants import REGISTER_URL
FULL_REGISTER_URL = URL + REGISTER_URL
@responses.activate
@mark.parametrize(
"payload,status,expected",
(
param({"json": {}}, 202, True, id="success"),
param({"json": {}}, 500, False, id="failure"),
param(
{"body": ConnectionError("Test connection error")},
200,
False,
id="exception",
),
),
)
def test_register_client(payload, status, expected):
responses.add(responses.POST, FULL_REGISTER_URL, **payload, status=status)
result = register_client(
URL,
APP_NAME,
INSTANCE_ID,
METRICS_INTERVAL,
CUSTOM_HEADERS,
CUSTOM_OPTIONS,
DEFAULT_STRATEGY_MAPPING,
REQUEST_TIMEOUT,
)
assert len(responses.calls) == 1
assert result is expected