test_spec.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import pytest
  2. import requests
  3. from pysportsdb.exceptions import ParameterNotAllowed, PateronOnlyEndpoint
  4. @pytest.mark.usefixtures("unpaid_spec")
  5. class TestdSpec:
  6. def test_default_api_key(self, unpaid_spec):
  7. assert unpaid_spec.API_KEY == "2"
  8. def test_lookup(self, unpaid_spec):
  9. with pytest.raises(PateronOnlyEndpoint):
  10. unpaid_spec.get_search_teams_url(t="Arsenal")
  11. def test_check_livescore_not_allowed(self, unpaid_spec):
  12. with pytest.raises(PateronOnlyEndpoint):
  13. unpaid_spec.get_livescore_url(s="Soccer")
  14. def test_no_params_allowed(self, unpaid_spec):
  15. with pytest.raises(ParameterNotAllowed):
  16. unpaid_spec.get_list_all_sports_url(s="")
  17. def test_wrong_params_not_allowed(self, unpaid_spec):
  18. with pytest.raises(ParameterNotAllowed):
  19. unpaid_spec.get_lookup_player_contracts_url(id="234", k="34234")
  20. def test_check_good_params(self, unpaid_spec):
  21. url = unpaid_spec.get_lookup_player_contracts_url(id="a9234")
  22. assert (
  23. url
  24. == "https://www.thesportsdb.com/api/v1/json/2/lookupcontracts.php?id=a9234"
  25. )
  26. def test_check_not_protected(self, unpaid_spec):
  27. url = unpaid_spec.get_list_all_sports_url()
  28. assert (
  29. url == "https://www.thesportsdb.com/api/v1/json/2/all_sports.php"
  30. )
  31. @pytest.mark.usefixtures("paid_spec")
  32. class TestPaidSpec:
  33. def test_default_api_key(self, paid_spec):
  34. assert paid_spec.API_KEY != "2"
  35. def test_lookup_paid_endpoint(self, paid_spec):
  36. url = paid_spec.get_search_teams_url(t="Arsenal")
  37. assert (
  38. url
  39. == "https://www.thesportsdb.com/api/v1/json/NOTNULL/searchteams.php?t=Arsenal"
  40. )
  41. def test_check_livescore_allowed(self, paid_spec):
  42. url = paid_spec.get_livescore_url(s="Soccer")
  43. assert (
  44. url
  45. == "https://www.thesportsdb.com/api/v2/json/NOTNULL/livescore.php?s=Soccer"
  46. )