12345678910111213141516171819202122232425262728293031323334353637383940 |
- import pytest
- import requests
- @pytest.mark.usefixtures("unpaid_client")
- 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 == ""
- @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")
- assert len(caplog.records) is 0
- assert (
- built_url
- == "https://www.thesportsdb.com/api/v1/json/20923423/lookupevent.php?id=0"
- )
- 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"
- )
- assert request == {}
|