Colin Powell 2 rokov pred
rodič
commit
b87b52bbb6
1 zmenil súbory, kde vykonal 18 pridanie a 12 odobranie
  1. 18 12
      tests/test_client.py

+ 18 - 12
tests/test_client.py

@@ -1,5 +1,8 @@
 import pytest
 import requests
+from mock import patch
+
+from pysportsdb.exceptions import PateronOnlyEndpoint
 
 
 @pytest.mark.usefixtures("unpaid_client")
@@ -7,24 +10,27 @@ class TestUnpaidClient:
     def test_default_client_version(self, unpaid_client):
         assert unpaid_client.API_VERSION is "v1"
 
-    def test_build_url_unsupported_endpoint(self, unpaid_client, caplog):
-        built_url = unpaid_client.get_lookup_event_url(id="0")
-        assert caplog.records[0].levelname == "ERROR"
-        assert caplog.records[0].msg == 'Endpoint "lookup_event" not supported'
-        assert built_url == ""
+    @patch("pysportsdb.TheSportsDbClient._make_request")
+    def test_build_url_unsupported_endpoint(
+        self, mock_make_request, unpaid_client, caplog
+    ):
+        mock_make_request.response = {}
+        with pytest.raises(PateronOnlyEndpoint):
+            response = unpaid_client.lookup_event(event_id="0")
 
 
 @pytest.mark.usefixtures("paid_client")
 class TestPaidClient:
     """A paid client is only distinguised by having an API key other tha '2'"""
 
-    def test_build_url_supported_endpoint(self, paid_client, caplog):
-        built_url = paid_client.get_lookup_event_url(id="0")
+    @patch("pysportsdb.TheSportsDbClient._make_request")
+    def test_build_url_supported_endpoint(
+        self, mock_make_request, paid_client, caplog
+    ):
+        mock_make_request.return_value = {}
+        response = paid_client.lookup_event(event_id="0")
         assert len(caplog.records) is 0
-        assert (
-            built_url
-            == "https://www.thesportsdb.com/api/v1/json/20923423/lookupevent.php?id=0"
-        )
+        assert response == {}
 
     def test_make_request_bad_url(self, paid_client):
         with pytest.raises(requests.exceptions.MissingSchema) as error:
@@ -35,6 +41,6 @@ class TestPaidClient:
         assert caplog.records[0].levelname == "ERROR"
         assert (
             caplog.records[0].msg
-            == "Received a non-JSON repsonse from request"
+            == "Received a non-JSON repsonse from request, check API key"
         )
         assert request == {}