|
1 from __future__ import absolute_import |
|
2 |
|
3 from cubicweb.pyramid.rest_api import EntityResource |
|
4 from cubicweb.pyramid.core import CubicWebPyramidRequest |
|
5 from pyramid.view import view_config |
|
6 |
|
7 from cubicweb.pyramid.test import PyramidCWTest |
|
8 |
|
9 |
|
10 class RestApiTest(PyramidCWTest): |
|
11 def includeme(self, config): |
|
12 config.include('cubicweb.pyramid.rest_api') |
|
13 config.include('cubicweb.pyramid.test.test_rest_api') |
|
14 |
|
15 def test_delete(self): |
|
16 with self.admin_access.repo_cnx() as cnx: |
|
17 cnx.create_entity('CWGroup', name=u'tmp') |
|
18 cnx.commit() |
|
19 |
|
20 self.login() |
|
21 res = self.webapp.delete('/cwgroup/tmp') |
|
22 self.assertEqual(res.status_int, 204) |
|
23 |
|
24 with self.admin_access.repo_cnx() as cnx: |
|
25 self.assertEqual(cnx.find('CWGroup', name=u'tmp').rowcount, 0) |
|
26 |
|
27 def test_rql_execute(self): |
|
28 with self.admin_access.repo_cnx() as cnx: |
|
29 cnx.create_entity('CWGroup', name=u'tmp') |
|
30 cnx.commit() |
|
31 self.login() |
|
32 params = {'test_rql_execute': 'test'} |
|
33 self.webapp.get('/cwgroup/tmp', params=params) |
|
34 |
|
35 |
|
36 @view_config( |
|
37 route_name='cwentities', |
|
38 context=EntityResource, |
|
39 request_method='GET', |
|
40 request_param=('test_rql_execute',) |
|
41 ) |
|
42 def rql_execute_view(context, request): |
|
43 """Return 500 response if rset.req is not a CubicWeb request. |
|
44 """ |
|
45 if isinstance(context.rset.req, CubicWebPyramidRequest): |
|
46 request.response.status_int = 204 |
|
47 else: |
|
48 request.response.status_int = 500 |
|
49 request.response.text = 'rset.req is not a CubicWeb request' |
|
50 return request.response |
|
51 |
|
52 |
|
53 def includeme(config): |
|
54 config.scan(__name__) |
|
55 |
|
56 |
|
57 if __name__ == '__main__': |
|
58 from unittest import main |
|
59 main() |