From 133702dc1d9091c5bb82a9f2276c30f447ea7f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Kub=C3=AD=C4=8Dek?= Date: Wed, 12 Mar 2025 21:49:10 +0100 Subject: [PATCH] test_superfaktura_api: fix format --- test/test_superfaktura_api.py | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/test/test_superfaktura_api.py b/test/test_superfaktura_api.py index c4e295e..7255bc3 100644 --- a/test/test_superfaktura_api.py +++ b/test/test_superfaktura_api.py @@ -10,21 +10,27 @@ from superfaktura.superfaktura_api import ( SuperFakturaAPIMissingCredentialsException, ) + @pytest.fixture def api(): - with patch.dict(os.environ, { - "SUPERFAKTURA_API_KEY": "test_key", - "SUPERFAKTURA_API_URL": "https://api.superfaktura.cz", - "SUPERFAKTURA_API_EMAIL": "test_email", - "SUPERFAKTURA_API_COMPANY_ID": "test_company_id" - }): + with patch.dict( + os.environ, + { + "SUPERFAKTURA_API_KEY": "test_key", + "SUPERFAKTURA_API_URL": "https://api.superfaktura.cz", + "SUPERFAKTURA_API_EMAIL": "test_email", + "SUPERFAKTURA_API_COMPANY_ID": "test_company_id", + }, + ): return SuperFakturaAPI() + def test_missing_credentials(): with patch.dict(os.environ, {}, clear=True): with pytest.raises(SuperFakturaAPIMissingCredentialsException): SuperFakturaAPI() + def test_get(api): with patch("requests.get") as mock_get: mock_get.return_value.status_code = 200 @@ -32,12 +38,14 @@ def test_get(api): response = api.get("test_endpoint") assert response == {"data": "test"} + def test_get_failure(api): with patch("requests.get") as mock_get: mock_get.return_value.status_code = 404 with pytest.raises(SuperFakturaAPIException): api.get("test_endpoint") + def test_download(api): with patch("requests.get") as mock_get: mock_get.return_value.status_code = 200 @@ -47,6 +55,7 @@ def test_download(api): api.download("test_endpoint", f) mock_file().write.assert_called_once_with(b"test_content") + def test_download_failure(api): with patch("requests.get") as mock_get: mock_get.return_value.status_code = 404 @@ -55,6 +64,7 @@ def test_download_failure(api): with pytest.raises(SuperFakturaAPIException): api.download("test_endpoint", f) + def test_post(api): with patch("requests.post") as mock_post: mock_post.return_value.status_code = 200 @@ -62,6 +72,7 @@ def test_post(api): response = api.post("test_endpoint", '{"name": "Example"}') assert response == {"data": "test"} + def test_post_failure(api): with patch("requests.post") as mock_post: mock_post.return_value.status_code = 404 @@ -69,15 +80,21 @@ def test_post_failure(api): with pytest.raises(SuperFakturaAPIException): api.post("test_endpoint", '{"name": "Example"}') + def test_get_invalid_json(api): with patch("requests.get") as mock_get: mock_response = MagicMock() mock_response.status_code = 200 - mock_response.json.side_effect = requests.exceptions.JSONDecodeError("msg", "doc", 0) + mock_response.json.side_effect = requests.exceptions.JSONDecodeError( + "msg", "doc", 0 + ) mock_get.return_value = mock_response - with pytest.raises(SuperFakturaAPIException, match="Unable to decode response as JSON"): + with pytest.raises( + SuperFakturaAPIException, match="Unable to decode response as JSON" + ): api.get("test_endpoint") + def test_download_not_writable_descriptor(api): with patch("requests.get") as mock_get: mock_get.return_value.status_code = 200