Permalink
Browse files

Refactoring!

  • Loading branch information...
1 parent 6bbe9ee commit d1b1cd755fda7df4b8a0442a812761622090ea9e @iurisilvio committed Mar 30, 2012
Showing with 7 additions and 15 deletions.
  1. +1 −7 bottle_sqlalchemy.py
  2. +6 −8 test.py
View
8 bottle_sqlalchemy.py
@@ -123,9 +123,7 @@ def apply(self, callback, route):
self.metadata.create_all(self.engine)
def wrapper(*args, **kwargs):
- session = self._sessionmaker()
- kwargs[keyword] = session
-
+ kwargs[keyword] = session = sessionmaker(self.engine)()
try:
rv = callback(*args, **kwargs)
if commit:
@@ -143,9 +141,5 @@ def wrapper(*args, **kwargs):
return wrapper
- def _sessionmaker(self):
- s = sessionmaker(self.engine)
- return s()
-
Plugin = SQLAlchemyPlugin
View
14 test.py
@@ -26,7 +26,6 @@ def wrapper(*args, **kwargs):
return wrapper
-
class SQLAlchemyPluginTest(unittest.TestCase):
def setUp(self):
@@ -165,19 +164,18 @@ def test(db, param):
self._request_path('/')
def test_install_other_plugin_before(self):
- app = bottle.Bottle(catchall=False)
- app.install(AnotherPlugin())
- app.install(sqlalchemy.Plugin(self.engine, create=False))
+ self.app.install(AnotherPlugin())
+ self.app.install(sqlalchemy.Plugin(self.engine, create=False))
- @app.get('/')
+ @self.app.get('/')
def test(db, param):
self.assertTrue(db is not None)
self.assertEqual(param, 1)
- self._request_path('/', app=app)
+ self._request_path('/')
- def _request_path(self, path, method='GET', app=None):
- (app or self.app)({'PATH_INFO': path, 'REQUEST_METHOD': method},
+ def _request_path(self, path, method='GET'):
+ self.app({'PATH_INFO': path, 'REQUEST_METHOD': method},
lambda x, y: None)
def _install_plugin(self, *args, **kwargs):

0 comments on commit d1b1cd7

Please sign in to comment.