Skip to content

Commit

Permalink
Merge pull request #783 from nationalarchives/renovate/astral-sh-ruff…
Browse files Browse the repository at this point in the history
…-pre-commit-0.x

chore(deps): update pre-commit hook astral-sh/ruff-pre-commit to v0.8.0
  • Loading branch information
jacksonj04 authored Nov 25, 2024
2 parents 16809be + e9d4dce commit 56687b8
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
id: ruff
- id: ruff-format
repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.4
rev: v0.8.0
- hooks:
- entry: script/build_xquery_type_dicts
id: build-xquery-type-dicts
Expand Down
36 changes: 23 additions & 13 deletions tests/client/test_advanced_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,13 @@ def test_user_can_view_unpublished_but_show_unpublished_is_false(
When the advanced_search method is called with the show_unpublished parameter set to False
Then it should call the MarkLogic module with the expected query parameters
"""
with patch.object(self.client, "invoke") as mock_invoke, patch.object(
self.client,
"user_can_view_unpublished_judgments",
return_value=True,
with (
patch.object(self.client, "invoke") as mock_invoke,
patch.object(
self.client,
"user_can_view_unpublished_judgments",
return_value=True,
),
):
self.client.advanced_search(
SearchParameters(
Expand Down Expand Up @@ -177,10 +180,13 @@ def test_user_can_view_unpublished_and_show_unpublished_is_true(
When the advanced_search method is called with the show_unpublished parameter set to True
Then it should call the MarkLogic module with the expected query parameters
"""
with patch.object(self.client, "invoke") as patched_invoke, patch.object(
self.client,
"user_can_view_unpublished_judgments",
return_value=True,
with (
patch.object(self.client, "invoke") as patched_invoke,
patch.object(
self.client,
"user_can_view_unpublished_judgments",
return_value=True,
),
):
self.client.advanced_search(
SearchParameters(
Expand All @@ -204,11 +210,15 @@ def test_user_cannot_view_unpublished_but_show_unpublished_is_true(
When the advanced_search method is called with the show_unpublished parameter set to True
Then it should call the MarkLogic module with the show_unpublished parameter set to False and log a warning
"""
with patch.object(self.client, "invoke") as patched_invoke, patch.object(
self.client,
"user_can_view_unpublished_judgments",
return_value=False,
), patch.object(logging, "warning") as mock_logging:
with (
patch.object(self.client, "invoke") as patched_invoke,
patch.object(
self.client,
"user_can_view_unpublished_judgments",
return_value=False,
),
patch.object(logging, "warning") as mock_logging,
):
self.client.advanced_search(
SearchParameters(
query="my-query",
Expand Down
11 changes: 7 additions & 4 deletions tests/client/test_checkout_checkin_judgment.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ def test_checkout_judgment(self):
)

def test_checkout_judgment_with_midnight_timeout(self):
with patch.object(self.client, "eval") as mock_eval, patch.object(
self.client,
"calculate_seconds_until_midnight",
return_value=3600,
with (
patch.object(self.client, "eval") as mock_eval,
patch.object(
self.client,
"calculate_seconds_until_midnight",
return_value=3600,
),
):
uri = DocumentURIString("ewca/civ/2004/632")
annotation = "locked by A KITTEN"
Expand Down
47 changes: 30 additions & 17 deletions tests/client/test_eval_xslt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ def setUp(self):

@patch.dict(os.environ, {"XSLT_IMAGE_LOCATION": "imagepath"}, clear=True)
def test_eval_xslt_user_can_view_unpublished(self):
with patch.object(self.client, "eval") as mock_eval, patch.object(
self.client,
"user_can_view_unpublished_judgments",
return_value=True,
with (
patch.object(self.client, "eval") as mock_eval,
patch.object(
self.client,
"user_can_view_unpublished_judgments",
return_value=True,
),
):
uri = DocumentURIString("judgment/uri")
expected_vars: XsltTransformDict = {
Expand All @@ -38,11 +41,15 @@ def test_eval_xslt_user_can_view_unpublished(self):
def test_eval_xslt_user_cannot_view_unpublished(self):
"""The user is not permitted to see unpublished judgments but is attempting to view them
Set `show_unpublished` to false and log a warning"""
with patch.object(self.client, "eval") as mock_eval, patch.object(
self.client,
"user_can_view_unpublished_judgments",
return_value=False,
), patch.object(logging, "warning") as mock_logging:
with (
patch.object(self.client, "eval") as mock_eval,
patch.object(
self.client,
"user_can_view_unpublished_judgments",
return_value=False,
),
patch.object(logging, "warning") as mock_logging,
):
uri = DocumentURIString("judgment/uri")
expected_vars: XsltTransformDict = {
"uri": MarkLogicDocumentURIString("/judgment/uri.xml"),
Expand All @@ -62,10 +69,13 @@ def test_eval_xslt_user_cannot_view_unpublished(self):

@patch.dict(os.environ, {"XSLT_IMAGE_LOCATION": "imagepath"}, clear=True)
def test_eval_xslt_with_filename(self):
with patch.object(self.client, "eval") as mock_eval, patch.object(
self.client,
"user_can_view_unpublished_judgments",
return_value=True,
with (
patch.object(self.client, "eval") as mock_eval,
patch.object(
self.client,
"user_can_view_unpublished_judgments",
return_value=True,
),
):
uri = DocumentURIString("judgment/uri")
expected_vars: XsltTransformDict = {
Expand All @@ -87,10 +97,13 @@ def test_eval_xslt_with_filename(self):

@patch.dict(os.environ, {"XSLT_IMAGE_LOCATION": "imagepath"}, clear=True)
def test_eval_xslt_with_query(self):
with patch.object(self.client, "eval") as mock_eval, patch.object(
self.client,
"user_can_view_unpublished_judgments",
return_value=True,
with (
patch.object(self.client, "eval") as mock_eval,
patch.object(
self.client,
"user_can_view_unpublished_judgments",
return_value=True,
),
):
uri = DocumentURIString("judgment/uri")
query = "the query string"
Expand Down
11 changes: 7 additions & 4 deletions tests/client/test_get_set_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,13 @@ def test_set_document_date(self):
assert mock_eval.call_args.kwargs["vars"] == json.dumps(expected_vars)

def test_set_judgment_date_warn(self):
with patch.object(warnings, "warn") as mock_warn, patch.object(
self.client,
"eval",
) as mock_eval:
with (
patch.object(warnings, "warn") as mock_warn,
patch.object(
self.client,
"eval",
) as mock_eval,
):
uri = DocumentURIString("judgment/uri")
content = "2022-01-01"
expected_vars = {"uri": "/judgment/uri.xml", "content": "2022-01-01"}
Expand Down
7 changes: 4 additions & 3 deletions tests/client/test_save_copy_delete_judgment.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ def test_save_locked_judgment_xml(self):
When `Client.save_locked_judgment_xml` is called with these as arguments
Then the xquery in `update_locked_judgment.xqy` is called on the Marklogic db with those arguments
"""
with patch.object(caselawclient.Client, "validate_content_hash"), patch.object(
self.client, "eval"
) as mock_eval:
with (
patch.object(caselawclient.Client, "validate_content_hash"),
patch.object(self.client, "eval") as mock_eval,
):
uri = DocumentURIString("ewca/civ/2004/632")
judgment_str = "<root>My updated judgment</root>"
judgment_xml = judgment_str.encode("utf-8")
Expand Down
13 changes: 8 additions & 5 deletions tests/client/test_verify_show_unpublished.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ def setUp(self):
# and with them asking for unpublished judgments or not
def test_hide_published_if_unauthorised_and_user_asks_for_unpublished(self):
# User cannot view unpublished but is asking to view unpublished judgments
with patch.object(
self.client,
"user_can_view_unpublished_judgments",
return_value=False,
), patch.object(logging, "warning") as mock_logger:
with (
patch.object(
self.client,
"user_can_view_unpublished_judgments",
return_value=False,
),
patch.object(logging, "warning") as mock_logger,
):
result = self.client.verify_show_unpublished(True)
assert result is False
# Check the logger was called
Expand Down
21 changes: 12 additions & 9 deletions tests/models/documents/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,18 @@ def test_returns_true_when_enriched_recently_is_true_and_validates_against_schem
can_enrich,
):
document = Document(DocumentURIString("test/1234"), mock_api_client)
with patch.object(
Document,
"enriched_recently",
new_callable=PropertyMock,
) as mock_enriched_recently, patch.object(
Document,
"validates_against_schema",
new_callable=PropertyMock,
) as mock_validates_against_schema:
with (
patch.object(
Document,
"enriched_recently",
new_callable=PropertyMock,
) as mock_enriched_recently,
patch.object(
Document,
"validates_against_schema",
new_callable=PropertyMock,
) as mock_validates_against_schema,
):
mock_enriched_recently.return_value = enriched_recently
mock_validates_against_schema.return_value = validates_against_schema

Expand Down

0 comments on commit 56687b8

Please sign in to comment.