当前位置: 首页>>代码示例>>Python>>正文


Python SQLAlchemyFixture.data方法代码示例

本文整理汇总了Python中fixture.SQLAlchemyFixture.data方法的典型用法代码示例。如果您正苦于以下问题:Python SQLAlchemyFixture.data方法的具体用法?Python SQLAlchemyFixture.data怎么用?Python SQLAlchemyFixture.data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fixture.SQLAlchemyFixture的用法示例。


在下文中一共展示了SQLAlchemyFixture.data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setup_app

# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
def setup_app(command, conf, vars):
    """Place any commands to setup tracking here"""
    load_environment(conf.global_conf, conf.local_conf)

    filename = os.path.split(conf.filename)[-1]

    if filename == 'test.ini':
        
        # Permanently drop any existing tables
        
        log.info("Dropping existing tables...")
        
        meta.Base.metadata.drop_all(bind=meta.engine, checkfirst=True)

    log.info("Creating tables...")

    # Create the tables if they don't already exist
    meta.Base.metadata.create_all(bind=meta.engine)
    
    log.info("Successfully set up.")
    
    if filename == 'development.ini':
    
        # load sample data during setup-app
    
        db = SQLAlchemyFixture(
                env=model, style=NamedDataStyle(),
                engine=meta.engine)
            
        data = db.data(PageviewsData)
        log.info("Loading sample data...")
        data.setup()
        
    log.info("Successfully set up.")
开发者ID:raygunsix,项目名称:tracking,代码行数:36,代码来源:websetup.py

示例2: TestListView

# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
class TestListView(TestCase):
    """Tests for DetailView."""
    urls = 'tests.integration.views.generic.urls'

    def setUp(self):
        setup_environment()

        self.fixture = SQLAlchemyFixture(
            env=models,
            session=session,
            style=NamedDataStyle(),
        )

    def test_list_view(self):
        """Test the list view."""
        with self.fixture.data(fixtures.PersonData) as data:
            response = self.client.get('/people/')

        self.assertEqual(response.status_code, 200)
        self.assertIn(data.PersonData.John.name, response.content)

    def test_list_view_allow_empty(self):
        """Test getting an empty list with allow_empty = True."""
        response = self.client.get('/people/')

        self.assertEqual(response.status_code, 200)

    def test_list_view_404(self):
        """Test getting an empty list with allow_empty = False."""
        response = self.client.get('/non_empty_people/')

        self.assertEqual(response.status_code, 404)
开发者ID:grampajoe,项目名称:tincture,代码行数:34,代码来源:test_list.py

示例3: install

# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
def install(app, *args):
    engine = m.create_tables(app)
    db = SQLAlchemyFixture(env=m, style=NamedDataStyle(), engine=engine)
    data = db.data(*args)
    data.setup()
    db.dispose()
    return data
开发者ID:JohnBrodie,项目名称:whatup-api,代码行数:9,代码来源:__init__.py

示例4: test_fixture_can_be_disposed

# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
def test_fixture_can_be_disposed():
    if sa_major < 0.5:
        from sqlalchemy.exceptions import InvalidRequestError
    else:
        from sqlalchemy.exc import InvalidRequestError
    engine = create_engine(conf.LITE_DSN)
    metadata.bind = engine
    metadata.create_all()
    Session = get_transactional_session()
    session = Session()
    fixture = SQLAlchemyFixture(
        env={'CategoryData':Category},
        engine=metadata.bind
    )
    
    class CategoryData(DataSet):
        class cars:
            name = 'cars'
        class free_stuff:
            name = 'get free stuff'
    
    clear_mappers()
    mapper(Category, categories)
        
    data = fixture.data(CategoryData)
    data.setup()
    data.teardown()
    
    fixture.dispose()
    
    # cannot use fixture anymore :
    try:
        data.setup()
    except InvalidRequestError:
        pass
    else:
        assert False, "data.setup() did not raise InvalidRequestError after connection was disposed"
    
    # a new instance of everything is needed :
    metadata.create_all()
    fixture = SQLAlchemyFixture(
        env={'CategoryData':Category},
        engine=metadata.bind
    )
    data = fixture.data(CategoryData)
    data.setup()
    data.teardown()
开发者ID:JamesX88,项目名称:tes,代码行数:49,代码来源:test_sqlalchemy_loadable.py

示例5: setUp

# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
 def setUp(self):
     self.app = create_app('config/test.ini').test_client()
     init_db()
     # TODO move this to the proper place in the code
     dbfixture = SQLAlchemyFixture(
         env={'UserData': User},
         engine=dailylog.db.engine)
     self.data = dbfixture.data(UserData)
     self.data.setup()
开发者ID:amitm,项目名称:DailyLog,代码行数:11,代码来源:test_dailylog.py

示例6: DBFixture

# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
class DBFixture(fixtures.Fixture):

    def setUp(self):
        super(DBFixture, self).setUp()
        self.dbfixture = SQLAlchemyFixture(engine=get_engine(),
                                           env={'TreeNodeData': TreeNode})
        self.data = self.dbfixture.data(TreeNodeData)
        self.data.setup()
        self.addCleanup(self.data.teardown)
开发者ID:jianingy,项目名称:treestore,代码行数:11,代码来源:test_service.py

示例7: DBFixture

# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
class DBFixture(fixtures.Fixture):

    def setUp(self):
        super(DBFixture, self).setUp()
        self.dbfixture = SQLAlchemyFixture(
            engine=get_engine(),
            env={'MpProviderData': Provider})
        self.data = self.dbfixture.data(MpProviderData)
        self.data.setup()
        self.addCleanup(self.data.teardown)
开发者ID:wzqwsrf,项目名称:itdb,代码行数:12,代码来源:test_provider_dal.py

示例8: DBFixture

# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
class DBFixture(fixtures.Fixture):

    def setUp(self):
        super(DBFixture, self).setUp()
        self.dbfixture = SQLAlchemyFixture(
            engine=get_engine(),
            env={'AssetInfoData': AssetInfoModel})
        self.data = self.dbfixture.data(AssetInfoData)
        self.data.setup()
        self.addCleanup(self.data.teardown)
开发者ID:wzqwsrf,项目名称:itdb,代码行数:12,代码来源:test_asset_info_dal.py

示例9: setUp

# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
 def setUp(self):
     db.create_all()
     
     fixture = SQLAlchemyFixture( env=models,
         style=TrimmedNameStyle(suffix="Data"),
         session=db.session)
     try:
         self.data = fixture.data(*self.fixtures)
     except TypeError:
         raise Error('You need overide "fixtures = None" with the name of some real fixtures')
     self.data.setup()
开发者ID:colwilson,项目名称:Flask-rename-your-application,代码行数:13,代码来源:tests.py

示例10: DBFixture

# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
class DBFixture(fixtures.Fixture):
    def setUp(self):
        super(DBFixture, self).setUp()
        self.session = get_session()
        self.dbfixture = SQLAlchemyFixture(
            engine=get_engine(),
            env=dict(UserData=UserHstore)
        )
        self.data = self.dbfixture.data(UserData)
        self.data.setup()
        self.addCleanup(self.data.teardown)
开发者ID:wzqwsrf,项目名称:hstore,代码行数:13,代码来源:test_user_service.py

示例11: DBFixture

# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
class DBFixture(fixtures.Fixture):
    def setUp(self):
        super(DBFixture, self).setUp()
        self.engine = db_api.get_engine()
        self.engine.connect()
        self.dbfixture = SQLAlchemyFixture(engine=self.engine, env={"StoreStateMock": StoreState})
        self.data = self.dbfixture.data(StoreStateMock)
        self.session = db_api.get_session()
        BASE.metadata.create_all(bind=self.engine)
        self.data.setup()
        self.addCleanup(self.data.teardown)
开发者ID:wzqwsrf,项目名称:itdb,代码行数:13,代码来源:test_store_state_dal.py

示例12: DBFixture

# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
class DBFixture(fixtures.Fixture):

    def setUp(self):
        super(DBFixture, self).setUp()
        self.dbfixture = SQLAlchemyFixture(
            engine=get_engine(),
            env={'AssetConsumeInfoData': AssetConsumeInfoModel})
        self.data = self.dbfixture.data(AssetConsumeInfoData)
        BASE.metadata.create_all(get_engine())
        self.data.setup()
        self.addCleanup(self.data.teardown)
开发者ID:wzqwsrf,项目名称:itdb,代码行数:13,代码来源:test_asset_consume_info_dal.py

示例13: DBFixture

# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
class DBFixture(fixtures.Fixture):

    def setUp(self):
        super(DBFixture, self).setUp()
        self.dbfixture = SQLAlchemyFixture(
            engine=get_engine(),
            env={'DeviceStateData': DeviceState})
        self.data = self.dbfixture.data(DeviceStateData)
        BASE.metadata.create_all(get_engine())
        self.data.setup()
        self.addCleanup(self.data.teardown)
开发者ID:wzqwsrf,项目名称:itdb,代码行数:13,代码来源:test_device_state_dal.py

示例14: DBFixture

# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
class DBFixture(fixtures.Fixture):

    def setUp(self):
        super(DBFixture, self).setUp()
        print get_engine()
        self.dbfixture = SQLAlchemyFixture(
            engine=get_engine(),
            env={'InOutData': InOutReason})
        self.data = self.dbfixture.data(InOutData)
        self.data.setup()
        self.addCleanup(self.data.teardown)
开发者ID:wzqwsrf,项目名称:itdb,代码行数:13,代码来源:test_in_out_reason_dal.py

示例15: TestCollidingSessions

# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
class TestCollidingSessions(unittest.TestCase):
    class CategoryData(DataSet):
        class cars:
            name = 'cars'
        class free_stuff:
            name = 'get free stuff'
            
    def setUp(self):
        self.engine = create_engine(conf.LITE_DSN)
        # self.conn = self.engine.connect()
        metadata.bind = self.engine
        # metadata.bind.echo = True
        metadata.create_all()
        # metadata.bind.echo = False
        self.ScopedSession = scoped_session(get_transactional_session())
        self.session = self.ScopedSession()
        self.fixture = SQLAlchemyFixture(
            env={'CategoryData':Category},
            engine=metadata.bind
        )
        
        clear_mappers()
        mapper(Category, categories)
    
    def tearDown(self):
        metadata.drop_all()
        self.session.close()
    
    @attr(functional=1)
    def test_setup_then_teardown(self):
        eq_(self.session.query(Category).all(), [])
        
        data = self.fixture.data(self.CategoryData)
        data.setup()
        clear_session(self.session)
        
        cats = self.session.query(Category).order_by('name').all()
        eq_(cats[0].name, 'cars')
        eq_(cats[1].name, 'get free stuff')
        
        # simulate the application running into some kind of error:
        new_cat = Category()
        new_cat.name = "doomed to non-existance"
        save_session(self.session, new_cat)
        self.session.rollback()
        self.ScopedSession.remove()
        
        data.teardown()
        clear_session(self.session)
        
        print [(c.id, c.name) for c in self.session.query(Category).all()]
开发者ID:JamesX88,项目名称:tes,代码行数:53,代码来源:test_sqlalchemy_loadable.py


注:本文中的fixture.SQLAlchemyFixture.data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。