diff --git a/.travis.yml b/.travis.yml index ddc8df2..c46e8f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,5 +7,11 @@ env: - TOX_ENV=coveralls install: - pip install tox +services: + - mysql +before_script: + - mysql -e 'create database trapp;' + - sh -c "mysql < tests/fixtures/tbl_games.sql" + - sh -c "mysql < tests/fixtures/tbl_players.sql" script: - tox -e $TOX_ENV diff --git a/tests/fixtures/tbl_games.sql b/tests/fixtures/tbl_games.sql new file mode 100644 index 0000000..80f05d8 --- /dev/null +++ b/tests/fixtures/tbl_games.sql @@ -0,0 +1,44 @@ +/* +SQLyog Community v10.3 +MySQL - 5.5.28-log : Database - scouting +********************************************************************* +*/ +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_games` */ + +DROP TABLE IF EXISTS `tbl_games`; + +CREATE TABLE `tbl_games` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `MatchTime` datetime DEFAULT NULL, + `MatchTypeID` int(10) unsigned NOT NULL DEFAULT '0', + `HteamID` int(11) DEFAULT NULL, + `Hscore` int(11) DEFAULT '0', + `AteamID` int(11) DEFAULT NULL, + `Ascore` int(11) DEFAULT '0', + `VenueID` int(11) DEFAULT NULL, + `Duration` int(11) unsigned NOT NULL DEFAULT '0', + `Attendance` int(11) DEFAULT NULL, + `MeanTemperature` int(3) unsigned DEFAULT NULL COMMENT 'Mean Daily Temperature, from Weather Underground', + `Precipitation` double(2,1) DEFAULT NULL, + `WeatherEvents` varchar(255) NOT NULL DEFAULT '""', + `Notes` text, + PRIMARY KEY (`ID`), + KEY `EventDate` (`MatchTime`), + KEY `HTeamID` (`HteamID`), + KEY `ATeamID` (`AteamID`) +) ENGINE=MyISAM AUTO_INCREMENT=1 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 */; diff --git a/tests/fixtures/tbl_players.sql b/tests/fixtures/tbl_players.sql new file mode 100644 index 0000000..f43ce68 --- /dev/null +++ b/tests/fixtures/tbl_players.sql @@ -0,0 +1,53 @@ +/* +SQLyog Community v10.3 +MySQL - 5.5.28-log : Database - scouting +********************************************************************* +*/ +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_players` */ + +DROP TABLE IF EXISTS `tbl_players`; + +CREATE TABLE `tbl_players` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `LastName` varchar(255) DEFAULT NULL, + `FirstName` varchar(255) DEFAULT NULL, + `Position` varchar(255) DEFAULT '', + `RosterNumber` int(3) unsigned DEFAULT NULL, + `Picture` varchar(50) DEFAULT 'coming_soon.gif', + `Class` int(4) DEFAULT '0', + `Eligible` char(1) NOT NULL DEFAULT '0', + `College` varchar(255) DEFAULT '', + `Current_Club` varchar(50) DEFAULT '', + `ContractStatus` tinyint(3) unsigned DEFAULT NULL, + `LastClub` varchar(50) DEFAULT NULL, + `YouthClub` varchar(50) DEFAULT NULL, + `Height_Feet` tinyint(4) DEFAULT NULL, + `Height_Inches` tinyint(4) DEFAULT NULL, + `Birthplace` varchar(255) DEFAULT NULL, + `HomeTown` varchar(255) DEFAULT NULL, + `Citizenship` varchar(255) DEFAULT NULL, + `Bio` text, + `Visible` int(1) NOT NULL DEFAULT '0', + `Award_Pts` double DEFAULT NULL, + `Intl_Pts` double DEFAULT NULL, + `Weight` double DEFAULT NULL, + `DOB` date DEFAULT NULL, + `Expansion2014` int(1) unsigned NOT NULL DEFAULT '0', + PRIMARY KEY (`ID`), + UNIQUE KEY `RosterID` (`ID`) +) ENGINE=MyISAM AUTO_INCREMENT=1 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 */; diff --git a/tests/test_database.py b/tests/test_database.py index 65bde41..1b8663c 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -import datetime from trapp.database import Database @@ -10,6 +9,37 @@ def test_database_init(): assert d.cursor == '' +def test_database_query(): + d = Database() + d.connect() + # Inserts + sql = ('INSERT INTO tbl_players ' + '(FirstName, LastName) ' + 'VALUES ' + '(%s, %s)') + params = ('Brian', 'McBride', ) + rs = d.query(sql, params) + assert d.warnings() is None + # Updates + sql = ('UPDATE tbl_players ' + 'SET Position = %s ' + 'WHERE FirstName = %s AND LastName = %s') + rs = d.query(sql, ('Forward', 'Brian', 'McBride', )) + assert d.warnings() is None + # Selects + sql = ('SELECT ID ' + 'FROM tbl_players ' + 'WHERE FirstName = %s AND LastName = %s') + rs = d.query(sql, params) + if (rs.with_rows): + records = rs.fetchall() + for term in records: + needleID = records[0][0] + assert needleID == 1 + assert d.warnings() is None + d.disconnect() + + def test_database_convertDate(): d = Database() testDate = (1996, 4, 13, 19, 30, 0, 0, 0, 0) diff --git a/trapp/connection.py b/trapp/connection.py index d1edda6..e3f51a3 100644 --- a/trapp/connection.py +++ b/trapp/connection.py @@ -1,4 +1,4 @@ -u = 'DBUSER' -p = 'DBPASSWORD' -h = 'DBHOST' -d = 'DBNAME' +u = 'travis' +p = '' +h = 'localhost' +d = 'trapp'