Begun adding basic pytest testings
This commit is contained in:
parent
5e56b6fbff
commit
5e6a4731a4
9
.gitignore
vendored
9
.gitignore
vendored
@ -1,8 +1,7 @@
|
||||
# Common Ignores
|
||||
.vscode
|
||||
__pycache__
|
||||
.pytest_cache
|
||||
dist
|
||||
|
||||
|
||||
# Personal Ignores
|
||||
# Mostly notes and testing
|
||||
dist
|
||||
# Minor testing
|
||||
test.py
|
@ -1,9 +1,6 @@
|
||||
import json
|
||||
import requests
|
||||
|
||||
from ergast_py.models.circuit import Circuit
|
||||
from ergast_py.models.constructor import Constructor
|
||||
from ergast_py.models.driver import Driver
|
||||
from uritemplate import URITemplate
|
||||
|
||||
host = 'https://ergast.com/api'
|
||||
@ -123,7 +120,7 @@ class Requester():
|
||||
}
|
||||
|
||||
|
||||
def run_request(self, season, round, criteria, resource, value, limit, offset) -> dict:
|
||||
def run_request(self, season, round, criteria, resource, value=None, limit=None, offset=None) -> dict:
|
||||
""" Takes values to run the request and return a dict """
|
||||
url_tmpl = URITemplate('https://ergast.com/api{/series}{/season}{/round}'
|
||||
'{/criteria*}{/resource}{/value}.json{?limit,offset}')
|
||||
@ -132,7 +129,11 @@ class Requester():
|
||||
criteria=criteria, resource=resource,
|
||||
value=value, limit=limit, offset=offset)
|
||||
|
||||
return json.loads(requests.get(url).text)
|
||||
response = requests.get(url)
|
||||
if response.status_code == 200:
|
||||
return json.loads(response.text)
|
||||
else:
|
||||
raise Exception(f"Failed with status code {response.status_code}. Error: {response.reason}")
|
||||
|
||||
#
|
||||
# Race and Results
|
||||
|
8
tests/test_ergast.py
Normal file
8
tests/test_ergast.py
Normal file
@ -0,0 +1,8 @@
|
||||
import ergast_py
|
||||
|
||||
class TestErgast():
|
||||
"""
|
||||
Tests for the Ergast class
|
||||
"""
|
||||
|
||||
e = ergast_py.Ergast()
|
@ -1,5 +1,10 @@
|
||||
from ergast_py import __version__
|
||||
|
||||
|
||||
def test_version():
|
||||
assert __version__ == '0.1.0'
|
||||
class TestErgastPy():
|
||||
"""
|
||||
Tests for the Ergast-py package
|
||||
"""
|
||||
|
||||
def test_version(self):
|
||||
assert __version__ == '0.1.0'
|
||||
|
16
tests/test_requester.py
Normal file
16
tests/test_requester.py
Normal file
@ -0,0 +1,16 @@
|
||||
import ergast_py
|
||||
import pytest
|
||||
|
||||
class TestRequester():
|
||||
"""
|
||||
Tests for the Requester class
|
||||
"""
|
||||
|
||||
r = ergast_py.Requester()
|
||||
|
||||
def test_run_request(self):
|
||||
self.r.run_request(season=2008, round=5, criteria=["drivers", "alonso"], resource="driverStandings")
|
||||
|
||||
def test_run_request_fails(self):
|
||||
with pytest.raises(Exception):
|
||||
self.r.run_request(season=2008, round=5, criteria=["drivers", "alonso"], resource="bad request")
|
8
tests/test_type_constructor.py
Normal file
8
tests/test_type_constructor.py
Normal file
@ -0,0 +1,8 @@
|
||||
import ergast_py
|
||||
|
||||
class TestTypeConstructor():
|
||||
"""
|
||||
Tests for the Type Constructor class
|
||||
"""
|
||||
|
||||
t = ergast_py.TypeConstructor()
|
Reference in New Issue
Block a user