208 lines
6.3 KiB
Python
208 lines
6.3 KiB
Python
#!/usr/bin/env python
|
|
|
|
"""Tests for `gamescrapyr` package."""
|
|
|
|
|
|
import unittest
|
|
|
|
from gamescrapyr import gamescrapyr
|
|
from os import getenv
|
|
import vcr
|
|
|
|
vcr_options = dict(
|
|
cassette_library_dir = "fixtures/vcr_cassettes/",
|
|
ignore_localhost=True,
|
|
filter_post_data_parameters=['email', 'password'],
|
|
# record_mode="new_episodes",
|
|
decode_compressed_response=True,
|
|
# allow_playback_repeats=True,
|
|
)
|
|
|
|
class TestGamescrapyr(unittest.TestCase):
|
|
"""Tests for `gamescrapyr` package."""
|
|
|
|
@vcr.use_cassette(**vcr_options)
|
|
def setUp(self):
|
|
"""Set up test fixtures, if any."""
|
|
email = getenv('email')
|
|
password = getenv('password')
|
|
self.client = gamescrapyr.GameChangerClient(email=email, password=password)
|
|
self.team_id = getenv('team_id')
|
|
self.season_slug = getenv('season_slug')
|
|
self.team_slug = getenv('team_slug')
|
|
pass
|
|
|
|
|
|
def tearDown(self):
|
|
"""Tear down test fixtures, if any."""
|
|
self.client.session.close()
|
|
|
|
@vcr.use_cassette(**vcr_options)
|
|
def test_000_get_roster(self):
|
|
"""Test something."""
|
|
kwargs = {
|
|
'season_slug':self.season_slug,
|
|
'team_id': self.team_id,
|
|
'team_slug': self.team_slug
|
|
}
|
|
roster = self.client.get_roster(**kwargs)
|
|
self.assertIsInstance(roster, list)
|
|
self.assertGreater(len(roster), 0)
|
|
for d in roster:
|
|
for key in ['fname', 'lname', 'player_id']:
|
|
self.assertIn(key, d.keys())
|
|
|
|
@vcr.use_cassette(**vcr_options)
|
|
def test_001_get_stats(self):
|
|
kwargs = {
|
|
'season_slug': self.season_slug,
|
|
'team_id': self.team_id,
|
|
'team_slug': self.team_slug
|
|
}
|
|
stats = self.client.get_stats(**kwargs)
|
|
self.assertIsInstance(stats, dict)
|
|
for player_id, d in stats.items():
|
|
for key in ['offensive', 'defensive']:
|
|
self.assertIn(key, d.keys())
|
|
pass
|
|
|
|
@vcr.use_cassette(**vcr_options)
|
|
def test_002_get_games(self):
|
|
kwargs = {
|
|
'season_slug': self.season_slug,
|
|
'team_id': self.team_id,
|
|
'team_slug': self.team_slug
|
|
}
|
|
games = self.client.get_games(**kwargs)
|
|
self.assertIsInstance(games, list)
|
|
for d in games:
|
|
for key in ['id', 'title', 'start']:
|
|
self.assertIn(key, d.keys())
|
|
pass
|
|
|
|
@vcr.use_cassette(**vcr_options)
|
|
def test_003_get_lineup(self):
|
|
kwargs = {
|
|
'season_slug': self.season_slug,
|
|
'team_id': self.team_id,
|
|
'team_slug': self.team_slug,
|
|
}
|
|
lineup = self.client.get_lineup(**kwargs)
|
|
self.assertIsInstance(lineup, list)
|
|
for d in lineup:
|
|
for key in ['player_id', 'position']:
|
|
self.assertIn(key, d.keys())
|
|
|
|
@vcr.use_cassette(**vcr_options, allow_playback_repeats=False)
|
|
def test_004_submit_lineup(self):
|
|
kwargs = {
|
|
'season_slug': self.season_slug,
|
|
'team_id': self.team_id,
|
|
'team_slug': self.team_slug
|
|
}
|
|
|
|
lineup_without_dh = [
|
|
{
|
|
"player_id": "625843b4579ba45cc6a8d75b",
|
|
"position": "CF"
|
|
}
|
|
]
|
|
|
|
resp = self.client.submit_lineup(lineup=lineup_without_dh, **kwargs)
|
|
check = self.client.get_lineup(**kwargs)
|
|
self.assertEqual(check, lineup_without_dh)
|
|
|
|
lineup_with_dh = [
|
|
{
|
|
"player_id": "625843b4579ba45cc6a8d755",
|
|
"position": "EH"
|
|
},
|
|
{
|
|
"player_id": "625843b4579ba45cc6a8d74d",
|
|
"position": "SS"
|
|
},
|
|
{
|
|
"player_id": "626d67d6043f7f5c95246710",
|
|
"position": "1B"
|
|
},
|
|
{
|
|
"player_id": "625843b4579ba45cc6a8d75b",
|
|
"position": "LF"
|
|
},
|
|
{
|
|
"player_id": "626d67d6043f7f5c95246711",
|
|
"position": "RF"
|
|
},
|
|
{
|
|
"player_id": "625843b4579ba45cc6a8d74b",
|
|
"position": "DH",
|
|
"forwhom": "625964a36f8f3b0bb266d1c3"
|
|
},
|
|
{
|
|
"player_id": "625964a36f8f3b0bb266d1c3",
|
|
"position": "P"
|
|
},
|
|
{
|
|
"player_id": "625843b5579ba45cc6a8d763",
|
|
"position": "C"
|
|
},
|
|
{
|
|
"player_id": "625964a36f8f3b0bb266d1c4",
|
|
"position": "3B"
|
|
},
|
|
{
|
|
"player_id": "625843b4579ba45cc6a8d743",
|
|
"position": "CF"
|
|
},
|
|
{
|
|
"player_id": "625843b4579ba45cc6a8d74f",
|
|
"position": "2B"
|
|
},
|
|
{
|
|
"player_id": "625843b4579ba45cc6a8d753",
|
|
"position": "EH"
|
|
}
|
|
]
|
|
|
|
resp = self.client.submit_lineup(lineup=lineup_with_dh, **kwargs)
|
|
check = self.client.get_lineup(**kwargs)
|
|
self.assertEqual(check, lineup_with_dh)
|
|
|
|
pass
|
|
|
|
@vcr.use_cassette(**vcr_options, allow_playback_repeats=False)
|
|
def test_005_is_authorized(self):
|
|
email = getenv('email')
|
|
password = getenv('password')
|
|
is_authorized = self.client.is_authorized()
|
|
self.assertTrue(is_authorized)
|
|
self.client.session.cookies.clear()
|
|
should_not_be_authorized = self.client.is_authorized()
|
|
self.assertFalse(should_not_be_authorized)
|
|
gamescrapyr.GameChangerClient(email=email, password=password)
|
|
should_be_authorized = self.client.is_authorized()
|
|
self.assertTrue(should_be_authorized)
|
|
self.client
|
|
|
|
@vcr.use_cassette(**vcr_options)
|
|
def test_006_test_teams(self):
|
|
kwargs = {
|
|
'season_slug': self.season_slug,
|
|
'team_id': self.team_id,
|
|
'team_slug': self.team_slug
|
|
}
|
|
teams = self.client.get_teams()
|
|
self.assertIsInstance(teams, list)
|
|
keys = ['name',
|
|
'id',
|
|
'season' ,
|
|
'season_slug',
|
|
'team_slug'
|
|
]
|
|
|
|
for d in teams:
|
|
for key in keys:
|
|
self.assertIn(key, d.keys())
|
|
self.assertNotEqual('', d.get(key))
|
|
|