def test_get_user_team(self): email = '*****@*****.**' log.info(f'Downloading team data for account {email}...') fpl = FPLPandas(email, 'TestMcTestFace') user_team, chips, transfers = fpl.get_user_team() log.info(f'Team data downloaded.') self.assertTrue(user_team.shape[0] > 0)
def test_get_user_team_with_user(self): test_data = { 'picks': [{ 'element': 1, 'attr1': 'value11', 'attr2': 'value12' }, { 'element': 2, 'attr1': 'value21', 'attr2': 'value22' }], 'chips': [{ 'attr1': 'value11', 'attr2': 'value12' }], 'transfers': { 'attr1': 'value11', 'attr2': 'value12' } } expected_picks_df = pd.DataFrame.from_dict( test_data['picks']).set_index('element').rename( index={'element': 'player_id'}) expected_chips_df = pd.DataFrame.from_dict(test_data['chips']) expected_transfers_df = pd.DataFrame.from_dict( [test_data['transfers']]) fpl_mock = mock.MagicMock() async def mock_login(email, password): self.assertEqual(email, 'email') self.assertEqual(password, 'password') async def mock_get_user_info(): return {'player': {'entry': '123'}} async def mock_get_user_team(user_id): self.assertEqual(user_id, '123') return test_data fpl_mock.get_user_team = mock_get_user_team fpl_mock.get_user_info = mock_get_user_info fpl_mock.login = mock_login fpl = FPLPandas('email', 'password', fpl=fpl_mock) actual_picks_df, actual_chips_df, actual_transfers_df = fpl.get_user_team( ) assert_frame_equal(expected_picks_df, actual_picks_df) assert_frame_equal(expected_chips_df, actual_chips_df) assert_frame_equal(expected_transfers_df, actual_transfers_df)
def test_get_user_team_no_password(self): fpl_mock = mock.MagicMock() fpl = FPLPandas('email', None, fpl=fpl_mock) with self.assertRaisesRegex(ValueError, 'password'): fpl.get_user_team()