From 74ef1a66fc27e0ba54621dcdaf0c796be1ccd8a1 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 25 Nov 2024 14:01:29 +0000 Subject: [PATCH 1/5] Update dependency ds-caselaw-marklogic-api-client to v28 --- requirements/base.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/base.txt b/requirements/base.txt index fbe395313..dbef2c660 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -17,7 +17,7 @@ xmltodict~=0.14.1 requests-toolbelt~=1.0.0 lxml~=5.3.0 wsgi-basic-auth~=1.1.0 -ds-caselaw-marklogic-api-client~=27.4.0 +ds-caselaw-marklogic-api-client~=28.0.0 ds-caselaw-utils~=2.0.0 rollbar django-stronghold==0.4.0 From 71360a31636625b27e0d4f02ee008c47e3f639b8 Mon Sep 17 00:00:00 2001 From: Nick Jackson Date: Mon, 25 Nov 2024 15:45:51 +0000 Subject: [PATCH 2/5] Replace test document URIs with DocumentURIString instances --- judgments/tests/factories.py | 4 +++- judgments/tests/test_associated_documents.py | 3 ++- judgments/tests/test_breadcrumbs.py | 7 ++++--- judgments/tests/test_document_edit.py | 11 ++++++----- judgments/tests/test_document_history.py | 15 +++++++++------ judgments/tests/test_document_hold.py | 9 +++++---- judgments/tests/test_document_publication.py | 9 +++++---- judgments/tests/test_document_toolbar.py | 13 +++++++------ judgments/tests/test_factories.py | 2 +- judgments/tests/test_judgments.py | 5 +++-- judgments/tests/test_metadata_panel.py | 3 ++- judgments/tests/test_unlock.py | 3 ++- judgments/tests/test_view_helpers.py | 3 ++- 13 files changed, 51 insertions(+), 36 deletions(-) diff --git a/judgments/tests/factories.py b/judgments/tests/factories.py index c39e91343..fdf405f25 100644 --- a/judgments/tests/factories.py +++ b/judgments/tests/factories.py @@ -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="

This is a Document Version.

", api_client=None, **kwargs: Any, diff --git a/judgments/tests/test_associated_documents.py b/judgments/tests/test_associated_documents.py index e53203ac7..aea569e10 100644 --- a/judgments/tests/test_associated_documents.py +++ b/judgments/tests/test_associated_documents.py @@ -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 @@ -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 diff --git a/judgments/tests/test_breadcrumbs.py b/judgments/tests/test_breadcrumbs.py index a2c45945a..3da1c15fe 100644 --- a/judgments/tests/test_breadcrumbs.py +++ b/judgments/tests/test_breadcrumbs.py @@ -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 @@ -90,7 +91,7 @@ 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"), ) @@ -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"), ) @@ -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", ) diff --git a/judgments/tests/test_document_edit.py b/judgments/tests/test_document_edit.py index b87f5ca5a..fbd0bb81e 100644 --- a/judgments/tests/test_document_edit.py +++ b/judgments/tests/test_document_edit.py @@ -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 @@ -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 @@ -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 @@ -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"), ) @@ -115,7 +116,7 @@ def test_bad_ncn_has_banner(self, linked_document_uri, mock_judgment): @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", @@ -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", diff --git a/judgments/tests/test_document_history.py b/judgments/tests/test_document_history.py index c0b94a6ba..6a8ebad1d 100644 --- a/judgments/tests/test_document_history.py +++ b/judgments/tests/test_document_history.py @@ -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 @@ -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"), ) @@ -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, @@ -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, @@ -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", diff --git a/judgments/tests/test_document_hold.py b/judgments/tests/test_document_hold.py index aa3259aca..96550b8f3 100644 --- a/judgments/tests/test_document_hold.py +++ b/judgments/tests/test_document_hold.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/judgments/tests/test_document_publication.py b/judgments/tests/test_document_publication.py index a0c086136..21366d36b 100644 --- a/judgments/tests/test_document_publication.py +++ b/judgments/tests/test_document_publication.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/judgments/tests/test_document_toolbar.py b/judgments/tests/test_document_toolbar.py index 1c122ecb5..bbd258b13 100644 --- a/judgments/tests/test_document_toolbar.py +++ b/judgments/tests/test_document_toolbar.py @@ -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 @@ -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) @@ -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) @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/judgments/tests/test_factories.py b/judgments/tests/test_factories.py index 53b81d54d..48063e2d3 100644 --- a/judgments/tests/test_factories.py +++ b/judgments/tests/test_factories.py @@ -11,7 +11,7 @@ def test_default_uri(self): assert judgment.uri != "" def test_uri(self): - judgment = JudgmentFactory.build(uri="test/1234/56") + judgment = JudgmentFactory.build(uri=DocumentURIString("test/1234/56")) assert judgment.uri == "test/1234/56" diff --git a/judgments/tests/test_judgments.py b/judgments/tests/test_judgments.py index c03c5458e..db79368d4 100644 --- a/judgments/tests/test_judgments.py +++ b/judgments/tests/test_judgments.py @@ -3,6 +3,7 @@ from urllib.parse import urlencode 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 @@ -18,7 +19,7 @@ def test_judgment_html_view(self, document_type, document_exists, mock_judgment) document_exists.return_value = None judgment = JudgmentFactory.build( - uri="hvtest/4321/123", + uri=DocumentURIString("hvtest/4321/123"), body=DocumentBodyFactory.build( name="Test v Tested", xml_string="This is our test judgment.", @@ -54,7 +55,7 @@ def test_judgment_html_view_with_parser_failure( document_exists.return_value = None judgment = JudgmentFactory.build( - uri="hvtest/4321/123", + uri=DocumentURIString("hvtest/4321/123"), body=DocumentBodyFactory.build(xml_string="Error log"), ) diff --git a/judgments/tests/test_metadata_panel.py b/judgments/tests/test_metadata_panel.py index 37d5d2e18..58379a895 100644 --- a/judgments/tests/test_metadata_panel.py +++ b/judgments/tests/test_metadata_panel.py @@ -2,6 +2,7 @@ import lxml.html 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 @@ -17,7 +18,7 @@ def test_metadata_panel(self, document_type, document_exists, mock_judgment): document_exists.return_value = None judgment = JudgmentFactory.build( - uri="hvtest/4321/123", + uri=DocumentURIString("hvtest/4321/123"), html="

Test Judgment

", body=DocumentBodyFactory.build(name="Test v Tested"), ) diff --git a/judgments/tests/test_unlock.py b/judgments/tests/test_unlock.py index 03ee724d3..52b52fc3a 100644 --- a/judgments/tests/test_unlock.py +++ b/judgments/tests/test_unlock.py @@ -2,6 +2,7 @@ import pytest from caselawclient.factories import JudgmentFactory +from caselawclient.models.documents import DocumentURIString from django.contrib.auth.models import User from django.test import Client from django.urls import reverse @@ -24,7 +25,7 @@ def test_break_lock_confirm_page(): @patch("judgments.views.unlock.messages") def test_break_lock_post(messages, break_checkout, mock_judgment): judgment = JudgmentFactory.build( - uri="ewca/civ/2023/1", + uri=DocumentURIString("ewca/civ/2023/1"), ) mock_judgment.return_value = judgment diff --git a/judgments/tests/test_view_helpers.py b/judgments/tests/test_view_helpers.py index e58dd41f6..80beb8642 100644 --- a/judgments/tests/test_view_helpers.py +++ b/judgments/tests/test_view_helpers.py @@ -4,6 +4,7 @@ import pytest from caselawclient.errors import DocumentNotFoundError from caselawclient.factories import DocumentBodyFactory, JudgmentFactory +from caselawclient.models.documents import DocumentURIString from django.contrib.auth.models import Group, User from django.http import Http404 from django.test import Client, TestCase @@ -88,7 +89,7 @@ def test_document_view_has_image( with open("judgments/tests/fixtures/sample_judgment.xml") as f: sample_judgment = f.read() mock_get_document_by_uri.return_value = JudgmentFactory.build( - uri="/eat/2023/1", + uri=DocumentURIString("/eat/2023/1"), body=DocumentBodyFactory.build(xml_string=sample_judgment), ) response = self.client.get("/eat/2023/1") From 2963473b9a34c19e50b54d4c9ec9d2558fa6e388 Mon Sep 17 00:00:00 2001 From: Nick Jackson Date: Mon, 25 Nov 2024 16:09:17 +0000 Subject: [PATCH 3/5] Fix instances of bad URIs in tests --- judgments/tests/factories.py | 2 +- judgments/tests/test_breadcrumbs.py | 12 ++++++------ judgments/tests/test_factories.py | 2 +- judgments/tests/test_view_helpers.py | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/judgments/tests/factories.py b/judgments/tests/factories.py index fdf405f25..1dfb06b2f 100644 --- a/judgments/tests/factories.py +++ b/judgments/tests/factories.py @@ -67,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 diff --git a/judgments/tests/test_breadcrumbs.py b/judgments/tests/test_breadcrumbs.py index 3da1c15fe..b8565fbe3 100644 --- a/judgments/tests/test_breadcrumbs.py +++ b/judgments/tests/test_breadcrumbs.py @@ -91,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=DocumentURIString("/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 = """