Skip to content

Commit

Permalink
Merge pull request #54 from matt-bernhardt/20_gameminutes
Browse files Browse the repository at this point in the history
Adds GameMinute (appearance) object
  • Loading branch information
matt-bernhardt committed Jan 10, 2016
2 parents 0838fca + 19d4002 commit ab15549
Show file tree
Hide file tree
Showing 9 changed files with 467 additions and 51 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ services:
- mysql
before_script:
- mysql -e 'create database trapp;'
- sh -c "mysql < tests/fixtures/tbl_gameminutes.sql"
- sh -c "mysql < tests/fixtures/tbl_games.sql"
- sh -c "mysql < tests/fixtures/tbl_players.sql"
- sh -c "mysql < tests/fixtures/tbl_teams.sql"
- sh -c "mysql < tests/fixtures/test_data.sql"
script:
- tox -e $TOX_ENV
37 changes: 37 additions & 0 deletions tests/fixtures/tbl_gameminutes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
SQLyog Community v10.3
MySQL - 5.5.28-log : Database - trapp
*********************************************************************
*/
USE trapp;

/*!40101 SET NAMES utf8 */;

/*!40101 SET SQL_MODE=''*/;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
/*Table structure for table `tbl_gameminutes` */

DROP TABLE IF EXISTS `tbl_gameminutes`;

CREATE TABLE `tbl_gameminutes` (
`ID` double NOT NULL AUTO_INCREMENT,
`GameID` int(11) DEFAULT NULL,
`TeamID` double DEFAULT NULL,
`PlayerID` double DEFAULT NULL,
`TimeOn` tinyint(3) unsigned DEFAULT '0',
`TimeOff` tinyint(3) unsigned DEFAULT '0',
`Ejected` int(11) DEFAULT '0',
PRIMARY KEY (`ID`),
UNIQUE KEY `ID` (`ID`),
KEY `ID_2` (`ID`),
KEY `GameID` (`GameID`)
) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
47 changes: 47 additions & 0 deletions tests/fixtures/test_data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
SQLyog Community v10.3
MySQL - 5.5.28-log : Database - trapp
*********************************************************************
*/


/*!40101 SET NAMES utf8 */;

/*!40101 SET SQL_MODE=''*/;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
USE `trapp`;

/*Data for the table `tbl_gameminutes` */

insert into `tbl_gameminutes`(`ID`,`GameID`,`TeamID`,`PlayerID`,`TimeOn`,`TimeOff`,`Ejected`) values (1,1,2,3,0,90,0);

/*Data for the table `tbl_players` */

insert into `tbl_players`(`ID`,`LastName`,`FirstName`,`Position`,`RosterNumber`,`Picture`,`Class`,`Eligible`,`College`,`Current_Club`,`ContractStatus`,`LastClub`,`YouthClub`,`Height_Feet`,`Height_Inches`,`Birthplace`,`HomeTown`,`Citizenship`,`Bio`,`Visible`,`Award_Pts`,`Intl_Pts`,`Weight`,`DOB`,`Expansion2014`) values (1,'the Rabbit','Harvey','Goalkeeper',NULL,'coming_soon.gif',0,'0','','',NULL,NULL,NULL,NULL,NULL,NULL,'Bedford Falls, NY',NULL,NULL,0,NULL,NULL,NULL,'1980-01-01',0);
insert into `tbl_players`(`ID`,`LastName`,`FirstName`,`Position`,`RosterNumber`,`Picture`,`Class`,`Eligible`,`College`,`Current_Club`,`ContractStatus`,`LastClub`,`YouthClub`,`Height_Feet`,`Height_Inches`,`Birthplace`,`HomeTown`,`Citizenship`,`Bio`,`Visible`,`Award_Pts`,`Intl_Pts`,`Weight`,`DOB`,`Expansion2014`) values (2,'Rains','Claude','Defender',NULL,'coming_soon.gif',0,'0','','',NULL,NULL,NULL,NULL,NULL,NULL,'Bedford Falls, NY',NULL,NULL,0,NULL,NULL,NULL,'1980-01-01',0);
insert into `tbl_players`(`ID`,`LastName`,`FirstName`,`Position`,`RosterNumber`,`Picture`,`Class`,`Eligible`,`College`,`Current_Club`,`ContractStatus`,`LastClub`,`YouthClub`,`Height_Feet`,`Height_Inches`,`Birthplace`,`HomeTown`,`Citizenship`,`Bio`,`Visible`,`Award_Pts`,`Intl_Pts`,`Weight`,`DOB`,`Expansion2014`) values (3,'Man','Invisible','Defender',NULL,'coming_soon.gif',0,'0','','',NULL,NULL,NULL,NULL,NULL,NULL,'Bedford Falls, NY',NULL,NULL,0,NULL,NULL,NULL,'1980-01-01',0);
insert into `tbl_players`(`ID`,`LastName`,`FirstName`,`Position`,`RosterNumber`,`Picture`,`Class`,`Eligible`,`College`,`Current_Club`,`ContractStatus`,`LastClub`,`YouthClub`,`Height_Feet`,`Height_Inches`,`Birthplace`,`HomeTown`,`Citizenship`,`Bio`,`Visible`,`Award_Pts`,`Intl_Pts`,`Weight`,`DOB`,`Expansion2014`) values (4,'Phantom','','Midfielder',NULL,'coming_soon.gif',0,'0','','',NULL,NULL,NULL,NULL,NULL,NULL,'Bedford Falls, NY',NULL,NULL,0,NULL,NULL,NULL,'1980-01-01',0);
insert into `tbl_players`(`ID`,`LastName`,`FirstName`,`Position`,`RosterNumber`,`Picture`,`Class`,`Eligible`,`College`,`Current_Club`,`ContractStatus`,`LastClub`,`YouthClub`,`Height_Feet`,`Height_Inches`,`Birthplace`,`HomeTown`,`Citizenship`,`Bio`,`Visible`,`Award_Pts`,`Intl_Pts`,`Weight`,`DOB`,`Expansion2014`) values (5,'Bogeyman','','Defender',NULL,'coming_soon.gif',0,'0','','',NULL,NULL,NULL,NULL,NULL,NULL,'Bedford Falls, NY',NULL,NULL,0,NULL,NULL,NULL,'1980-01-01',0);
insert into `tbl_players`(`ID`,`LastName`,`FirstName`,`Position`,`RosterNumber`,`Picture`,`Class`,`Eligible`,`College`,`Current_Club`,`ContractStatus`,`LastClub`,`YouthClub`,`Height_Feet`,`Height_Inches`,`Birthplace`,`HomeTown`,`Citizenship`,`Bio`,`Visible`,`Award_Pts`,`Intl_Pts`,`Weight`,`DOB`,`Expansion2014`) values (6,'Gyfre','','Defender',NULL,'coming_soon.gif',0,'0','','',NULL,NULL,NULL,NULL,NULL,NULL,'Bedford Falls, NY',NULL,NULL,0,NULL,NULL,NULL,'1980-01-01',0);
insert into `tbl_players`(`ID`,`LastName`,`FirstName`,`Position`,`RosterNumber`,`Picture`,`Class`,`Eligible`,`College`,`Current_Club`,`ContractStatus`,`LastClub`,`YouthClub`,`Height_Feet`,`Height_Inches`,`Birthplace`,`HomeTown`,`Citizenship`,`Bio`,`Visible`,`Award_Pts`,`Intl_Pts`,`Weight`,`DOB`,`Expansion2014`) values (7,'Potter','Harry','Midfielder',NULL,'coming_soon.gif',0,'0','','',NULL,NULL,NULL,NULL,NULL,NULL,'Surrey, England',NULL,NULL,0,NULL,NULL,NULL,'1980-01-01',0);
insert into `tbl_players`(`ID`,`LastName`,`FirstName`,`Position`,`RosterNumber`,`Picture`,`Class`,`Eligible`,`College`,`Current_Club`,`ContractStatus`,`LastClub`,`YouthClub`,`Height_Feet`,`Height_Inches`,`Birthplace`,`HomeTown`,`Citizenship`,`Bio`,`Visible`,`Award_Pts`,`Intl_Pts`,`Weight`,`DOB`,`Expansion2014`) values (8,'Storm','Sue','Midfielder',NULL,'coming_soon.gif',0,'0','','',NULL,NULL,NULL,NULL,NULL,NULL,'Bedford Falls, NY',NULL,NULL,0,NULL,NULL,NULL,'1980-01-01',0);
insert into `tbl_players`(`ID`,`LastName`,`FirstName`,`Position`,`RosterNumber`,`Picture`,`Class`,`Eligible`,`College`,`Current_Club`,`ContractStatus`,`LastClub`,`YouthClub`,`Height_Feet`,`Height_Inches`,`Birthplace`,`HomeTown`,`Citizenship`,`Bio`,`Visible`,`Award_Pts`,`Intl_Pts`,`Weight`,`DOB`,`Expansion2014`) values (9,'Griffin','','Defender',NULL,'coming_soon.gif',0,'0','','',NULL,NULL,NULL,NULL,NULL,NULL,'Bedford Falls, NY',NULL,NULL,0,NULL,NULL,NULL,'1980-01-01',0);
insert into `tbl_players`(`ID`,`LastName`,`FirstName`,`Position`,`RosterNumber`,`Picture`,`Class`,`Eligible`,`College`,`Current_Club`,`ContractStatus`,`LastClub`,`YouthClub`,`Height_Feet`,`Height_Inches`,`Birthplace`,`HomeTown`,`Citizenship`,`Bio`,`Visible`,`Award_Pts`,`Intl_Pts`,`Weight`,`DOB`,`Expansion2014`) values (10,'Vehl','Mahr','Midfielder',NULL,'coming_soon.gif',0,'0','','',NULL,NULL,NULL,NULL,NULL,NULL,'Bedford Falls, NY',NULL,NULL,0,NULL,NULL,NULL,'1980-01-01',0);
insert into `tbl_players`(`ID`,`LastName`,`FirstName`,`Position`,`RosterNumber`,`Picture`,`Class`,`Eligible`,`College`,`Current_Club`,`ContractStatus`,`LastClub`,`YouthClub`,`Height_Feet`,`Height_Inches`,`Birthplace`,`HomeTown`,`Citizenship`,`Bio`,`Visible`,`Award_Pts`,`Intl_Pts`,`Weight`,`DOB`,`Expansion2014`) values (11,'Faustus','Doctor','Midfielder',NULL,'coming_soon.gif',0,'0','','',NULL,NULL,NULL,NULL,NULL,NULL,'Bedford Falls, NY',NULL,NULL,0,NULL,NULL,NULL,'1980-01-01',0);
insert into `tbl_players`(`ID`,`LastName`,`FirstName`,`Position`,`RosterNumber`,`Picture`,`Class`,`Eligible`,`College`,`Current_Club`,`ContractStatus`,`LastClub`,`YouthClub`,`Height_Feet`,`Height_Inches`,`Birthplace`,`HomeTown`,`Citizenship`,`Bio`,`Visible`,`Award_Pts`,`Intl_Pts`,`Weight`,`DOB`,`Expansion2014`) values (12,'Mephistopheles','','Midfielder',NULL,'coming_soon.gif',0,'0','','',NULL,NULL,NULL,NULL,NULL,NULL,'Bedford Falls, NY',NULL,NULL,0,NULL,NULL,NULL,'1980-01-01',0);
insert into `tbl_players`(`ID`,`LastName`,`FirstName`,`Position`,`RosterNumber`,`Picture`,`Class`,`Eligible`,`College`,`Current_Club`,`ContractStatus`,`LastClub`,`YouthClub`,`Height_Feet`,`Height_Inches`,`Birthplace`,`HomeTown`,`Citizenship`,`Bio`,`Visible`,`Award_Pts`,`Intl_Pts`,`Weight`,`DOB`,`Expansion2014`) values (13,'Caine','Sebastian','Forward',NULL,'coming_soon.gif',0,'0','','',NULL,NULL,NULL,NULL,NULL,NULL,'Bedford Falls, NY',NULL,NULL,0,NULL,NULL,NULL,'1980-01-01',0);
insert into `tbl_players`(`ID`,`LastName`,`FirstName`,`Position`,`RosterNumber`,`Picture`,`Class`,`Eligible`,`College`,`Current_Club`,`ContractStatus`,`LastClub`,`YouthClub`,`Height_Feet`,`Height_Inches`,`Birthplace`,`HomeTown`,`Citizenship`,`Bio`,`Visible`,`Award_Pts`,`Intl_Pts`,`Weight`,`DOB`,`Expansion2014`) values (14,'Hart','Amos','Forward',NULL,'coming_soon.gif',0,'0','','',NULL,NULL,NULL,NULL,NULL,NULL,'Bedford Falls, NY',NULL,NULL,0,NULL,NULL,NULL,'1980-01-01',0);
insert into `tbl_players`(`ID`,`LastName`,`FirstName`,`Position`,`RosterNumber`,`Picture`,`Class`,`Eligible`,`College`,`Current_Club`,`ContractStatus`,`LastClub`,`YouthClub`,`Height_Feet`,`Height_Inches`,`Birthplace`,`HomeTown`,`Citizenship`,`Bio`,`Visible`,`Award_Pts`,`Intl_Pts`,`Weight`,`DOB`,`Expansion2014`) values (15,'Player','Sample','Midfielder',NULL,'coming_soon.gif',0,'0','','',NULL,NULL,NULL,NULL,NULL,NULL,'Oneonta, NY',NULL,NULL,0,NULL,NULL,NULL,'1980-01-01',0);
insert into `tbl_players`(`ID`,`LastName`,`FirstName`,`Position`,`RosterNumber`,`Picture`,`Class`,`Eligible`,`College`,`Current_Club`,`ContractStatus`,`LastClub`,`YouthClub`,`Height_Feet`,`Height_Inches`,`Birthplace`,`HomeTown`,`Citizenship`,`Bio`,`Visible`,`Award_Pts`,`Intl_Pts`,`Weight`,`DOB`,`Expansion2014`) values (16,'Substitution','','Midfielder',NULL,'coming_soon.gif',0,'0','','',NULL,NULL,NULL,NULL,NULL,NULL,'Oneonta, NY',NULL,NULL,0,NULL,NULL,NULL,'1980-01-01',0);
insert into `tbl_players`(`ID`,`LastName`,`FirstName`,`Position`,`RosterNumber`,`Picture`,`Class`,`Eligible`,`College`,`Current_Club`,`ContractStatus`,`LastClub`,`YouthClub`,`Height_Feet`,`Height_Inches`,`Birthplace`,`HomeTown`,`Citizenship`,`Bio`,`Visible`,`Award_Pts`,`Intl_Pts`,`Weight`,`DOB`,`Expansion2014`) values (17,'Substitution','First','Midfielder',NULL,'coming_soon.gif',0,'0','','',NULL,NULL,NULL,NULL,NULL,NULL,'Oneonta, NY',NULL,NULL,0,NULL,NULL,NULL,'1980-01-01',0);
insert into `tbl_players`(`ID`,`LastName`,`FirstName`,`Position`,`RosterNumber`,`Picture`,`Class`,`Eligible`,`College`,`Current_Club`,`ContractStatus`,`LastClub`,`YouthClub`,`Height_Feet`,`Height_Inches`,`Birthplace`,`HomeTown`,`Citizenship`,`Bio`,`Visible`,`Award_Pts`,`Intl_Pts`,`Weight`,`DOB`,`Expansion2014`) values (18,'Substitution','Second','Midfielder',NULL,'coming_soon.gif',0,'0','','',NULL,NULL,NULL,NULL,NULL,NULL,'Oneonta, NY',NULL,NULL,0,NULL,NULL,NULL,'1980-01-01',0);
insert into `tbl_players`(`ID`,`LastName`,`FirstName`,`Position`,`RosterNumber`,`Picture`,`Class`,`Eligible`,`College`,`Current_Club`,`ContractStatus`,`LastClub`,`YouthClub`,`Height_Feet`,`Height_Inches`,`Birthplace`,`HomeTown`,`Citizenship`,`Bio`,`Visible`,`Award_Pts`,`Intl_Pts`,`Weight`,`DOB`,`Expansion2014`) values (19,'Substitution','Third','Midfielder',NULL,'coming_soon.gif',0,'0','','',NULL,NULL,NULL,NULL,NULL,NULL,'Oneonta, NY',NULL,NULL,0,NULL,NULL,NULL,'1980-01-01',0);

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
106 changes: 106 additions & 0 deletions tests/test_gameminute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import pytest
from trapp.gameminute import GameMinute
from trapp.log import Log


def test_gameminute_init():
gm = GameMinute()
# object types
assert isinstance(gm, GameMinute)
assert isinstance(gm.data, dict)
# Default values


def test_gameminute_connect():
gm = GameMinute()
assert hasattr(gm, 'db') is False
gm.connectDB()
assert hasattr(gm, 'db')


def test_gameminute_disconnect():
gm = GameMinute()
gm.connectDB()
assert hasattr(gm, 'db')
gm.disconnectDB()
assert hasattr(gm, 'db') is False


def test_gameminute_checkData():
gm = GameMinute()
required = ['GameID', 'TeamID', 'PlayerID']

# This should raise a format error
with pytest.raises(RuntimeError) as excinfo:
needle = 'Foo'
gm.checkData(needle, required)
assert 'lookupID requires a dictionary' in str(excinfo.value)

# This should raise a field error
with pytest.raises(RuntimeError) as excinfo:
needle = {
'Foo': 'Bar'
}
gm.checkData(needle, required)
assert 'Submitted data is missing the following fields' in str(excinfo.value)


def test_gameminute_lookupID():
log = Log('test.log')
gm = GameMinute()
gm.connectDB()

needle = {
'GameID': 1,
'TeamID': 2,
'PlayerID': 3
}
result = gm.lookupID(needle, log)
assert len(result) == 1

needle = {
'GameID': 0,
'TeamID': 0,
'PlayerID': 0
}
result = gm.lookupID(needle, log)
assert len(result) == 0


def test_gameminute_saveDict():
log = Log('test.log')
gm = GameMinute()
gm.connectDB()

# Formats
with pytest.raises(RuntimeError) as excinfo:
data = 'foo'
gm.saveDict(data, log)
assert 'saveDict requires a dictionary' in str(excinfo.value)

# Inserts
data = {
'GameID': 1,
'TeamID': 1,
'PlayerID': 1,
'TimeOn': 0,
'TimeOff': 90,
'Ejected': 0
}
assert gm.saveDict(data, log) is True
assert gm.db.warnings() is None

# Updates
data = {
'ID': 1,
'GameID': 2,
'TeamID': 2,
'PlayerID': 2,
'TimeOn': 0,
'TimeOff': 89,
'Ejected': 1
}
assert gm.saveDict(data, log) is True
assert gm.db.warnings() is None
21 changes: 16 additions & 5 deletions tests/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_importer_parsePlayer(excel, lineup):
player = 'Sample Player'
result = importer.parsePlayer(player, game, team)
assert len(result) == 1
assert result == [{'playername': 'Sample Player', 'timeon': 0, 'timeoff': 90, 'ejected': False, 'matchid': 1, 'teamid': 1}]
assert result == [{'PlayerID': 15, 'PlayerName': 'Sample Player', 'TimeOn': 0, 'TimeOff': 90, 'Ejected': False, 'GameID': 1, 'TeamID': 1}]
player = "Sample Player (Substitution 50')"
result = importer.parsePlayer(player, game, team)
assert len(result) == 2
Expand All @@ -115,10 +115,10 @@ def test_importer_parsePlayer(excel, lineup):
player = 'Sample Player (First Substitution 50 (Second Substitution 76 (Third Substitution 84 (sent off 88))))'
result = importer.parsePlayer(player, game, team)
assert len(result) == 4
assert result[3]['playername'] == 'Third Substitution'
assert result[3]['ejected'] is True
assert result[3]['timeon'] == 84
assert result[3]['timeoff'] == 88
assert result[3]['PlayerName'] == 'Third Substitution'
assert result[3]['Ejected'] is True
assert result[3]['TimeOn'] == 84
assert result[3]['TimeOff'] == 88

# starter = 'Sample Player'
# gameID = 1
Expand All @@ -137,6 +137,17 @@ def test_importer_parsePlayerRemoveTime(excel, lineup):
assert player == 'Sample Player'


def test_importer_parsePlayerSplit(excel):
log = Log('test.log')
importer = ImporterLineups(excel, log)
string = 'Player Name'
assert importer.parsePlayerSplit(string) == ['Player Name']
string = 'Player Name (Substitute 63)'
assert importer.parsePlayerSplit(string) == ['Player Name', 'Substitute 63']
string = 'Sample Player (First Substitution 50 (Second Substitution 76 (Third Substitution 84 (sent off 88))))'
assert importer.parsePlayerSplit(string) == ['Sample Player', 'First Substitution 50', 'Second Substitution 76', 'Third Substitution 84', 'sent off 88']


def test_importer_setLog(excel):
log = Log('test.log')
log2 = Log('test2.log')
Expand Down
31 changes: 31 additions & 0 deletions tests/test_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,37 @@ def test_player_lookupID():
# Need a test of successful lookups


def test_player_lookupIDbyName():
# Setup
log = Log('test.log')
p = Player()
p.connectDB()

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

# Missing fields error
with pytest.raises(RuntimeError) as excinfo:
needle = {
'FirstName': 'Wil',
'LastName': 'Trapp'
}
p.lookupIDbyName(needle, log)
assert 'Submitted data is missing the following fields' in str(excinfo.value)

needle = {
'PlayerName': 'asdf',
}
assert p.lookupIDbyName(needle, log) == []

needle = {
'PlayerName': 'Delete Me',
}
assert len(p.lookupIDbyName(needle, log)) > 1

def test_player_merge():
p = Player()
assert p.merge(1, 2) is False
Expand Down
Loading

0 comments on commit ab15549

Please sign in to comment.