Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_init():
fixture = Fixture(fixture_data)
for k, v in fixture_data.items():
if k != 'stats':
assert getattr(fixture, k) == v
async def test_fixtures(self, loop, fpl):
fixtures = await fpl.get_fixtures()
assert isinstance(fixtures, list)
assert isinstance(fixtures[0], Fixture)
fixtures = await fpl.get_fixtures(return_json=True)
assert isinstance(fixtures[0], dict)
async def test_fixture(self, loop, fpl):
# test fixture with unknown id
with pytest.raises(ValueError):
await fpl.get_fixture(0)
fixture = await fpl.get_fixture(6)
assert isinstance(fixture, Fixture)
fixture = await fpl.get_fixture(6, return_json=True)
assert isinstance(fixture, dict)
gameweek_fixtures = await fetch(
self.session,
API_URLS["gameweek_fixtures"].format(fixture_gameweek))
try:
fixture = next(fixture for fixture in gameweek_fixtures
if fixture["id"] == fixture_id)
except StopIteration:
raise ValueError(
f"Fixture with ID {fixture_id} not found in gameweek fixtures")
if return_json:
return fixture
return Fixture(fixture)
:type return_json: bool
:rtype: list
"""
gameweeks = range(1, 39)
tasks = [asyncio.ensure_future(
fetch(self.session,
API_URLS["gameweek_fixtures"].format(gameweek)))
for gameweek in gameweeks]
gameweek_fixtures = await asyncio.gather(*tasks)
fixtures = list(itertools.chain(*gameweek_fixtures))
if return_json:
return fixtures
return [Fixture(fixture) for fixture in fixtures]