From 0e121e194da1ab722ae5947f163501d8e9c5d517 Mon Sep 17 00:00:00 2001 From: Martin Malina Date: Mon, 25 Nov 2024 14:46:57 +0100 Subject: [PATCH] fix(RELEASE-1285): add pyxis.patch tests Signed-off-by: Martin Malina --- pyxis/test_pyxis.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pyxis/test_pyxis.py b/pyxis/test_pyxis.py index 3e6a216..c172f65 100644 --- a/pyxis/test_pyxis.py +++ b/pyxis/test_pyxis.py @@ -72,6 +72,37 @@ def test_post_error(mock_get_session: MagicMock) -> None: pyxis.post(API_URL, {}) +@patch("pyxis.session", None) +@patch("pyxis._get_session") +def test_patch(mock_get_session: MagicMock) -> None: + resp = pyxis.patch(API_URL, {}) + + assert resp == mock_get_session.return_value.patch.return_value + mock_get_session.assert_called_once_with() + + +@patch("pyxis.session") +@patch("pyxis._get_session") +def test_patch_existing_session(mock_get_session, mock_session: MagicMock) -> None: + resp = pyxis.patch(API_URL, {}) + + assert resp == mock_session.patch.return_value + mock_get_session.assert_not_called() + + +@patch("pyxis.session", None) +@patch("pyxis._get_session") +def test_patch_error(mock_get_session: MagicMock) -> None: + response = Response() + response.status_code = 400 + mock_get_session.return_value.patch.return_value.raise_for_status.side_effect = HTTPError( + response=response + ) + + with pytest.raises(HTTPError): + pyxis.patch(API_URL, {}) + + @patch("pyxis.post") def test_graphql_query__success(mock_post: MagicMock): mock_data = {