diff --git a/tests/classes_test.py b/tests/classes_test.py index 7683fbb..eb57bf3 100644 --- a/tests/classes_test.py +++ b/tests/classes_test.py @@ -1,8 +1,13 @@ +from http import HTTPStatus +from unittest.mock import Mock, patch + +import pytest +import requests + from pyplayht.classes import Client -def test_client(): - client = Client() +def test_client(client: Client): # check for available methods assert hasattr(client, "get_voices") and callable(client.get_voices) assert hasattr(client, "new_conversion_job") and callable( @@ -12,3 +17,26 @@ def test_client(): client.get_coversion_job_status, ) assert hasattr(client, "download_file") and callable(client.download_file) + + +@pytest.mark.parametrize( + "method", + [ + "GET", + "POST", + ], +) +def test_request(method: str, client: Client): + response = client._request( + method=method, path=f"https://postman-echo.com/{method.lower()}" + ) + assert isinstance(response, requests.Response) + assert response.status_code == HTTPStatus.OK + + +def test_download_file(client: Client): + mock_request = Mock() + mock_request.content = bytes() + with patch("pyplayht.classes.Client._request", return_value=mock_request): + response = client.download_file("http://127.0.0.1/test_path") + assert isinstance(response, bytes) diff --git a/tests/conftest.py b/tests/conftest.py index e69de29..ed6bd81 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -0,0 +1,8 @@ +import pytest + +from pyplayht.classes import Client + + +@pytest.fixture +def client() -> Client: + return Client()