-
Notifications
You must be signed in to change notification settings - Fork 2k
/
test_api.py
52 lines (42 loc) · 1.71 KB
/
test_api.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
# encoding: utf-8
from ckan.tests.legacy.functional.api.base import (
ApiTestCase,
ControllerTestCase,
Api3TestCase,
)
from ckan.tests.helpers import body_contains
class ApiTestCase(ApiTestCase, ControllerTestCase):
def test_get_api(self, app):
offset = self.offset("")
res = app.get(offset, status=[200])
self.assert_version_data(res)
def assert_version_data(self, res):
data = self.data_from_res(res)
assert "version" in data, data
expected_version = self.get_expected_api_version()
assert data["version"] == expected_version
class TestApi3(Api3TestCase, ApiTestCase):
def test_readonly_is_get_able_with_normal_url_params(self, app):
"""Test that a read-only action is GET-able
Picks an action within `get.py` and checks that it works if it's
invoked with a http GET request. The action's data_dict is
populated from the url parameters.
"""
offset = self.offset("/action/package_search")
params = {"q": "russian"}
res = app.get(offset, params=params, status=[200])
def test_sideeffect_action_is_not_get_able(self, app):
"""Test that a non-readonly action is not GET-able.
Picks an action outside of `get.py`, and checks that it 400s if an
attempt to invoke with a http GET request is made.
"""
offset = self.offset("/action/package_create")
data_dict = {"type": "dataset", "name": "a-name"}
res = app.get(
offset, json=data_dict, status=400
)
assert body_contains(
res,
"Bad request - JSON Error: Invalid request."
" Please use POST method for your request"
)