Skip to content

Commit

Permalink
Merge pull request #1519 from nationalarchives/chore/apic-v27
Browse files Browse the repository at this point in the history
[FCL-409] Upgrade Utilities and API Client
  • Loading branch information
jacksonj04 authored Oct 29, 2024
2 parents af04c10 + b6296a3 commit 00d6cbe
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block precontent %}
<div class="judgment-toolbar">
<div class="judgment-toolbar__container">
<h1 class="judgment-toolbar__title">{{ judgement_name }}</h1>
<h1 class="judgment-toolbar__title">{{ judgment_name }}</h1>
<p class="judgment-toolbar__reference">Press Summaries</p>
</div>
</div>
Expand Down
7 changes: 4 additions & 3 deletions judgments/models/document_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

import environ
import requests
from caselawclient.models.documents import DocumentURIString

from judgments.utils import formatted_document_uri


class DocumentPdf:
def __init__(self, document_uri: str):
self.document_uri = document_uri
def __init__(self, document_uri: DocumentURIString):
self.document_uri: DocumentURIString = document_uri

@cached_property
def size(self):
Expand All @@ -29,7 +30,7 @@ def size(self):
return None

@cached_property
def uri(self):
def uri(self) -> str:
return self.generate_uri() if self.size else formatted_document_uri(self.document_uri, "pdf")

def generate_uri(self):
Expand Down
6 changes: 3 additions & 3 deletions judgments/templatetags/document_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

@register.filter
def get_title_to_display_in_html(document: Document) -> str:
if not document.name:
if not document.body.name:
return ""

if document.document_noun == "press summary":
return document.name.removeprefix("Press Summary of ")
return document.body.name.removeprefix("Press Summary of ")

return document.name
return document.body.name


@register.simple_tag
Expand Down
76 changes: 0 additions & 76 deletions judgments/tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,84 +1,8 @@
import datetime
from typing import Any
from unittest.mock import Mock

from caselawclient.models.documents import Document
from caselawclient.models.judgments import Judgment
from caselawclient.models.press_summaries import PressSummary
from factory.django import DjangoModelFactory

from judgments.models import CourtDates


class DocumentFactory:
target_class = Document

# "name_of_attribute": ("name of incoming param", "default value")
PARAMS_MAP: dict[str, Any] = {
"uri": "test/2023/123",
"name": "Judgment v Judgement",
"neutral_citation": "[2023] Test 123",
"court": "Court of Testing",
"judgment_date_as_string": "2023-02-03",
"document_date_as_string": "2023-02-03",
"date": "2023-02-03",
"document_date_as_date": datetime.date.today(),
"is_published": False,
"is_sensitive": False,
"is_anonymised": False,
"has_supplementary_materials": False,
"is_failure": False,
"source_name": "Example Uploader",
"source_email": "[email protected]",
"consignment_reference": "TDR-12345",
"assigned_to": "",
"versions": [],
"document_noun": "document",
}

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

judgment_mock.return_value.content_as_html.return_value = kwargs.pop(
"html",
"<p>This is a judgment in HTML.</p>",
)

judgment_mock.return_value.content_as_xml = kwargs.pop(
"xml",
"""
<?xml version="1.0" encoding="UTF-8"?>
<judgment>
<p>This is a judgment in XML.</p>
</judgment>
""",
)

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

judgment_mock.return_value.best_human_identifier = kwargs.get("neutral_citation") or cls.PARAMS_MAP.get(
"neutral_citation"
)
return judgment_mock()


class JudgmentFactory(DocumentFactory):
target_class = Judgment
PARAMS_MAP = dict(DocumentFactory.PARAMS_MAP)
PARAMS_MAP["document_noun"] = "judgment"


class PressSummaryFactory(DocumentFactory):
target_class = PressSummary
PARAMS_MAP = dict(DocumentFactory.PARAMS_MAP)
PARAMS_MAP["document_noun"] = "press summary"


class CourtDateFactory(DjangoModelFactory):
class Meta:
model = CourtDates
Expand Down
Loading

0 comments on commit 00d6cbe

Please sign in to comment.