Skip to content

Commit

Permalink
Merge pull request #1007 from nationalarchives/fix/missing-metadata-i…
Browse files Browse the repository at this point in the history
…n-judgment-list

Fix for missing metadata in list of unpublished judgments
  • Loading branch information
jacksonj04 authored Jun 27, 2023
2 parents 9774929 + 79fefbf commit 6f8748c
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 16 deletions.
32 changes: 16 additions & 16 deletions ds_caselaw_editor_ui/templates/includes/judgments_list_item.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
<ul class="judgments-list__judgment-details-meta">
<li class="judgments-list__judgment-details-submitted-mobile">
<span class="judgments-list__judgment-details-meta-key">{% translate "judgments.submission_datetime" %}</span>
<span class="judgments-list__judgment-details-meta-value">{{ item.meta.submission_datetime }}</span>
<span class="judgments-list__judgment-details-meta-value">{{ item.metadata.submission_datetime }}</span>
</li>
<li>
<span class="judgments-list__judgment-details-meta-key">{% translate "judgments.consignmentref" %}</span>
<span class="judgments-list__judgment-details-meta-value">{{ item.meta.consignment_reference }}</span>
<span class="judgments-list__judgment-details-meta-value">{{ item.metadata.consignment_reference }}</span>
</li>
<li>
<span class="judgments-list__judgment-details-meta-key">{% translate "judgments.ncn" %}</span>
Expand All @@ -29,7 +29,7 @@
</li>
<li>
<span class="judgments-list__judgment-details-meta-key">{% translate "judgments.submitter" %}</span>
<span class="judgments-list__judgment-details-meta-value">{{ item.meta.author }}</span>
<span class="judgments-list__judgment-details-meta-value">{{ item.metadata.author }}</span>
</li>
<li>
<span class="judgments-list__judgment-details-meta-key">{% translate "judgments.editor_priority" %}</span>
Expand All @@ -39,15 +39,15 @@
<input type="hidden" name="judgment_uri" value="{{ item.uri }}" />
<select name="priority" id="editor_priority">
<option value="low"
{% if item.meta.editor_priority == "10" %}selected{% endif %}>
{% if item.metadata.editor_priority == "10" %}selected{% endif %}>
Low
</option>
<option value="medium"
{% if item.meta.editor_priority == "20" %}selected{% endif %}>
{% if item.metadata.editor_priority == "20" %}selected{% endif %}>
Medium
</option>
<option value="high"
{% if item.meta.editor_priority == "30" %}selected{% endif %}>
{% if item.metadata.editor_priority == "30" %}selected{% endif %}>
High
</option>
</select>
Expand All @@ -58,24 +58,24 @@
<li>
<span class="judgments-list__judgment-details-meta-key">{% translate "judgments.editor_status" %}</span>
<span class="judgments-list__judgment-details-meta-value">
{{ item.meta.editor_status }}
{% if item.meta.assigned_to %}
<form action="{% if item.meta.editor_hold == 'true' %}{% url 'unhold' %}{% else %}{% url 'hold' %}{% endif %}"
{{ item.metadata.editor_status }}
{% if item.metadata.assigned_to %}
<form action="{% if item.metadata.editor_hold == 'true' %}{% url 'unhold' %}{% else %}{% url 'hold' %}{% endif %}"
method="post">
{% csrf_token %}
<input type="hidden" name="judgment_uri" value="{{ item.uri }}" />
<input type="submit"
name="submit"
value="{% if item.meta.editor_hold == 'true' %}Release{% else %}Hold{% endif %} judgment"/>
value="{% if item.metadata.editor_hold == 'true' %}Release{% else %}Hold{% endif %} judgment"/>
</form>
{% endif %}
</span>
</li>
<li class="judgments-list__judgment-details-assigned-mobile">
<span class="judgments-list__judgment-details-meta-key">{% translate "judgments.assigned_to" %}</span>
<span class="judgments-list__judgment-details-meta-value">
{% if item.meta.assigned_to %}
<a href="{% url 'edit-judgment' item.uri %}#assigned_to">{{ item.meta.assigned_to }}</a>
{% if item.metadata.assigned_to %}
<a href="{% url 'edit-judgment' item.uri %}#assigned_to">{{ item.metadata.assigned_to }}</a>
{% else %}
<form action="{% url "assign" %}"
method="post"
Expand All @@ -93,13 +93,13 @@
</ul>
</div>
<div class="judgments-list__judgment-submitted">
{{ item.meta.submission_datetime|date:"d M Y" }}
{{ item.metadata.submission_datetime|date:"d M Y" }}
<br />
{{ item.meta.submission_datetime|time:"h:i a" }}
{{ item.metadata.submission_datetime|time:"h:i a" }}
</div>
<div class="judgments-list__judgment-assigned">
{% if item.meta.assigned_to %}
<a href="{% url 'edit-judgment' item.uri %}#assigned_to">{{ item.meta.assigned_to }}</a>
{% if item.metadata.assigned_to %}
<a href="{% url 'edit-judgment' item.uri %}#assigned_to">{{ item.metadata.assigned_to }}</a>
{% else %}
<form action="{% url "assign" %}"
method="post"
Expand Down
48 changes: 48 additions & 0 deletions judgments/tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import datetime
from typing import Any
from unittest.mock import Mock

import factory
from caselawclient.models.judgments import Judgment
from caselawclient.responses.search_result import SearchResult, SearchResultMetadata
from django.contrib.auth import get_user_model
from typing_extensions import TypeAlias

User = get_user_model()

Expand Down Expand Up @@ -56,3 +59,48 @@ def build(cls, **kwargs) -> Judgment:
setattr(judgment_mock.return_value, map_to, map_from[1])

return judgment_mock()


class SimpleFactory:
# "name_of_attribute": ("name of incoming param", "default value")
PARAMS_MAP: dict[str, Any]

target_class: TypeAlias = object

@classmethod
def build(cls, **kwargs) -> target_class:
mock_object = Mock(spec=cls.target_class, autospec=True)

for param, default in cls.PARAMS_MAP.items():
if param in kwargs:
setattr(mock_object.return_value, param, kwargs[param])
else:
setattr(mock_object.return_value, param, default)

return mock_object()


class SearchResultMetadataFactory(SimpleFactory):
target_class = SearchResultMetadata
# "name_of_attribute": ("name of incoming param", "default value")
PARAMS_MAP = {
"author": factory.Faker("name"),
"author_email": factory.Faker("email"),
"consignment_reference": "TDR-2023-ABC",
"submission_datetime": datetime.datetime(2023, 2, 3, 9, 12, 34),
}


class SearchResultFactory(SimpleFactory):
target_class = SearchResult

# "name_of_attribute": ("name of incoming param", "default value")
PARAMS_MAP = {
"uri": "test/2023/123",
"name": "Judgment v Judgement",
"neutral_citation": "[2023] Test 123",
"court": "Court of Testing",
"date": datetime.date(2023, 2, 3),
"metadata": SearchResultMetadataFactory.build(),
"is_failure": False,
}
77 changes: 77 additions & 0 deletions judgments/tests/test_judgment_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import re
from unittest.mock import patch

from django.contrib.auth.models import User
from django.test import TestCase
from django.urls import reverse
from django.utils.translation import gettext
from factories import SearchResultFactory, SearchResultMetadataFactory


def assert_match(regex, string):
assert re.search(regex, string) is not None


class TestJudgmentView(TestCase):
@patch("judgments.utils.view_helpers.search_judgments_and_parse_response")
def test_judgment_list_smoketest(self, mock_search_results):
mock_search_results.return_value.results = []
mock_search_results.return_value.total = 0

self.client.force_login(User.objects.get_or_create(username="testuser")[0])

response = self.client.get(reverse("home"))

assert response.status_code == 200

@patch("judgments.utils.view_helpers.search_judgments_and_parse_response")
def test_judgment_list_total_count(self, mock_search_results):
mock_search_results.return_value.results = [
SearchResultFactory.build(),
SearchResultFactory.build(),
]
mock_search_results.return_value.total = 2

self.client.force_login(User.objects.get_or_create(username="testuser")[0])

response = self.client.get(reverse("home"))

decoded_response = response.content.decode("utf-8")

assert "{}: 2".format(gettext("home.recent")) in decoded_response

@patch("judgments.utils.view_helpers.search_judgments_and_parse_response")
def test_judgment_list_items(self, mock_search_results):
mock_search_results.return_value.results = [
SearchResultFactory.build(
uri="test/2023/123",
name="Test Judgment 1",
metadata=SearchResultMetadataFactory.build(
author="Author One",
consignment_reference="TDR-2023-AB1",
),
),
SearchResultFactory.build(
uri="test/2023/456",
name="Test Judgment 2",
metadata=SearchResultMetadataFactory.build(
author="Author Two",
consignment_reference="TDR-2023-CD2",
),
),
]
mock_search_results.return_value.total = 2

self.client.force_login(User.objects.get_or_create(username="testuser")[0])

response = self.client.get(reverse("home"))

decoded_response = response.content.decode("utf-8")

assert "Test Judgment 1" in decoded_response
assert "Author One" in decoded_response
assert "TDR-2023-AB1" in decoded_response

assert "Test Judgment 2" in decoded_response
assert "Author Two" in decoded_response
assert "TDR-2023-CD2" in decoded_response

0 comments on commit 6f8748c

Please sign in to comment.