From 687fedfffa402e049c59668f2a6248ad2ba17910 Mon Sep 17 00:00:00 2001 From: Christopher Baklid Date: Sun, 20 May 2018 21:11:18 +0200 Subject: Tests directory (#73) moves all tests into a testing directory and splits the tests into separate files --- tests/test_api.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/test_api.py (limited to 'tests/test_api.py') diff --git a/tests/test_api.py b/tests/test_api.py new file mode 100644 index 00000000..a0b22846 --- /dev/null +++ b/tests/test_api.py @@ -0,0 +1,25 @@ +from tests import SiteTest, app + +class ApiEndpointsRootEndpoints(SiteTest): + """ Test cases for the api subdomain """ + def test_api_unknown_route(self): + """ Check api unknown route """ + response = self.client.get('/', app.config['API_SUBDOMAIN']) + self.assertEqual(response.json, {'error_code': 0, 'error_message': 'Unknown API route'}) + self.assertEqual(response.status_code, 404) + + def test_api_healthcheck(self): + """ Check healthcheck url responds """ + response = self.client.get('/healthcheck', app.config['API_SUBDOMAIN']) + self.assertEqual(response.json, {'status': 'ok'}) + self.assertEqual(response.status_code, 200) + + def test_api_route_errors(self): + """ Check api route errors """ + from pysite.base_route import APIView + from pysite.constants import ErrorCodes + + av = APIView() + av.error(ErrorCodes.unauthorized) + av.error(ErrorCodes.bad_data_format) + -- cgit v1.2.3