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


Python ProductEnvironment.reset_db方法代码示例

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


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

示例1: ProductAttachmentTestCase

# 需要导入模块: from multiproduct.env import ProductEnvironment [as 别名]
# 或者: from multiproduct.env.ProductEnvironment import reset_db [as 别名]
class ProductAttachmentTestCase(AttachmentTestCase, MultiproductTestCase):

    def setUp(self):
        try:
            AttachmentTestCase.setUp(self)
        except:
            self.global_env = self.env
            self.tearDown()
            raise
        else:
            self.global_env = global_env = self.env
            self._upgrade_mp(global_env)
            self._setup_test_log(global_env)
            self._load_product_from_data(global_env, self.default_product)
            self.env = ProductEnvironment(global_env, self.default_product)

            # Root folder for default product environment
            self.attachments_dir = os.path.join(self.global_env.path,
                    'products', self.default_product, 'files', 'attachments')

    def tearDown(self):
        if os.path.exists(self.global_env.path):
            shutil.rmtree(self.global_env.path)
        self.env.reset_db()

    def test_product_path_isolation(self):
        product_attachment = Attachment(self.env, 'ticket', '42')
        global_attachment = Attachment(self.global_env, 'ticket', '42')
        global_attachment.filename = product_attachment.filename = 'foo.txt'

        self.assertNotEqual(product_attachment.path, global_attachment.path)
开发者ID:mohsadki,项目名称:dargest,代码行数:33,代码来源:attachment.py

示例2: ProductTestCase

# 需要导入模块: from multiproduct.env import ProductEnvironment [as 别名]
# 或者: from multiproduct.env.ProductEnvironment import reset_db [as 别名]
class ProductTestCase(unittest.TestCase):
    """Unit tests covering the Product model"""
    INITIAL_PREFIX = 'tp'
    INITIAL_NAME = 'test project'
    INITIAL_DESCRIPTION = 'a test project'

    def setUp(self):
        self.env = EnvironmentStub(enable=['trac.*', 'multiproduct.*'])
        self.env.path = tempfile.mkdtemp(prefix='bh-product-tempenv-')

        self.mpsystem = MultiProductSystem(self.env)
        try:
            self.mpsystem.upgrade_environment(self.env.db_transaction)
        except self.env.db_exc.OperationalError:
            # table remains but database version is deleted
            pass

        self.listener = self._enable_resource_change_listener()
        self.default_data = {'prefix':self.INITIAL_PREFIX,
                             'name':self.INITIAL_NAME,
                             'description':self.INITIAL_DESCRIPTION}

        self.global_env = self.env
        self.product = Product(self.env)
        self.product._data.update(self.default_data)
        self.product.insert()

    def tearDown(self):
        shutil.rmtree(self.env.path)
        self.env.reset_db()

    def _enable_resource_change_listener(self):
        listener = TestResourceChangeListener(self.env)
        listener.resource_type = Product
        listener.callback = self.listener_callback
        return listener

    def listener_callback(self, action, resource, context, old_values = None):
        # pylint: disable=unused-argument
        # pylint: disable=attribute-defined-outside-init
        self.prefix = resource.prefix
        self.name = resource.name
        self.description = resource.description

    def test_set_table_field(self):
        """tests that table.field style update works"""
        test = {'prefix': 'td',
                'name': 'test field access',
                'description': 'product to test field setting'}

        product = Product(self.env)

        # attempt to set the fields from the data
        product.prefix = test['prefix']
        product.name = test['name']
        product.description = test['description']

        self.assertEqual(product._data['prefix'], test['prefix'])
        self.assertEqual(product._data['name'], test['name'])
        self.assertEqual(product._data['description'], test['description'])

    def test_select(self):
        """tests that select can search Products by fields"""

        p2_data = {'prefix':'tp2',
                   'name':'test project 2',
                   'description':'a different test project'}
        p3_data = {'prefix':'tp3',
                   'name':'test project 3',
                   'description':'test project'}

        product2 = Product(self.env)
        product2._data.update(p2_data)
        product3 = Product(self.env)
        product3._data.update(p3_data)

        product2.insert()
        product3.insert()

        products = list(Product.select(self.env, where={'prefix':'tp'}))
        self.assertEqual(1, len(products))
        products = list(Product.select(self.env,
            where={'name':'test project'}))
        self.assertEqual(1, len(products))
        products = list(Product.select(self.env,
            where={'prefix':'tp3', 'name':'test project 3'}))
        self.assertEqual(1, len(products))

    def test_update(self):
        """tests that we can use update to push data to the database"""
        product = list(Product.select(self.env, where={'prefix':'tp'}))[0]
        self.assertEqual('test project', product._data['name'])

        new_data = {'prefix':'tp',
                    'name':'updated',
                    'description':'nothing'}
        product._data.update(new_data)
        product.update()

        comp_product = list(Product.select(self.env, where={'prefix':'tp'}))[0]
#.........这里部分代码省略.........
开发者ID:mohsadki,项目名称:dargest,代码行数:103,代码来源:model.py


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