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

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

项目:stalker_pyramid    作者:eoyilmaz    | 项目源码 | 文件源码
def tearDown(self):
        """clean up the test
        """
        shutil.rmtree(defaults.server_side_storage_path)

        # remove generic_temp_folder
        shutil.rmtree(self.temp_test_data_folder, ignore_errors=True)

        # remove repository
        shutil.rmtree(self.test_repo_path, ignore_errors=True)

        # clean up test database
        # from stalker.db.declarative import Base
        # Base.metadata.drop_all(db.DBSession.connection())
        # db.DBSession.commit()
        db.DBSession.remove()
        testing.tearDown()
项目:stalker_pyramid    作者:eoyilmaz    | 项目源码 | 文件源码
def tearDown(self):
        """clean up the test
        """
        import datetime
        import transaction
        from stalker import defaults
        from stalker.db.session import DBSession
        from stalker.db.declarative import Base
        from pyramid import testing

        testing.tearDown()

        # clean up test database
        connection = DBSession.connection()
        engine = connection.engine
        connection.close()
        Base.metadata.drop_all(engine)
        transaction.commit()
        DBSession.remove()

        defaults.timing_resolution = datetime.timedelta(hours=1)
项目:stalker_pyramid    作者:eoyilmaz    | 项目源码 | 文件源码
def tearDown(self):
        """clean up the test
        """
        import datetime
        import transaction
        from stalker import defaults
        from stalker.db.declarative import Base
        from stalker.db.session import DBSession

        from pyramid import testing
        testing.tearDown()

        # clean up test database
        connection = DBSession.connection()
        engine = connection.engine
        connection.close()
        Base.metadata.drop_all(engine)
        transaction.commit()
        DBSession.remove()

        defaults.timing_resolution = datetime.timedelta(hours=1)
项目: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
项目: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
项目:pyramid_runner    作者:asif-mahmud    | 项目源码 | 文件源码
def tearDown(self):
        """Calls `pyramid.testing.tearDown` and `transaction.abort`.

        Prior to calling these methods if any `clean_db` method is
        defined, it will be called. Do database clean ups there.
        """
        try:
            __clean_db = self.__getattribute__('clean_db')
            if callable(__clean_db):
                with transaction.manager:
                    __clean_db()
        except AttributeError:
            pass

        testing.tearDown()
        transaction.abort()
项目: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
项目: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')
项目: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
项目: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
项目:fantasy-dota-heroes    作者:ThePianoDentist    | 项目源码 | 文件源码
def tearDown(self):
        DBSession.remove()
        testing.tearDown()
项目:fantasy-dota-heroes    作者:ThePianoDentist    | 项目源码 | 文件源码
def tearDown(self):
        DBSession.remove()
        testing.tearDown()
项目:eea.corpus    作者:eea    | 项目源码 | 文件源码
def teardown_class(cls):
        testing.tearDown()
项目:eea.corpus    作者:eea    | 项目源码 | 文件源码
def teardown_class(cls):
        testing.tearDown()
项目: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 tearDown(self):
        DBSession.remove()
        testing.tearDown()
项目:pyramid_starter    作者:jmercouris    | 项目源码 | 文件源码
def tearDown(self):
        DBSession.remove()
        testing.tearDown()
项目:lagendacommun    作者:ecreall    | 项目源码 | 文件源码
def tearDown(self):
        stop_ioloop()
        import shutil
        testing.tearDown()
        self.db.close()
        shutil.rmtree(self.tmpdir)
项目:lagendacommun    作者:ecreall    | 项目源码 | 文件源码
def tearDown(self):
        super(RobotLayer, self).tearDown()
        self.server.shutdown()
项目:pyramid-cookiecutter-starter-chameleon    作者:mikeckennedy    | 项目源码 | 文件源码
def tearDown(self):
        testing.tearDown()
项目: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
项目:turingtweets    作者:jjfeore    | 项目源码 | 文件源码
def test_app(request):
    """Instantiate a turing tweet app for testing."""
    from webtest import TestApp
    from pyramid.config import Configurator

    def main(global_config, **settings):
        """Return a Pyramid WSGI application."""
        settings['sqlalchemy.url'] = os.environ.get('DATABASE_URL_TESTING')
        config = Configurator(settings=settings)
        config.include('pyramid_jinja2')
        config.include('.models')
        config.include('.routes')
        config.scan()
        return config.make_wsgi_app()

    app = main({})
    testapp = TestApp(app)

    session_factory = app.registry["dbsession_factory"]
    engine = session_factory().bind
    Base.metadata.create_all(bind=engine)

    def tearDown():
        Base.metadata.drop_all(bind=engine)
    request.addfinalizer(tearDown)
    return testapp
项目:unsonic    作者:redshodan    | 项目源码 | 文件源码
def ptesting(xmllint):
    yield testing
    testing.tearDown()
项目:nflpool    作者:prcutler    | 项目源码 | 文件源码
def tearDown(self):
        testing.tearDown()
项目:openregistry.api    作者:openprocurement    | 项目源码 | 文件源码
def tearDown(self):
        testing.tearDown()
项目:consuming_services_python_demos    作者:mikeckennedy    | 项目源码 | 文件源码
def tearDown(self):
        testing.tearDown()
项目: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 tearDown(self):
        from .models.meta import Base

        testing.tearDown()
        transaction.abort()
        Base.metadata.drop_all(self.engine)
项目:pyramid-zappa-api-boilerplate    作者:web-masons    | 项目源码 | 文件源码
def tearDown(self):
        from .models.meta import Base

        testing.tearDown()
        transaction.abort()
        Base.metadata.drop_all(self.engine)
项目:talk-python-search-service    作者:mikeckennedy    | 项目源码 | 文件源码
def tearDown(self):
        testing.tearDown()
项目:safe_giveaway    作者:Jeremydavisvt    | 项目源码 | 文件源码
def tearDown(self):
        DBSession.remove()
        testing.tearDown()
项目:safe_giveaway    作者:Jeremydavisvt    | 项目源码 | 文件源码
def tearDown(self):
        DBSession.remove()
        testing.tearDown()
项目:annotran    作者:BirkbeckCTP    | 项目源码 | 文件源码
def tearDown(self):
        testing.tearDown()
项目:work4la    作者:alexchao    | 项目源码 | 文件源码
def tearDown(self):
        testing.tearDown()
项目:pyramidVue    作者:eddyekofo94    | 项目源码 | 文件源码
def tearDown(self):
        testing.tearDown()
项目:websauna    作者:websauna    | 项目源码 | 文件源码
def csrf_app(request):
    """py.test fixture to set up a dummy app for CSRF testing.

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

    session = DummySession()

    config = testing.setUp()
    config.set_default_csrf_options(require_csrf=True)
    config.add_route("home", "/")
    config.add_route("csrf_sample", "/csrf_sample")
    config.add_route("csrf_exempt_sample", "/csrf_exempt_sample")
    config.add_route("csrf_exempt_sample_context", "/csrf_exempt_sample_context")
    config.add_route("csrf_sample_double_argument", "/csrf_sample_double_argument/{arg}")
    config.add_route("csrf_exempt_sample_double_argument", "/csrf_exempt_sample_double_argument/{arg}")
    config.scan(csrfsamples)

    # We need sessions in order to use CSRF feature

    def dummy_session_factory(secret):
        # Return the same session over and over again
        return session

    config.set_session_factory(dummy_session_factory)

    def teardown():
        testing.tearDown()

    app = TestApp(config.make_wsgi_app())
    # Expose session data for tests to read
    app.session = session
    return app
项目:websauna    作者:websauna    | 项目源码 | 文件源码
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()
项目:assignment_aa    作者:RaHus    | 项目源码 | 文件源码
def tearDown(self):
        from .models.meta import Base

        testing.tearDown()
        transaction.abort()
        Base.metadata.drop_all(self.engine)
项目:EDDB_JsonAPI    作者:FuelRats    | 项目源码 | 文件源码
def tearDown(self):
        from .models.meta import Base

        testing.tearDown()
        transaction.abort()
        Base.metadata.drop_all(self.engine)
项目:dbas    作者:hhucn    | 项目源码 | 文件源码
def tearDown(self):
        testing.tearDown()
项目:dbas    作者:hhucn    | 项目源码 | 文件源码
def tearDown(self):
        testing.tearDown()
        clear_seen_by_of('Tobias')
        clear_clicks_of('Tobias')
        clear_seen_by_of('Björn')
        clear_clicks_of('Björn')
项目:dbas    作者:hhucn    | 项目源码 | 文件源码
def tearDown(self):
        testing.tearDown()
项目:dbas    作者:hhucn    | 项目源码 | 文件源码
def tearDown(self):
        testing.tearDown()
项目:dbas    作者:hhucn    | 项目源码 | 文件源码
def tearDown(self):
        testing.tearDown()
项目:dbas    作者:hhucn    | 项目源码 | 文件源码
def tearDown(self):
        testing.tearDown()
项目:dbas    作者:hhucn    | 项目源码 | 文件源码
def tearDown(self):
        testing.tearDown()
项目:dbas    作者:hhucn    | 项目源码 | 文件源码
def tearDown(self):
        testing.tearDown()
项目:dbas    作者:hhucn    | 项目源码 | 文件源码
def tearDown(self):
        testing.tearDown()