Skip to content

Commit

Permalink
Clean up old code and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rlskoeser committed Sep 6, 2024
1 parent b41caf1 commit 7d410d0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 262 deletions.
26 changes: 8 additions & 18 deletions cdhweb/blog/tests/test_pages.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
import pytest
from wagtail.test.utils import WagtailPageTestCase

from cdhweb.blog.models import BlogLinkPageArchived, BlogPost
from cdhweb.blog.models import BlogLandingPage, BlogLinkPageArchived, BlogPost


class TestBlogPost:
def test_short_title(self, article):
"""blog post should truncate title to 65char with ellipsis"""
# article fixture has a long title
assert (
article.short_title
== "We wrote an article together, and it got published on the CDH we…"
)

def test_short_description(self, article):
"""blog post should truncate description to 250char with ellipsis"""
# article fixture has a long description
assert article.short_description == (
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do "
"eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut "
"enim ad minim veniam, quis nostrud exercitation ullamco laboris "
"nisi ut aliquip ex ea commodo con…"
)
assert article.short_title == "We wrote an article together for the CDH website"

def test_author_list(self, article, staffer, postdoc):
"""blog post should list author names in order"""
Expand All @@ -38,12 +25,13 @@ def test_author_list(self, article, staffer, postdoc):
assert article.authors.all()[1].person == staffer

def test_str(self, article):
"""blog post should display as title + formatted date"""
"""blog post should display as title"""
assert (
str(article)
== '"We wrote an article together, and it got published on the CDH we…" (March 4, 2019)'
== "We wrote an article together, and it got published on the CDH website"
)

@pytest.mark.skip("updated logic; test get_url_parts?")
def test_get_url(self, article):
"""blog post should be accessed via custom url with y/m/d info"""
# should pad with zeroes and include year, month, day, slug
Expand All @@ -70,7 +58,9 @@ def test_subpage_types(self):

def test_parent_page_types(self):
"""blog posts always go under the blog link page"""
self.assertAllowedParentPageTypes(BlogPost, [BlogLinkPageArchived])
self.assertAllowedParentPageTypes(
BlogPost, [BlogLinkPageArchived, BlogLandingPage]
)


class TestBlogLinkPageArchived(WagtailPageTestCase):
Expand Down
69 changes: 5 additions & 64 deletions cdhweb/projects/tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,8 @@ def test_website_url(self, client, derrida):
project=derrida, type=website, url="https://derridas-margins.princeton.edu"
)

# should display "Project Website" as well as full URL inside link
response = client.get(derrida.get_url())
assertContains(response, '<a href="%s">' % derrida_site.url)
assertContains(response, "<span>Project Website</span>", html=True)
assertContains(
response,
'<span class="url">%s</span>' % derrida_site.display_url,
html=True,
)

def test_contributors(self, client, derrida):
"""project detail page should display current project team and alums"""
Expand All @@ -66,11 +59,12 @@ def test_grants(self, client, derrida):
dcg = derrida.grants.get(grant_type__grant_type="Dataset Curation")
rpg = derrida.grants.get(grant_type__grant_type="Research Partnership")

# should display with years
# should display label and years
response = client.get(derrida.get_url())
assertContains(response, "CDH Grant History")
assertContains(response, "%s Dataset Curation" % dcg.years)
assertContains(response, "%s Research Partnership" % rpg.years)
assertContains(response, "Dataset Curation")
assertContains(response, dcg.years)
assertContains(response, "Research Partnership")
assertContains(response, rpg.years)

def test_long_description(self, client, derrida):
"""project detail page should display long description (body) if set"""
Expand All @@ -81,56 +75,3 @@ def test_long_description(self, client, derrida):
# should display with rich text
response = client.get(derrida.get_url())
assertContains(response, "<b>About Derrida</b>", html=True)


class TestProjectLists:
def test_page_titles(self, client, projects):
"""project list pages should show title and past title as headings"""
# sponsored projects (none currently past)
response = client.get(reverse("projects:sponsored"))
assertContains(response, "<h1>Sponsored Projects</h1>")
assertNotContains(response, "<h2>Past Projects</h2>")

# staff & postdoc projects (none currently past)
response = client.get(reverse("projects:staff"))
assertContains(response, "<h1>Staff Projects</h1>")
assertNotContains(response, "<h2>Past Projects</h2>")

# working groups (no past shown)
response = client.get(reverse("projects:working-groups"))
assertContains(response, "<h1>DH Working Groups</h1>")
assertNotContains(response, "<h2>Past Projects</h2>")

# make all projects past: delete all grants except latest; end yesterday
for _, project in projects.items():
grant = project.latest_grant()
project.grants.exclude(pk=grant.pk).delete()
grant.end_date = date.today() - timedelta(days=1)
grant.save()

# sponsored projects, past section should display
response = client.get(reverse("projects:sponsored"))
assertContains(response, "<h2>Past Projects</h2>")

# staff & postdoc projects, past section should display
response = client.get(reverse("projects:staff"))
assertContains(response, "<h2>Past Projects</h2>")

# working groups should never be past, even if grant is
response = client.get(reverse("projects:working-groups"))
assertNotContains(response, "<h2>Past Projects</h2>")

def test_project_card(self, client, projects):
"""project list pages should display cards for each project"""
# one project card for each staff/postdoc project
response = client.get(reverse("projects:staff"))
assertTemplateUsed("projects/snippets/project_card.html")
assertContains(response, '<div class="card project', count=2)

# card contains link to project page, title, and short description
assertContains(response, '<a href="%s">' % projects["pliny"].get_url())
assertContains(response, '<a href="%s">' % projects["ocampo"].get_url())
assertContains(response, "<h2>%s</h2>" % projects["pliny"].title)
assertContains(response, "<h2>%s</h2>" % projects["ocampo"].title)
assertContains(response, "<p>%s</p>" % projects["pliny"].short_description)
assertContains(response, "<p>%s</p>" % projects["ocampo"].short_description)
82 changes: 0 additions & 82 deletions cdhweb/projects/tests/test_views.py

This file was deleted.

12 changes: 0 additions & 12 deletions cdhweb/projects/urls.py

This file was deleted.

86 changes: 0 additions & 86 deletions cdhweb/projects/views.py

This file was deleted.

0 comments on commit 7d410d0

Please sign in to comment.