This repository was archived by the owner on Jan 5, 2023. It is now read-only.
File tree 8 files changed +57
-10
lines changed 8 files changed +57
-10
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,18 @@ $ black src tests --config setup.cfg
37
37
See the black [ documentation] ( https://github.com/psf/black#editor-integration ) for details on how
38
38
to configure your editor to automatically format your code.
39
39
40
+ ##Swagger
41
+
42
+ The swagger documentation for this service can be found at the /swagger endpoint. If running
43
+ locally, navigate to http://localhost:8080/swagger to see it.
44
+
45
+ If any new endpoints are added to the service or if the service is updated in such a way that any of
46
+ the existing endpoints' contracts change, the swagger documentation must be updated to reflect the
47
+ new state of the service before that change can be merged to master.
48
+
49
+ Documentation for how the swagger documentation is done can be found
50
+ [ here] ( https://flask-restplus.readthedocs.io/en/stable/swagger.html ) .
51
+
40
52
## Deploy
41
53
42
54
Deployment is done via helm to [ kanopy] ( https://github.com/10gen/kanopy-docs#index ) . The project
Original file line number Diff line number Diff line change 1
1
black == 19.3b0
2
2
gunicorn == 19.9.0
3
3
pytest-flake8 == 1.0.4
4
- pytest == 4 .2.1
4
+ pytest == 5 .2.0
Original file line number Diff line number Diff line change 38
38
],
39
39
install_requires = [
40
40
'flask==1.0.4' ,
41
+ 'flask-restplus==0.13.0' ,
41
42
],
42
43
entry_points = {
43
44
'console_scripts' : [
Original file line number Diff line number Diff line change 2
2
Application to serve API of selected-tests service.
3
3
"""
4
4
5
- from flask import Flask , jsonify
5
+ from flask import Flask
6
+ from flask_restplus import Api
7
+
8
+ from selectedtests .app .controllers .health_controller import add_health_endpoints
6
9
7
10
DEFAULT_PORT = 8080
8
11
@@ -14,13 +17,15 @@ def create_app() -> Flask:
14
17
:return: Instance of flask application.
15
18
"""
16
19
app = Flask (__name__ )
17
-
18
- @app .route ("/health" )
19
- def health ():
20
- """
21
- Get information about whether service is running
22
- """
23
- return jsonify ({"online" : True })
20
+ api = Api (
21
+ app ,
22
+ version = "1.0" ,
23
+ title = "Selected Tests Service" ,
24
+ description = "This service is used to predict which tests need to run based on code changes" ,
25
+ doc = "/swagger" ,
26
+ )
27
+
28
+ add_health_endpoints (api )
24
29
25
30
return app
26
31
Original file line number Diff line number Diff line change
1
+ """
2
+ The controller for the health endpoints.
3
+ """
4
+ from flask import jsonify
5
+ from flask_restplus import Api , Resource , fields
6
+
7
+
8
+ def add_health_endpoints (api : Api ):
9
+ """
10
+ This adds to the given app instance the health endpoints of the service
11
+ :param api: An instance of a Flask Restplus Api that wraps a Flask instance
12
+ """
13
+
14
+ ns = api .namespace ("health" , description = "Health check endpoint" )
15
+
16
+ health_model = ns .model ("HealthCheckResponse" , {"online" : fields .Boolean })
17
+
18
+ @ns .route ("" )
19
+ class Health (Resource ):
20
+ """
21
+ The class that represents the collection of endpoints that give the health of the service.
22
+ """
23
+
24
+ @ns .response (200 , "Success" , health_model )
25
+ def get (self ):
26
+ """
27
+ Get the current status of the service
28
+ """
29
+ return jsonify ({"online" : True })
File renamed without changes.
Original file line number Diff line number Diff line change 1
1
from flask import testing
2
2
3
3
4
- def test_health (app_client : testing .FlaskClient ):
4
+ def test_health_endpoint (app_client : testing .FlaskClient ):
5
5
"""
6
6
Test /health endpoint
7
7
"""
You can’t perform that action at this time.
0 commit comments