]> Nutra Git (v2) - nutratech/cli.git/commitdiff
cover api
authorShane Jaroch <chown_tee@proton.me>
Fri, 19 Apr 2024 18:05:50 +0000 (14:05 -0400)
committerShane Jaroch <chown_tee@proton.me>
Fri, 19 Apr 2024 18:05:50 +0000 (14:05 -0400)
tests/services/test_api.py

index 5b33e9b0cb63e10fb8e4a3900a1c1fa9dc29fedd..73bede9e497588e5e225174c91359c6403f6c3d9 100644 (file)
@@ -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