Skip to content

Commit

Permalink
Add tests for Project.display_tags
Browse files Browse the repository at this point in the history
Also, fix the various failures up the tree which prevented these new tests from
passing
  • Loading branch information
haydngreatnews committed Jul 22, 2024
1 parent 5c2c5ae commit 39fe271
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 7 deletions.
2 changes: 2 additions & 0 deletions cdhweb/pages/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from wagtail.models import Page, Site
from wagtail_factories import ImageFactory

from cdhweb.pages.models import ContentPage, ExternalAttachment, HomePage, LandingPage
from cdhweb.pages.views import LastModifiedListMixin, LastModifiedMixin
Expand All @@ -34,6 +35,7 @@ def make_homepage(site):
body=json.dumps(
[{"type": "paragraph", "value": "<p>content of the home page</p>"}]
),
hero_image=ImageFactory(),
)
root.add_child(instance=home)
root.save()
Expand Down
10 changes: 10 additions & 0 deletions cdhweb/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,16 @@ def get_sitemap_urls(self, request):
return urls

def display_tags(self):
"""
Get role, method and field values as tag-y objects
The method/field/role fields are used for filtering
the projects in the search, but CDH have also
requested that they be shown the same way tags are
for many other types of object -- This function
delivers them in a (template-equivalent) manner so
they can be displayed
"""
return sorted(
str(t)
for t in itertools.chain(
Expand Down
5 changes: 2 additions & 3 deletions cdhweb/projects/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest
from django.utils import timezone
from wagtail_factories import ImageFactory

from cdhweb.people.models import Person
from cdhweb.projects.models import (
Expand Down Expand Up @@ -34,9 +35,7 @@ def add_project_member(project, role, start_date=None, end_date=None, **person_o

def make_projects_landing_page(homepage):
"""create a test projects landing page underneath the homepage"""
plp = ProjectsLandingPageArchived(
title="projects", slug="projects", tagline="let's do some stuff"
)
plp = ProjectsLandingPageArchived(title="projects", slug="projects")
homepage.add_child(instance=plp)
homepage.save()
return plp
Expand Down
42 changes: 41 additions & 1 deletion cdhweb/projects/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
from datetime import datetime, timedelta

from cdhweb.pages.models import RelatedLinkType
from cdhweb.projects.models import GrantType, Project, ProjectRelatedLink, Role
from cdhweb.projects.models import (
GrantType,
Project,
ProjectField,
ProjectMethod,
ProjectRelatedLink,
ProjectRole,
Role,
)


class TestGrantType:
Expand Down Expand Up @@ -140,3 +148,35 @@ def test_display_url(self, derrida):
# https
res.url = "https://%s" % base_url
assert res.display_url == base_url


class TestProjectDisplayTags:
def test_no_values(self, derrida):
assert derrida.display_tags() == []

def test_just_role(self, derrida):
role = ProjectRole(role="test role")
role.save()
derrida.role.add(role)
assert derrida.display_tags() == ["test role"]

def test_all_relations(self, derrida):
role1 = ProjectRole(role="test role 1")
role2 = ProjectRole(role="test role 2")
method = ProjectMethod(method="test method")
field = ProjectField(field="test field")
role1.save()
role2.save()
method.save()
field.save()

derrida.role.add(role1)
derrida.role.add(role2)
derrida.method.add(method)
derrida.field.add(field)
assert derrida.display_tags() == [
"test field",
"test method",
"test role 1",
"test role 2",
]
3 changes: 1 addition & 2 deletions docker/application/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ RUN --mount=type=cache,target=/var/lib/apt/lists \
netcat

RUN --mount=type=cache,target=/root/.cache/pip \
pip3 install -r /app/requirements/dev.txt \
npm install
pip3 install -r /app/requirements/dev.txt

# No COPY here as the local directory is volume-mounted in docker-compose

Expand Down
3 changes: 2 additions & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ wheel
# fix issue with taggit fields: https://github.com/makecodes/django-dbml/pull/4
django-dbml
#git+https://github.com/thatbudakguy/django-dbml@patch-1#egg=django-dbml
percy-selenium
percy-selenium
wagtail-factories~=4.2.1

0 comments on commit 39fe271

Please sign in to comment.