本文整理汇总了Python中multiproduct.env.ProductEnvironment类的典型用法代码示例。如果您正苦于以下问题:Python ProductEnvironment类的具体用法?Python ProductEnvironment怎么用?Python ProductEnvironment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProductEnvironment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ProductMilestoneTestCase
class ProductMilestoneTestCase(MilestoneTestCase, MultiproductTestCase):
def setUp(self):
self.global_env = self._setup_test_env(create_folder=True)
self._upgrade_mp(self.global_env)
self._setup_test_log(self.global_env)
self._load_product_from_data(self.global_env, self.default_product)
self.env = ProductEnvironment(self.global_env, self.default_product)
self._load_default_data(self.env)
def tearDown(self):
shutil.rmtree(self.global_env.path)
self.global_env.reset_db()
self.env = self.global_env = None
def test_update_milestone(self):
self.env.db_transaction("INSERT INTO milestone (name) VALUES ('Test')")
milestone = Milestone(self.env, 'Test')
t1 = datetime(2001, 01, 01, tzinfo=utc)
t2 = datetime(2002, 02, 02, tzinfo=utc)
milestone.due = t1
milestone.completed = t2
milestone.description = 'Foo bar'
milestone.update()
self.assertEqual(
[('Test', to_utimestamp(t1), to_utimestamp(t2), 'Foo bar',
self.default_product)],
self.env.db_query("SELECT * FROM milestone WHERE name='Test'"))
示例2: ProductAttachmentTestCase
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)
示例3: _get_product_info
def _get_product_info(self, product, href, resource, max_):
penv = ProductEnvironment(self.env, product.prefix)
results = []
# some queries return a list/tuple, some a generator,
# hence count() to get the result length
def count(iter_):
try:
return len(iter_)
except TypeError:
return sum(1 for _ in iter_)
query = resource['type'].select(penv)
for q in itertools.islice(query, max_):
q.url = href(resource['name'], q.name) \
if resource.get('hrefurl') \
else Query.from_string(penv,
'%s=%s&%s&col=%s' % (resource['name'], q.name,
self.COMMON_QUERY, resource['name'])
).get_href(href)
q.ticket_count = penv.db_query("""
SELECT COUNT(*) FROM ticket WHERE ticket.%s='%s'
AND ticket.status <> 'closed'
""" % (resource['name'], q.name))[0][0]
results.append(q)
# add a '(No <milestone/component/version>)' entry if there are
# tickets without an assigned resource in the product
ticket_count = penv.db_query(
"""SELECT COUNT(*) FROM ticket WHERE %s=''
AND status <> 'closed'""" % (resource['name'],))[0][0]
if ticket_count != 0:
q = resource['type'](penv)
q.name = '(No %s)' % (resource['name'],)
q.url = Query.from_string(penv,
'status=!closed&col=id&col=summary&col=owner'
'&col=status&col=priority&order=priority&%s='
% (resource['name'],)
).get_href(href)
q.ticket_count = ticket_count
results.append(q)
results.sort(key=lambda x: x.ticket_count, reverse=True)
# add a link to the resource list if there are
# more than max resources defined
if count(query) > max_:
q = resource['type'](penv)
q.name = _('... more')
q.ticket_count = None
q.url = href(resource['name']) if resource.get('hrefurl') \
else href.dashboard()
results.append(q)
return results
示例4: add_template_data
def add_template_data(self, req, data, tickets):
if isinstance(self.env, ProductEnvironment):
super(ProductBatchModifyModule, self).add_template_data(req, data,
tickets)
return
data['batch_modify'] = True
data['query_href'] = req.session['query_href'] or req.href.query()
tickets_by_product = {}
for t in tickets:
tickets_by_product.setdefault(t['product'], []).append(t)
data['action_controls'] = []
global_env = ProductEnvironment.lookup_global_env(self.env)
cache = {}
for k, v in tickets_by_product.iteritems():
batch_module = cache.get(k or '')
if batch_module is None:
env = ProductEnvironment(global_env, k) if k else global_env
cache[k] = batch_module = ProductBatchModifyModule(env)
data['action_controls'] += batch_module._get_action_controls(req,
v)
batch_list_modes = [
{'name': _("add"), 'value': "+"},
{'name': _("remove"), 'value': "-"},
{'name': _("add / remove"), 'value': "+-"},
{'name': _("set to"), 'value': "="},
]
add_script_data(req, batch_list_modes=batch_list_modes,
batch_list_properties=self._get_list_fields())
示例5: product_admincmd_mgr
def product_admincmd_mgr(self, prefix):
try:
product_env = ProductEnvironment.lookup_env(self.env, prefix)
except LookupError:
raise AdminCommandError('Unknown product %s' % (prefix,))
else:
return AdminCommandManager(product_env)
示例6: test_get_tickets
def test_get_tickets(self):
for pdata in (
{'prefix': 'p2', 'name':'product, too', 'description': ''},
{'prefix': 'p3', 'name':'strike three', 'description': ''},
):
num_tickets = 5
product = Product(self.global_env)
product._data.update(pdata)
product.insert()
self.env = ProductEnvironment(self.global_env, product)
for i in range(num_tickets):
ticket = Ticket(self.env)
ticket['summary'] = 'hello ticket #%s-%d' % (product.prefix, i)
ticket['reporter'] = 'admin'
tid = ticket.insert()
# retrieve tickets using both global and product scope
tickets_from_global = [(t['product'], t['id']) for t in
Product.get_tickets(self.global_env, product.prefix)]
self.assertEqual(len(tickets_from_global), num_tickets)
tickets_from_product = [(t['product'], t['id']) for t in
Product.get_tickets(self.env)]
self.assertEqual(len(tickets_from_product), num_tickets)
# both lists should contain same elements
intersection = set(tickets_from_global) & set(tickets_from_product)
self.assertEqual(len(intersection), num_tickets)
示例7: setUp
def setUp(self):
self.global_env = self._setup_test_env(create_folder=True)
self._upgrade_mp(self.global_env)
self._setup_test_log(self.global_env)
self._load_product_from_data(self.global_env, self.default_product)
self.env = ProductEnvironment(self.global_env, self.default_product)
self._load_default_data(self.env)
示例8: ProductResourceTestCase
class ProductResourceTestCase(MultiproductTestCase):
def setUp(self):
self._mp_setup()
self.global_env = self.env
self._load_product_from_data(self.global_env, u'xü')
self.env = ProductEnvironment(self.global_env, self.default_product)
self.env1 = ProductEnvironment(self.global_env, u'xü')
self._load_default_data(self.global_env)
self._load_default_data(self.env1)
# Enable product system component in product context
self.env.enable_component(MultiProductSystem)
def tearDown(self):
self.global_env.reset_db()
self.global_env = self.env = None
示例9: setUp
def setUp(self):
self._mp_setup()
self.env.path = '/path/to/env'
self.env.abs_href = Href('http://globalenv.com/trac.cgi')
url_pattern = getattr(getattr(self, self._testMethodName).im_func,
'product_base_url', '')
self.env.config.set('multiproduct', 'product_base_url', url_pattern)
self.env.config.set('trac', 'base_url', 'http://globalenv.com/trac.cgi')
self.product_env = ProductEnvironment(self.env, self.default_product)
示例10: post_process_request
def post_process_request(self, req, template, data, content_type):
"""Append necessary ticket data
"""
try:
tm = self._get_ticket_module()
except TracError:
# no ticket module so no create ticket button
return template, data, content_type
if (template, data, content_type) != (None,) * 3: # TODO: Check !
if data is None:
data = {}
dum_req = dummy_request(self.env)
dum_req.perm = req.perm
ticket = Ticket(self.env)
tm._populate(dum_req, ticket, False)
all_fields = dict([f['name'], f]
for f in tm._prepare_fields(dum_req, ticket)
if f['type'] == 'select')
product_field = all_fields.get('product')
if product_field:
# When at product scope, set the default selection to the
# product at current scope. When at global scope the default
# selection is determined by [ticket] default_product
if self.env.product and \
self.env.product.prefix in product_field['options']:
product_field['value'] = self.env.product.prefix
# Transform the options field to dictionary of product
# attributes and filter out products for which user doesn't
# have TICKET_CREATE permission
product_field['options'] = [
dict(value=p,
new_ticket_url=dum_req.href.products(p, 'newticket'),
description=ProductEnvironment.lookup_env(self.env, p)
.product.name
)
for p in product_field['options']
if req.perm.has_permission('TICKET_CREATE',
Neighborhood('product', p)
.child(None, None))]
else:
msg = _("Missing ticket field '%(field)s'.", field='product')
if ProductTicketModule is not None and \
self.env[ProductTicketModule] is not None:
# Display warning alert to users
add_warning(req, msg)
else:
# Include message in logs since this might be a failure
self.log.warning(msg)
data['qct'] = {
'fields': [all_fields[k] for k in self.qct_fields
if k in all_fields],
'hidden_fields': [all_fields[k] for k in all_fields.keys()
if k not in self.qct_fields] }
return template, data, content_type
示例11: setUp
def setUp(self):
self._mp_setup()
self.global_env = self.env
self.env = ProductEnvironment(self.global_env, self.default_product)
self.global_env.enable_component(TestRequestSpy)
self.env.enable_component(TestRequestSpy)
TestRequestSpy(self.global_env).testMatch = self._assert_product_match
PermissionSystem(self.global_env).grant_permission('testuser', 'PRODUCT_CREATE')
PermissionSystem(self.global_env).grant_permission('testuser', 'PRODUCT_VIEW')
PermissionSystem(self.global_env).grant_permission('testuser', 'PRODUCT_MODIFY')
示例12: post_process_request
def post_process_request(self, req, template, data, content_type):
"""Append necessary ticket data
"""
try:
tm = self._get_ticket_module()
except TracError:
# no ticket module so no create ticket button
return template, data, content_type
if (template, data, content_type) != (None,) * 3: # TODO: Check !
if data is None:
data = {}
req = dummy_request(self.env)
ticket = Ticket(self.env)
tm._populate(req, ticket, False)
all_fields = dict([f['name'], f]
for f in tm._prepare_fields(req, ticket)
if f['type'] == 'select')
product_field = all_fields['product']
if product_field:
if self.env.product:
product_field['value'] = self.env.product.prefix
else:
# Global scope, now check default_product_prefix is valid
default_prefix = self.config.get('multiproduct',
'default_product_prefix')
try:
ProductEnvironment.lookup_env(self.env, default_prefix)
except LookupError:
product_field['value'] = product_field['options'][0]
else:
product_field['value'] = default_prefix
data['qct'] = {
'fields': [all_fields[k] for k in self.qct_fields
if k in all_fields],
'hidden_fields': [all_fields[k] for k in all_fields.keys()
if k not in self.qct_fields]
}
return template, data, content_type
示例13: setUp
def setUp(self):
self._mp_setup()
self.global_env = self.env
self._load_product_from_data(self.global_env, u'xü')
self.env = ProductEnvironment(self.global_env, self.default_product)
self.env1 = ProductEnvironment(self.global_env, u'xü')
self._load_default_data(self.global_env)
self._load_default_data(self.env1)
# Enable product system component in product context
self.env.enable_component(MultiProductSystem)
示例14: _process_doc
def _process_doc(self, doc):
ui_doc = dict(doc)
if doc.get('product'):
env = ProductEnvironment(self.env, doc['product'])
product_href = ProductEnvironment.resolve_href(env, self.env)
ui_doc["href"] = product_href(doc['type'], doc['id'])
else:
ui_doc["href"] = self.env.href(doc['type'], doc['id'])
ui_doc['title'] = str(doc['type'] + ": " + doc['_stored_name']).title()
return ui_doc
示例15: setUp
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')