-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #555 from nationalarchives/1704-add-helper-to-get-…
…press-summaries-for-a-document Add a helper to get press summaries for a document
- Loading branch information
Showing
7 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
xquery version "1.0-ml"; | ||
|
||
declare namespace akn = "http://docs.oasis-open.org/legaldocml/ns/akn/3.0"; | ||
declare namespace uk = "https://caselaw.nationalarchives.gov.uk/akn"; | ||
|
||
declare variable $parent_uri as xs:string external; | ||
declare variable $component as xs:string external; | ||
|
||
let $collectionQuery := cts:collection-query(("http://marklogic.com/collections/dls/latest-version")) | ||
let $docTypeQuery := cts:element-attribute-value-query( | ||
xs:QName("akn:doc"), | ||
xs:QName("name"), | ||
$component | ||
) | ||
let $refQuery := cts:element-query( | ||
xs:QName("uk:summaryOf"), | ||
concat("https://caselaw.nationalarchives.gov.uk/id", $parent_uri) | ||
) | ||
|
||
return xdmp:node-uri(cts:search(//akn:akomaNtoso, cts:and-query(($refQuery, $collectionQuery, $docTypeQuery)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from unittest import TestCase | ||
from unittest.mock import call, patch | ||
|
||
from caselawclient.Client import MarklogicApiClient | ||
|
||
|
||
class TestGetPressSummariesForDocumentUri(TestCase): | ||
def setUp(self): | ||
self.client = MarklogicApiClient("", "", "", False) | ||
|
||
@patch("caselawclient.Client.PressSummary", autospec=True) | ||
@patch("caselawclient.Client.MarklogicApiClient._send_to_eval") | ||
@patch("caselawclient.Client.get_multipart_strings_from_marklogic_response") | ||
def test_get_press_summaries_for_document_uri( | ||
self, mock_get_marklogic_response, mock_eval, mock_press_summary | ||
): | ||
mock_eval.return_value = "EVAL" | ||
mock_get_marklogic_response.return_value = ["/foo/bar/baz/1", "/foo/bar/baz/2"] | ||
|
||
for uri in ["foo/bar", "/foo/bar"]: | ||
with self.subTest(uri=uri): | ||
self.client.get_press_summaries_for_document_uri(uri) | ||
|
||
mock_get_marklogic_response.assert_called_with("EVAL") | ||
mock_eval.assert_called_with( | ||
{ | ||
"parent_uri": "/foo/bar", | ||
"component": "pressSummary", | ||
}, | ||
"get_components_for_document.xqy", | ||
) | ||
|
||
mock_press_summary.assert_has_calls( | ||
[ | ||
call("/foo/bar/baz/1", self.client), | ||
call("/foo/bar/baz/2", self.client), | ||
], | ||
any_order=True, | ||
) |