本文整理汇总了Python中multiproduct.env.ProductEnvironment.db_direct_query方法的典型用法代码示例。如果您正苦于以下问题:Python ProductEnvironment.db_direct_query方法的具体用法?Python ProductEnvironment.db_direct_query怎么用?Python ProductEnvironment.db_direct_query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiproduct.env.ProductEnvironment
的用法示例。
在下文中一共展示了ProductEnvironment.db_direct_query方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EnvironmentUpgradeTestCase
# 需要导入模块: from multiproduct.env import ProductEnvironment [as 别名]
# 或者: from multiproduct.env.ProductEnvironment import db_direct_query [as 别名]
class EnvironmentUpgradeTestCase(unittest.TestCase):
def setUp(self, options=()):
env_path = tempfile.mkdtemp(prefix='bh-product-tempenv-')
self.env = Environment(env_path, create=True, options=options)
DummyPlugin.version = 1
def tearDown(self):
shutil.rmtree(self.env.path)
def test_can_upgrade_environment_with_multi_product_disabled(self):
self.env.upgrade()
# Multiproduct was not enabled so multiproduct tables should not exist
for table in BLOODHOUND_TABLES:
with self.assertFailsWithMissingTable():
self.env.db_direct_query("SELECT * FROM %s" % table)
for table in TABLES_WITH_PRODUCT_FIELD:
with self.assertFailsWithMissingColumn():
self.env.db_direct_query("SELECT product FROM %s" % table)
def test_upgrade_creates_multi_product_tables_and_adds_product_column(self):
self._enable_multiproduct()
self.env.upgrade()
with self.env.db_direct_transaction as db:
for table in BLOODHOUND_TABLES:
db("SELECT * FROM %s" % table)
for table in TABLES_WITH_PRODUCT_FIELD:
db("SELECT product FROM %s" % table)
def test_upgrade_creates_default_product(self):
self._enable_multiproduct()
self.env.upgrade()
products = Product.select(self.env)
self.assertEqual(len(products), 1)
def test_upgrade_moves_tickets_and_related_objects_to_default_prod(self):
self._add_custom_field('custom_field')
with self.env.db_direct_transaction as db:
db("""INSERT INTO ticket (id) VALUES (1)""")
db("""INSERT INTO attachment (type, id, filename)
VALUES ('ticket', '1', '')""")
db("""INSERT INTO ticket_custom (ticket, name, value)
VALUES (1, 'custom_field', '42')""")
db("""INSERT INTO ticket_change (ticket, time, field)
VALUES (1, 42, 'summary')""")
self._enable_multiproduct()
self.env.upgrade()
with self.product('@'):
ticket = Ticket(self.env, 1)
attachments = list(Attachment.select(self.env,
ticket.resource.realm,
ticket.resource.id))
self.assertEqual(len(attachments), 1)
self.assertEqual(ticket['custom_field'], '42')
changes = ticket.get_changelog()
self.assertEqual(len(changes), 3)
def test_upgrade_moves_custom_wikis_to_default_product(self):
with self.env.db_direct_transaction as db:
db("""INSERT INTO wiki (name, version) VALUES ('MyPage', 1)""")
db("""INSERT INTO attachment (type, id, filename)
VALUES ('wiki', 'MyPage', '')""")
self._enable_multiproduct()
self.env.upgrade()
with self.env.db_direct_transaction as db:
self.assertEqual(
len(db("""SELECT * FROM wiki WHERE product='@'""")), 1)
self.assertEqual(
len(db("""SELECT * FROM attachment
WHERE product='@'
AND type='wiki'""")), 1)
def test_upgrade_moves_system_wikis_to_products(self):
with self.env.db_direct_transaction as db:
db("""INSERT INTO wiki (name, version) VALUES ('WikiStart', 1)""")
db("""INSERT INTO attachment (type, id, filename)
VALUES ('wiki', 'WikiStart', '')""")
self._enable_multiproduct()
self.env.upgrade()
with self.env.db_direct_transaction as db:
self.assertEqual(
len(db("""SELECT * FROM wiki WHERE product='@'""")), 1)
self.assertEqual(
len(db("""SELECT * FROM attachment
WHERE product='@'
AND type='wiki'""")), 1)
self.assertEqual(
len(db("""SELECT * FROM wiki WHERE product=''""")), 0)
self.assertEqual(
len(db("""SELECT * FROM attachment
#.........这里部分代码省略.........