Skip to content

Commit

Permalink
test(classes_test.py): add tests for _request and download_file
Browse files Browse the repository at this point in the history
  • Loading branch information
dobizz committed Nov 5, 2023
1 parent 513b5f6 commit 0a1c75a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
32 changes: 30 additions & 2 deletions tests/classes_test.py
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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)
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pytest

from pyplayht.classes import Client


@pytest.fixture
def client() -> Client:
return Client()

0 comments on commit 0a1c75a

Please sign in to comment.