Skip to content

Commit

Permalink
test(tests): fix incorrect patching of a method
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksonj04 committed Nov 13, 2024
1 parent dfa3455 commit f144447
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions tests/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,38 +126,36 @@ def test_eval_calls_request(self, MockPath):
mock_path_instance = MockPath.return_value
mock_path_instance.read_text.return_value = "mock-query"

self.client.session.request = MagicMock()

self.client.eval("mock-query-path.xqy", vars='{{"testvar":"test"}}')

self.client.session.request.assert_called_with(
"POST",
url=self.client._path_to_request_url("LATEST/eval"),
headers={
"Content-type": "application/x-www-form-urlencoded",
"Accept": "multipart/mixed",
},
data={"xquery": "mock-query", "vars": '{{"testvar":"test"}}'},
)
with patch.object(self.client.session, "request") as patched_request:
self.client.eval("mock-query-path.xqy", vars='{{"testvar":"test"}}')

patched_request.assert_called_with(
"POST",
url=self.client._path_to_request_url("LATEST/eval"),
headers={
"Content-type": "application/x-www-form-urlencoded",
"Accept": "multipart/mixed",
},
data={"xquery": "mock-query", "vars": '{{"testvar":"test"}}'},
)

@patch("caselawclient.Client.Path")
def test_invoke_calls_request(self, MockPath):
mock_path_instance = MockPath.return_value
mock_path_instance.read_text.return_value = "mock-query"

self.client.session.request = MagicMock()

self.client.invoke("mock-query-path.xqy", vars='{{"testvar":"test"}}')

self.client.session.request.assert_called_with(
"POST",
url=self.client._path_to_request_url("LATEST/invoke"),
headers={
"Content-type": "application/x-www-form-urlencoded",
"Accept": "multipart/mixed",
},
data={"module": "mock-query-path.xqy", "vars": '{{"testvar":"test"}}'},
)
with patch.object(self.client.session, "request") as patched_request:
self.client.invoke("mock-query-path.xqy", vars='{{"testvar":"test"}}')

patched_request.assert_called_with(
"POST",
url=self.client._path_to_request_url("LATEST/invoke"),
headers={
"Content-type": "application/x-www-form-urlencoded",
"Accept": "multipart/mixed",
},
data={"module": "mock-query-path.xqy", "vars": '{{"testvar":"test"}}'},
)

def test_format_uri(self):
uri = DocumentURIString("/ewca/2022/123")
Expand Down

0 comments on commit f144447

Please sign in to comment.