diff --git a/app/public/cantusdata/settings.py b/app/public/cantusdata/settings.py index 0c646b61..8e95caa7 100644 --- a/app/public/cantusdata/settings.py +++ b/app/public/cantusdata/settings.py @@ -175,3 +175,5 @@ CELERY_RESULT_EXTENDED = True CELERY_APP = "cantusdata" CELERY_TASK_TRACK_STARTED = True + +TEST_MEI_FILES_PATH = "cantusdata/test/core/helpers/mei_processing/test_mei_files" diff --git a/app/public/cantusdata/test/core/helpers/mei_processing/test_mei_tokenizer.py b/app/public/cantusdata/test/core/helpers/mei_processing/test_mei_tokenizer.py index 8a0c85f8..746530ab 100644 --- a/app/public/cantusdata/test/core/helpers/mei_processing/test_mei_tokenizer.py +++ b/app/public/cantusdata/test/core/helpers/mei_processing/test_mei_tokenizer.py @@ -2,19 +2,13 @@ from os import path import json from typing import List, cast -from cantusdata.settings import BASE_DIR +from django.conf import settings from cantusdata.helpers.mei_processing.mei_tokenizer import MEITokenizer from cantusdata.helpers.mei_processing.mei_parsing_types import NgramDocument from cantusdata.helpers.neume_helpers import NEUME_GROUPS, NeumeName TEST_MEI_FILE = path.join( - BASE_DIR, - "cantusdata", - "test", - "core", - "helpers", - "mei_processing", - "test_mei_files", + settings["TEST_MEI_FILES_PATH"], "123723", "cdn-hsmu-m2149l4_001r.mei", ) diff --git a/app/public/cantusdata/test/core/management/commands/test_index_manuscript_mei.py b/app/public/cantusdata/test/core/management/commands/test_index_manuscript_mei.py index f2f12e5f..d25c1526 100644 --- a/app/public/cantusdata/test/core/management/commands/test_index_manuscript_mei.py +++ b/app/public/cantusdata/test/core/management/commands/test_index_manuscript_mei.py @@ -12,7 +12,7 @@ from solr.core import SolrConnection # type: ignore -TEST_MEI_FILES_PATH = "cantusdata/test/core/helpers/mei_processing/test_mei_files" +TEST_MEI_FILES_PATH = settings["TEST_MEI_FILES_PATH"] class IndexManuscriptMeiTestCase(TestCase): @@ -26,6 +26,11 @@ def setUpTestData(cls) -> None: Folio.objects.create(number="001r", manuscript=manuscript) Folio.objects.create(number="001v", manuscript=manuscript) + @classmethod + def tearDownClass(cls) -> None: + call_command("index_manuscript_mei", "123723", "--flush-index") + super().tearDownClass() + def test_index_manuscript_mei(self) -> None: # Assert that prior to the command run, the folio "999r" does not # exist in the database @@ -123,3 +128,8 @@ def tearDown(self) -> None: os.rmdir("/test-mei-dir/123723") os.rmdir("/test-mei-dir") os.rmdir("/empty-mei-dir") + + @classmethod + def tearDownClass(cls) -> None: + call_command("index_manuscript_mei", "123723", "--flush-index") + super().tearDownClass() diff --git a/app/public/cantusdata/test/core/views/test_search_notation_view.py b/app/public/cantusdata/test/core/views/test_search_notation_view.py index 8bf8762d..c2b02616 100644 --- a/app/public/cantusdata/test/core/views/test_search_notation_view.py +++ b/app/public/cantusdata/test/core/views/test_search_notation_view.py @@ -1,12 +1,11 @@ from rest_framework.test import APITestCase from django.core.management import call_command from django.urls import reverse +from django.conf import settings from cantusdata.views.search_notation import SearchNotationView, NotationSearchException from cantusdata.models import Manuscript, Folio -TEST_MEI_FILES_PATH = "cantusdata/test/core/helpers/mei_processing/test_mei_files" - class TestSearchNotationView(APITestCase): search_notation_view = SearchNotationView() @@ -33,7 +32,8 @@ def setUpTestData(cls) -> None: image_uri="test_001r.jpg", ) - def setUp(self) -> None: + @classmethod + def setUpClass(cls) -> None: call_command( "index_manuscript_mei", "123723", @@ -42,8 +42,9 @@ def setUp(self) -> None: "--max-ngram", "5", "--mei-dir", - TEST_MEI_FILES_PATH, + settings.TEST_MEI_FILES_PATH, ) + super().setUpClass() def test_create_query_string(self) -> None: with self.subTest("Test invalid query"): @@ -163,5 +164,7 @@ def test_get(self) -> None: self.assertIn("results", response_data) self.assertIn("numFound", response_data) - def tearDown(self) -> None: + @classmethod + def tearDownClass(cls) -> None: call_command("index_manuscript_mei", "123723", "--flush-index") + super().tearDownClass()