Began type_constructor tests
This commit is contained in:
parent
fb792337cf
commit
21d2d6247b
@ -112,8 +112,11 @@ class Requester():
|
|||||||
"criteria": criteria
|
"criteria": criteria
|
||||||
}
|
}
|
||||||
|
|
||||||
def _run_request(self, season, round_no, criteria, resource, value=None, limit=None,
|
def run_request(self, season, round_no, criteria, resource, value=None, limit=None,
|
||||||
offset=None) -> dict:
|
offset=None) -> dict:
|
||||||
|
"""
|
||||||
|
Run a request against the API and return the JSON dictionary result
|
||||||
|
"""
|
||||||
url_tmpl = URITemplate('https://ergast.com/api{/series}{/season}{/round}'
|
url_tmpl = URITemplate('https://ergast.com/api{/series}{/season}{/round}'
|
||||||
'{/criteria*}{/resource}{/value}.json{?limit,offset}')
|
'{/criteria*}{/resource}{/value}.json{?limit,offset}')
|
||||||
url = url_tmpl.expand(host=HOST, series=SERIES,
|
url = url_tmpl.expand(host=HOST, series=SERIES,
|
||||||
@ -131,7 +134,7 @@ class Requester():
|
|||||||
params = get_params(param)
|
params = get_params(param)
|
||||||
filters = get_criteria(params, resource)
|
filters = get_criteria(params, resource)
|
||||||
|
|
||||||
return self._run_request(season=params["season"], round_no=params["round"],
|
return self.run_request(season=params["season"], round_no=params["round"],
|
||||||
criteria=filters["criteria"], resource=filters["resource"],
|
criteria=filters["criteria"], resource=filters["resource"],
|
||||||
value=filters["value"], limit=params["paging"]["limit"],
|
value=filters["value"], limit=params["paging"]["limit"],
|
||||||
offset=params["paging"]["offset"])
|
offset=params["paging"]["offset"])
|
||||||
|
@ -6,6 +6,7 @@ authors = ["Samuel Roach <samuelroach.2000@gmail.com>"]
|
|||||||
repository = "https://github.com/Samuel-Roach/ergast-py"
|
repository = "https://github.com/Samuel-Roach/ergast-py"
|
||||||
license = "GPL-3.0-only"
|
license = "GPL-3.0-only"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
include = ["img/banner.png"]
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.10"
|
python = "^3.10"
|
||||||
|
@ -52,4 +52,15 @@ SILVERSTONE = {
|
|||||||
"locality":"Silverstone",
|
"locality":"Silverstone",
|
||||||
"country":"UK"
|
"country":"UK"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LECLERC = {
|
||||||
|
"driverId":"leclerc",
|
||||||
|
"permanentNumber":"16",
|
||||||
|
"code":"LEC",
|
||||||
|
"url":"http://en.wikipedia.org/wiki/Charles_Leclerc",
|
||||||
|
"givenName":"Charles",
|
||||||
|
"familyName":"Leclerc",
|
||||||
|
"dateOfBirth":"1997-10-16",
|
||||||
|
"nationality":"Monegasque"
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import ergast_py
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import tests.test_constants as test_constants
|
import tests.test_constants as test_constants
|
||||||
|
from ergast_py.requester import Requester
|
||||||
|
|
||||||
|
|
||||||
class TestRequester():
|
class TestRequester():
|
||||||
@ -11,7 +11,7 @@ class TestRequester():
|
|||||||
<Note>
|
<Note>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
r = ergast_py.Requester()
|
r = Requester()
|
||||||
|
|
||||||
def _construct_test_params(self, season=None, seasons=None, round=None, driver=None, constructor=None, grid=None,
|
def _construct_test_params(self, season=None, seasons=None, round=None, driver=None, constructor=None, grid=None,
|
||||||
qualifying=None, sprint=None, result=None, fastest=None, circuit=None, status=None,
|
qualifying=None, sprint=None, result=None, fastest=None, circuit=None, status=None,
|
||||||
@ -39,12 +39,12 @@ class TestRequester():
|
|||||||
|
|
||||||
|
|
||||||
def test_run_request(self):
|
def test_run_request(self):
|
||||||
self.r.run_request(season=2008, round=5, criteria=["drivers", "alonso"], resource="driverStandings")
|
self.r.run_request(season=2008, round_no=5, criteria=["drivers", "alonso"], resource="driverStandings")
|
||||||
|
|
||||||
|
|
||||||
def test_run_request_fails(self):
|
def test_run_request_fails(self):
|
||||||
with pytest.raises(Exception):
|
with pytest.raises(Exception):
|
||||||
self.r.run_request(season=2008, round=5, criteria=["drivers", "alonso"], resource="bad request")
|
self.r.run_request(season=2008, round_no=5, criteria=["drivers", "alonso"], resource="bad request")
|
||||||
|
|
||||||
|
|
||||||
def test_get_circuit(self):
|
def test_get_circuit(self):
|
||||||
|
@ -1,95 +1,204 @@
|
|||||||
import ergast_py
|
from copyreg import constructor
|
||||||
|
import datetime
|
||||||
|
from ergast_py.models.average_speed import AverageSpeed
|
||||||
|
|
||||||
|
from ergast_py.models.circuit import Circuit
|
||||||
|
from ergast_py.models.constructor import Constructor
|
||||||
|
from ergast_py.models.driver import Driver
|
||||||
|
from ergast_py.models.fastest_lap import FastestLap
|
||||||
|
from ergast_py.models.location import Location
|
||||||
|
from ergast_py.models.result import Result
|
||||||
|
from ergast_py.requester import Requester
|
||||||
|
from ergast_py.type_constructor import TypeConstructor
|
||||||
|
|
||||||
|
import tests.test_constants as test_constants
|
||||||
|
|
||||||
|
|
||||||
class TestTypeConstructor():
|
class TestTypeConstructor():
|
||||||
"""
|
"""
|
||||||
Tests for the Type Constructor class
|
Tests for the Type Constructor class
|
||||||
"""
|
"""
|
||||||
|
|
||||||
t = ergast_py.TypeConstructor()
|
t = TypeConstructor()
|
||||||
|
r = Requester()
|
||||||
|
|
||||||
def test_construct_location(self):
|
def _assert_locations(self, expected: Location, actual: Location):
|
||||||
pass
|
assert actual.latitude == expected.latitude
|
||||||
|
assert actual.longitude == expected.longitude
|
||||||
|
assert actual.locality == expected.locality
|
||||||
|
assert actual.country == expected.country
|
||||||
|
|
||||||
|
def _assert_circuits(self, expected: Circuit, actual: Circuit):
|
||||||
|
assert actual.circuit_id == expected.circuit_id
|
||||||
|
assert actual.url == expected.url
|
||||||
|
assert actual.circuit_name == expected.circuit_name
|
||||||
|
self._assert_locations(expected.location, actual.location)
|
||||||
|
|
||||||
|
def _assert_constructors(self, expected: Constructor, actual: Constructor):
|
||||||
|
assert actual.constructor_id == expected.constructor_id
|
||||||
|
assert actual.url == expected.url
|
||||||
|
assert actual.name == expected.name
|
||||||
|
assert actual.nationality == expected.nationality
|
||||||
|
|
||||||
|
def _assert_drivers(self, expected: Driver, actual: Driver):
|
||||||
|
assert actual.driver_id == expected.driver_id
|
||||||
|
assert actual.code == expected.code
|
||||||
|
assert actual.url == expected.url
|
||||||
|
assert actual.given_name == expected.given_name
|
||||||
|
assert actual.family_name == expected.family_name
|
||||||
|
assert actual.date_of_birth == expected.date_of_birth
|
||||||
|
assert actual.nationality == expected.nationality
|
||||||
|
assert actual.permanent_number == expected.permanent_number
|
||||||
|
|
||||||
|
def _assert_average_speeds(self, expected: AverageSpeed, actual: AverageSpeed):
|
||||||
|
assert actual.units == expected.units
|
||||||
|
assert actual.speed == expected.speed
|
||||||
|
|
||||||
|
def _assert_fastest_laps(self, expected: FastestLap, actual: FastestLap):
|
||||||
|
assert actual.rank == expected.rank
|
||||||
|
assert actual.lap == expected.lap
|
||||||
|
assert actual.time == expected.time
|
||||||
|
assert actual.average_speed == expected.average_speed
|
||||||
|
|
||||||
|
def _assert_results(self, expected: Result, actual: Result):
|
||||||
|
assert actual.number == expected.number
|
||||||
|
assert actual.position == expected.position
|
||||||
|
assert actual.position_text == expected.position_text
|
||||||
|
assert actual.points == expected.points
|
||||||
|
self._assert_drivers(expected.driver, actual.driver)
|
||||||
|
self._assert_constructors(expected.constructor, actual.constructor)
|
||||||
|
assert actual.grid == expected.grid
|
||||||
|
assert actual.laps == expected.laps
|
||||||
|
assert actual.status == expected.status
|
||||||
|
assert actual.time == expected.time
|
||||||
|
self._assert_fastest_laps(expected.fastest_lap, actual.fastest_lap)
|
||||||
|
assert actual.qual_1 == expected.qual_1
|
||||||
|
assert actual.qual_2 == expected.qual_2
|
||||||
|
assert actual.qual_3 == expected.qual_3
|
||||||
|
|
||||||
|
#
|
||||||
|
# Tests
|
||||||
|
#
|
||||||
|
|
||||||
def test_construct_circuit(self):
|
def test_construct_circuit(self):
|
||||||
pass
|
params = {
|
||||||
|
"circuitId":"bahrain",
|
||||||
|
"url":"http://en.wikipedia.org/wiki/Bahrain_International_Circuit",
|
||||||
|
"circuitName":"Bahrain International Circuit",
|
||||||
|
"Location":{
|
||||||
|
"lat":"26.0325",
|
||||||
|
"long":"50.5106",
|
||||||
|
"locality":"Sakhir",
|
||||||
|
"country":"Bahrain"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def test_construct_circuits(self):
|
location = Location(latitude=26.0325,
|
||||||
pass
|
longitude=50.5106,
|
||||||
|
locality="Sakhir",
|
||||||
|
country="Bahrain")
|
||||||
|
|
||||||
|
expected = Circuit(circuit_id="bahrain",
|
||||||
|
url="http://en.wikipedia.org/wiki/Bahrain_International_Circuit",
|
||||||
|
circuit_name="Bahrain International Circuit",
|
||||||
|
location=location)
|
||||||
|
|
||||||
|
actual = self.t.construct_circuit(params)
|
||||||
|
self._assert_circuits(expected, actual)
|
||||||
|
|
||||||
def test_construct_constructor(self):
|
def test_construct_constructor(self):
|
||||||
pass
|
params = test_constants.ALPINE
|
||||||
|
|
||||||
def test_construct_constructors(self):
|
expected = Constructor(constructor_id="alpine",
|
||||||
pass
|
url="http://en.wikipedia.org/wiki/Alpine_F1_Team",
|
||||||
|
name="Alpine F1 Team",
|
||||||
|
nationality="French")
|
||||||
|
|
||||||
|
actual = self.t.construct_constructor(params)
|
||||||
|
self._assert_constructors(expected, actual)
|
||||||
|
|
||||||
def test_construct_driver(self):
|
def test_construct_driver(self):
|
||||||
pass
|
params = test_constants.ALONSO
|
||||||
|
|
||||||
def test_construct_drivers(self):
|
expected = Driver(driver_id="alonso",
|
||||||
pass
|
code="ALO",
|
||||||
|
url="http://en.wikipedia.org/wiki/Fernando_Alonso",
|
||||||
|
given_name="Fernando",
|
||||||
|
family_name="Alonso",
|
||||||
|
date_of_birth=datetime.date(year=1981, month=7, day=29),
|
||||||
|
nationality="Spanish",
|
||||||
|
permanent_number=14
|
||||||
|
)
|
||||||
|
|
||||||
def test_construct_race(self):
|
actual = self.t.construct_driver(params)
|
||||||
pass
|
self._assert_drivers(expected, actual)
|
||||||
|
|
||||||
def test_construct_races(self):
|
def test_construct_races(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_construct_result(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_construct_results(self):
|
def test_construct_results(self):
|
||||||
pass
|
params ={
|
||||||
|
"number":"16",
|
||||||
|
"position":"1",
|
||||||
|
"positionText":"1",
|
||||||
|
"points":"26",
|
||||||
|
"Driver": test_constants.LECLERC,
|
||||||
|
"Constructor": test_constants.FERRARI,
|
||||||
|
"grid":"1",
|
||||||
|
"laps":"57",
|
||||||
|
"status":"Finished",
|
||||||
|
"Time":{
|
||||||
|
"millis":"5853584",
|
||||||
|
"time":"1:37:33.584"
|
||||||
|
},
|
||||||
|
"FastestLap":{
|
||||||
|
"rank":"1",
|
||||||
|
"lap":"51",
|
||||||
|
"Time":{
|
||||||
|
"time":"1:34.570"
|
||||||
|
},
|
||||||
|
"AverageSpeed":{
|
||||||
|
"units":"kph",
|
||||||
|
"speed":"206.018"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def test_construct_fastest_lap(self):
|
avg_speed = AverageSpeed(units="kph", speed=206.018)
|
||||||
pass
|
fastest_lap = FastestLap(rank=1, lap=51,
|
||||||
|
time=datetime.time(minute=1, second=34, microsecond=570000),
|
||||||
|
average_speed=avg_speed)
|
||||||
|
driver = Driver(driver_id="leclerc", code="LEC",
|
||||||
|
url="http://en.wikipedia.org/wiki/Charles_Leclerc",
|
||||||
|
given_name="Charles", family_name="Leclerc",
|
||||||
|
date_of_birth=datetime.date(year=1997, month=10, day=16),
|
||||||
|
nationality="Monegasque", permanent_number=16)
|
||||||
|
constructor = Constructor(constructor_id="ferrari",
|
||||||
|
url="http://en.wikipedia.org/wiki/Scuderia_Ferrari",
|
||||||
|
name="Ferrari", nationality="Italian")
|
||||||
|
|
||||||
|
expected = Result(number=16, position=1, position_text="1", points=26, driver=driver,
|
||||||
|
constructor=constructor, grid=1, laps=57, status=1,
|
||||||
|
time=datetime.time(hour=1, minute=37, second=33, microsecond=584000),
|
||||||
|
fastest_lap=fastest_lap, qual_1=None, qual_2=None, qual_3=None)
|
||||||
|
|
||||||
def test_construct_average_speed(self):
|
actual = self.t.construct_result(params)
|
||||||
pass
|
self._assert_results(expected, actual)
|
||||||
|
|
||||||
def test_construct_pit_stop(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_construct_pit_stops(self):
|
def test_construct_pit_stops(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_construct_lap(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_construct_laps(self):
|
def test_construct_laps(self):
|
||||||
pass
|
# Check Timings too
|
||||||
|
|
||||||
def test_construct_timing(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_construct_timings(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_construct_season(self):
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_construct_seasons(self):
|
def test_construct_seasons(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_construct_status(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_construct_statuses(self):
|
def test_construct_statuses(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_construct_driver_standing(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_construct_driver_standings(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_construct_constructor_standing(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_construct_constructor_standings(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_construct_standings_list(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_construct_standings_lists(self):
|
def test_construct_standings_lists(self):
|
||||||
|
# Check Driver Standings
|
||||||
|
# Check constructor standings
|
||||||
pass
|
pass
|
||||||
|
Reference in New Issue
Block a user