import pytest import requests from mock import patch from pysportsdb.exceptions import PateronOnlyEndpoint @pytest.mark.usefixtures("unpaid_client") class TestUnpaidClient: def test_default_client_version(self, unpaid_client): assert unpaid_client.API_VERSION is "v1" @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'""" @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 response == {} def test_make_request_bad_url(self, paid_client): with pytest.raises(requests.exceptions.MissingSchema) as error: paid_client._make_request("bad-url") def test_make_request_html_response(self, paid_client, caplog): request = paid_client._make_request("https://www.google.com") assert caplog.records[0].levelname == "ERROR" assert ( caplog.records[0].msg == "Received a non-JSON repsonse from request, check API key" ) assert request == {}