Permalink
Browse files

Merge branch 'master' of github.com:TeamGamma/directedstudies

  • Loading branch information...
2 parents b7b50e6 + 6c416d9 commit 66b71d60fa012771c902a833afffca807fc1142c @robbles robbles committed Mar 1, 2012
Showing with 45 additions and 13 deletions.
  1. +36 −0 sps/config.py
  2. +5 −10 sps/database/session.py
  3. +4 −3 tests/test_commands.py
View
@@ -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
+
View
@@ -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
@@ -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
View
@@ -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):
@@ -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'
@@ -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):

0 comments on commit 66b71d6

Please sign in to comment.