Exemplo n.º 1
0
    def test_get_players(self):
        warnings.filterwarnings(action='ignore',
                                message='unclosed',
                                category=ResourceWarning)

        log.info(f'Downloading data for all players ...')
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore")
            fpl = FPLPandas()
            players, history_past, history, fixtures = fpl.get_players()
        log.info(f'Downloaded {players.shape[0]} players.')

        self.assertTrue(players.shape[0] > 0)
        self.assertTrue(history_past.shape[0] > 0)
        self.assertTrue(history.shape[0] >= 0)
        self.assertTrue(fixtures.shape[0] >= 0)
Exemplo n.º 2
0
    def test_get_players_with_ids(self):
        test_data = [{
            'id':
            1,
            'attr1':
            'value11',
            'attr2':
            'value12',
            'history_past': [{
                'season_name': '2017/18',
                'attr1': 'value11',
                'attr2': 'value12'
            }, {
                'season_name': '2018/19',
                'attr1': 'value21',
                'attr2': 'value22'
            }],
            'history': [{
                'fixture': 1,
                'attr1': 'value11',
                'attr2': 'value12'
            }, {
                'fixture': 2,
                'attr1': 'value21',
                'attr2': 'value22'
            }],
            'fixtures': [{
                'event': 1,
                'attr1': 'value11',
                'attr2': 'value12'
            }, {
                'event': 2,
                'attr1': 'value21',
                'attr2': 'value22'
            }]
        }, {
            'id':
            2,
            'attr1':
            'value21',
            'attr2':
            'value22',
            'history_past': [{
                'season_name': '2017/18',
                'attr1': 'value11',
                'attr2': 'value12'
            }, {
                'season_name': '2018/19',
                'attr1': 'value21',
                'attr2': 'value22'
            }],
            'history': [{
                'fixture': 1,
                'attr1': 'value11',
                'attr2': 'value12'
            }, {
                'fixture': 2,
                'attr1': 'value21',
                'attr2': 'value22'
            }],
            'fixtures': [{
                'event': 1,
                'attr1': 'value11',
                'attr2': 'value12'
            }, {
                'event': 2,
                'attr1': 'value21',
                'attr2': 'value22'
            }]
        }]

        expected_players = [{
            'id': 1,
            'attr1': 'value11',
            'attr2': 'value12'
        }, {
            'id': 2,
            'attr1': 'value21',
            'attr2': 'value22'
        }]
        expected_history_past = [{
            'season_name': '2017/18',
            'attr1': 'value11',
            'attr2': 'value12',
            'player_id': 1
        }, {
            'season_name': '2018/19',
            'attr1': 'value21',
            'attr2': 'value22',
            'player_id': 1
        }, {
            'season_name': '2017/18',
            'attr1': 'value11',
            'attr2': 'value12',
            'player_id': 2
        }, {
            'season_name': '2018/19',
            'attr1': 'value21',
            'attr2': 'value22',
            'player_id': 2
        }]
        expected_history = [{
            'fixture': 1,
            'attr1': 'value11',
            'attr2': 'value12',
            'player_id': 1
        }, {
            'fixture': 2,
            'attr1': 'value21',
            'attr2': 'value22',
            'player_id': 1
        }, {
            'fixture': 1,
            'attr1': 'value11',
            'attr2': 'value12',
            'player_id': 2
        }, {
            'fixture': 2,
            'attr1': 'value21',
            'attr2': 'value22',
            'player_id': 2
        }]
        expected_fixtures = [{
            'event': 1,
            'attr1': 'value11',
            'attr2': 'value12',
            'player_id': 1
        }, {
            'event': 2,
            'attr1': 'value21',
            'attr2': 'value22',
            'player_id': 1
        }, {
            'event': 1,
            'attr1': 'value11',
            'attr2': 'value12',
            'player_id': 2
        }, {
            'event': 2,
            'attr1': 'value21',
            'attr2': 'value22',
            'player_id': 2
        }]

        expected_players_df = pd.DataFrame.from_dict(
            expected_players).set_index('id').rename(index={'id': 'player_id'})
        expected_history_past_df = pd.DataFrame.from_dict(
            expected_history_past).set_index(['player_id', 'season_name'])
        expected_history_df = pd.DataFrame.from_dict(
            expected_history).set_index(['player_id', 'fixture'])
        expected_fixtures_df = pd.DataFrame.from_dict(
            expected_fixtures).set_index(['player_id', 'event'])

        fpl_mock = mock.MagicMock()

        async def mock_get_players(player_ids, include_summary, return_json):
            self.assertIsNotNone(player_ids)
            self.assertEqual(player_ids, [1, 2])
            self.assertEqual(include_summary, True)
            self.assertEqual(return_json, True)

            return test_data

        fpl_mock.get_players = mock_get_players

        fpl = FPLPandas(fpl=fpl_mock)
        actual_players_df, actual_history_past_df, actual_history_df, actual_fixture_df = fpl.get_players(
            [1, 2])

        assert_frame_equal(expected_players_df, actual_players_df)
        assert_frame_equal(expected_history_past_df, actual_history_past_df)
        assert_frame_equal(expected_history_df, actual_history_df)
        assert_frame_equal(expected_fixtures_df, actual_fixture_df)