-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_client.py
73 lines (49 loc) · 2.1 KB
/
test_client.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
70
71
72
73
from urllib.parse import urljoin
import pytest
import vcr
from requests.exceptions import HTTPError
from openformsclient.client import Client
from .data.forms import test_form
CASSETTE_PATH_FORMS = "fixtures/cassettes/forms.yaml"
CASSETTE_PATH_INVALID = "fixtures/cassettes/invalid.yaml"
VCR_DEFAULTS = {
"record_mode": "none", # use new_episodes to record casettes
"filter_headers": ["authorization"],
}
def test_client_has_config(client):
bogus_client = Client("", "", "")
assert client.has_config()
assert not bogus_client.has_config()
@vcr.use_cassette(CASSETTE_PATH_FORMS, **VCR_DEFAULTS)
def test_client_is_healthy(client):
health, msg = client.is_healthy()
assert health
assert msg == ""
@vcr.use_cassette(CASSETTE_PATH_FORMS, **VCR_DEFAULTS)
def test_get_forms(client):
results = client.get_forms()["results"]
assert test_form in results
@vcr.use_cassette(CASSETTE_PATH_INVALID, **VCR_DEFAULTS)
def test_get_forms_unauthorized(bogus_client):
url = urljoin(bogus_client.api_root, "public/forms")
msg = f"401 Client Error: Unauthorized for url: {url}"
with pytest.raises(HTTPError, match=msg):
bogus_client.get_forms()
@vcr.use_cassette(CASSETTE_PATH_FORMS, **VCR_DEFAULTS)
def test_get_single_form(client):
result = client.get_form(uuid_or_slug=test_form["uuid"])
assert result["uuid"] == test_form["uuid"]
assert result["name"] == test_form["name"]
@vcr.use_cassette(CASSETTE_PATH_FORMS, **VCR_DEFAULTS)
def test_get_single_form_not_found(client):
bogus_uuid = "aaaa-bbbb-cccc-dddd"
url = urljoin(client.api_root, f"forms/{bogus_uuid}")
msg = f"404 Client Error: Not Found for url: {url}"
with pytest.raises(HTTPError, match=msg):
client.get_form(uuid_or_slug=bogus_uuid)
@vcr.use_cassette(CASSETTE_PATH_INVALID, **VCR_DEFAULTS)
def test_get_single_form_unauthorized(bogus_client):
url = urljoin(bogus_client.api_root, f"forms/{test_form['uuid']}")
msg = f"401 Client Error: Unauthorized for url: {url}"
with pytest.raises(HTTPError, match=msg):
bogus_client.get_form(uuid_or_slug=test_form["uuid"])