From ef6264852b6849a9129539f5aa28ea1ec933cb91 Mon Sep 17 00:00:00 2001 From: Shane Jaroch Date: Fri, 19 Apr 2024 14:05:50 -0400 Subject: [PATCH] cover api --- tests/services/test_api.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tests/services/test_api.py b/tests/services/test_api.py index 5b33e9b..73bede9 100644 --- a/tests/services/test_api.py +++ b/tests/services/test_api.py @@ -5,11 +5,12 @@ Created on Fri Apr 12 16:14:03 2024 @author: shane """ import unittest +from unittest.mock import patch import pytest import requests_mock as r_mock -from ntclient.services.api import URLS_API, cache_mirrors +from ntclient.services.api import URLS_API, ApiClient, cache_mirrors if __name__ == "__main__": pytest.main() @@ -30,19 +31,25 @@ def test_cache_mirrors_failing_mirrors_return_empty_string( requests_mock.get(url, status_code=503) assert cache_mirrors() == str() + class TestApiClient(unittest.TestCase): """Test the ApiClient class.""" + with patch( + "ntclient.services.api.cache_mirrors", return_value="https://api.nutra.tk" + ): + api_client = ApiClient() + def test_post(self) -> None: """Test the post method.""" with r_mock.Mocker() as m: - m.post("https://api.nutra.tk/endpoint", status_code=200) - client = cache_mirrors() - assert client.post("endpoint", {}) is not None + m.post("https://api.nutra.tk/test-endpoint", json={}) + res = TestApiClient.api_client.post("test-endpoint", {}) + assert res def test_post_bug(self) -> None: """Test the post_bug method.""" with r_mock.Mocker() as m: - m.post("https://api.nutra.tk/endpoint", status_code=200) - client = cache_mirrors() - assert client.post_bug({}) is not None \ No newline at end of file + m.post("https://api.nutra.tk/bug", json={}) + res = TestApiClient.api_client.post_bug({}) + assert res -- 2.52.0