Skip to content

Commit

Permalink
github actions: build index before tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DonHaul authored and drjova committed Aug 14, 2024
1 parent c47905b commit 4d997cd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test-backoffice.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
12 changes: 9 additions & 3 deletions backoffice/backoffice/workflows/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion backoffice/config/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4d997cd

Please sign in to comment.