diff --git a/tests/client/test_client.py b/tests/client/test_client.py index 8586c341..0f51d509 100644 --- a/tests/client/test_client.py +++ b/tests/client/test_client.py @@ -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")