Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added util unit tests for NFL, NCAAF, and NCAAB: #782

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/sportsipy.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions tests/unit/test_ncaab_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import mock
from flexmock import flexmock
from sportsipy import utils
from sportsipy.ncaab.ncaab_utils import _retrieve_all_teams


def mock_pyquery(url):
class MockPQ:
def __init__(self, html_contents, status_code=200):
self.status_code = status_code
self.html_contents = html_contents
self.text = html_contents
self.url = url
self.reason = 'Invalid'
self.headers = {}

def __call__(self, div):
return self.html_contents

if '2021' in url:
return MockPQ('<div/>', status_code=404)
else:
return MockPQ('<div id="div_totals-team"/>'
'<div id="div_totals-opponent"/>')


class TestNCAABUtils:
@mock.patch('requests.get', side_effect=mock_pyquery)
def test_ncaab_2020_season_default_to_previous(self, *args, **kwargs):
flexmock(utils) \
.should_receive('_find_year_for_season') \
.and_return(2021)

_, year = _retrieve_all_teams(None)

assert year == '2020'
36 changes: 36 additions & 0 deletions tests/unit/test_ncaaf_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import mock
from flexmock import flexmock
from sportsipy import utils
from sportsipy.ncaaf.ncaaf_utils import _retrieve_all_teams


def mock_pyquery(url):
class MockPQ:
def __init__(self, html_contents, status_code=200):
self.status_code = status_code
self.html_contents = html_contents
self.text = html_contents
self.url = url
self.reason = 'Invalid'
self.headers = {}

def __call__(self, div):
return self.html_contents

if '2021' in url:
return MockPQ('<div/>', status_code=404)
else:
return MockPQ('<div id="div_totals-team"/>'
'<div id="div_totals-opponent"/>')


class TestNCAAFUtils:
@mock.patch('requests.get', side_effect=mock_pyquery)
def test_ncaaf_2020_season_default_to_previous(self, *args, **kwargs):
flexmock(utils) \
.should_receive('_find_year_for_season') \
.and_return(2021)

_, year = _retrieve_all_teams(None)

assert year == '2020'
36 changes: 36 additions & 0 deletions tests/unit/test_nfl_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import mock
from flexmock import flexmock
from sportsipy import utils
from sportsipy.nfl.nfl_utils import _retrieve_all_teams


def mock_pyquery(url):
class MockPQ:
def __init__(self, html_contents, status_code=200):
self.status_code = status_code
self.html_contents = html_contents
self.text = html_contents
self.url = url
self.reason = 'Invalid'
self.headers = {}

def __call__(self, div):
return self.html_contents

if '2021' in url:
return MockPQ('<div/>', status_code=404)
else:
return MockPQ('<div id="div_totals-team"/>'
'<div id="div_totals-opponent"/>')


class TestNFLUtils:
@mock.patch('requests.get', side_effect=mock_pyquery)
def test_nfl_2020_season_default_to_previous(self, *args, **kwargs):
flexmock(utils) \
.should_receive('_find_year_for_season') \
.and_return(2021)

_, year = _retrieve_all_teams(None)

assert year == '2020'