Skip to content

Commit

Permalink
refactor(tests): fix lint errors in test_chant.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dchiller committed Oct 3, 2024
1 parent d10152e commit 34c130f
Showing 1 changed file with 33 additions and 29 deletions.
62 changes: 33 additions & 29 deletions django/cantusdb_project/main_app/tests/test_views/test_chant.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,11 @@ def test_chant_edit_link(self):
)

# have to create project manager user - "View | Edit" toggle only visible for those with edit access for a chant's source
self.user = get_user_model().objects.create(email="[email protected]")
self.user.set_password("pass")
self.user.save()
self.client = Client()
pm_user = get_user_model().objects.create(email="[email protected]")
pm_user.set_password("pass")
pm_user.save()
project_manager = Group.objects.get(name="project manager")
project_manager.user_set.add(self.user)
project_manager.user_set.add(pm_user)
self.client.login(email="[email protected]", password="pass")

response = self.client.get(reverse("chant-detail", args=[chant.id]))
Expand Down Expand Up @@ -502,7 +501,8 @@ def test_filter_by_melody(self):
source=source,
volpiano=make_fake_volpiano(),
)
chant_without_melody = Chant.objects.create(source=source)
# Create a chant without a melody
Chant.objects.create(source=source)
response = self.client.get(reverse("chant-search"), {"melodies": "true"})
# only chants with melodies should be in the result
self.assertEqual(len(response.context["chants"]), 1)
Expand Down Expand Up @@ -554,9 +554,11 @@ def test_search_bar_search(self):
manuscript_full_text="Full text contains, but does not start with 'the'",
cantus_id="123456",
)
chant_starting_with_a_number = make_fake_chant(
# Create a chant starting with a number that won't be found by either
# search term
make_fake_chant(
manuscript_full_text=(
"1 is a number. " "How unusual, to find an arabic numeral in a chant!"
"1 is a number. How unusual, to find an arabic numeral in a chant!"
),
cantus_id="234567",
)
Expand Down Expand Up @@ -1371,7 +1373,7 @@ def test_column_header_links(self):
# additional properties for which there are search fields
feast = make_fake_feast()
position = make_random_string(1)
chant = make_fake_chant(
make_fake_chant(
manuscript_full_text_std_spelling=fulltext,
service=service,
genre=genre,
Expand Down Expand Up @@ -1528,7 +1530,7 @@ def test_feast_column(self):
url = feast.get_absolute_url()
fulltext = "manuscript full text"
search_term = "full"
chant = make_fake_chant(
make_fake_chant(
source=source,
manuscript_full_text_std_spelling=fulltext,
feast=feast,
Expand All @@ -1552,7 +1554,7 @@ def test_service_column(self):
url = service.get_absolute_url()
fulltext = "manuscript full text"
search_term = "full"
chant = make_fake_chant(
make_fake_chant(
source=source,
manuscript_full_text_std_spelling=fulltext,
service=service,
Expand All @@ -1576,7 +1578,7 @@ def test_genre_column(self):
url = genre.get_absolute_url()
fulltext = "manuscript full text"
search_term = "full"
chant = make_fake_chant(
make_fake_chant(
source=source,
manuscript_full_text_std_spelling=fulltext,
genre=genre,
Expand Down Expand Up @@ -1819,7 +1821,8 @@ def test_filter_by_melody(self):
source=source,
volpiano=make_fake_volpiano,
)
chant_without_melody = Chant.objects.create(source=source)
# Create a chant without melody that won't be in the result
Chant.objects.create(source=source)
response = self.client.get(
reverse("chant-search-ms", args=[source.id]), {"melodies": "true"}
)
Expand All @@ -1837,11 +1840,11 @@ def test_keyword_search_starts_with(self):
source=source,
manuscript_full_text_std_spelling="quick brown fox jumps over the lazy dog",
)
chant_2 = make_fake_chant(
make_fake_chant(
source=source,
manuscript_full_text_std_spelling="brown fox jumps over the lazy dog",
)
chant_3 = make_fake_chant(
make_fake_chant(
source=source,
manuscript_full_text_std_spelling="lazy brown fox jumps quick over the dog",
)
Expand All @@ -1860,7 +1863,8 @@ def test_keyword_search_contains(self):
source=source,
manuscript_full_text_std_spelling="Quick brown fox jumps over the lazy dog",
)
chant_2 = make_fake_chant(
# Make a chant that won't be returned by the search term
make_fake_chant(
source=source,
manuscript_full_text_std_spelling="brown fox jumps over the lazy dog",
)
Expand All @@ -1886,11 +1890,11 @@ def test_indexing_notes_search_starts_with(self):
source=source,
indexing_notes="quick brown fox jumps over the lazy dog",
)
chant_2 = make_fake_chant(
make_fake_chant(
source=source,
indexing_notes="brown fox jumps over the lazy dog",
)
chant_3 = make_fake_chant(
make_fake_chant(
source=source,
indexing_notes="lazy brown fox jumps quick over the dog",
)
Expand All @@ -1909,7 +1913,8 @@ def test_indexing_notes_search_contains(self):
source=source,
indexing_notes="Quick brown fox jumps over the lazy dog",
)
chant_2 = make_fake_chant(
# Make a chant that won't be returned by the search term
make_fake_chant(
source=source,
indexing_notes="brown fox jumps over the lazy dog",
)
Expand All @@ -1932,13 +1937,13 @@ def test_keyword_search_searching_all_fields(self):
doesnt_include_search_term = "longevity is the soul of wit"
source = make_fake_source()

chant_ms_spelling = make_fake_chant(
make_fake_chant(
source=source,
manuscript_full_text=includes_search_term, # <== includes_search_term
manuscript_full_text_std_spelling=doesnt_include_search_term,
)

chant_std_spelling = make_fake_chant(
make_fake_chant(
source=source,
manuscript_full_text=doesnt_include_search_term,
manuscript_full_text_std_spelling=includes_search_term, # <==
Expand All @@ -1955,7 +1960,8 @@ def test_keyword_search_searching_all_fields(self):
manuscript_full_text_std_spelling=None,
)

chant_without_search_term = make_fake_chant(
# This chant contains no search terms
make_fake_chant(
source=source,
manuscript_full_text=doesnt_include_search_term,
manuscript_full_text_std_spelling=doesnt_include_search_term,
Expand Down Expand Up @@ -2344,7 +2350,7 @@ def test_column_header_links(self):
# additional properties for which there are search fields
feast = make_fake_feast()
position = make_random_string(1)
chant = make_fake_chant(
make_fake_chant(
service=service,
genre=genre,
cantus_id=cantus_id,
Expand Down Expand Up @@ -2450,9 +2456,7 @@ def test_source_link_column(self):
url = source.get_absolute_url()
fulltext = "manuscript full text"
search_term = "full"
chant = make_fake_chant(
source=source, manuscript_full_text_std_spelling=fulltext
)
make_fake_chant(source=source, manuscript_full_text_std_spelling=fulltext)
response = self.client.get(
reverse("chant-search-ms", args=[source.id]),
{"keyword": search_term, "op": "contains"},
Expand Down Expand Up @@ -2488,7 +2492,7 @@ def test_feast_column(self):
url = feast.get_absolute_url()
fulltext = "manuscript full text"
search_term = "full"
chant = make_fake_chant(
make_fake_chant(
source=source,
manuscript_full_text_std_spelling=fulltext,
feast=feast,
Expand All @@ -2513,7 +2517,7 @@ def test_service_column(self):
url = service.get_absolute_url()
fulltext = "manuscript full text"
search_term = "full"
chant = make_fake_chant(
make_fake_chant(
source=source,
manuscript_full_text_std_spelling=fulltext,
service=service,
Expand All @@ -2538,7 +2542,7 @@ def test_genre_column(self):
url = genre.get_absolute_url()
fulltext = "manuscript full text"
search_term = "full"
chant = make_fake_chant(
make_fake_chant(
source=source,
manuscript_full_text_std_spelling=fulltext,
genre=genre,
Expand Down

0 comments on commit 34c130f

Please sign in to comment.