Skip to content

Commit

Permalink
Expose jurisdictions in search results
Browse files Browse the repository at this point in the history
  • Loading branch information
timcowlishaw committed Jan 31, 2024
1 parent 6cb7e47 commit 3111eb7
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog 1.0.0].

## Unreleased

- Expose court jurisdictions in search results

## [Release 21.0.0]

- **Breaking:** `Client.get_pending_enrichment_for_version` now requires both a target enrichment version and a target parser version, and will not include documents which have not been parsed with the target version.
Expand Down
24 changes: 12 additions & 12 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ requests-toolbelt = ">=0.10.1,<1.1.0"
urllib3 = "^1.26.15"
memoization = "^0.4.0"
lxml = "^5.0.0"
ds-caselaw-utils = "^1.3.3"
ds-caselaw-utils = "^1.4.0"
boto3 = "^1.26.112"
typing-extensions = "^4.7.1"
mypy-boto3-s3 = "^1.26.104"
Expand Down
7 changes: 5 additions & 2 deletions src/caselawclient/models/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ def jurisdiction(self) -> str:

@property
def court_and_jurisdiction(self) -> str:
return "/".join((self.court, self.jurisdiction))
if self.jurisdiction != "":
return "/".join((self.court, self.jurisdiction))
else:
return self.court

@cached_property
def document_date_as_string(self) -> str:
Expand Down Expand Up @@ -435,7 +438,7 @@ def has_name(self) -> bool:
@cached_property
def has_valid_court(self) -> bool:
try:
return bool(courts.get_by_code(self.court))
return bool(courts.get_by_code(self.court_and_jurisdiction))
except CourtNotFoundException:
return False

Expand Down
7 changes: 7 additions & 0 deletions src/caselawclient/responses/search_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ def court(
"""

court_code = self._get_xpath_match_string("search:extracted/uk:court/text()")
jurisdiction_code = self._get_xpath_match_string(
"search:extracted/uk:jurisdiction/text()"
)

if jurisdiction_code:
court_code = "%s/%s" % (court_code, jurisdiction_code)

try:
court = courts.get_by_code(court_code)
except CourtNotFoundException:
Expand Down
41 changes: 40 additions & 1 deletion tests/models/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,12 @@ def test_has_court_is_covered_by_has_valid_court(self, mock_api_client):
document_without_court = Document("test/1234", mock_api_client)
document_without_court.court = ""

document_with_court_and_jurisdiction = Document("test/1234", mock_api_client)
document_with_court_and_jurisdiction.court = "UKFTT-GRC"
document_with_court_and_jurisdiction.jurisdiction = "InformationRights"

assert document_with_court.has_valid_court is True
assert document_with_court_and_jurisdiction.has_valid_court is True
assert document_without_court.has_valid_court is False

@pytest.mark.parametrize(
Expand Down Expand Up @@ -580,7 +585,9 @@ def test_jurisdiction(self, opening_tag, closing_tag, mock_api_client):
('doc name="pressSummary"', "doc"),
],
)
def test_court_and_jurisdiction(self, opening_tag, closing_tag, mock_api_client):
def test_court_and_jurisdiction_with_jurisdiction(
self, opening_tag, closing_tag, mock_api_client
):
mock_api_client.get_judgment_xml_bytestring.return_value = f"""
<akomaNtoso xmlns:uk="https://caselaw.nationalarchives.gov.uk/akn"
xmlns="http://docs.oasis-open.org/legaldocml/ns/akn/3.0">
Expand All @@ -604,6 +611,38 @@ def test_court_and_jurisdiction(self, opening_tag, closing_tag, mock_api_client)
"test/1234", show_unpublished=True
)

@pytest.mark.parametrize(
"opening_tag, closing_tag",
[
("judgment", "judgment"),
('doc name="pressSummary"', "doc"),
],
)
def test_court_and_jurisdiction_without_jurisdiction(
self, opening_tag, closing_tag, mock_api_client
):
mock_api_client.get_judgment_xml_bytestring.return_value = f"""
<akomaNtoso xmlns:uk="https://caselaw.nationalarchives.gov.uk/akn"
xmlns="http://docs.oasis-open.org/legaldocml/ns/akn/3.0">
<{opening_tag}>
<meta>
<proprietary>
<uk:court>CourtOfTesting</uk:court>
</proprietary>
</meta>
</{closing_tag}>
</akomaNtoso>
""".encode(
"utf-8"
)

document = Document("test/1234", mock_api_client)

assert document.court_and_jurisdiction == "CourtOfTesting"
mock_api_client.get_judgment_xml_bytestring.assert_called_once_with(
"test/1234", show_unpublished=True
)

@pytest.mark.parametrize(
"opening_tag, closing_tag",
[
Expand Down
24 changes: 24 additions & 0 deletions tests/responses/test_search_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,30 @@ def test_create_from_node_with_valid_court_code(self):
assert isinstance(search_result.court, Court)
assert search_result.court.name == "United Kingdom Supreme Court"

def test_create_from_node_with_valid_court_and_jurisdiction_code(self):
"""
GIVEN an XML node with a valid court code
AND a valid jurisdiction code
WHEN creating a SearchResult object from the node
THEN the court attribute is set to the corresponding Court object
"""
xml = (
'<search:result xmlns:search="http://marklogic.com/appservices/search" uri="/uksc/2015/20.xml">\n '
'<search:extracted kind="element">'
'<uk:court xmlns:uk="https://caselaw.nationalarchives.gov.uk/akn">UKFTT-GRC</uk:court>'
'<uk:jurisdiction xmlns:uk="https://caselaw.nationalarchives.gov.uk/akn">InformationRights</uk:jurisdiction>'
"</search:extracted>"
"</search:result>"
)
node = etree.fromstring(xml)
search_result = SearchResult(node, self.client)

assert isinstance(search_result.court, Court)
assert (
search_result.court.name
== "First-tier Tribunal (General Regulatory Chamber) – Information Rights"
)

def test_create_from_node_with_invalid_court_code(self):
"""
GIVEN an XML node with an invalid court code
Expand Down

0 comments on commit 3111eb7

Please sign in to comment.