From 6cfb670e27051d0d7cb5b8352325c0bc2d0a9c0b Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 1 Oct 2026 19:35:21 +0000 Subject: [PATCH 1/2] Run unit tests without the Elasticsearch data load. Move the heartbeat check, which calls the live index, into the integration suite. Load the test dump only before integration tests, and run those against the API. Skip the old v1 integration module. Co-authored-by: Joseph Rhoads --- .github/workflows/run_tests.yml | 27 ++++++++++++++++--- rorapi/tests/tests_integration/tests.py | 6 +++++ .../tests_integration/tests_heartbeat.py | 10 +++++++ rorapi/tests/tests_unit/tests_views_v2.py | 14 ---------- 4 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 rorapi/tests/tests_integration/tests_heartbeat.py diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 392cabdf..5992660a 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -60,14 +60,33 @@ jobs: run: | python -Wd manage.py check python manage.py makemigrations --check --dry-run + - name: Run unit tests + working-directory: ./ror-api + run: | + python -Wa manage.py test rorapi.tests.tests_unit - name: Load test data working-directory: ./ror-api run: | python manage.py setup ${{ env.TEST_DATA_DUMP_FILE }} -t - - name: Run Tests + - name: Run integration tests working-directory: ./ror-api + env: + ROR_BASE_URL: http://127.0.0.1:8000 run: | - python -Wa manage.py test rorapi.tests.tests_unit - # TODO fix these tests running in GitHub Action - # python manage.py test rorapi.tests.tests_integration + python manage.py runserver 127.0.0.1:8000 --noreload > /tmp/runserver.log 2>&1 & + ready=0 + for i in $(seq 1 30); do + if curl -sf http://127.0.0.1:8000/heartbeat; then + ready=1 + break + fi + sleep 2 + done + if [ "$ready" != 1 ]; then + echo "API did not become ready" + cat /tmp/runserver.log + exit 1 + fi + python manage.py test rorapi.tests.tests_integration + # tests_functional stays off until the evaluation harness passes # python manage.py test rorapi.tests.tests_functional diff --git a/rorapi/tests/tests_integration/tests.py b/rorapi/tests/tests_integration/tests.py index 73364146..2c8ec622 100644 --- a/rorapi/tests/tests_integration/tests.py +++ b/rorapi/tests/tests_integration/tests.py @@ -2,6 +2,8 @@ import json import os import re +import unittest + import requests from django.test import SimpleTestCase @@ -11,6 +13,10 @@ os.environ.get('ROR_BASE_URL', 'http://localhost')) +@unittest.skip( + 'Expects the removed v1 response shape (name, country.country_code). ' + 'v2 coverage is tests_v2.py.' +) class APITestCase(SimpleTestCase): def get_total(self, output): return output['number_of_results'] diff --git a/rorapi/tests/tests_integration/tests_heartbeat.py b/rorapi/tests/tests_integration/tests_heartbeat.py new file mode 100644 index 00000000..29869c5a --- /dev/null +++ b/rorapi/tests/tests_integration/tests_heartbeat.py @@ -0,0 +1,10 @@ +from django.test import SimpleTestCase + + +class HeartbeatViewTestCase(SimpleTestCase): + """Needs a live organizations-v2 index, so it runs with the integration suite.""" + + def test_heartbeat_success(self): + response = self.client.get('/heartbeat') + self.assertEqual(response.status_code, 200) + self.assertEqual(response.content, b'OK') diff --git a/rorapi/tests/tests_unit/tests_views_v2.py b/rorapi/tests/tests_unit/tests_views_v2.py index 5816532d..e046f443 100644 --- a/rorapi/tests/tests_unit/tests_views_v2.py +++ b/rorapi/tests/tests_unit/tests_views_v2.py @@ -389,20 +389,6 @@ def test_index_ror_success_with_auth_headers(self, index_mock): ) self.assertEqual(response.status_code, 200) -class HeartbeatViewTestCase(SimpleTestCase): - def setUp(self): - with open( - os.path.join(os.path.dirname(__file__), - 'data/test_data_search_es7_v2.json'), 'r') as f: - self.test_data = json.load(f) - - @mock.patch('elasticsearch_dsl.Search.execute') - def test_heartbeat_success(self, search_mock): - search_mock.return_value = \ - IterableAttrDict(self.test_data, self.test_data['hits']['hits']) - response = self.client.get('/v2/heartbeat') - self.assertEqual(response.status_code, 200) - class BulkUpdateViewTestCase(SimpleTestCase): def setUp(self): self.csv_errors_empty = [] From e6b8e1db4034c2e310ce4fd06b94c910e46b81d6 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 1 Oct 2026 19:38:48 +0000 Subject: [PATCH 2/2] Run only the heartbeat integration test in CI. The HTTP integration suites expect a full public corpus and fail against the CI test dump. Heartbeat only needs the indexed organizations-v2 index. Co-authored-by: Joseph Rhoads --- .github/workflows/run_tests.yml | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 5992660a..9788738f 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -70,23 +70,11 @@ jobs: python manage.py setup ${{ env.TEST_DATA_DUMP_FILE }} -t - name: Run integration tests working-directory: ./ror-api - env: - ROR_BASE_URL: http://127.0.0.1:8000 run: | - python manage.py runserver 127.0.0.1:8000 --noreload > /tmp/runserver.log 2>&1 & - ready=0 - for i in $(seq 1 30); do - if curl -sf http://127.0.0.1:8000/heartbeat; then - ready=1 - break - fi - sleep 2 - done - if [ "$ready" != 1 ]; then - echo "API did not become ready" - cat /tmp/runserver.log - exit 1 - fi - python manage.py test rorapi.tests.tests_integration - # tests_functional stays off until the evaluation harness passes + python manage.py test rorapi.tests.tests_integration.tests_heartbeat + # HTTP suites assume a full public corpus (specific ROR IDs, >50k + # records). The CI test dump does not satisfy that, so they stay off. + # python manage.py test rorapi.tests.tests_integration.tests_v2 + # python manage.py test rorapi.tests.tests_integration.tests_search_v2 + # python manage.py test rorapi.tests.tests_integration.tests_matching_v2 # python manage.py test rorapi.tests.tests_functional