def test_no_shared_resources( self, mockiifpres, client, document, source, fragment, join ): # a list object initialized once in iiif_utils.base_annotation_list # was getting reused, resulting in annotations being aggregated # and kept every time annotation lists were generated # test to confirm the fix # remove iiif url from fragment fixture fragment.iiif_url = "" fragment.save() # add a footnote with transcription content to document Footnote.objects.create( content_object=document, source=source, content={"html": "here is my transcription text"}, doc_relation=Footnote.EDITION, ) # and another to the join document Footnote.objects.create( content_object=join, source=source, content={"html": "here is completely different transcription text"}, doc_relation=Footnote.EDITION, ) # request once for document client.get(reverse(self.view_name, args=[document.pk])) # then request for join doc response = client.get(reverse(self.view_name, args=[join.pk])) assertNotContains(response, "here is my transcription text") assertContains(response, "completely different transcription text")
def test_speakers_list_gone(client): response = client.get("/people/speakers/") assert response.status_code == 410 assertContains(response, "410", status_code=410) assertContains(response, "That page isn't here anymore.", status_code=410) assertNotContains(response, "404", status_code=410) assertNotContains(response, "can't seem to find", status_code=410)
def test_source_title(self, client, document, twoauthor_source): """Document scholarship template should show source titles if present""" Footnote.objects.create(content_object=document, source=twoauthor_source) response = client.get( reverse("corpus:document-scholarship", args=[document.pk])) assertContains(response, "<em>The C Programming Language</em>") twoauthor_source.title = "" twoauthor_source.save() response = client.get( reverse("corpus:document-scholarship", args=[document.pk])) assertNotContains(response, "<em>The C Programming Language</em>")
def test_blog_list_contains_2(rf): assert Post.objects.count() == 0 post1 = PostFactory(category=Post.Category.GENERAL) post2 = PostFactory(category=Post.Category.GENERAL) post3 = PostFactory(category=Post.Category.TECH) assert Post.objects.count() == 3 request = rf.get(reverse('blog:list')) response = PostListView.as_view()(request) assertContains(response, post1.title) assertContains(response, post2.title) assertNotContains(response, post3.title)
def test_no_edit_event_button_anonymous_user(client, base_event): """If the user is logged in, the edit-event button should appear. (note this will fail once we establish roles only users who can edit should be able to see the vent button). """ url = reverse("stocking:stocking-event-detail", kwargs={"stock_id": base_event.stock_id}) response = client.get(url) edit_url = reverse("stocking:edit-stocking-event", kwargs={"stock_id": base_event.stock_id}) assertNotContains(response, edit_url, html=True)
def test_no_cwt_panel_without_cwts_appears(client, base_event): """If the stocking event does not have any cwts, the additional html elements should not be incuded in the response. """ url = reverse("stocking:stocking-event-detail", kwargs={"stock_id": base_event.stock_id}) response = client.get(url) not_expected = "<h5>Coded Wire Tags</h5>" assertNotContains(response, not_expected, html=True)
def test_cwt_list_filters(client, reused_cwt_stocking_events, filter, expected, excluded, prefetch): """Verify that the the cwt sequence filters behave as expected. This test is parmeterized to accept a series of four element tuples - the filter to be applied, the excepted list of cwts numbers, a list of cwt numbers that should not be returned, and an optional string specifying a prefetch_related to pass to the queryset. Several of the cwts in the supplied fixture have been re-used. These tests verify that filters applied to events with re-used tags, returns the correct events using the stock_id and (not other events that used the same cwt tag number but do not meet the filtered criteria). """ url = reverse("stocking:cwt-list") response = client.get(url, filter) assert response.status_code == 200 # ensure that the filter buttons are added as well as links to the cwt # detail page for each of the expected cwt should be in the # response. # skip the buttons if the filters are both 'first_year' and 'last_year' # the urls are more complicated than we are testing here: if not set(filter.keys()) == {"first_year", "last_year"}: button_html = ( '<a href="/stocking/cwts/" class="mini ui icon {2} button">' '{0} = {1}<i class="times icon"></i></a>') # we need to fill the html with the correct colour, key, and value: for key, val in filter.items(): colour = filter_colour(key) html = button_html.format(key, val, colour) assertContains(response, html, html=True) html = '<tr id="{}">' # verify that the correct stock ID numbers are returned - can't # use cwt because they are confounded if cwts are re-used. for value in expected: assertContains(response, html.format(value)) for value in excluded: assertNotContains(response, html.format(value))
def test_download_transcription_link_anonymous(self, client, document, typed_texts): edition = Footnote.objects.create( content_object=document, source=typed_texts, doc_relation=Footnote.EDITION, content={ "html": "some transcription text", "text": "some transcription text", }, ) response = client.get(document.get_absolute_url()) # typed text fixture authored by Goitein # should not be available to anonymous users (suppressed for now) assertNotContains(response, "Download Goitein's edition")