Skip to content

Commit

Permalink
test: Run django tests in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjwebb committed Jan 29, 2025
1 parent ae36074 commit 67df403
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,22 @@ jobs:
- name: Fetch stats
run: |
mkdir out
./mock_stats_for_unit_tests.sh
- name: Run tests
./partial_stats_for_unit_tests.sh
- name: Set up django
env:
DATABASE_URL: "postgres://postgres:postgres@localhost:5432/test_database_name"
run: |
python manage.py collectstatic
python manage.py migrate
python manage.py dashboard_import
- name: Run non-django tests
env:
DATABASE_URL: "postgres://postgres:postgres@localhost:5432/test_database_name"
run: pytest --cov .
- name: Run django tests
env:
DATABASE_URL: "postgres://postgres:postgres@localhost:5432/test_database_name"
run: python manage.py test
# - name: Coveralls
# run: coveralls --service=github-actions
# env:
Expand Down
4 changes: 2 additions & 2 deletions iati_dashboard/ui/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_top_pages(self):

self.assertEqual(self.client.get(reverse("dash-index")).status_code, 200)
self.assertEqual(self.client.get(reverse("dash-headlines-publishers")).status_code, 200)
self.assertEqual(self.client.get(reverse("dash-headlines-publisher-detail", args=("undp",))).status_code, 200)
self.assertEqual(self.client.get(reverse("dash-headlines-publisher-detail", args=("zsl",))).status_code, 200)
self.assertEqual(
self.client.get(reverse("dash-headlines-publisher-detail", args=("not-a-valid-publisher",))).status_code,
404,
Expand Down Expand Up @@ -237,7 +237,7 @@ def test_slug_page_redirects(self):
"""Test pages with slugs redirect to the section page"""

self.assertRedirects(
self.client.get(r"/publisher/undp.html"), reverse("dash-headlines-publishers"), status_code=301
self.client.get(r"/publisher/zsl.html"), reverse("dash-headlines-publishers"), status_code=301
)
self.assertRedirects(self.client.get(r"/license/cc-by.html"), reverse("dash-licenses"), status_code=301)
self.assertRedirects(
Expand Down
9 changes: 0 additions & 9 deletions mock_stats_for_unit_tests.sh

This file was deleted.

23 changes: 23 additions & 0 deletions partial_stats_for_unit_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
set -eux

publisher_short_name=zsl

if [ -d stats-calculated ]; then
echo "stats-calculated directory already exists, exiting."
exit
fi
wget -m --no-parent https://dev.merged.dashboard.iatistandard.org/stats/current/aggregated/
wget -m --no-parent https://dev.merged.dashboard.iatistandard.org/stats/current/aggregated-publisher/$publisher_short_name/
wget -m --no-parent https://dev.merged.dashboard.iatistandard.org/stats/current/aggregated-file/$publisher_short_name/
wget -m --no-parent https://dev.merged.dashboard.iatistandard.org/stats/current/inverted-publisher/
wget -m --no-parent https://dev.merged.dashboard.iatistandard.org/stats/current/inverted-file/
wget -m --no-parent https://dev.merged.dashboard.iatistandard.org/stats/current/inverted-file-publisher/$publisher_short_name/
wget -m --no-parent https://dev.merged.dashboard.iatistandard.org/stats/gitaggregate-publisher-dated/$publisher_short_name/
mv dev.merged.dashboard.iatistandard.org/stats stats-calculated
for file in ckan.json licenses.json gitdate.json; do
curl --compressed https://dev.merged.dashboard.iatistandard.org/stats/$file > stats-calculated/$file
done

cat stats-calculated/current/inverted-publisher/activities.json | jq "{$publisher_short_name: .$publisher_short_name}" > activities.json
mv activities.json stats-calculated/current/inverted-publisher/activities.json
rm stats-calculated/current/aggregated-publisher/$publisher_short_name/index.html*

0 comments on commit 67df403

Please sign in to comment.