Python pyramid.testing 模块,setUp() 实例源码

我们从Python开源项目中,提取了以下48个代码示例,用于说明如何使用pyramid.testing.setUp()

项目:CF401-Project-1---PyListener    作者:PyListener    | 项目源码 | 文件源码
def configuration(request):
    """Set up a Configurator instance.

    This Configurator instance sets up a pointer to the location of the
        database.
    It also includes the models from your app's model package.
    Finally it tears everything down, including the Postgres database.

    This configuration will persist for the entire duration of your PyTest run.
    """
    settings = {
        'sqlalchemy.url': TEST_DB}
    config = testing.setUp(settings=settings)
    config.include('pylistener.models')
    config.include('pylistener.routes')

    def teardown():
        testing.tearDown()

    request.addfinalizer(teardown)
    return config
项目:unsonic    作者:redshodan    | 项目源码 | 文件源码
def bootstrap(dbinfo):
    # Initialize the db layer
    config = testing.setUp()
    settings = config.get_settings()
    here = "/".join(os.path.dirname(__file__).split("/")[:-2])
    global_settings = {"__file__": os.path.join(here, "test/testing.ini"),
                       "here": here, "venv":CONFIG.venv()}
    web.init(global_settings, settings, dbinfo)

    # Sync the database with mishmash
    __main__.main(["-D", dbinfo.url, "-c", "test/testing.ini", "sync"])

    # Create test users
    session = dbinfo.SessionMaker()
    user = models.addUser(session, "test", "test", auth.Roles.def_user_roles)
    user.avatar = 3
    session.add(user)
    session.commit()
    session.close()

    # Load the users
    models.load()
项目:unsonic    作者:redshodan    | 项目源码 | 文件源码
def lsession():
    db = Path(os.path.join(CONFIG.venv(), "testing2.sqlite"))
    if db.exists():
        db.unlink()

    config = testing.setUp()
    settings = config.get_settings()
    here = "/".join(os.path.dirname(__file__).split("/")[:-2])
    global_settings = {"__file__": os.path.join(here, "test/testing2.ini"),
                       "here": here,  "venv":CONFIG.venv()}
    web.init(global_settings, settings, None)

    session = models.session_maker()
    yield session
    session.close()

    db = Path(os.path.join(CONFIG.venv(), "testing2.sqlite"))
    db.unlink()
项目:pyramid_runner    作者:asif-mahmud    | 项目源码 | 文件源码
def setUp(self):
        """Defines useful variables and initializes database.

        After this, following variables will be available-
            1. config: Application configuration
            2. engine: DB engine
            3. session: DB session instance
            4. test_app: Test WSGI app
        """
        settings = self.get_settings()
        app = services.main({}, **settings)
        self.test_app = webtest.TestApp(app=app)

        self.config = testing.setUp(settings=settings)

        self.engine = models.get_engine(settings)
        session_factory = models.get_session_factory(self.engine)

        self.session = models.get_tm_session(
            session_factory,
            transaction.manager
        )

        self.__init_database()
项目:pyramid_runner    作者:asif-mahmud    | 项目源码 | 文件源码
def __init_database(self):
        """Initialize the database models.

        Define a method called `init_db` to initialize
        any database instance. This method will automatically
        be called at `setUp`.

        Caution: If `init_db` is defined, a `clean_db` method
        should also be defined which will be called at
        `tearDown`.
        """
        meta.Base.metadata.create_all(self.engine)

        try:
            __init_db = self.__getattribute__('init_db')
            if callable(__init_db):
                with transaction.manager:
                    __init_db()
        except AttributeError:
            pass
项目:peecp    作者:peereesook    | 项目源码 | 文件源码
def setUp(self):
        self.config = testing.setUp(settings={
            'sqlalchemy.url': 'sqlite:///:memory:'
        })
        self.config.include('.models')
        settings = self.config.get_settings()

        from .models import (
            get_engine,
            get_session_factory,
            get_tm_session,
            )

        self.engine = get_engine(settings)
        session_factory = get_session_factory(self.engine)

        self.session = get_tm_session(session_factory, transaction.manager)
项目:pyramid-zappa-api-boilerplate    作者:web-masons    | 项目源码 | 文件源码
def setUp(self):
        self.config = testing.setUp(settings={
            'sqlalchemy.url': 'sqlite:///:memory:'
        })
        self.config.include('.models')
        settings = self.config.get_settings()

        from .models import (
            get_engine,
            get_session_factory,
            get_tm_session,
            )

        self.engine = get_engine(settings)
        session_factory = get_session_factory(self.engine)

        self.session = get_tm_session(session_factory, transaction.manager)
项目:websauna    作者:websauna    | 项目源码 | 文件源码
def app(request):
    """py.test fixture to set up a dummy app for Redis testing.

    :param request: pytest's FixtureRequest (internal class, cannot be hinted on a signature)
    """

    config = testing.setUp()
    config.add_route("home", "/")
    config.add_route("redis_test", "/redis_test")
    config.add_view(redis_test, route_name="redis_test")

    # same is in test.ini
    config.registry.settings["redis.sessions.url"] = "redis://localhost:6379/14"

    def teardown():
        testing.tearDown()

    config.registry.redis = create_redis(config.registry)

    app = TestApp(config.make_wsgi_app())
    return app
项目:EDDB_JsonAPI    作者:FuelRats    | 项目源码 | 文件源码
def setUp(self):
        self.config = testing.setUp(settings={
            'sqlalchemy.url': 'sqlite:///:memory:'
        })
        self.config.include('.models')
        settings = self.config.get_settings()

        from .models import (
            get_engine,
            get_session_factory,
            get_tm_session,
            )

        self.engine = get_engine(settings)
        session_factory = get_session_factory(self.engine)

        self.session = get_tm_session(session_factory, transaction.manager)
项目:papersummarize    作者:mrdrozdov    | 项目源码 | 文件源码
def makePaper(self, arxiv_id):
        from ..models import Paper
        return Paper(arxiv_id=arxiv_id)


# class ViewWikiTests(unittest.TestCase):
#     def setUp(self):
#         self.config = testing.setUp()
#         self.config.include('..routes')

#     def tearDown(self):
#         testing.tearDown()

#     def _callFUT(self, request):
#         from papersummarize.views.default import view_wiki
#         return view_wiki(request)

#     def test_it(self):
#         request = testing.DummyRequest()
#         response = self._callFUT(request)
#         self.assertEqual(response.location, 'http://example.com/FrontPage')
项目:hel    作者:hel-repo    | 项目源码 | 文件源码
def setUp(self):
        from pymongo import MongoClient

        url = 'mongodb://localhost:37017'
        if 'HEL_TESTING_MONGODB_ADDR' in os.environ:
            url = os.environ['HEL_TESTING_MONGODB_ADDR']
        self.client = MongoClient(url)
        self.db = self.client.hel
        self.db['packages'].delete_many({})
        self.pkg1 = self.pkg1m.data
        self.pkg2 = self.pkg2m.data
        self.pkg3 = self.pkg3m.data
        self.db['packages'].insert_one(self.pkg1m.pkg)
        self.db['packages'].insert_one(self.pkg2m.pkg)
        self.db['packages'].insert_one(self.pkg3m.pkg)

        self.config = testing.setUp()
项目:dearhrc.us    作者:JessaWitzel    | 项目源码 | 文件源码
def setUp(self):
        self.config = testing.setUp(settings={
            'sqlalchemy.url': 'sqlite:///:memory:'
        })
        self.config.include('.models')
        settings = self.config.get_settings()

        from .models import (
            get_engine,
            get_session_factory,
            get_tm_session,
            )

        self.engine = get_engine(settings)
        session_factory = get_session_factory(self.engine)

        self.session = get_tm_session(session_factory, transaction.manager)
项目:Octojobs    作者:OctoJobs    | 项目源码 | 文件源码
def configuration(request):
    """Set up a Configurator instance.

    This Configurator instance sets up a pointer to the location of the
    database. It also includes the models from the octojobs model package.
    Finally it tears everything down, including the in-memory database.

    This configuration will persist for the entire duration of your PyTest run.
    """
    settings = {
        'sqlalchemy.url': 'postgres:///test_jobs'}
    config = testing.setUp(settings=settings)
    config.include('octojobs.models')
    config.include('octojobs.routes')

    def teardown():
        testing.tearDown()

    request.addfinalizer(teardown)
    return config
项目:survivor-pool    作者:bitedgeco    | 项目源码 | 文件源码
def sqlengine(request):
    """Create an engine."""
    config = testing.setUp(settings=TEST_DB_SETTINGS)
    config.include("..models")
    config.include("..routes")
    settings = config.get_settings()
    engine = get_engine(settings)
    Base.metadata.create_all(engine)

    def teardown():
        testing.tearDown()
        transaction.abort()
        Base.metadata.drop_all(engine)

    request.addfinalizer(teardown)
    return engine
项目:expense_tracker_401d6    作者:codefellows    | 项目源码 | 文件源码
def configuration(request):
    """Set up a Configurator instance.

    This Configurator instance sets up a pointer to the location of the
        database.
    It also includes the models from your app's model package.
    Finally it tears everything down, including the in-memory SQLite database.

    This configuration will persist for the entire duration of your PyTest run.
    """
    config = testing.setUp(settings={
        'sqlalchemy.url': 'postgres://localhost:5432/test_expenses'
    })
    config.include("expense_tracker.models")
    config.include("expense_tracker.routes")

    def teardown():
        testing.tearDown()

    request.addfinalizer(teardown)
    return config
项目:pyramid-cookiecutter-alchemy    作者:Pylons    | 项目源码 | 文件源码
def setUp(self):
        self.config = testing.setUp(settings={
            'sqlalchemy.url': 'sqlite:///:memory:'
        })
        self.config.include('.models')
        settings = self.config.get_settings()

        from .models import (
            get_engine,
            get_session_factory,
            get_tm_session,
            )

        self.engine = get_engine(settings)
        session_factory = get_session_factory(self.engine)

        self.session = get_tm_session(session_factory, transaction.manager)
项目:MoodBot    作者:Bonanashelby    | 项目源码 | 文件源码
def configuration(request):
    """Set up a Configurator instance.

    This Configurator instance sets up a pointer to the location of the
        database.
    It also includes the models from your app's model package.
    Finally it tears everything down, including the in-memory SQLite database.

    This configuration will persist for the entire duration of your PyTest run.
    """
    config = testing.setUp(settings={
        'sqlalchemy.url': 'postgres://localhost:5432/test_moodybot'
    })
    config.include("mood_bot.models")
    config.include("mood_bot.routes")
    config.include("mood_bot.security")

    def teardown():
        testing.tearDown()

    request.addfinalizer(teardown)
    return config
项目:stalker_pyramid    作者:eoyilmaz    | 项目源码 | 文件源码
def setUp(self):
        """setup test
        """
        import datetime
        from stalker import defaults
        defaults.timing_resolution = datetime.timedelta(hours=1)
        from pyramid import testing
        testing.setUp()

        # init database
        from stalker import db
        db.setup(self.config)
        db.init()
项目:stalker_pyramid    作者:eoyilmaz    | 项目源码 | 文件源码
def setUp(self):
        """set up the test
        """
        import transaction
        from pyramid import paster, testing
        from webtest import TestApp
        from stalker import db
        from stalker.db.session import DBSession

        testing.setUp()
        import os
        import stalker_pyramid
        app = paster.get_app(
            os.path.join(
                os.path.dirname(
                    stalker_pyramid.__path__[0],
                ),
                'testing.ini'
            ).replace('\\', '/')
        )

        self.test_app = TestApp(app)

        # patch DBSession commit, to let the db.init() work
        # with its calls to DBSession.commit()
        _orig_commit = DBSession.commit
        DBSession.commit = transaction.commit
        db.setup(app.registry.settings)
        db.init()
        # restore DBSession.commit
        DBSession.commit = _orig_commit

        from stalker import User
        self.admin = User.query.filter(User.name == 'admin').first()
项目:fantasy-dota-heroes    作者:ThePianoDentist    | 项目源码 | 文件源码
def setUp(self):
        self.config = testing.setUp()
        from sqlalchemy import create_engine
        engine = create_engine('sqlite://')
        from .models import (
            Base,
            MyModel,
            )
        DBSession.configure(bind=engine)
        Base.metadata.create_all(engine)
        with transaction.manager:
            model = MyModel(name='one', value=55)
            DBSession.add(model)
项目:fantasy-dota-heroes    作者:ThePianoDentist    | 项目源码 | 文件源码
def setUp(self):
        self.config = testing.setUp()
        from sqlalchemy import create_engine
        engine = create_engine('sqlite://')
        from .models import (
            Base,
            MyModel,
            )
        DBSession.configure(bind=engine)
项目:eea.corpus    作者:eea    | 项目源码 | 文件源码
def setup_class(cls):
        cls.config = testing.setUp()
        cls.config.scan('eea.corpus.processing')
项目:eea.corpus    作者:eea    | 项目源码 | 文件源码
def setup_class(cls):
        cls.config = testing.setUp()
        cls.config.scan('eea.corpus.processing')
项目:pyramid_sms    作者:websauna    | 项目源码 | 文件源码
def sms_app(request):

    config = testing.setUp()
    config.set_default_csrf_options(require_csrf=True)
    config.add_route("test-sms", "/test-sms")
    config.add_view(sms_view_test, route_name="test-sms")
    config.registry.registerAdapter(factory=DummySMSService, required=(IRequest,), provided=ISMSService)
    config.registry.settings["sms.default_sender"] = "+15551231234"
    config.registry.settings["sms.async"] = "false"

    def teardown():
        testing.tearDown()

    app = TestApp(config.make_wsgi_app())
    return app
项目:pyramid_starter    作者:jmercouris    | 项目源码 | 文件源码
def setUp(self):
        self.config = testing.setUp()
        from sqlalchemy import create_engine
        engine = create_engine('sqlite://')
        from .models import (
            Base,
            MyModel,
            )
        DBSession.configure(bind=engine)
        Base.metadata.create_all(engine)
        with transaction.manager:
            model = MyModel(name='one', value=55)
            DBSession.add(model)
项目:pyramid_starter    作者:jmercouris    | 项目源码 | 文件源码
def setUp(self):
        self.config = testing.setUp()
        from sqlalchemy import create_engine
        engine = create_engine('sqlite://')
        from .models import (
            Base,
            MyModel,
            )
        DBSession.configure(bind=engine)
项目:lagendacommun    作者:ecreall    | 项目源码 | 文件源码
def setUp(self):
        super(FunctionalTests, self).setUp()
项目:lagendacommun    作者:ecreall    | 项目源码 | 文件源码
def setUp(self):
        super(RobotLayer, self).setUp()
        self.server = http.StopableWSGIServer.create(self.app, port=8080)
项目:pyramid-cookiecutter-starter-chameleon    作者:mikeckennedy    | 项目源码 | 文件源码
def setUp(self):
        self.config = testing.setUp()
项目:pyramid-cookiecutter-starter-chameleon    作者:mikeckennedy    | 项目源码 | 文件源码
def setUp(self):
        from {{ cookiecutter.repo_name }} import main
        app = main({})
        from webtest import TestApp
        self.testapp = TestApp(app)
项目:turingtweets    作者:jjfeore    | 项目源码 | 文件源码
def configuration(request):
    """Set up a configurator instance."""
    config = testing.setUp(settings={
        'sqlalchemy.url': os.environ.get('DATABASE_URL_TESTING')
    })
    config.include("turingtweets.models")
    config.include("turingtweets.routes")

    def teardown():
        testing.tearDown()

    request.addfinalizer(teardown)
    return config
项目:kinto-ldap    作者:Kinto    | 项目源码 | 文件源码
def test_include_fails_if_kinto_was_not_initialized(self):
        config = testing.setUp()
        with self.assertRaises(ConfigurationError):
            config.include(includeme)
项目:kinto-ldap    作者:Kinto    | 项目源码 | 文件源码
def test_settings_are_filled_with_defaults(self):
        config = testing.setUp()
        kinto.core.initialize(config, '0.0.1')
        config.include(includeme)
        settings = config.get_settings()
        self.assertIsNotNone(settings.get('ldap.cache_ttl_seconds'))
项目:kinto-ldap    作者:Kinto    | 项目源码 | 文件源码
def test_a_heartbeat_is_registered_at_oauth(self):
        config = testing.setUp()
        kinto.core.initialize(config, '0.0.1')
        config.registry.heartbeats = {}
        config.include(includeme)
        self.assertIsNotNone(config.registry.heartbeats.get('ldap'))
项目:kinto-ldap    作者:Kinto    | 项目源码 | 文件源码
def test_connection_manager_is_instantiated_with_settings(self):
        config = testing.setUp()
        kinto.core.initialize(config, '0.0.1')
        with mock.patch('kinto_ldap.ConnectionManager') as mocked:
            includeme(config)
            mocked.assert_called_with(retry_delay=0.1,
                                      retry_max=3,
                                      size=10,
                                      timeout=30,
                                      uri='ldap://ldap.db.scl3.mozilla.com')
项目:kinto-ldap    作者:Kinto    | 项目源码 | 文件源码
def test_include_fails_if_ldap_filters_contains_multiple_keys(self):
        config = testing.setUp()
        settings = config.get_settings()
        settings['ldap.filters'] = '{uid}{mail}'
        kinto.core.initialize(config, '0.0.1')
        with self.assertRaises(ConfigurationError) as e:
            config.include(includeme)
        message = "ldap.filters should take a 'mail' argument only, got: '{uid}{mail}'"
        self.assertEqual(str(e.exception), message)
项目:nflpool    作者:prcutler    | 项目源码 | 文件源码
def setUp(self):
        self.config = testing.setUp()
项目:nflpool    作者:prcutler    | 项目源码 | 文件源码
def setUp(self):
        from nflpool import main
        app = main({})
        from webtest import TestApp
        self.testapp = TestApp(app)
项目:openregistry.api    作者:openprocurement    | 项目源码 | 文件源码
def setUp(self):
        self.config = testing.setUp()
项目:openregistry.api    作者:openprocurement    | 项目源码 | 文件源码
def setUp(self):
        super(TestAPIResourceListing, self).setUp()
        self.config.include('cornice')
        self.config.scan('.views')

        self.request = testing.DummyRequest()
        self.request.registry.db = Mock()
        self.request.registry.server_id = Mock()
        self.request.registry.couchdb_server = Mock()
        self.request.registry.update_after = True

        self.context = Mock()
项目:consuming_services_python_demos    作者:mikeckennedy    | 项目源码 | 文件源码
def setUp(self):
        self.config = testing.setUp()
项目:consuming_services_python_demos    作者:mikeckennedy    | 项目源码 | 文件源码
def setUp(self):
        from consuming_services_apis import main
        app = main({})
        from webtest import TestApp
        self.testapp = TestApp(app)
项目:kinto-portier    作者:Kinto    | 项目源码 | 文件源码
def test_include_fails_if_kinto_was_not_initialized(self):
        config = testing.setUp()
        with self.assertRaises(ConfigurationError):
            config.include(includeme)
项目:kinto-portier    作者:Kinto    | 项目源码 | 文件源码
def test_settings_are_filled_with_defaults(self):
        config = testing.setUp()
        kinto.core.initialize(config, '0.0.1')
        config.include(includeme)
        settings = config.get_settings()
        self.assertIsNotNone(settings.get('portier.broker_uri'))
项目:kinto-portier    作者:Kinto    | 项目源码 | 文件源码
def test_a_heartbeat_is_registered_at_portier(self):
        config = testing.setUp()
        kinto.core.initialize(config, '0.0.1')
        config.registry.heartbeats = {}
        config.include(includeme)
        self.assertIsNotNone(config.registry.heartbeats.get('portier'))
项目:pyramid_notebook    作者:websauna    | 项目源码 | 文件源码
def pyramid_request(request):

    from pyramid import testing

    testing.setUp()
    def teardown():
        testing.tearDown()

    request.addfinalizer(teardown)

    _request = testing.DummyRequest()
    return _request
项目:peecp    作者:peereesook    | 项目源码 | 文件源码
def setUp(self):
        super(TestMyViewSuccessCondition, self).setUp()
        self.init_database()

        from .models import MyModel

        model = MyModel(name='one', value=55)
        self.session.add(model)
项目:pyramid-zappa-api-boilerplate    作者:web-masons    | 项目源码 | 文件源码
def setUp(self):
        super(TestMyViewSuccessCondition, self).setUp()
        self.init_database()

        from .models import MyModel

        model = MyModel(name='one', value=55)
        self.session.add(model)