Skip to content

Commit

Permalink
Merge pull request #1771 from nationalarchives/renovate/ds-caselaw-ma…
Browse files Browse the repository at this point in the history
…rklogic-api-client-28.x

Update dependency ds-caselaw-marklogic-api-client to v28
  • Loading branch information
jacksonj04 authored Nov 26, 2024
2 parents 65aacd2 + 7c44fd5 commit 67a38b1
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ <h3>
Document URI/NCN mismatch
</h3>
<p>
This document is located at <a href="{% url 'full-text-html' judgment.uri %}"><strong>/{{ judgment.uri }}</strong></a> but has an NCN of <a href="{{ corrected_ncn_url }}"><strong>{{ judgment.best_human_identifier }}</strong></a>
This document is currently located at <strong>/{{ judgment.uri }}</strong> but based on its NCN should be at <strong>/{{ corrected_ncn_url }}</strong>
</p>
<input type="hidden" name="judgment_uri" value="{{ document_uri }}" />
<div>
<input type="submit"
name="move_document"
value="Move to {{ corrected_ncn_url }}"
value="Move to /{{ corrected_ncn_url }}"
class="button-cta button-small" />
</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions judgments/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ class Meta:
class DocumentVersionFactory(DocumentFactory):
DocumentClass: TypeAlias = Document

default_document_uri = DocumentURIString("test/2023/123")

@classmethod
def build(
cls,
uri="test/2023/123",
uri=default_document_uri,
html="<p>This is a Document Version.</p>",
api_client=None,
**kwargs: Any,
Expand Down Expand Up @@ -65,7 +67,7 @@ def build(
uri = document.uri
_id = uri.split("/")[-1]
version.uri = DocumentURIString(
f"{uri}/_xml_versions/{version.version_number}-{_id}.xml",
f"{uri}/_xml_versions/{version.version_number}-{_id}",
)

return version
Expand Down
3 changes: 2 additions & 1 deletion judgments/tests/test_associated_documents.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest.mock import patch

from caselawclient.factories import DocumentBodyFactory, JudgmentFactory
from caselawclient.models.documents import DocumentURIString
from caselawclient.models.judgments import Judgment
from django.contrib.auth.models import User
from django.test import TestCase
Expand All @@ -16,7 +17,7 @@ def test_associated_documents_view(self, document_type, document_exists, mock_ju
document_exists.return_value = None

judgment = JudgmentFactory.build(
uri="associateddocumentstest/4321/123",
uri=DocumentURIString("associateddocumentstest/4321/123"),
body=DocumentBodyFactory.build(name="Test v Tested"),
)
mock_judgment.return_value = judgment
Expand Down
13 changes: 7 additions & 6 deletions judgments/tests/test_breadcrumbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest
from caselawclient.factories import DocumentBodyFactory, JudgmentFactory, PressSummaryFactory
from caselawclient.models.documents import DocumentURIString
from django.http import Http404
from django.test import Client, TestCase

Expand Down Expand Up @@ -90,13 +91,13 @@ def test_breadcrumb_when_press_summary(
self.client.force_login(User.objects.get_or_create(username="testuser")[0])
mock_get_linked_document_uri.return_value = "my_related_document_uri"
judgment = PressSummaryFactory.build(
uri="/eat/2023/1/press-summary/1/",
uri=DocumentURIString("eat/2023/1/press-summary/1"),
document_noun="press summary",
body=DocumentBodyFactory.build(name="Press Summary of Judgment A"),
)

mock_get_document_by_uri.return_value = judgment
response = self.client.get("/eat/2023/1/press-summary/1/")
response = self.client.get("/eat/2023/1/press-summary/1")
breadcrumb_html = """
<nav class="page-header__breadcrumbs-container" aria-label="Breadcrumb">
<span class="page-header__breadcrumbs-you-are-in">You are in:</span>
Expand Down Expand Up @@ -128,7 +129,7 @@ def test_breadcrumb_when_judgment(
"""
self.client.force_login(User.objects.get_or_create(username="testuser")[0])
mock_get_document_by_uri.return_value = JudgmentFactory.build(
uri="/eat/2023/1",
uri=DocumentURIString("eat/2023/1"),
document_noun="judgment",
body=DocumentBodyFactory.build(name="Judgment A"),
)
Expand Down Expand Up @@ -160,7 +161,7 @@ def test_breadcrumb_when_unnamed_document(
"""
self.client.force_login(User.objects.get_or_create(username="testuser")[0])
judgment = JudgmentFactory.build(
uri="/eat/2023/1",
uri=DocumentURIString("eat/2023/1"),
name="",
document_noun="judgment",
)
Expand Down Expand Up @@ -193,7 +194,7 @@ def test_breadcrumb_when_404(

mock_get_document_by_uri.side_effect = Http404

response = self.client.get("/eat/2023/1/")
response = self.client.get("/eat/2023/1")
breadcrumb_html = """
<nav class="page-header__breadcrumbs-container" aria-label="Breadcrumb">
<span class="page-header__breadcrumbs-you-are-in">You are in:</span>
Expand Down Expand Up @@ -222,7 +223,7 @@ def test_breadcrumb_when_server_error(

mock_get_document_by_uri.side_effect = Exception

response = self.client.get("/eat/2023/1/")
response = self.client.get("/eat/2023/1")
breadcrumb_html = """
<nav class="page-header__breadcrumbs-container" aria-label="Breadcrumb">
<span class="page-header__breadcrumbs-you-are-in">You are in:</span>
Expand Down
15 changes: 8 additions & 7 deletions judgments/tests/test_document_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lxml.html
from caselawclient.factories import DocumentBodyFactory, JudgmentFactory, PressSummaryFactory
from caselawclient.models.documents import DocumentURIString
from django.contrib.auth.models import User
from django.contrib.messages import get_messages
from django.test import TestCase
Expand All @@ -22,7 +23,7 @@ def test_judgment_edit_view_redirects(self):
@patch("judgments.views.judgment_edit.get_document_by_uri_or_404")
def test_edit_judgment(self, mock_judgment, api_client):
judgment = JudgmentFactory.build(
uri="edittest/4321/123",
uri=DocumentURIString("edittest/4321/123"),
name="Test v Tested",
)
mock_judgment.return_value = judgment
Expand Down Expand Up @@ -62,7 +63,7 @@ def test_edit_judgment(self, mock_judgment, api_client):
@patch("judgments.views.judgment_edit.get_document_by_uri_or_404")
def test_date_error(self, mock_judgment, api_client):
judgment = JudgmentFactory.build(
uri="edittest/4321/123",
uri=DocumentURIString("edittest/4321/123"),
name="Test v Tested",
)
mock_judgment.return_value = judgment
Expand Down Expand Up @@ -90,7 +91,7 @@ class TestDocumentBadURIWarning(TestCase):
@patch("judgments.utils.view_helpers.get_linked_document_uri")
def test_bad_ncn_has_banner(self, linked_document_uri, mock_judgment):
judgment = JudgmentFactory.build(
uri="uksc/1234/123",
uri=DocumentURIString("uksc/1234/123"),
neutral_citation="[1234] UKSC 999",
body=DocumentBodyFactory.build(name="Test v Tested"),
)
Expand All @@ -106,16 +107,16 @@ def test_bad_ncn_has_banner(self, linked_document_uri, mock_judgment):
root = lxml.html.fromstring(response.content)
message = lxml.html.tostring(root.xpath("//div[@class='page-notification--warning']")[0])
assert b"Document URI/NCN mismatch" in message
assert b'This document is located at <a href="/uksc/1234/123">' in message
assert b'but has an NCN of <a href="/uksc/1234/999">' in message
assert b"This document is currently located at <strong>/uksc/1234/123</strong>" in message
assert b"but based on its NCN should be at <strong>/uksc/1234/999</strong>" in message
assert b'<input type="hidden" name="judgment_uri" value="uksc/1234/123">' in message

@patch("judgments.views.judgment_edit.api_client")
@patch("judgments.views.judgment_edit.update_document_uri")
@patch("judgments.views.judgment_edit.get_document_by_uri_or_404")
def test_update_uri_called(self, mock_judgment, update_document_uri, api_client):
judgment = JudgmentFactory.build(
uri="uksc/4321/123",
uri=DocumentURIString("uksc/4321/123"),
name="Test v Tested",
neutral_citation="[1234] UKSC 321",
best_human_identifier="[1234] UKSC 321",
Expand All @@ -140,7 +141,7 @@ def test_update_uri_called(self, mock_judgment, update_document_uri, api_client)
@patch("judgments.views.judgment_edit.get_document_by_uri_or_404")
def test_update_uri_not_called_for_press_summary(self, mock_judgment, update_document_uri, api_client):
judgment = PressSummaryFactory.build(
uri="uksc/4321/123",
uri=DocumentURIString("uksc/4321/123"),
name="Test v Tested",
neutral_citation="[1234] UKSC 321",
best_human_identifier="[1234] UKSC 321",
Expand Down
15 changes: 9 additions & 6 deletions judgments/tests/test_document_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from caselawclient.client_helpers import VersionAnnotation, VersionType
from caselawclient.factories import DocumentBodyFactory, JudgmentFactory
from caselawclient.models.documents import VersionsDict
from caselawclient.models.documents import DocumentURIString, VersionsDict
from caselawclient.models.judgments import Judgment
from django.contrib.auth.models import Group, User
from django.test import TestCase
Expand All @@ -25,7 +25,7 @@ def test_document_history_view(self, document_type, document_exists, mock_get_do
document_exists.return_value = None

document = JudgmentFactory.build(
uri="ewca/civ/2005/1444",
uri=DocumentURIString("ewca/civ/2005/1444"),
versions=[VersionsDict({"uri": "/ewca/civ/2005/1444_xml_versions/1-1444.xml", "version": 1})],
body=DocumentBodyFactory.build(name="Test v Tested"),
)
Expand Down Expand Up @@ -56,7 +56,7 @@ def test_document_history_view(self, document_type, document_exists, mock_get_do
class TestStructuredDocumentHistoryLogic(TestCase):
def test_build_event_object_without_submitter(self):
version_document = DocumentVersionFactory.build(
uri="test/4321/123",
uri=DocumentURIString("test/4321/123"),
name="Test v Tested",
annotation=VersionAnnotation(
VersionType.SUBMISSION,
Expand Down Expand Up @@ -392,12 +392,12 @@ def test_structured_history_with_legacy(
document_exists.return_value = None

document = JudgmentFactory.build( # This was a DocumentFactory; this may not work properly with Press Summaries
uri="test/4321/123",
uri=DocumentURIString("test/4321/123"),
name="Test v Tested",
)
document.versions_as_documents = [
DocumentVersionFactory.build(
uri="test/4321/123",
uri=DocumentURIString("test/4321/123"),
name="Test v Tested",
annotation="Legacy annotation 1",
version_number=123,
Expand Down Expand Up @@ -436,7 +436,10 @@ def test_structured_history(
document_type.return_value = Judgment
document_exists.return_value = None

document = JudgmentFactory.build(uri="test/4321/123", body=DocumentBodyFactory.build(name="Test v Tested"))
document = JudgmentFactory.build(
uri=DocumentURIString("test/4321/123"),
body=DocumentBodyFactory.build(name="Test v Tested"),
)
document.versions_as_documents = [
DocumentVersionFactory.build(
uri="test/4321/123",
Expand Down
9 changes: 5 additions & 4 deletions judgments/tests/test_document_hold.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest.mock import Mock, patch

from caselawclient.factories import DocumentBodyFactory, JudgmentFactory
from caselawclient.models.documents import DocumentURIString
from caselawclient.models.judgments import Judgment
from django.contrib.auth.models import User
from django.test import TestCase
Expand All @@ -16,7 +17,7 @@ def test_document_hold_view(self, document_type, document_exists, mock_judgment)
document_exists.return_value = None

judgment = JudgmentFactory.build(
uri="holdtest/4321/123",
uri=DocumentURIString("holdtest/4321/123"),
body=DocumentBodyFactory.build(name="Test v Tested"),
)
mock_judgment.return_value = judgment
Expand Down Expand Up @@ -71,7 +72,7 @@ def test_document_hold_success_view(
document_exists.return_value = None

judgment = JudgmentFactory.build(
uri="holdtest/4321/123",
uri=DocumentURIString("holdtest/4321/123"),
body=DocumentBodyFactory.build(name="Test v Tested"),
)
mock_judgment.return_value = judgment
Expand Down Expand Up @@ -101,7 +102,7 @@ def test_document_unhold_view(self, document_type, document_exists, mock_judgmen
document_exists.return_value = None

judgment = JudgmentFactory.build(
uri="unholdtest/4321/123",
uri=DocumentURIString("unholdtest/4321/123"),
body=DocumentBodyFactory.build(name="Test v Tested"),
)
mock_judgment.return_value = judgment
Expand Down Expand Up @@ -156,7 +157,7 @@ def test_document_hold_success_view(
document_exists.return_value = None

judgment = JudgmentFactory.build(
uri="unholdtest/4321/123",
uri=DocumentURIString("unholdtest/4321/123"),
body=DocumentBodyFactory.build(name="Test v Tested"),
)
mock_judgment.return_value = judgment
Expand Down
9 changes: 5 additions & 4 deletions judgments/tests/test_document_publication.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest.mock import Mock, patch

from caselawclient.factories import DocumentBodyFactory, JudgmentFactory
from caselawclient.models.documents import DocumentURIString
from caselawclient.models.judgments import Judgment
from django.contrib.auth.models import User
from django.test import TestCase
Expand All @@ -16,7 +17,7 @@ def test_document_publish_view(self, document_type, document_exists, mock_judgme
document_exists.return_value = None

judgment = JudgmentFactory.build(
uri="pubtest/4321/123",
uri=DocumentURIString("pubtest/4321/123"),
body=DocumentBodyFactory.build(name="Test v Tested"),
)
mock_judgment.return_value = judgment
Expand Down Expand Up @@ -75,7 +76,7 @@ def test_document_publish_success_view(
document_exists.return_value = None

judgment = JudgmentFactory.build(
uri="pubtest/4321/123",
uri=DocumentURIString("pubtest/4321/123"),
body=DocumentBodyFactory.build(name="Test v Tested"),
)
mock_judgment.return_value = judgment
Expand Down Expand Up @@ -110,7 +111,7 @@ def test_document_unpublish_view(
document_exists.return_value = None

judgment = JudgmentFactory.build(
uri="pubtest/4321/123",
uri=DocumentURIString("pubtest/4321/123"),
body=DocumentBodyFactory.build(name="Test v Tested"),
)
mock_judgment.return_value = judgment
Expand Down Expand Up @@ -168,7 +169,7 @@ def test_document_unpublish_success_view(
document_exists.return_value = None

judgment = JudgmentFactory.build(
uri="pubtest/4321/123",
uri=DocumentURIString("pubtest/4321/123"),
body=DocumentBodyFactory.build(name="Test v Tested"),
)
mock_judgment.return_value = judgment
Expand Down
13 changes: 7 additions & 6 deletions judgments/tests/test_document_toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from unittest.mock import patch

from caselawclient.factories import JudgmentFactory
from caselawclient.models.documents import DocumentURIString
from caselawclient.models.judgments import Judgment
from django.contrib.auth.models import Group, User
from django.test import TestCase
Expand All @@ -22,7 +23,7 @@ def setUp(self):
@patch("judgments.utils.api_client.document_exists")
def test_editor_tools_if_editor(self, document_exists, mock_judgment):
mock_judgment.return_value = JudgmentFactory.build(
uri="failures/TDR-ref",
uri=DocumentURIString("failures/TDR-ref"),
is_failure=True,
)
self.client.force_login(self.editor_user)
Expand All @@ -40,7 +41,7 @@ def test_no_editor_tools_if_not_priviledged(
mock_judgment,
):
mock_judgment.return_value = JudgmentFactory.build(
uri="failures/TDR-ref",
uri=DocumentURIString("failures/TDR-ref"),
is_failure=True,
)
self.client.force_login(self.standard_user)
Expand All @@ -65,7 +66,7 @@ def test_delete_button_when_failure(
document_exists.return_value = None

judgment = JudgmentFactory.build(
uri="failures/TDR-ref",
uri=DocumentURIString("failures/TDR-ref"),
is_failure=True,
)
mock_judgment.return_value = judgment
Expand Down Expand Up @@ -100,7 +101,7 @@ def test_no_delete_button_when_not_failure(
document_exists.return_value = None

judgment = JudgmentFactory.build(
uri="good-document",
uri=DocumentURIString("good-document"),
is_failure=False,
)
mock_judgment.return_value = judgment
Expand Down Expand Up @@ -129,7 +130,7 @@ def test_get_locked_banner_if_locked(
document_exists.return_value = None

judgment = JudgmentFactory.build(
uri="good-document",
uri=DocumentURIString("good-document"),
is_failure=False,
)
judgment.is_locked = True
Expand All @@ -153,7 +154,7 @@ def test_get_no_locked_banner_if_not_locked(
document_exists.return_value = None

judgment = JudgmentFactory.build(
uri="good-document",
uri=DocumentURIString("good-document"),
is_failure=False,
)
judgment.is_locked = False
Expand Down
Loading

0 comments on commit 67a38b1

Please sign in to comment.