本文整理汇总了Python中trytond.tests.test_tryton.POOL类的典型用法代码示例。如果您正苦于以下问题:Python POOL类的具体用法?Python POOL怎么用?Python POOL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了POOL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_0100_template_trans_tag_with_expr
def test_0100_template_trans_tag_with_expr(self):
"""
Test for
{% trans user=user.username %}Hello {{ user }}!{% endtrans %} tag
"""
TranslationSet = POOL.get('ir.translation.set', type='wizard')
IRTranslation = POOL.get('ir.translation')
with Transaction().start(DB_NAME, USER, CONTEXT):
session_id, _, _ = TranslationSet.create()
set_wizard = TranslationSet(session_id)
# Set the nereid_template translations alone
set_wizard.set_nereid_template()
# XXX: See how {{ user }} changed to %(user)s
translation, = IRTranslation.search([
('type', '=', 'nereid_template'),
('module', '=', 'nereid_test'),
('src', '=', 'Hello %(name)s!')
])
self.assertEqual(
translation.comments, 'Translation with an expression'
)
self.assertEqual(translation.res_id, 26)
示例2: test_0100_product_images
def test_0100_product_images(self):
"""
Test for adding product images
"""
Product = POOL.get('product.product')
StaticFolder = POOL.get("nereid.static.folder")
StaticFile = POOL.get("nereid.static.file")
Media = POOL.get('product.media')
with Transaction().start(DB_NAME, USER, CONTEXT):
self.setup_defaults()
self.create_test_products()
folder, = StaticFolder.create([{
'name': 'Test'
}])
file_buffer = buffer('test-content')
file, = StaticFile.create([{
'name': 'test.png',
'folder': folder.id,
'file_binary': file_buffer
}])
product, = Product.search([], limit=1)
Media.create([{
'product': product.id,
'template': product.template.id,
'static_file': file.id,
}])
app = self.get_app()
with app.test_request_context('/'):
home_template = render_template('home.jinja', product=product)
self.assertTrue(file.name in home_template)
示例3: _create_fiscal_year
def _create_fiscal_year(self, date=None, company=None):
"""
Creates a fiscal year and requried sequences
"""
FiscalYear = POOL.get('account.fiscalyear')
Sequence = POOL.get('ir.sequence')
Company = POOL.get('company.company')
if date is None:
date = datetime.date.today()
if company is None:
company, = Company.search([], limit=1)
fiscal_year, = FiscalYear.create([{
'name': '%s' % date.year,
'start_date': date + relativedelta(month=1, day=1),
'end_date': date + relativedelta(month=12, day=31),
'company': company,
'post_move_sequence': Sequence.create([{
'name': '%s' % date.year,
'code': 'account.move',
'company': company,
}])[0],
}])
FiscalYear.create_period([fiscal_year])
return fiscal_year
示例4: test_0080_import_sale_order_with_bundle_product
def test_0080_import_sale_order_with_bundle_product(self):
"""
Tests import of sale order with bundle product using magento data
"""
Sale = POOL.get('sale.sale')
Category = POOL.get('product.category')
with Transaction().start(DB_NAME, USER, CONTEXT):
self.setup_defaults()
with Transaction().set_context({
'current_channel': self.channel1.id,
}):
order_states_list = load_json('order-states', 'all')
for code, name in order_states_list.iteritems():
self.channel1.create_order_state(code, name)
category_tree = load_json('categories', 'category_tree')
Category.create_tree_using_magento_data(category_tree)
orders = Sale.search([])
self.assertEqual(len(orders), 0)
order_data = load_json('orders', '300000001')
with patch(
'magento.Customer', mock_customer_api(), create=True):
self.Party.find_or_create_using_magento_id(
order_data['customer_id']
)
with Transaction().set_context(company=self.company):
# Create sale order using magento data
with patch(
'magento.Product', mock_product_api(), create=True
):
order = Sale.find_or_create_using_magento_data(
order_data
)
self.assertEqual(order.state, 'confirmed')
orders = Sale.search([])
self.assertEqual(len(orders), 1)
# Item lines + shipping line should be equal to lines on tryton
self.assertEqual(len(order.lines), 2)
self.assertEqual(
order.total_amount, Decimal(order_data['base_grand_total'])
)
# There should be a BoM for the bundle product
product = self.channel1.import_product('VGN-TXN27N-BW')
self.assertEqual(len(product.boms), 1)
self.assertEqual(
len(product.boms[0].bom.inputs), 2
)
示例5: _create_fiscal_year
def _create_fiscal_year(self, date=None, company=None):
"""
Creates a fiscal year and requried sequences
"""
Sequence = POOL.get('ir.sequence')
SequenceStrict = POOL.get('ir.sequence.strict')
if date is None:
date = datetime.date.today()
if company is None:
company, = self.Company.search([], limit=1)
invoice_sequence, = SequenceStrict.create([{
'name': '%s' % date.year,
'code': 'account.invoice',
'company': company,
}])
fiscal_year, = self.FiscalYear.create([{
'name': '%s' % date.year,
'start_date': date + relativedelta(month=1, day=1),
'end_date': date + relativedelta(month=12, day=31),
'company': company,
'post_move_sequence': Sequence.create([{
'name': '%s' % date.year,
'code': 'account.move',
'company': company,
}])[0],
'out_invoice_sequence': invoice_sequence,
'in_invoice_sequence': invoice_sequence,
'out_credit_note_sequence': invoice_sequence,
'in_credit_note_sequence': invoice_sequence,
}])
self.FiscalYear.create_period([fiscal_year])
return fiscal_year
示例6: setUp
def setUp(self):
trytond.tests.test_tryton.install_module('nereid_s3')
self.static_file = POOL.get('nereid.static.file')
self.static_folder = POOL.get('nereid.static.folder')
# Mock S3Connection
self.s3_api_patcher = patch(
'boto.s3.connection.S3Connection', autospec=True
)
PatchedS3 = self.s3_api_patcher.start()
# Mock S3Key
self.s3_key_patcher = patch(
'boto.s3.key.Key', autospec=True
)
PatchedS3Key = self.s3_key_patcher.start()
PatchedS3.return_value = connection.S3Connection('ABCD', '123XYZ')
PatchedS3.return_value.get_bucket = lambda bucket_name: Bucket(
PatchedS3.return_value, 'tryton-test-s3'
)
PatchedS3Key.return_value = Key(
Bucket(PatchedS3.return_value, 'tryton-test-s3'), 'some key'
)
PatchedS3Key.return_value.key = "some key"
PatchedS3Key.return_value.get_contents_as_string = lambda *a: 'testfile'
PatchedS3Key.return_value.set_contents_from_string = \
lambda value: 'testfile'
示例7: _create_auth_net_gateway_for_site
def _create_auth_net_gateway_for_site(self):
"""
A helper function that creates the authorize.net gateway and assigns
it to the websites.
"""
PaymentGateway = POOL.get('payment_gateway.gateway')
NereidWebsite = POOL.get('nereid.website')
Journal = POOL.get('account.journal')
cash_journal, = Journal.search([
('name', '=', 'Cash')
])
gateway = PaymentGateway(
name='Authorize.net',
journal=cash_journal,
provider='authorize_net',
method='credit_card',
authorize_net_login='327deWY74422',
authorize_net_transaction_key='32jF65cTxja88ZA2',
test=True
)
gateway.save()
websites = NereidWebsite.search([])
NereidWebsite.write(websites, {
'accept_credit_card': True,
'save_payment_profile': True,
'credit_card_gateway': gateway.id,
})
return gateway
示例8: setUp
def setUp(self):
install_module('test')
self.one2many = POOL.get('test.copy.one2many')
self.one2many_target = POOL.get('test.copy.one2many.target')
self.one2many_reference = POOL.get('test.copy.one2many_reference')
self.one2many_reference_target = \
POOL.get('test.copy.one2many_reference.target')
示例9: setUp
def setUp(self):
trytond.tests.test_tryton.install_module('elastic_search')
self.IndexBacklog = POOL.get('elasticsearch.index_backlog')
self.DocumentType = POOL.get('elasticsearch.document.type')
self.User = POOL.get('res.user')
self.Model = POOL.get('ir.model')
self.Trigger = POOL.get('ir.trigger')
示例10: test_0020_render_unicode
def test_0020_render_unicode(self):
'''
Render the report without PDF conversion but having unicode template
'''
UserReport = POOL.get('res.user', type='report')
IRReport = POOL.get('ir.action.report')
with Transaction().start(DB_NAME, USER, context=CONTEXT):
self.setup_defaults()
with Transaction().set_context(company=self.company.id):
report_html, = IRReport.create([{
'name': 'HTML Report',
'model': 'res.user',
'report_name': 'res.user',
'report_content': buffer(
"<h1>Héllø, {{data['name']}}!</h1>"
),
'extension': 'html',
}])
val = UserReport.execute([USER], {'name': u'Cédric'})
self.assertEqual(val[0], u'html')
self.assertEqual(
str(val[1]), '<h1>Héllø, Cédric!</h1>'
)
示例11: test_0010_render_report_xhtml
def test_0010_render_report_xhtml(self):
'''
Render the report without PDF conversion
'''
UserReport = POOL.get('res.user', type='report')
IRReport = POOL.get('ir.action.report')
with Transaction().start(DB_NAME, USER, context=CONTEXT):
self.setup_defaults()
with Transaction().set_context(company=self.company.id):
report_html, = IRReport.create([{
'name': 'HTML Report',
'model': 'res.user',
'report_name': 'res.user',
'report_content': buffer(
'<h1>Hello, {{records[0].name}}!</h1>'
),
'extension': 'html',
}])
val = UserReport.execute([USER], {})
self.assertEqual(val[0], u'html')
self.assertEqual(
str(val[1]), '<h1>Hello, Administrator!</h1>'
)
示例12: test_0400_translation_export
def test_0400_translation_export(self):
"""
Export the translations and test
"""
TranslationSet = POOL.get('ir.translation.set', type='wizard')
TranslationUpdate = POOL.get('ir.translation.update', type='wizard')
IRTranslation = POOL.get('ir.translation')
IRLanguage = POOL.get('ir.lang')
with Transaction().start(DB_NAME, USER, CONTEXT):
# First create all the translations
session_id, _, _ = TranslationSet.create()
set_wizard = TranslationSet(session_id)
set_wizard.transition_set_()
# set an additional language as translatable
new_lang, = IRLanguage.search([
('translatable', '=', False)
], limit=1)
new_lang.translatable = True
new_lang.save()
# Now update the translations
session_id, _, _ = TranslationUpdate.create()
update_wizard = TranslationUpdate(session_id)
update_wizard.start.language = new_lang
update_wizard.do_update(update_wizard.update.get_action())
# TODO: Check the contents of the po file
IRTranslation.translation_export(new_lang.code, 'nereid_test')
IRTranslation.translation_export(new_lang.code, 'nereid')
示例13: test_0300_translation_update
def test_0300_translation_update(self):
"""
Check if the update does not break this functionality
"""
TranslationSet = POOL.get('ir.translation.set', type='wizard')
TranslationUpdate = POOL.get('ir.translation.update', type='wizard')
IRTranslation = POOL.get('ir.translation')
IRLanguage = POOL.get('ir.lang')
with Transaction().start(DB_NAME, USER, CONTEXT):
# First create all the translations
session_id, _, _ = TranslationSet.create()
set_wizard = TranslationSet(session_id)
set_wizard.transition_set_()
# set an additional language as translatable
new_lang, = IRLanguage.search([
('translatable', '=', False)
], limit=1)
new_lang.translatable = True
new_lang.save()
count_before = IRTranslation.search([], count=True)
# Now update the translations
session_id, _, _ = TranslationUpdate.create()
update_wizard = TranslationUpdate(session_id)
update_wizard.start.language = new_lang
update_wizard.do_update(update_wizard.update.get_action())
# check the count now
count_after = IRTranslation.search([], count=True)
self.assertEqual(count_after, count_before * 2)
示例14: test_0200_translation_clean
def test_0200_translation_clean(self):
"""
Check if the cleaning of translations work
"""
TranslationSet = POOL.get('ir.translation.set', type='wizard')
TranslationClean = POOL.get('ir.translation.clean', type='wizard')
IRTranslation = POOL.get('ir.translation')
IRModule = POOL.get('ir.module.module')
with Transaction().start(DB_NAME, USER, CONTEXT):
# First create all the translations
session_id, _, _ = TranslationSet.create()
set_wizard = TranslationSet(session_id)
set_wizard.transition_set_()
# Uninstall nereid_test and there should be no translations
# belonging to that module with type as nereid or
# nereid_template
nereid_test, = IRModule.search([('name', '=', 'nereid_test')])
nereid_test.state = 'uninstalled'
nereid_test.save()
session_id, _, _ = TranslationClean.create()
clean_wizard = TranslationClean(session_id)
clean_wizard.transition_clean()
count = IRTranslation.search([
('module', '=', 'nereid_test'),
('type', 'in', ('nereid', 'nereid_template'))
], count=True)
self.assertEqual(count, 0)
示例15: test_0090_import_sale_order_with_bundle_product_check_duplicate
def test_0090_import_sale_order_with_bundle_product_check_duplicate(self):
"""
Tests import of sale order with bundle product using magento data
This tests that the duplication of BoMs doesnot happen
"""
Sale = POOL.get('sale.sale')
ProductTemplate = POOL.get('product.template')
Category = POOL.get('product.category')
MagentoOrderState = POOL.get('magento.order_state')
with Transaction().start(DB_NAME, USER, CONTEXT):
self.setup_defaults()
with Transaction().set_context({
'magento_instance': self.instance1.id,
'magento_store_view': self.store_view.id,
'magento_website': self.website1.id,
}):
MagentoOrderState.create_all_using_magento_data(
load_json('order-states', 'all'),
)
category_tree = load_json('categories', 'category_tree')
Category.create_tree_using_magento_data(category_tree)
order_data = load_json('orders', '300000001')
with patch(
'magento.Customer', mock_customer_api(), create=True):
self.Party.find_or_create_using_magento_id(
order_data['customer_id']
)
with Transaction().set_context({'company': self.company.id}):
# Create sale order using magento data
with patch(
'magento.Product', mock_product_api(), create=True
):
Sale.find_or_create_using_magento_data(order_data)
# There should be a BoM for the bundle product
product_template = \
ProductTemplate.find_or_create_using_magento_id(158)
product = product_template.products[0]
self.assertTrue(len(product.boms), 1)
self.assertTrue(len(product.boms[0].bom.inputs), 2)
order_data = load_json('orders', '300000001-a')
# Create sale order using magento data
with patch('magento.Product', mock_product_api(), create=True):
Sale.find_or_create_using_magento_data(order_data)
# There should be a BoM for the bundle product
product_template = \
ProductTemplate.find_or_create_using_magento_id(
158
)
self.assertEqual(len(product.boms), 1)
self.assertEqual(len(product.boms[0].bom.inputs), 2)