File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55from fastapi .middleware .cors import CORSMiddleware
66from fastapi .responses import RedirectResponse
77from prometheus_fastapi_instrumentator import Instrumentator
8- from pydantic import BaseModel , Field
98
109from hackspaceapi import VERSION
10+ from hackspaceapi .models import HealthResponseModel
1111
1212from .events import events
1313from .spaceapi import spaceapi
3434Instrumentator ().instrument (app ).expose (app , include_in_schema = False )
3535
3636
37- class HealthResponse (BaseModel ):
38- health : str = Field (description = "State of the API" , examples = ["ok" , "error" ])
39- version : str = Field (description = "Version of the API" , examples = [VERSION ])
40-
41-
4237@app .get ("/" , include_in_schema = False )
4338def root ():
4439 return RedirectResponse ("/docs" )
@@ -49,5 +44,5 @@ def root():
4944 description = "Healthcheck endpoint to ensure the API is running correctly" ,
5045 tags = ["Health" ],
5146)
52- def health () -> HealthResponse :
53- return HealthResponse (health = "ok" , version = VERSION )
47+ def health () -> HealthResponseModel :
48+ return HealthResponseModel (health = "ok" , version = VERSION )
Original file line number Diff line number Diff line change 1+ from pydantic import BaseModel , Field
2+
3+ from hackspaceapi import VERSION
4+
5+
6+ class HealthResponseModel (BaseModel ):
7+ health : str = Field (description = "State of the API" , examples = ["ok" , "error" ])
8+ version : str = Field (description = "Version of the API" , examples = [VERSION ])
Original file line number Diff line number Diff line change 1+ from hackspaceapi import VERSION
2+ from tests .utils import FastAPIVCRTestCase , client
3+
4+
5+ class HealthTestCase (FastAPIVCRTestCase ):
6+ """
7+ Test the health endpoint
8+ """
9+
10+ def test_health_endpoint (self ):
11+ response = client .get ("/health" )
12+ assert response .status_code == 200
13+ assert response .headers ["Content-Type" ] == "application/json"
14+
15+ data = response .json ()
16+
17+ assert data ["health" ] == "ok"
18+ assert data ["version" ] == VERSION
You can’t perform that action at this time.
0 commit comments