From ab01e87050e0d64849b3edb003a357f245facf4f Mon Sep 17 00:00:00 2001 From: Bee Webb Date: Tue, 25 Feb 2025 17:04:18 +0000 Subject: [PATCH] test: Update to handle element page change, by creating/loading fixture --- .github/workflows/ci.yml | 7 ++++++- README.md | 8 ++------ iati_dashboard/tests/test_page_speed.py | 9 ++++++--- iati_dashboard/ui/tests.py | 2 ++ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ed05bbd4..acde73f94 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,10 +49,15 @@ jobs: python manage.py collectstatic python manage.py migrate python manage.py dashboard_import + mkdir iati_dashboard/fixtures/ + python manage.py dumpdata iati_dashboard.Publisher > iati_dashboard/fixtures/publishers.json - name: Run tests env: DATABASE_URL: "postgres://postgres:postgres@localhost:5432/test_database_name" - run: pytest . + DASHBOARD_ROOT_URL: "http://localhost:8000" + run: | + python manage.py runserver & + pytest . # - name: Coveralls # run: coveralls --service=github-actions # env: diff --git a/README.md b/README.md index 771f1090e..006dc8d64 100644 --- a/README.md +++ b/README.md @@ -99,15 +99,11 @@ There are some unit tests written using `pytest` and site testing using Django's Once the development dependencies have been installed the unit tests can be run with: ``` +mkdir iati_dashboard/fixtures/ +python manage.py dumpdata iati_dashboard.Publisher > iati_dashboard/fixtures/publishers.json pytest ``` -The Django site tests can be run from the `dashboard/` directory with: - -``` -python manage.py test -v 2 -``` - ### Calculating your own statistics The IATI Dashboard requires a `stats-calculated` directory, which can be downloaded using the `get_stats.sh` shell script as described above. This can also be calculated using [Code for IATI Stats](http://github.com/codeforIATI/IATI-Stats) where `stats-calculated` corresponds to the `gitout` directory generated by [`git.sh` in IATI-Stats](https://github.com/codeforIATI/IATI-Stats#running-for-every-commit-in-the-data-directory). diff --git a/iati_dashboard/tests/test_page_speed.py b/iati_dashboard/tests/test_page_speed.py index c2d4c4f0f..384d6b901 100644 --- a/iati_dashboard/tests/test_page_speed.py +++ b/iati_dashboard/tests/test_page_speed.py @@ -85,8 +85,11 @@ @pytest.mark.parametrize("page", EXAMPLE_PAGES) -def test_page_speed(page, live_server): - host = os.environ.get("DASHBOARD_ROOT_URL", live_server.url) - r = requests.get(f"{host}/{page}") +def test_page_speed(page): + if "DASHBOARD_ROOT_URL" in os.environ: + dashboard_url = os.environ["DASHBOARD_ROOT_URL"] + else: + pytest.skip() + r = requests.get(f"{dashboard_url}/{page}") assert r.status_code == 200 assert r.elapsed.total_seconds() < 2 diff --git a/iati_dashboard/ui/tests.py b/iati_dashboard/ui/tests.py index fcdc7f8d5..5116a89b9 100644 --- a/iati_dashboard/ui/tests.py +++ b/iati_dashboard/ui/tests.py @@ -10,6 +10,8 @@ class BasicPageTests(TestCase): list the tests as they run. """ + fixtures = ["publishers"] + def test_top_pages(self): """Test the index and top hierarchy pages return a 200 status code"""