From 4d997cd70e34038ce6392bed97af0bbc653df293 Mon Sep 17 00:00:00 2001 From: DonHaul Date: Tue, 13 Aug 2024 17:36:18 +0200 Subject: [PATCH] github actions: build index before tests * ref: cern-sis/issues-inspire/issues/529 --- .github/workflows/test-backoffice.yml | 3 ++- backoffice/backoffice/workflows/tests/test_views.py | 12 +++++++++--- backoffice/config/settings/test.py | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-backoffice.yml b/.github/workflows/test-backoffice.yml index a982f19a..61e21ddb 100644 --- a/.github/workflows/test-backoffice.yml +++ b/.github/workflows/test-backoffice.yml @@ -63,6 +63,7 @@ jobs: docker run --pull always --network=host + --entrypoint poetry --env DJANGO_SETTINGS_MODULE=config.settings.test --env DISABLE_SECURITY_PLUGIN=true --env POSTGRES_DB=inspire @@ -71,4 +72,4 @@ jobs: --env POSTGRES_HOST=127.0.0.1 --env OPENSEARCH_HOST=127.0.0.1:9200 registry.cern.ch/cern-sis/inspire/backoffice@${{ needs.build.outputs.image-id }} - sh -c "poetry run python manage.py opensearch index create --force && poetry run pytest" + run pytest" diff --git a/backoffice/backoffice/workflows/tests/test_views.py b/backoffice/backoffice/workflows/tests/test_views.py index 0e0c6782..0c8737dd 100644 --- a/backoffice/backoffice/workflows/tests/test_views.py +++ b/backoffice/backoffice/workflows/tests/test_views.py @@ -1,14 +1,16 @@ +import contextlib import uuid import dateutil import dateutil.parser +import opensearchpy import pytest from django.apps import apps from django.contrib.auth import get_user_model from django.contrib.auth.models import Group from django.test import TransactionTestCase from django.urls import reverse -from opensearch_dsl import Index +from django_opensearch_dsl.registries import registry from rest_framework.test import APIClient from backoffice.workflows import airflow_utils @@ -81,8 +83,12 @@ class TestWorkflowSearchViewSet(BaseTransactionTestCase): def setUp(self): super().setUp() - index = Index("backoffice-backend-test-workflows") - index.delete(ignore=[400, 404]) + + index = registry.get_indices().pop() + with contextlib.suppress(opensearchpy.exceptions.NotFoundError): + index.delete() + index.create() + self.workflow = Workflow.objects.create( data={}, status=StatusChoices.APPROVAL, core=True, is_update=False ) diff --git a/backoffice/config/settings/test.py b/backoffice/config/settings/test.py index 7ee0cbda..14744110 100644 --- a/backoffice/config/settings/test.py +++ b/backoffice/config/settings/test.py @@ -34,7 +34,7 @@ # MEDIA # ------------------------------------------------------------------------------ # https://docs.djangoproject.com/en/dev/ref/settings/#media-url -MEDIA_URL = "http://media.testserver" +MEDIA_URL = "http://media.testserver/" # Opensearch # ------------------------------------------------------------------------------ # Name of the Opensearch index