test_client.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import pytest
  2. import requests
  3. @pytest.mark.usefixtures("unpaid_client")
  4. class TestUnpaidClient:
  5. def test_default_client_version(self, unpaid_client):
  6. assert unpaid_client.API_VERSION is "v1"
  7. def test_build_url_unsupported_endpoint(self, unpaid_client, caplog):
  8. built_url = unpaid_client.get_lookup_event_url(id="0")
  9. assert caplog.records[0].levelname == "ERROR"
  10. assert caplog.records[0].msg == 'Endpoint "lookup_event" not supported'
  11. assert built_url == ""
  12. @pytest.mark.usefixtures("paid_client")
  13. class TestPaidClient:
  14. """A paid client is only distinguised by having an API key other tha '2'"""
  15. def test_build_url_supported_endpoint(self, paid_client, caplog):
  16. built_url = paid_client.get_lookup_event_url(id="0")
  17. assert len(caplog.records) is 0
  18. assert (
  19. built_url
  20. == "https://www.thesportsdb.com/api/v1/json/20923423/lookupevent.php?id=0"
  21. )
  22. def test_make_request_bad_url(self, paid_client):
  23. with pytest.raises(requests.exceptions.MissingSchema) as error:
  24. paid_client._make_request("bad-url")
  25. def test_make_request_html_response(self, paid_client, caplog):
  26. request = paid_client._make_request("https://www.google.com")
  27. assert caplog.records[0].levelname == "ERROR"
  28. assert (
  29. caplog.records[0].msg
  30. == "Received a non-JSON repsonse from request"
  31. )
  32. assert request == {}