-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(source/chant detail): add JSONResponseMixin
- Loading branch information
Showing
5 changed files
with
92 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,25 +29,31 @@ | |
from main_app.tests.test_functions import mock_requests_get | ||
from main_app.models import Chant, Source, Feast, Service | ||
from main_app.views.chant import get_feast_selector_options | ||
from users.models import User as UserAnnotation | ||
|
||
|
||
# Create a Faker instance with locale set to Latin | ||
faker = Faker("la") | ||
|
||
|
||
class ChantDetailViewTest(TestCase): | ||
pm_group: ClassVar[Group] | ||
pm_user: ClassVar[UserAnnotation] | ||
|
||
@classmethod | ||
def setUpTestData(cls): | ||
Group.objects.create(name="project manager") | ||
def setUpTestData(cls) -> None: | ||
cls.pm_group = Group.objects.create(name="project manager") | ||
cls.pm_user = get_user_model().objects.create(email="[email protected]") | ||
cls.pm_user.groups.add(cls.pm_group) | ||
|
||
def test_url_and_templates(self): | ||
def test_url_and_templates(self) -> None: | ||
chant = make_fake_chant() | ||
response = self.client.get(reverse("chant-detail", args=[chant.id])) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertTemplateUsed(response, "base.html") | ||
self.assertTemplateUsed(response, "chant_detail.html") | ||
|
||
def test_context_folios(self): | ||
def test_context_folios(self) -> None: | ||
# create a source and several chants in it | ||
source = make_fake_source() | ||
chant = make_fake_chant(source=source, folio="001r") | ||
|
@@ -62,7 +68,7 @@ def test_context_folios(self): | |
folios = response.context["folios"] | ||
self.assertEqual(list(folios), ["001r", "001v", "002r", "002v"]) | ||
|
||
def test_context_previous_and_next_folio(self): | ||
def test_context_previous_and_next_folio(self) -> None: | ||
# create a source and several chants in it | ||
source = make_fake_source() | ||
# three folios: 001r, 001v, 002r | ||
|
@@ -93,7 +99,7 @@ def test_context_previous_and_next_folio(self): | |
self.assertEqual(response.context["previous_folio"], "001v") | ||
self.assertIsNone(response.context["next_folio"]) | ||
|
||
def test_published_vs_unpublished(self): | ||
def test_published_vs_unpublished(self) -> None: | ||
source = make_fake_source() | ||
chant = make_fake_chant(source=source) | ||
|
||
|
@@ -107,21 +113,11 @@ def test_published_vs_unpublished(self): | |
response = self.client.get(reverse("chant-detail", args=[chant.id])) | ||
self.assertEqual(response.status_code, 403) | ||
|
||
def test_chant_edit_link(self): | ||
def test_chant_edit_link(self) -> None: | ||
source = make_fake_source() | ||
chant = make_fake_chant( | ||
source=source, | ||
folio="001r", | ||
manuscript_full_text_std_spelling="manuscript_full_text_std_spelling", | ||
) | ||
chant = make_fake_chant(source=source, folio="001r") | ||
|
||
# have to create project manager user - "View | Edit" toggle only visible for those with edit access for a chant's source | ||
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(pm_user) | ||
self.client.login(email="[email protected]", password="pass") | ||
self.client.force_login(self.pm_user) | ||
|
||
response = self.client.get(reverse("chant-detail", args=[chant.id])) | ||
expected_url_fragment = ( | ||
|
@@ -130,21 +126,23 @@ def test_chant_edit_link(self): | |
|
||
self.assertIn(expected_url_fragment, str(response.content)) | ||
|
||
def test_chant_with_volpiano_with_no_fulltext(self): | ||
# in the past, a Chant Detail page will error rather than loading properly when the chant has volpiano but no fulltext | ||
def test_chant_with_volpiano_with_no_fulltext(self) -> None: | ||
# in the past, a Chant Detail page will error rather than loading | ||
# properly when the chant has volpiano but no fulltext | ||
source = make_fake_source() | ||
chant = make_fake_chant( | ||
source=source, | ||
volpiano="1---c--g--e---e---d---c---c---f---e---e--d---d---c", | ||
manuscript_full_text=None, | ||
manuscript_full_text_std_spelling=None, | ||
) | ||
chant.manuscript_full_text = None | ||
chant.manuscript_full_text_std_spelling = None | ||
chant.save() | ||
|
||
response = self.client.get(reverse("chant-detail", args=[chant.id])) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_chant_with_volpiano_with_no_incipit(self): | ||
# in the past, a Chant Detail page will error rather than loading properly when the chant has volpiano but no fulltext/incipit | ||
def test_chant_with_volpiano_with_no_incipit(self) -> None: | ||
# in the past, a Chant Detail page will error rather than loading properly | ||
# when the chant has volpiano but no fulltext/incipit | ||
source = make_fake_source() | ||
chant = make_fake_chant( | ||
source=source, | ||
|
@@ -157,6 +155,17 @@ def test_chant_with_volpiano_with_no_incipit(self): | |
response = self.client.get(reverse("chant-detail", args=[chant.id])) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_json_response(self) -> None: | ||
chant = make_fake_chant() | ||
response = self.client.get( | ||
reverse("chant-detail", args=[chant.id]), HTTP_ACCEPT="application/json" | ||
) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response["Content-Type"], "application/json") | ||
resp_chant = response.json()["chant"] | ||
self.assertEqual(resp_chant["id"], chant.id) | ||
self.assertEqual(resp_chant["manuscript_full_text"], chant.manuscript_full_text) | ||
|
||
|
||
class SourceEditChantsViewTest(TestCase): | ||
@classmethod | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters