diff --git a/.github/workflows/espn-api-test.yml b/.github/workflows/espn-api-test.yml index f13ed3e2..f1a0df8b 100644 --- a/.github/workflows/espn-api-test.yml +++ b/.github/workflows/espn-api-test.yml @@ -16,4 +16,6 @@ jobs: - name: Install dependencies run: python setup.py install - name: Test integration - run: python3 setup.py nosetests --tests tests/football/integration/ \ No newline at end of file + run: | + python3 setup.py nosetests --tests tests/football/integration/ + python3 setup.py nosetests --tests tests/basketball/integration/ \ No newline at end of file diff --git a/.github/workflows/package-release.yml b/.github/workflows/package-release.yml new file mode 100644 index 00000000..50bde15c --- /dev/null +++ b/.github/workflows/package-release.yml @@ -0,0 +1,27 @@ +name: Python package release +on: + release: + types: [created] +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Setup Python + uses: actions/setup-python@v1 + with: + python-version: "3.x" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python setup.py install + pip install twine + + - name: Build Python package + run: python setup.py sdist bdist_wheel + + - name: Twine check + run: twine check dist/* + + - name: Publish to PyPI + run: twine upload dist/* -u ${{ secrets.PYPI_USER }} -p ${{ secrets.PYPI_PASSWORD }} \ No newline at end of file diff --git a/espn_api/basketball/player.py b/espn_api/basketball/player.py index 15fa420f..5fc4448b 100644 --- a/espn_api/basketball/player.py +++ b/espn_api/basketball/player.py @@ -11,7 +11,7 @@ def __init__(self, data): self.eligibleSlots = [POSITION_MAP[pos] for pos in json_parsing(data, 'eligibleSlots')] self.acquisitionType = json_parsing(data, 'acquisitionType') self.proTeam = PRO_TEAM_MAP[json_parsing(data, 'proTeamId')] - self.injuryStatus = data['playerPoolEntry']['player']['injuryStatus'] + self.injuryStatus = json_parsing(data, 'injuryStatus') self.stats = {} # add available stats diff --git a/espn_api/basketball/team.py b/espn_api/basketball/team.py index 6360bcee..70f4fe3f 100644 --- a/espn_api/basketball/team.py +++ b/espn_api/basketball/team.py @@ -12,19 +12,21 @@ def __init__(self, data, member, roster, schedule): self.division_id = data['divisionId'] self.wins = data['record']['overall']['wins'] self.losses = data['record']['overall']['losses'] - self.stats = {STATS_MAP[i]: j for i, j in data['valuesByStat'].items()} self.owner = 'None' + self.logo_url = '' + self.stats = None + self.standing = data['playoffSeed'] + self.final_standing = data['rankCalculatedFinal'] + self.roster = [] + self.schedule = [] + + if 'valuesByStat' in data: + self.stats = {STATS_MAP[i]: j for i, j in data['valuesByStat'].items()} if member: self.owner = "%s %s" % (member['firstName'], member['lastName']) if 'logo' in data: self.logo_url = data['logo'] - else: - self.logo_url = '' - self.standing = data['playoffSeed'] - self.final_standing = data['rankCalculatedFinal'] - self.roster = [] - self.schedule = [] self._fetch_roster(roster) self._fetch_schedule(schedule) diff --git a/tests/basketball/__init__.py b/tests/basketball/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/basketball/integration/__init__.py b/tests/basketball/integration/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/basketball/integration/test_league.py b/tests/basketball/integration/test_league.py new file mode 100644 index 00000000..6469f387 --- /dev/null +++ b/tests/basketball/integration/test_league.py @@ -0,0 +1,29 @@ +from unittest import TestCase +from espn_api.basketball import League + +# Integration test to make sure ESPN's API didnt change +class LeagueTest(TestCase): + + def test_league_init(self): + league = League(411647, 2019) + + self.assertEqual(league.scoringPeriodId, 178) + + def test_league_scoreboard(self): + league = League(411647, 2019) + scores = league.scoreboard() + + self.assertEqual(scores[0].home_final_score, 4240.0) + self.assertEqual(scores[0].away_final_score, 2965.0) + + def test_past_league(self): + league = League(411647, 2017) + + self.assertEqual(league.scoringPeriodId, 170) + + def test_past_league_scoreboard(self): + league = League(411647, 2017) + scores = league.scoreboard() + + self.assertEqual(scores[0].home_final_score, 4211.0) + self.assertEqual(scores[0].away_final_score, 3548.5)