Skip to content

Commit

Permalink
refactor: modify data setup and test mei files setting
Browse files Browse the repository at this point in the history
Moves the TEST_MEI_FILES_PATH setting to settings.py rather than
setting it separately for each test.

Makes some changes to test set-up and break-down to remove the need to index
MEI before each test.
  • Loading branch information
dchiller committed Sep 23, 2024
1 parent ac06363 commit 9835c88
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
2 changes: 2 additions & 0 deletions app/public/cantusdata/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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()
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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",
Expand All @@ -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"):
Expand Down Expand Up @@ -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()

0 comments on commit 9835c88

Please sign in to comment.