/
test_api.py
51 lines (40 loc) · 1.75 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
# encoding: utf-8
from nose.tools import assert_in
from ckan.tests.legacy.functional.api.base import *
class ApiTestCase(ApiTestCase, ControllerTestCase):
def test_get_api(self):
offset = self.offset('')
res = self.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()
self.assert_equal(data['version'], expected_version)
class TestApi3(Api3TestCase, ApiTestCase):
def test_readonly_is_get_able_with_normal_url_params(self):
'''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 = self.app.get(offset, params=params, status=[200])
def test_sideeffect_action_is_not_get_able(self):
'''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 = self.app.get(offset,
params=data_dict,
status=[400],
expect_errors=True)
assert_in('Bad request - JSON Error: Invalid request.'\
' Please use POST method for your request',
res.body)