Skip to content

Commit

Permalink
Merge pull request #76 from rcpch/mbarton/pr-check
Browse files Browse the repository at this point in the history
Add tests to PR checks
  • Loading branch information
mbarton authored Jan 6, 2025
2 parents 6f89387 + 4c1465e commit 3b5d5ad
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 45 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Runs the Pytest test suite when PRs are made against any branch

name: Run pr-check script on all PRs

on:
pull_request:
branches:
- "*"

jobs:
build-and-run-pytest-suite-in-docker-compose:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
lfs: true # ensures large files are downloaded using Git LFS

- name: Create .env file from example
run: cp envs/example.env envs/.env

- name: Run pr-check script
run: s/pr-check


18 changes: 8 additions & 10 deletions envs/example.env
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# these env vars are ONLY for development

RCPCH_NHS_ORGANISATIONS_SECRET_KEY=mysecretkey
DJANGO_ALLOWED_HOSTS=0.0.0.0
DJANGO_CSRF_TRUSTED_ORIGINS=https://localhost,https://0.0.0.0

# ENVIRONMENT VARIABLES FOR LOCAL DEVELOPMENT ONLY
# THIS FILE MUST NEVER BE ADDED TO VERSION CONTROL
# SECTIONS IN ALPHABETICAL ORDER ASCENDING
Expand All @@ -21,14 +17,16 @@ DJANGO_ALLOWED_HOSTS="localhost,127.0.0.1,rcpch-nhs-organisations.localhost"
DEBUG="True" # Set DEBUG=True for Local dev and Development, not Staging or Live
DJANGO_STARTUP_COMMAND="python manage.py runserver 0.0.0.0:8003" # for local development with auto-reload
# DJANGO_STARTUP_COMMAND="gunicorn --bind=0.0.0.0:8003 --timeout 600 rcpch-audit-engine.wsgi" # for live deployment
RCPCH_NHS_ORGANISATIONS_SECRET_KEY="###########"
RCPCH_NHS_ORGANISATIONS_SECRET_KEY="mysecretkey"

# DJANGO POSTGRES DATABASE CONNECTION
PGDATABASE="nhsorganisationsdb"
PGUSER="nhsorganisationsuser"
PGPASSWORD="password"
PGHOST="postgis"
PGPORT="5432"
POSTGRES_DB="nhsorganisationsdb"
POSTGRES_USER="nhsorganisationsuser"
POSTGRES_PASSWORD="password"
POSTGRES_HOST="postgis"
POSTGRES_PORT="5432"



# EMAIL
EMAIL_DEFAULT_FROM_EMAIL="########"
Expand Down
10 changes: 5 additions & 5 deletions rcpch_nhs_organisations/hospitals/tests/test_viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,24 @@ def local_authority_districts():

@pytest.mark.django_db
def test_list_local_authority_districts(api_client, local_authority_districts):
url = reverse("local_authority_district-list")
url = reverse("local_authority_districts-list")
response = api_client.get(url)

assert response.status_code == status.HTTP_200_OK
assert len(response.data["features"]) == 3
assert len(response.data) == 3


@pytest.mark.django_db
def test_within_radius(api_client, local_authority_districts):
url = reverse("local_authority_district-within-radius")
url = reverse("local_authority_districts-within-radius")
response = api_client.get(
url, {"lat": 53.0, "long": -3.0, "radius": 500000}
) # within 500km
assert response.status_code == status.HTTP_200_OK
assert len(response.data["features"]) == 3
assert len(response.data) == 3

response = api_client.get(
url, {"lat": 53.0, "long": -3.0, "radius": 5}
) # within 5 km
assert response.status_code == status.HTTP_200_OK
assert len(response.data["features"]) == 0
assert len(response.data) == 0
2 changes: 1 addition & 1 deletion rcpch_nhs_organisations/hospitals/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
router.register(
r"local_authority_districts",
viewset=LocalAuthorityDistrictViewSet,
basename="london_borough",
basename="local_authority_districts",
)
# NHS England Region endpoints
router.register(
Expand Down
32 changes: 8 additions & 24 deletions rcpch_nhs_organisations/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,12 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv("DEBUG", "False") == "True"

ALLOWED_HOSTS = os.getenv("DJANGO_ALLOWED_HOSTS", "").split(",") + [
"127.0.0.1",
"localhost",
"0.0.0.0",
]

if os.getenv("WEBSITE_SITE_NAME"):
ALLOWED_HOSTS = ["*"]
else:
ALLOWED_HOSTS = [
"127.0.0.1",
"localhost",
"0.0.0.0",
"rcpch-nhs-organisations.localhost",
]

CSRF_TRUSTED_ORIGINS = os.getenv("DJANGO_CSRF_TRUSTED_ORIGINS", "").split(",") + [
"https://rcpch-nhs-organisations.localhost",
"https://127.0.0.1",
"https://localhost",
"https://0.0.0.0",
]
ALLOWED_HOSTS = os.getenv("DJANGO_ALLOWED_HOSTS", "").split(",")

CSRF_TRUSTED_ORIGINS = os.getenv("DJANGO_CSRF_TRUSTED_ORIGINS", "").split(",")

# Enables Django to use the X-Forwarded-Host header in preference to the Host header.
# Fixes CSRF errors when using Caddy to forward requests to Django.
Expand Down Expand Up @@ -119,11 +103,11 @@
DATABASES = {
"default": {
"ENGINE": "django.contrib.gis.db.backends.postgis",
"NAME": os.environ.get("PGDATABASENAME"),
"USER": os.environ.get("PGUSER"),
"PASSWORD": os.environ.get("PGPASSWORD"),
"PORT": os.environ.get("PGPORT"),
"HOST": os.environ.get("PGHOST"),
"NAME": os.environ.get("POSTGRES_DB"),
"USER": os.environ.get("POSTGRES_USER"),
"PASSWORD": os.environ.get("POSTGRES_PASSWORD"),
"PORT": os.environ.get("POSTGRES_PORT"),
"HOST": os.environ.get("POSTGRES_HOST"),
}
}

Expand Down
3 changes: 1 addition & 2 deletions requirements/common-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ python-dateutil==2.9.0.post0

# third party imports
django==4.2.17
# PINNED: see https://github.com/rcpch/rcpch-nhs-organisations/issues/55
djangorestframework==3.14.0
djangorestframework==3.15.2
djangorestframework-gis==1.0
drf-spectacular==0.27.1
django-filter==24.1
Expand Down
3 changes: 3 additions & 0 deletions s/django-shell
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -e

docker compose exec -it django python manage.py shell
6 changes: 6 additions & 0 deletions s/pr-check
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash -e

s/up --detach
# I tried --wait and a healthcheck but still got connection refused from postgres
sleep 5
s/test
2 changes: 1 addition & 1 deletion s/test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash -e

# scripts may need to be made executable on some platforms before they can be run
# chmod +x <filename> is the command to do this on unixy systems
Expand Down
4 changes: 2 additions & 2 deletions s/up
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
#!/bin/bash -e

# scripts may need to be made executable on some platforms before they can be run
# chmod +x <filename> is the command to do this on unixy systems

# starts all docker compose services
docker compose up
docker compose up $*

0 comments on commit 3b5d5ad

Please sign in to comment.