コード例 #1
0
 def setUp(self):
     app = main(
         {}, 
         **{'debug_authorization': 'false',
            'debug_notfound': 'false',
            'debug_routematch': 'false',
            'debug_templates': 'true',
            'default_locale_name': 'en',
            'ming.chef.database': 'chef',
            'ming.chef.master': 'mim:///',
            'reload_templates': 'true',
            'key_strength': 1536,
            'session_secret': 'itsasecret'}
         )
     self.app = webtest.TestApp(app)
     
     urllib2.install_opener(
         urllib2.build_opener(_TestUrlLibHandler(self.app)))
     self.bootstrap_data()
     self.chef_1_validator = chef.ChefAPI(
         'test://test',
         key=StringIO(validator_1_key.exportKey()),
         client='test-1-validator',
         version='0.10')
     self.chef_2_validator = chef.ChefAPI(
         'test://test',
         key=StringIO(validator_1_key.exportKey()),
         client='test-2-validator',
         version='0.10')
     self.chef_user_1 = chef.ChefAPI(
         'test://test',
         key=StringIO(user_1_key.exportKey()),
         client='test-user-1',
         version='0.10')
     self.chef_user_2 = chef.ChefAPI(
         'test://test',
         key=StringIO(user_1_key.exportKey()),
         client='test-user-2',
         version='0.10')
     self.chef_user_3 = chef.ChefAPI(
         'test://test',
         key=StringIO(user_3_key.exportKey()),
         client='test-user-3',
         version='0.10')
コード例 #2
0
ファイル: bootstrap.py プロジェクト: rick446/MongoPyChef
import sys
import ConfigParser
from contextlib import contextmanager

from ming.odm import ThreadLocalODMSession

from mongopychef import main
from mongopychef import model as M

configfile, shortname, name = sys.argv[1:]

cp = ConfigParser.ConfigParser()
cp.read(configfile)
config_dict = dict(cp.items('app:MongoPyChef'))

app = main({},  **config_dict)

@contextmanager
def flush_context():
    ThreadLocalODMSession.close_all()
    try:
        yield
        ThreadLocalODMSession.flush_all()
    finally:
        ThreadLocalODMSession.close_all()

with flush_context():
    account, groups = M.Account.bootstrap(shortname=shortname)
    account.name = name
    M.Environment(account_id=account._id, name='_default')
    client, private = M.Client.generate(account, admin=True)