Finished type_constrcutor base tests

This commit is contained in:
Samuel Roach 2022-06-11 00:22:05 +01:00
parent 664ebcff98
commit 1f3ee480b4
2 changed files with 162 additions and 17 deletions

View File

@ -64,3 +64,15 @@ LECLERC = {
"dateOfBirth":"1997-10-16",
"nationality":"Monegasque"
}
BAHRAIN = {
"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"
}
}

View File

@ -1,15 +1,24 @@
from copyreg import constructor
import datetime
from this import d
from ergast_py.constants import expected
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.constructor_standing import ConstructorStanding
from ergast_py.models.driver import Driver
from ergast_py.models.driver_standing import DriverStanding
from ergast_py.models.fastest_lap import FastestLap
from ergast_py.models.location import Location
from ergast_py.models.pit_stop import PitStop
from ergast_py.models.race import Race
from ergast_py.models.result import Result
from ergast_py.models.season import Season
from ergast_py.models.standings_list import StandingsList
from ergast_py.models.status import Status
from ergast_py.models.timing import Timing
from ergast_py.models.lap import Lap
from ergast_py.requester import Requester
from ergast_py.type_constructor import TypeConstructor
@ -29,17 +38,7 @@ class TestTypeConstructor():
#
def test_construct_circuit(self):
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"
}
}]
params = [test_constants.BAHRAIN]
location = Location(latitude=26.0325,
longitude=50.5106,
@ -79,7 +78,54 @@ class TestTypeConstructor():
assert expected == self.t.construct_drivers(params)
def test_construct_races(self):
pass
params = [{
"season":"2022",
"round":"1",
"url":"http://en.wikipedia.org/wiki/2022_Bahrain_Grand_Prix",
"raceName":"Bahrain Grand Prix",
"Circuit": test_constants.BAHRAIN,
"date":"2022-03-20",
"time":"15:00:00Z",
"FirstPractice":{
"date":"2022-03-18",
"time":"12:00:00Z"
},
"SecondPractice":{
"date":"2022-03-18",
"time":"15:00:00Z"
},
"ThirdPractice":{
"date":"2022-03-19",
"time":"12:00:00Z"
},
"Qualifying":{
"date":"2022-03-19",
"time":"15:00:00Z"
}
}]
location = Location(latitude=26.0325,
longitude=50.5106,
locality="Sakhir",
country="Bahrain")
bahrain = Circuit(circuit_id="bahrain",
url="http://en.wikipedia.org/wiki/Bahrain_International_Circuit",
circuit_name="Bahrain International Circuit",
location=location)
expected = [Race(
season=2022, round_no=1, url="http://en.wikipedia.org/wiki/2022_Bahrain_Grand_Prix",
race_name="Bahrain Grand Prix", circuit=bahrain,
date=datetime.datetime(year=2022, month=3, day=20, hour=15, tzinfo=datetime.timezone.utc), results=[],
first_practice=datetime.datetime(year=2022, month=3, day=18, hour=12, tzinfo=datetime.timezone.utc),
second_practice=datetime.datetime(year=2022, month=3, day=18, hour=15, tzinfo=datetime.timezone.utc),
third_practice=datetime.datetime(year=2022, month=3, day=19, hour=12, tzinfo=datetime.timezone.utc),
sprint=None, sprint_results=[],
qualifying=datetime.datetime(year=2022, month=3, day=19, hour=15, tzinfo=datetime.timezone.utc),
qualifying_results=[], pit_stops=[], laps=[]
)]
assert expected == self.t.construct_races(params)
def test_construct_results(self):
params = [{
@ -149,16 +195,103 @@ class TestTypeConstructor():
assert expected == self.t.construct_pit_stops(params)
def test_construct_laps(self):
# Check Timings too
pass
params = [{
"number":"1",
"Timings":[{
"driverId":"leclerc",
"position":"1",
"time":"1:39.070"
}]
}]
timing = Timing(
driver_id="leclerc",
position=1,
time=datetime.time(minute=1, second=39, microsecond=70000))
expected = [Lap(number=1, timings=[timing])]
assert expected == self.t.construct_laps(params)
def test_construct_seasons(self):
pass
params = [{
"season":"2022",
"url":"http://en.wikipedia.org/wiki/2022_Formula_One_World_Championship"
}]
expected = [Season(
season=2022,
url="http://en.wikipedia.org/wiki/2022_Formula_One_World_Championship"
)]
assert expected == self.t.construct_seasons(params)
def test_construct_statuses(self):
pass
params = [{
"statusId":"1",
"count":"1",
"status":"Finished"
}]
expected = [Status(
status_id=1,
count=1,
status="Finished"
)]
assert expected == self.t.construct_statuses(params)
def test_construct_standings_lists(self):
# Check Driver Standings
# Check constructor standings
pass
params = [{
"season":"2005",
"round":"19",
"DriverStandings":[{
"position":"1",
"positionText":"1",
"points":"133",
"wins":"7",
"Driver":test_constants.ALONSO,
"Constructors":[test_constants.ALPINE]
}],
"ConstructorStandings":[{
"position":"1",
"positionText":"1",
"points":"235",
"wins":"5",
"Constructor": test_constants.FERRARI
}]
}]
alpine = Constructor(constructor_id="alpine",
url="http://en.wikipedia.org/wiki/Alpine_F1_Team",
name="Alpine F1 Team",
nationality="French")
alonso = Driver(driver_id="alonso",
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
)
driver_standings = DriverStanding(
position=1, position_text="1", points=133, wins=7, driver=alonso, constructors=[alpine]
)
ferrari = Constructor(constructor_id="ferrari",
url="http://en.wikipedia.org/wiki/Scuderia_Ferrari",
name="Ferrari", nationality="Italian")
constructor_standings = ConstructorStanding(
position=1, position_text="1", points=235, wins=5, constructor=ferrari
)
expected = [StandingsList(
season=2005,
round_no=19,
driver_standings=[driver_standings],
constructor_standings=[constructor_standings]
)]
assert expected == self.t.construct_standings_lists(params)