Skip to content

Commit

Permalink
test: Update to handle element page change, by creating/loading fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjwebb committed Feb 26, 2025
1 parent 6b43ac5 commit 98e525e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
9 changes: 6 additions & 3 deletions iati_dashboard/tests/test_page_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions iati_dashboard/ui/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down

0 comments on commit 98e525e

Please sign in to comment.