This guide is intended to be a workflow to update from a testing schema used in 2017 to 2018's project season.
There are a few things that have happened:
- The test runner used by many teams
noseis no longer maintained so we are deprecating its use. - Many teams relyed on some sort of test db creation or loading of fixture data. This year we are assuming all projects are read only and will run against prod.
While updating from the 2017 to 2018 you may have already run into some dependency issues related to test packages and have begun this process. But this will assume you are starting from scratch.
-
Remove any references to
noseornose_coveragein thesettings.pyfile -
Also remove these packages from the requirements files.
-
Confirm you have these testing packages in the
common.txt:
# Testing
pytest-django==3.2.1
tblib==1.3.2
- Create a
pytest.inifile at the project root (ReplaceemerresponseAPIwith actual project name):
[pytest]
DJANGO_SETTINGS_MODULE = emerresponseAPI.settings
python_files = tests.py test_*.py *_tests.py
addopts = --reuse-db
- Create a
confttest.pyfile also at the project root (Again updating to project name as needed):
import pytest
import os
import emerresponseAPI
@pytest.fixture(scope='session')
def django_db_setup():
emerresponseAPI.settings.DATABASES['default'] = {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'PASSWORD': os.environ.get('POSTGRES_PASSWORD'),
'NAME': os.environ.get('POSTGRES_NAME'),
'USER': os.environ.get('POSTGRES_USER'),
'HOST': os.environ.get('POSTGRES_HOST'),
'PORT': os.environ.get('POSTGRES_PORT')
}
-
Remove any fixture files from the project and comment out all current tests.
-
Begin with a test on the root endpoint and confirm it passes:
from django.test import TestCase
from rest_framework.test import APIClient, RequestsClient
class RootTest(TestCase):
""" Test for Crash model """
def setUp(self):
pass
class RootEndpointsTestCase(TestCase):
def setUp(self):
self.client = APIClient()
def test_list_200_response(self):
response = self.client.get('/emergency/')
assert response.status_code == 200
- Now go tests, confirming they pass one by one. You will need to do two things:
- Make sure nothing is attempting to write/create/destroy any data.
- Make sure the expected data results match those returned