Some API projects have been implemented with dummy tests that just call pass. This was done to get around a Travis issue where it would fail every job when it detected 0 tests in the project.
Since then we've had many containers that deploy without being able to pass the basic "health check" from ALB (which is implemented as a GET request for the base route for each API project, looking for a 200-299 HTTP response). e.g. for the Local Elections API, ALB requests /local-elections/ and is currently receiving a 404 Not Found response (see bug 3 for details). (Also see #140, and ignore the fact I closed that issue without addressing it.)
So to prevent these jank containers from deploying, and causing a lot of ECS thrash (cf. #149), we need at least a bare minimum test that validates the following:
gunicorn is running
Django code isn’t crashing, and
there’s a 200 responding on at least the tested endpoint
@BrianHGrant is the Django man - as always, he volunteered up the perfect snippet:
from django.test import TestCase
from rest_framework.test import APIClient, RequestsClient
class RootTest(TestCase):
""" Test for Root Endpoint"""
def setUp(self):
pass
class RootEndpointsTestCase(TestCase):
def setUp(self):
self.client = APIClient()
def test_list_200_response(self):
response = self.client.get('/transportation-systems/')
assert response.status_code == 200
I realize it’s not actually inspecting the response to see that it’s Django, nor whether the response is a valid output e.g. good HTML, valid JSON, anything like that. However, what with the pass “tests” we’ve implemented in most projects to get past the test phase of Travis, this has to be far better, and should catch some of the Django startup issues that we’ve been screwed by, before they get deployed to ECS.
Some API projects have been implemented with dummy tests that just call
pass
. This was done to get around a Travis issue where it would fail every job when it detected 0 tests in the project.Since then we've had many containers that deploy without being able to pass the basic "health check" from ALB (which is implemented as a GET request for the base route for each API project, looking for a 200-299 HTTP response). e.g. for the Local Elections API, ALB requests
/local-elections/
and is currently receiving a 404 Not Found response (see bug 3 for details). (Also see #140, and ignore the fact I closed that issue without addressing it.)So to prevent these jank containers from deploying, and causing a lot of ECS thrash (cf. #149), we need at least a bare minimum test that validates the following:
@BrianHGrant is the Django man - as always, he volunteered up the perfect snippet:
I realize it’s not actually inspecting the response to see that it’s Django, nor whether the response is a valid output e.g. good HTML, valid JSON, anything like that. However, what with the
pass
“tests” we’ve implemented in most projects to get past the test phase of Travis, this has to be far better, and should catch some of the Django startup issues that we’ve been screwed by, before they get deployed to ECS.Let's get this into all the API projects: