Browse Source

Add typing for function signature

Guénaël Muller 6 years ago
parent
commit
9164202ab7

+ 2 - 1
hapic/doc.py View File

@@ -2,6 +2,7 @@
2 2
 import json
3 3
 
4 4
 import typing
5
+import marshmallow
5 6
 import yaml
6 7
 
7 8
 from apispec import APISpec
@@ -14,7 +15,7 @@ from hapic.decorator import DecoratedController
14 15
 from hapic.description import ControllerDescription
15 16
 
16 17
 
17
-def generate_schema_ref(spec, schema):
18
+def generate_schema_ref(spec:APISpec, schema: marshmallow.Schema):
18 19
     schema_class = spec.schema_class_resolver(
19 20
         spec,
20 21
         schema

tests/func/fake_api/test_bottle.py → tests/func/fake_api/test_fake_api.py View File


+ 0 - 95
tests/func/fake_api/test_flask.py View File

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

+ 0 - 97
tests/func/fake_api/test_pyramid.py View File

@@ -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