Skip to content

Commit

Permalink
refactor(Document): initialising a Document now requires a DocumentUR…
Browse files Browse the repository at this point in the history
…IString, not a str

This previously accepted a str and would attempt to strip it and remove slashes. It now only accepts a DocumentURIString object.

BREAKING CHANGE: Document can now no longer be initialised with a string as the `uri`, it must be a `DocumentURIString`.
  • Loading branch information
jacksonj04 committed Nov 13, 2024
1 parent d3db2c9 commit 6bfc155
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog 1.0.0].

## Unreleased

### BREAKING CHANGE

- Document can now no longer be initialised with a string as the `uri`, it must be a `DocumentURIString`.

## v27.4.0 (2024-11-07)

### Change of behaviour
Expand Down
4 changes: 2 additions & 2 deletions src/caselawclient/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing_extensions import TypeAlias

from caselawclient.Client import MarklogicApiClient
from caselawclient.models.documents import Document
from caselawclient.models.documents import Document, DocumentURIString
from caselawclient.models.documents.body import DocumentBody
from caselawclient.models.judgments import Judgment
from caselawclient.models.press_summaries import PressSummary
Expand Down Expand Up @@ -54,7 +54,7 @@ class DocumentFactory:
@classmethod
def build(
cls,
uri: str = "test/2023/123",
uri: DocumentURIString = DocumentURIString("test/2023/123"),
html: str = "<p>This is a judgment.</p>",
api_client: Optional[MarklogicApiClient] = None,
**kwargs: Any,
Expand Down
10 changes: 6 additions & 4 deletions src/caselawclient/models/documents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ class Document:
Individual document classes should extend this list where necessary to validate document type-specific attributes.
"""

def __init__(self, uri: str, api_client: "MarklogicApiClient", search_query: Optional[str] = None):
def __init__(self, uri: DocumentURIString, api_client: "MarklogicApiClient", search_query: Optional[str] = None):
"""
:param uri: For historical reasons this accepts a pseudo-URI which may include leading or trailing slashes.
:param uri: The URI of the document to retrieve from MarkLogic.
:param api_client: An instance of the API client object to handle communication with the MarkLogic server.
:param search_query: Optionally, a search string which should be highlighted if it appears in the document body.
:raises DocumentNotFoundError: The document does not exist within MarkLogic
"""
self.uri: DocumentURIString = DocumentURIString(uri.strip("/"))
self.uri: DocumentURIString = uri
self.api_client: MarklogicApiClient = api_client
if not self.document_exists():
raise DocumentNotFoundError(f"Document {self.uri} does not exist")
Expand All @@ -123,7 +125,7 @@ def __init__(self, uri: str, api_client: "MarklogicApiClient", search_query: Opt
search_query=search_query,
),
)
""" `Document.body` represents the XML of the document itself, without any information such as version tracking or properties. """
""" `Document.body` represents the body of the document itself, without any information such as version tracking or properties. """

def __repr__(self) -> str:
name = self.body.name or "un-named"
Expand Down

0 comments on commit 6bfc155

Please sign in to comment.