Skip to content

Commit

Permalink
Merge pull request #32 from matt-bernhardt/14_mock_database
Browse files Browse the repository at this point in the history
Adds mock, starts applying to Database.query method
  • Loading branch information
matt-bernhardt committed Dec 12, 2015
2 parents 261fdd6 + 92d2fa6 commit 39b6d95
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
44 changes: 44 additions & 0 deletions tests/fixtures/tbl_games.sql
Original file line number Diff line number Diff line change
@@ -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 */;
53 changes: 53 additions & 0 deletions tests/fixtures/tbl_players.sql
Original file line number Diff line number Diff line change
@@ -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 */;
32 changes: 31 additions & 1 deletion tests/test_database.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import datetime
from trapp.database import Database


Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions trapp/connection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
u = 'DBUSER'
p = 'DBPASSWORD'
h = 'DBHOST'
d = 'DBNAME'
u = 'travis'
p = ''
h = 'localhost'
d = 'trapp'

0 comments on commit 39b6d95

Please sign in to comment.