Skip to content

Commit

Permalink
Add unit test for health check
Browse files Browse the repository at this point in the history
  • Loading branch information
Lijinyu3 committed Jul 20, 2024
1 parent 72e510d commit e22f52c
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions backend/tests/unit_tests/test_api_health.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# coding=utf-8

# Copyright [2024] [SkywardAI]
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest
import fastapi
from fastapi.testclient import TestClient
import httpx
from src.api.routes import health


class TestAPIHealth(unittest.TestCase):
"""
Test the FastAPI application attributes
"""

@classmethod
def setUpClass(cls):
cls.app = fastapi.FastAPI()
cls.app.include_router(health.router)
cls.client = TestClient(cls.app)

@classmethod
def tearDownClass(cls):
pass

def test_api_health(self):
"""
Test the health check API
"""
response: httpx.Response = self.client.get("/health")
self.assertIsInstance(response, httpx.Response)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), {"status": "ok"})

0 comments on commit e22f52c

Please sign in to comment.