Merge pull request #104 from cisagov/sspj/django-tests

Add testing to the CI pipeline
This commit is contained in:
Seamus Johnston 2022-09-08 13:48:51 +00:00 committed by GitHub
commit d2da8d1d8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 0 deletions

View file

@ -33,3 +33,40 @@ jobs:
- name: Run bandit security scanning - name: Run bandit security scanning
working-directory: ./src working-directory: ./src
run: bandit -r . run: bandit -r .
python-test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_DB: app
POSTGRES_USER: user
POSTGRES_PASSWORD: feedabee
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
- name: Install Django
working-directory: ./src
run: |
python -m pip install --upgrade pip
pip install pipenv
pipenv install --system --dev
- name: Test
working-directory: ./src
env:
PYTHONUNBUFFERED: yup
DATABASE_URL: postgres://user:feedabee@localhost/app
DJANGO_SETTINGS_MODULE: registrar.config.settings
DJANGO_SECRET_KEY: feedabee
DJANGO_DEBUG: True
run: ./manage.py test

View file

@ -50,6 +50,12 @@ Django's test suite:
docker-compose exec app ./manage.py test docker-compose exec app ./manage.py test
``` ```
OR
```shell
docker-compose exec app python -Wa ./manage.py test # view deprecation warnings
```
Linters: Linters:
```shell ```shell

View file

View file

View file

@ -0,0 +1,11 @@
from django.test import Client, TestCase
class HealthTest(TestCase):
def setUp(self):
self.client = Client()
def test_health_check_endpoint(self):
response = self.client.get("/health/")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, b"OK")