コード例 #1
0
 def test_attachments(self, client, content_page, attachment):
     """content page should display attachments if present"""
     # no attachments, shouldn't render template
     response = client.get(content_page.get_url())
     assertTemplateNotUsed(response, "snippets/attachments.html")
     # add an attachment, should render template + info
     content_page.attachments = [("link", attachment)]
     content_page.save()
     response = client.get(content_page.get_url())
     assertTemplateUsed(response, "snippets/attachments.html")
コード例 #2
0
def test_event_edit_button_not_rended_for_anon_user(client, stocking_events):
    """
    The edit stocking event form should not be accessible to regular
        agency users, if the do try to access the url, the will be
        redirected to the login page.

    """

    for event in stocking_events:
        url = reverse("stocking:edit-stocking-event",
                      kwargs={"stock_id": event.stock_id})
        response = client.get(url, follow=True)
        assertTemplateNotUsed(response, "stocking/stocking_event_form.html")
        assertTemplateUsed(response, "registration/login.html")
        content = str(response.content)
        assert "Edit Stocking Event {}".format(event.stock_id) not in content
コード例 #3
0
def test_event_edit_button_not_rended_for_agency_user(client, huron_mdnr_user,
                                                      stocking_events):
    """The edit stocking event form should not be accessible to regular
    agency users, if the do try to access the url, the will be
    redirected to the detail page for that stocking event.

    """

    login = client.login(email=huron_mdnr_user.email, password="******")
    assert login is True

    for event in stocking_events:
        url = reverse("stocking:edit-stocking-event",
                      kwargs={"stock_id": event.stock_id})
        response = client.get(url, follow=True)
        assertTemplateNotUsed(response, "stocking/stocking_event_form.html")
        assertTemplateUsed(response, "stocking/stocking_detail.html")
        content = str(response.content)
        assert "Edit Stocking Event {}".format(event.stock_id) not in content
コード例 #4
0
def test_edit_stocking_event_form_not_accessible_for_agency_coordinators(
        client, huron_mdnr_sc, stocking_events):
    """An agency stocking coordinator NOT should be able to access the
    edit form for a stocking events conducted by other their agencies
    or in lakes they are not responsible for.

    """

    login = client.login(email=huron_mdnr_sc.email, password="******")
    assert login is True
    # event[0] is ours, events[1-3] belong to someone else.
    for event in stocking_events[1:]:
        url = reverse("stocking:edit-stocking-event",
                      kwargs={"stock_id": event.stock_id})
        response = client.get(url, follow=True)
        assertTemplateNotUsed(response, "stocking/stocking_event_form.html")
        assertTemplateUsed(response, "stocking/stocking_detail.html")
        content = str(response.content)
        assert "Edit Stocking Event {}".format(event.stock_id) not in content
コード例 #5
0
 def test_empty_featured_pages(self, client, site, homepage):
     """homepage should not render featured pages if missing or unpublished"""
     # no about or consult page: nothing rendered
     response = client.get(homepage.relative_url(site))
     assertTemplateNotUsed(response, "cdhpages/snippets/featured_pages.html")
     # only about page: nothing rendered
     about = ContentPage(title="about", slug="about", body="")
     homepage.add_child(instance=about)
     homepage.save()
     response = client.get(homepage.relative_url(site))
     assertTemplateNotUsed(response, "cdhpages/snippets/featured_pages.html")
     # only consults page is live: nothing rendered
     about.unpublish()
     consult = ContentPage(title="consult", slug="consult")
     homepage.add_child(instance=consult)
     homepage.save()
     response = client.get(homepage.relative_url(site))
     assertTemplateNotUsed(response, "cdhpages/snippets/featured_pages.html")
     # both pages live; should render
     about.save_revision().publish()
     response = client.get(homepage.relative_url(site))
     assertTemplateUsed(response, "cdhpages/snippets/featured_pages.html")
コード例 #6
0
 def test_empty_events(self, client, site, homepage):
     """homepage should display message when no events are available"""
     response = client.get(homepage.relative_url(site))
     assertTemplateNotUsed(response, "events/snippets/event_card.html")
     assertContains(response, "Next semester's events are being scheduled.")
コード例 #7
0
 def test_empty_projects(self, client, site, homepage):
     """homepage should not render projects if none exist"""
     response = client.get(homepage.relative_url(site))
     assertTemplateNotUsed(response, "projects/snippets/project_card.html")
コード例 #8
0
 def test_empty_posts(self, client, site, homepage):
     """homepage should not render carousel if no blog posts exist"""
     response = client.get(homepage.relative_url(site))
     assertTemplateNotUsed(response, "snippets/carousel.html")