|
@@ -1,97 +0,0 @@
|
1
|
|
-from webtest import TestApp
|
2
|
|
-from pyramid.config import Configurator
|
3
|
|
-import hapic
|
4
|
|
-from hapic.ext.pyramid import PyramidContext
|
5
|
|
-from example.fake_api.pyramid_api import hapic
|
6
|
|
-from example.fake_api.pyramid_api import PyramidController
|
7
|
|
-from tests.func.fake_api.common import SWAGGER_DOC_API
|
8
|
|
-
|
9
|
|
-
|
10
|
|
-def test_func_pyramid_fake_api_doc():
|
11
|
|
- configurator = Configurator(autocommit=True)
|
12
|
|
- controllers = PyramidController()
|
13
|
|
- controllers.bind(configurator)
|
14
|
|
- hapic.set_context(PyramidContext(configurator))
|
15
|
|
- app = TestApp(configurator.make_wsgi_app())
|
16
|
|
- doc = hapic.generate_doc(
|
17
|
|
- title='Fake API',
|
18
|
|
- description='just an example of hapic API'
|
19
|
|
- )
|
20
|
|
-
|
21
|
|
- assert doc == SWAGGER_DOC_API
|
22
|
|
- resp = app.get('/about')
|
23
|
|
- assert resp.status_int == 200
|
24
|
|
- assert resp.json == {'datetime': '2017-12-07T10:55:08.488996+00:00',
|
25
|
|
- 'version': '1.2.3'}
|
26
|
|
-
|
27
|
|
- resp = app.get('/users')
|
28
|
|
- assert resp.status_int == 200
|
29
|
|
- assert resp.json == {
|
30
|
|
- 'items':
|
31
|
|
- [
|
32
|
|
- {
|
33
|
|
- 'username': 'some_user',
|
34
|
|
- 'display_name': 'Damien Accorsi',
|
35
|
|
- 'company': 'Algoo', 'id': 4
|
36
|
|
- }
|
37
|
|
- ],
|
38
|
|
- 'pagination': {
|
39
|
|
- 'first_id': 0,
|
40
|
|
- 'last_id': 5,
|
41
|
|
- 'current_id': 0,
|
42
|
|
- },
|
43
|
|
- 'item_nb': 1,
|
44
|
|
- }
|
45
|
|
-
|
46
|
|
- resp = app.get('/users/1')
|
47
|
|
- assert resp.status_int == 200
|
48
|
|
- assert resp.json == {
|
49
|
|
- 'last_name': 'Accorsi',
|
50
|
|
- 'username': 'some_user',
|
51
|
|
- 'first_name': 'Damien',
|
52
|
|
- 'id': 4,
|
53
|
|
- 'display_name': 'Damien Accorsi',
|
54
|
|
- 'email_address': 'some.user@hapic.com',
|
55
|
|
- 'company': 'Algoo'
|
56
|
|
- }
|
57
|
|
-
|
58
|
|
- resp = app.post('/users/', status='*')
|
59
|
|
- assert resp.status_int == 400
|
60
|
|
- assert resp.json == {
|
61
|
|
- 'code': None,
|
62
|
|
- 'details': {
|
63
|
|
- 'email_address': ['Missing data for required field.'],
|
64
|
|
- 'username': ['Missing data for required field.'],
|
65
|
|
- 'display_name': ['Missing data for required field.'],
|
66
|
|
- 'last_name': ['Missing data for required field.'],
|
67
|
|
- 'first_name': ['Missing data for required field.'],
|
68
|
|
- 'company': ['Missing data for required field.']},
|
69
|
|
- 'message': 'Validation error of input data'}
|
70
|
|
-
|
71
|
|
- user = {
|
72
|
|
- 'email_address': 'some.user@hapic.com',
|
73
|
|
- 'username': 'some_user',
|
74
|
|
- 'display_name': 'Damien Accorsi',
|
75
|
|
- 'last_name': 'Accorsi',
|
76
|
|
- 'first_name': 'Damien',
|
77
|
|
- 'company': 'Algoo',
|
78
|
|
- }
|
79
|
|
-
|
80
|
|
- resp = app.post_json('/users/', user)
|
81
|
|
- assert resp.status_int == 200
|
82
|
|
- assert resp.json == {
|
83
|
|
- 'last_name': 'Accorsi',
|
84
|
|
- 'username': 'some_user',
|
85
|
|
- 'first_name': 'Damien',
|
86
|
|
- 'id': 4,
|
87
|
|
- 'display_name': 'Damien Accorsi',
|
88
|
|
- 'email_address': 'some.user@hapic.com',
|
89
|
|
- 'company': 'Algoo',
|
90
|
|
- }
|
91
|
|
-
|
92
|
|
- # INFO - G.M - 2017-12-07 - Test for delete desactivated(Webtest check fail)
|
93
|
|
- # Webtest check content_type. Up to know pyramid_api return json as
|
94
|
|
- # content_type with 204 NO CONTENT status code which return an error in
|
95
|
|
- # WebTest check.
|
96
|
|
- # resp = app.delete('/users/1', status='*')
|
97
|
|
- # assert resp.status_int == 204
|