Skip to content

Commit

Permalink
Merge pull request #75 from matt-bernhardt/test_coverage
Browse files Browse the repository at this point in the history
Increases test coverage
  • Loading branch information
matt-bernhardt committed Jan 23, 2016
2 parents b062d16 + fd2ac90 commit 6e6448e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 59 deletions.
74 changes: 22 additions & 52 deletions tests/test_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def test_player_lookupID():
# Setup
log = Log('test.log')
p = Player()
p.connectDB()

# Format error
with pytest.raises(RuntimeError) as excinfo:
Expand All @@ -70,9 +71,17 @@ def test_player_lookupID():
assert 'Submitted data is missing the following fields' in str(excinfo.value)

# Need a test of successful lookups
needle = {
'FirstName': 'Sample',
'LastName': 'Player',
'Position': 'Midfielder',
'DOB': (1980, 1, 1, 0, 0, 0, 0, 0, 0,),
'Hometown': 'Oneonta, NY'
}
assert p.lookupID(needle, log) == [15]


def test_player_lookupIDbyGame():
def test_player_lookupIDbyGoal():
# Setup
log = Log('test.log')
p = Player()
Expand All @@ -93,6 +102,14 @@ def test_player_lookupIDbyGame():
p.lookupIDbyGoal(needle, log)
assert 'Submitted data is missing the following fields' in str(excinfo.value)

# TODO: Need to actually look something up...
needle = {
'playername': 'Man',
'TeamID': 2,
'GameID': 1,
}
assert p.lookupIDbyGoal(needle, log) == [3]


def test_player_lookupIDbyName():
# Setup
Expand All @@ -115,15 +132,17 @@ def test_player_lookupIDbyName():
p.lookupIDbyName(needle, log)
assert 'Submitted data is missing the following fields' in str(excinfo.value)

# Look up a player we know doesn't exist.
needle = {
'PlayerName': 'asdf',
}
assert p.lookupIDbyName(needle, log) == []

# Look up a known player in the test dataset.
needle = {
'PlayerName': 'Sample Player',
}
assert len(p.lookupIDbyName(needle, log)) == 1
assert p.lookupIDbyName(needle, log) == [15]


def test_player_merge():
Expand All @@ -134,60 +153,11 @@ def test_player_merge():
def test_player_saveDict():
log = Log('test.log')
p = Player()
p.connectDB()

# Format error
with pytest.raises(RuntimeError) as excinfo:
needle = 'Foo'
p.saveDict(needle, log)
assert 'saveDict requires a dictionary' in str(excinfo.value)

# New player
# TODO: Need to make sure this player doesn't already exist
needle = {
'FirstName': 'Imported',
'LastName': 'Player',
'Position': 'Midfielder',
'DOB': (1980, 1, 1, 0, 0, 0, 0, 0, 0),
'Hometown': ''
}
assert p.saveDict(needle, log) is True
assert p.db.warnings() is None


def test_player_saveDict_update():
log = Log('test.log')
p = Player()
p.connectDB()

# Existing player scenario:
# 1. Load a known record
needle = 1
p.loadByID(needle)

# 2. Verify the known record
assert p.data['Hometown'] == 'Bedford Falls, NY'

# 3. Change one part of the record
p.data['Hometown'] = 'Paris, France'
# TODO: Shouldn't need to re-establish DOB here
p.data['DOB'] = (1980, 1, 1, 0, 0, 0, 0, 0, 0)
assert p.saveDict(p.data, log) is True

# 4. Re-load that record
p.data = ''
p.loadByID(needle)

# 5. Confirm the change was recorded
assert p.data['Hometown'] == 'Paris, France'

# 6. Change the record back to its original state
p.data['Hometown'] = 'Bedford Falls, NY'
# TODO: Shouldn't need to re-establish DOB here
p.data['DOB'] = (1980, 1, 1, 0, 0, 0, 0, 0, 0)
p.saveDict(p.data, log)

# 7. Confirm the change was recorded
p.data = ''
p.loadByID(needle)
assert p.data['Hometown'] == 'Bedford Falls, NY'
# TODO: Need to actually save something
8 changes: 1 addition & 7 deletions tests/test_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pytest
from trapp.team import Team
from trapp.log import Log
import trapp.connection as connection


def test_team_init():
Expand Down Expand Up @@ -36,11 +35,6 @@ def test_game_lookupID(data_teams):
t = Team()
t.connectDB()

# Populate table for later querying
# TODO do this via setup/teardown?
sql = 'INSERT INTO tbl_teams (teamname) VALUES ("Sample Team")'
t.db.query(sql, ())

# This should raise a format error
with pytest.raises(RuntimeError) as excinfo:
needle = 'My favorite team'
Expand All @@ -57,6 +51,6 @@ def test_game_lookupID(data_teams):

# This should bring back one record
needle = {
'teamname': 'Sample Team'
'teamname': 'Columbus Crew'
}
assert len(t.lookupID(needle, log)) >= 1

0 comments on commit 6e6448e

Please sign in to comment.