Skip to content

Commit

Permalink
Merge branch 'master' of github.com:TeamGamma/directedstudies
Browse files Browse the repository at this point in the history
  • Loading branch information
robbles committed Mar 1, 2012
2 parents b7b50e6 + 6c416d9 commit 66b71d6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
36 changes: 36 additions & 0 deletions sps/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import sps.quotes.client

class ConfigObject():
"""
Provides default values for all possible keys in the configuration file
"""
TRANSACTION_SERVER_PORT = 6000

DATABASE_CONNECTION_ARGS = {
'drivername': 'mysql',
'host': '127.0.0.1',
'port': 3306,
'database': 'sps',
'username': 'root',
'password': 'root',
}
DATABASE_ENGINE_ARGS = {
'echo': True,
}

QUOTE_CLIENT = sps.quotes.client.RandomQuoteClient


# The global configuration object
config = ConfigObject()


def read_config_file(filename):
"""
Reads a Python configuration file and replaces attributes in the
configuration. Returns the global ConfigObject.
"""
global config
execfile(filename, globals(), config.__dict__)
return config

15 changes: 5 additions & 10 deletions sps/database/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@
from sqlalchemy.engine.url import URL
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sps.config import config

_URL = URL(
'mysql',
username='root', password='root',
host='127.0.0.1', port=3306, database='sps'
)
_SESSION_MAKER = None

# Log all statements
SQLALCHEMY_ECHO = True


def setup_database(engine=None):
global _SESSION_MAKER
global _SESSION_MAKER, _URL

_URL = URL(**config.DATABASE_CONNECTION_ARGS)

if not engine:
# TODO: determine optimal pool size
Expand All @@ -26,7 +21,7 @@ def setup_database(engine=None):
engine = create_engine(_URL,
creator=pool.create,
pool_size=pool.max_size,
echo=SQLALCHEMY_ECHO
**config.DATABASE_ENGINE_ARGS
)
else:
engine = engine
Expand Down
7 changes: 4 additions & 3 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_return_value(self):

def test_nonexistent_user(self):
""" Should return an error message if the user does not exist """
self.assertRaises(commands.UserNotFoundError,
self.assertRaises(commands.UserNotFoundError,
self.command.run, userid='unicorn', amount='100')

def test_postcondition_add(self):
Expand Down Expand Up @@ -101,7 +101,8 @@ class _TransactionCommandTest(object):
The base test case for any of the four transaction commands:
COMMIT_BUY, COMMIT_SELL, CANCEL_BUY, CANCEL_SELL
These tests should only be run by a sub-class.
These tests are all shared by TestCOMMIT_BUYCommand,
TestCOMMIT_SELLCommand, TestCANCEL_BUYCommand, and TestCANCEL_SELLCommand
"""
command = None # The command class to run
operation = None # 'BUY' or 'SELL'
Expand Down Expand Up @@ -133,7 +134,7 @@ def test_committed_transaction(self):
operation=self.operation, committed=True, quantity=1,
stock_value=Money(10, 54))
)
self.assertRaises(self.missing_exception,
self.assertRaises(self.missing_exception,
self.command.run, userid='user')

def test_expired_transaction(self):
Expand Down

0 comments on commit 66b71d6

Please sign in to comment.