1. Dan Connolly
  2. quacken


Dan Connolly  committed 0fedc21

integrate mock data to run per development.ini
- never mind pyramid_debugtoolbar; the server produces JSON
- bootstrap_db config option
- update views.py w.r.t. session re-factoring

  • Participants
  • Parent commits 64f1b12
  • Branches default

Comments (0)

Files changed (4)

File finjax/development.ini

View file
 pyramid.debug_routematch = false
 pyramid.default_locale_name = en
 pyramid.includes =
-    pyramid_debugtoolbar
 sqlalchemy.url = sqlite:///%(here)s/finjax.db
+bootstrap_db = true
 use = egg:waitress#main

File finjax/finjax/__init__.py

View file
 from pyramid.config import Configurator
 import sqlalchemy
-from .models import DBConfig
-from .views import FinjaxAPI
+import models
+import views
 def main(global_config, **settings):
     @param settings: settings for this application
     @return: a WSGI application.
-    finjax, config = RunTime.make(settings, [FinjaxAPI, Configurator])
+    finjax, config = RunTime.make(settings, [views.FinjaxAPI, Configurator])
     return config.make_wsgi_app()
     def db(self, section='sqlalchemy.'):
-        return sqlalchemy.engine_from_config(self._settings, section)
+        e = sqlalchemy.engine_from_config(self._settings, section)
+        if 'bootstrap_db' in self._settings:
+            models.Mock().bootstrap(e)
+        return e
     def make(cls, settings, what):
         @param what: list of classes to instantiate;
                      use None as list item to get the whole Injector depgraph.
-        mods = [cls(settings), DBConfig()]
+        mods = [cls(settings), models.DBConfig()]
         depgraph = injector.Injector(mods)
         return [depgraph.get(it) if it else depgraph
                 for it in what]

File finjax/finjax/models.py

View file
         return [depgraph.get(it) if it else depgraph
                 for it in what]
+    @singleton
     def engine_with_mock_data(self, url='sqlite:///'):
         engine = create_engine(url)
+        self.bootstrap(engine)
+        return engine
+    def bootstrap(self, engine):
         engine.execute(Transaction.__table__.insert(), self.transactions)
         engine.execute(Split.__table__.insert(), self.splits)
-        return engine
     def mock_accounts(self):
         return [dict(name=acct.name,

File finjax/finjax/views.py

View file
 from dotdict import dotdict
 from models import (
     Account, Transaction,
-    KSessionMaker
+    KSession
 class JSONDBView(object):
     '''View to access DB and render to JSON.
-    @inject(session=KSessionMaker)
+    @inject(session=KSession)
     def __init__(self, session):
         self._session = session