本文整理汇总了Python中pyramid.testing.setUp函数的典型用法代码示例。如果您正苦于以下问题:Python setUp函数的具体用法?Python setUp怎么用?Python setUp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setUp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_user_edit_view_no_matchdict
def test_user_edit_view_no_matchdict(self):
"""
user edit view -- matchdict test & redirect
if matchdict is invalid, expect redirect
"""
from c3sar.views.user import user_edit
request = testing.DummyRequest()
self.config = testing.setUp(request=request)
_registerRoutes(self.config)
instance = self._makeUser()
self.dbsession.add(instance)
self.dbsession.flush()
result = user_edit(request)
# test: a redirect is triggered iff no matchdict
self.assertTrue(isinstance(result, HTTPFound), 'no redirect seen')
self.assertTrue('not_found' in str(result.headers),
'not redirecting to not_found')
# and one more with faulty matchdict
request = testing.DummyRequest()
self.config = testing.setUp(request=request)
_registerRoutes(self.config)
request.matchdict['user_id'] = 'foo'
result = user_edit(request)
# test: a redirect is triggered iff matchdict faulty
self.assertTrue(isinstance(result, HTTPFound), 'no redirect seen')
self.assertTrue('not_found' in str(result.headers),
'not redirecting to not_found')
示例2: setUp
def setUp(self):
self.config = testing.setUp()
self.regis = Registry()
self.regis.register_provider(trees)
config = testing.setUp()
config.add_route('home', 'foo')
config.add_settings(settings)
示例3: setUp
def setUp(self):
import tempfile
import os.path
self.tmpdir = tempfile.mkdtemp()
dbpath = os.path.join( self.tmpdir, 'test.db')
uri = 'file://' + dbpath
settings = {'zodbconn.uri': uri,
'substanced.secret': 'sosecret',
'substanced.initial_login': 'admin',
'substanced.initial_password': 'admin',
'pyramid.includes': [
'substanced',
'pyramid_chameleon',
'pyramid_layout',
'pyramid_mailer.testing', # have to be after substanced to override the mailer
'pyramid_tm',
'dace',
'pontus',
]}
app = main({}, **settings)
self.db = app.registry._zodb_databases['']
request = DummyRequest()
testing.setUp(registry=app.registry, request=request)
self.app = root_factory(request)
request.root = self.app
from webtest import TestApp
self.testapp = TestApp(app)
self.request = request
import time; time.sleep(2)
示例4: setUp
def setUp(self):
testing.setUp()
self.config = testing.setUp()
from webhook import main
app = main.main({})
from webtest import TestApp
self.testapp = TestApp(app)
示例5: setUp
def setUp(self):
from pyramid.paster import get_app
from bookie.tests import BOOKIE_TEST_INI
app = get_app(BOOKIE_TEST_INI, 'main')
from webtest import TestApp
self.testapp = TestApp(app)
testing.setUp()
示例6: setUp
def setUp(self):
print ('TEST setup')
self.config = testing.setUp()
from sqlalchemy import create_engine
engine = create_engine(settings['sqlalchemy.url'])
from .Models import (
Base, ObservationDynProp,
ProtocoleType,
ProtocoleType_ObservationDynProp,
ObservationDynPropValue,
Observation
)
self.engine = create_engine(settings['sqlalchemy.url'])
self.config = testing.setUp()
# self.engine = create_engine(settings['sqlalchemy.url'])
self.connection = self.engine.connect()
self.trans = self.connection.begin()
DBSession.configure(bind=self.connection)
self.DBSession = DBSession()
Base.session = self.DBSession
示例7: test_cookie
def test_cookie(self):
settings = {'pyramid.includes': '\n pyramid_kvs.testing',
'kvs.session': """{"kvs": "mock",
"key_name": "SessionId",
"session_type": "cookie",
"codec": "json",
"key_prefix": "cookie::",
"ttl": 20}"""}
testing.setUp(settings=settings)
factory = SessionFactory(settings)
MockCache.cached_data = {
b'cookie::chocolate': '{"anotherkey": "another val"}'
}
self.assertEqual(factory.session_class, CookieSession)
request = testing.DummyRequest(cookies={'SessionId': 'chocolate'})
session = factory(request)
client = session.client
self.assertIsInstance(client, MockCache)
self.assertEqual(client._serializer.dumps, serializer.json.dumps)
self.assertEqual(client.ttl, 20)
self.assertEqual(client.key_prefix, b'cookie::')
self.assertEqual(session['anotherkey'], 'another val')
self.assertEqual(request.response_callbacks,
deque([session.save_session]))
testing.tearDown()
示例8: setUp
def setUp(self):
EPUBMixInTestCase.setUp(self)
testing.setUp(settings=self.settings)
init_db(self.db_conn_str)
# Assign API keys for testing
self.set_up_api_keys()
示例9: setUp
def setUp(self):
from pyramid import testing
from lasco.models import DBSession
from lasco.models import initialize_sql
testing.setUp()
initialize_sql(TESTING_DB)
self.session = DBSession
示例10: setUp
def setUp(self):
testing.setUp()
self.engine = create_engine('sqlite:///:memory:')
self.session = sessionmaker(bind=self.engine)()
Base.metadata.create_all(self.engine)
self.request = testing.DummyRequest()
self.request.db = self.session
示例11: test_user_view
def test_user_view(self):
"""
test the user_view view
if a user with user_id from URL exists,
"""
from c3sar.views.user import user_view
request = testing.DummyRequest()
request.matchdict['user_id'] = '1'
self.config = testing.setUp(request=request)
_registerRoutes(self.config)
instance = self._makeUser()
self.dbsession.add(instance)
# one more user
instance2 = self._makeUser2()
self.dbsession.add(instance2)
self.dbsession.flush()
result = user_view(request)
# test: view returns a dict containing a user
self.assertEquals(result['user'].username, instance.username)
request = testing.DummyRequest()
request.matchdict['user_id'] = '2'
self.config = testing.setUp(request=request)
result = user_view(request)
示例12: test_backup
def test_backup(dbsession, ini_settings):
"""Execute backup script with having our settings content."""
f = NamedTemporaryFile(delete=False)
temp_fname = f.name
f.close()
ini_settings["websauna.backup_script"] = "websauna.tests:backup_script.bash"
ini_settings["backup_test.filename"] = temp_fname
# We have some scoping issues with the dbsession here, make sure we close transaction at the end of the test
with transaction.manager:
init = get_init(dict(__file__=ini_settings["_ini_file"]), ini_settings)
init.run()
testing.setUp(registry=init.config.registry)
# Check we have faux AWS variable to export
secrets = get_secrets(get_current_registry())
assert "aws.access_key_id" in secrets
try:
# This will run the bash script above
backup_site()
# The result should be generated here
assert os.path.exists(temp_fname)
contents = io.open(temp_fname).read()
# test-secrets.ini, AWS access key
assert contents.strip() == "foo"
finally:
testing.tearDown()
示例13: test_should_renew_session_on_invalidate
def test_should_renew_session_on_invalidate(self):
settings = {'pyramid.includes': '\n pyramid_kvs.testing',
'kvs.session': """{"kvs": "mock",
"key_name": "SessionId",
"session_type": "cookie",
"codec": "json",
"key_prefix": "cookie::",
"ttl": 20}"""}
testing.setUp(settings=settings)
factory = SessionFactory(settings)
MockCache.cached_data = {
b'cookie::chocolate': '{"stuffing": "chocolate"}'
}
request = testing.DummyRequest(cookies={'SessionId': 'chocolate'})
session = factory(request)
# Ensure session is initialized
self.assertEqual(session['stuffing'], 'chocolate')
# Invalidate session
session.invalidate()
# session is invalidated
self.assertFalse('stuffing' in session)
# ensure it can be reused immediately
session['stuffing'] = 'macadamia'
self.assertEqual(session['stuffing'], 'macadamia')
testing.tearDown()
示例14: setUp
def setUp(self):
"""Setup Tests"""
from pyramid.paster import get_app
app = get_app('test.ini', 'main')
from webtest import TestApp
self.testapp = TestApp(app)
testing.setUp()
示例15: setup_method
def setup_method(self, _):
testing.setUp(
settings={
"default_locale_name": "fr",
"default_max_age": 1000,
}
)