1 from __future__ import absolute_import |
1 from __future__ import absolute_import |
2 |
2 |
3 from . import PyramidCWTest |
3 from . import PyramidCWTest |
|
4 |
|
5 from pyramid_cubicweb.rest_api import EntityResource |
|
6 from pyramid_cubicweb.core import CubicWebPyramidRequest |
|
7 from pyramid.view import view_config |
4 |
8 |
5 |
9 |
6 class RestApiTest(PyramidCWTest): |
10 class RestApiTest(PyramidCWTest): |
7 def includeme(self, config): |
11 def includeme(self, config): |
8 config.include('pyramid_cubicweb.rest_api') |
12 config.include('pyramid_cubicweb.rest_api') |
|
13 config.include('pyramid_cubicweb.tests.test_rest_api') |
9 |
14 |
10 def test_delete(self): |
15 def test_delete(self): |
11 with self.admin_access.repo_cnx() as cnx: |
16 with self.admin_access.repo_cnx() as cnx: |
12 cnx.create_entity('CWGroup', name=u'tmp') |
17 cnx.create_entity('CWGroup', name=u'tmp') |
13 cnx.commit() |
18 cnx.commit() |
16 res = self.webapp.delete('/cwgroup/tmp') |
21 res = self.webapp.delete('/cwgroup/tmp') |
17 self.assertEqual(res.status_int, 204) |
22 self.assertEqual(res.status_int, 204) |
18 |
23 |
19 with self.admin_access.repo_cnx() as cnx: |
24 with self.admin_access.repo_cnx() as cnx: |
20 self.assertEqual(cnx.find('CWGroup', name=u'tmp').rowcount, 0) |
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 test_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__) |