Changed scenario by unittest test
This commit is contained in:
parent
a24d681a9e
commit
0755e5cc16
|
@ -1,181 +0,0 @@
|
|||
====================================
|
||||
Quality Control Stress Test Scenario
|
||||
====================================
|
||||
|
||||
Imports::
|
||||
>>> import datetime
|
||||
>>> from dateutil.relativedelta import relativedelta
|
||||
>>> from decimal import Decimal
|
||||
>>> from operator import attrgetter
|
||||
>>> from proteus import config, Model, Wizard
|
||||
>>> today = datetime.date.today()
|
||||
|
||||
Create database::
|
||||
|
||||
>>> config = config.set_trytond()
|
||||
>>> config.pool.test = True
|
||||
|
||||
Install quality_test module::
|
||||
|
||||
>>> Module = Model.get('ir.module.module')
|
||||
>>> module, = Module.find(
|
||||
... [('name', '=', 'quality_control_stress_test')])
|
||||
>>> module.click('install')
|
||||
>>> Wizard('ir.module.module.install_upgrade').execute('upgrade')
|
||||
|
||||
Create company::
|
||||
|
||||
>>> Currency = Model.get('currency.currency')
|
||||
>>> CurrencyRate = Model.get('currency.currency.rate')
|
||||
>>> currencies = Currency.find([('code', '=', 'USD')])
|
||||
>>> if not currencies:
|
||||
... currency = Currency(name='US Dollar', symbol=u'$', code='USD',
|
||||
... rounding=Decimal('0.01'), mon_grouping='[]',
|
||||
... mon_decimal_point='.')
|
||||
... currency.save()
|
||||
... CurrencyRate(date=today + relativedelta(month=1, day=1),
|
||||
... rate=Decimal('1.0'), currency=currency).save()
|
||||
... else:
|
||||
... currency, = currencies
|
||||
>>> Company = Model.get('company.company')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> company_config = Wizard('company.company.config')
|
||||
>>> company_config.execute('company')
|
||||
>>> company = company_config.form
|
||||
>>> party = Party(name='Dunder Mifflin')
|
||||
>>> party.save()
|
||||
>>> company.party = party
|
||||
>>> company.currency = currency
|
||||
>>> company_config.execute('add')
|
||||
>>> company, = Company.find([])
|
||||
|
||||
Reload the context::
|
||||
|
||||
>>> User = Model.get('res.user')
|
||||
>>> config._context = User.get_preferences(True, config.context)
|
||||
|
||||
Create product::
|
||||
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> Product = Model.get('product.product')
|
||||
>>> product = Product()
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'product'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'service'
|
||||
>>> template.list_price = Decimal('40')
|
||||
>>> template.cost_price = Decimal('25')
|
||||
>>> template.save()
|
||||
>>> product.template = template
|
||||
>>> product.save()
|
||||
|
||||
Create Quality Configuration::
|
||||
|
||||
>>> Sequence = Model.get('ir.sequence')
|
||||
>>> sequence = Sequence.find([('code','=','quality.test')])[0]
|
||||
>>> Configuration = Model.get('quality.configuration')
|
||||
>>> configuration = Configuration()
|
||||
>>> configuration.name = 'Configuration'
|
||||
>>> Product = Model.get('product.product')
|
||||
>>> ConfigLine = Model.get('quality.configuration.line')
|
||||
>>> config_line = ConfigLine()
|
||||
>>> configuration.allowed_documents.append(config_line)
|
||||
>>> config_line.quality_sequence = sequence
|
||||
>>> models = Model.get('ir.model')
|
||||
>>> allowed_doc, = models.find([('model','=','product.product')])
|
||||
>>> config_line.document = allowed_doc
|
||||
>>> configuration.save()
|
||||
|
||||
Create Qualitative Proof::
|
||||
|
||||
>>> Proof = Model.get('quality.proof')
|
||||
>>> QualityValue = Model.get('quality.qualitative.value')
|
||||
>>> Method = Model.get('quality.proof.method')
|
||||
>>> val1 = QualityValue(name='Val1')
|
||||
>>> val2 = QualityValue(name='Val2')
|
||||
>>> qlproof = Proof(name='Qualitative Proof', type='qualitative')
|
||||
>>> method1 = Method(name='Method 1')
|
||||
>>> qlproof.methods.append(method1)
|
||||
>>> method1.possible_values.append(val1)
|
||||
>>> method1.possible_values.append(val2)
|
||||
>>> qlproof.save()
|
||||
|
||||
|
||||
Create Quantitative Proof::
|
||||
|
||||
>>> Proof = Model.get('quality.proof')
|
||||
>>> Method = Model.get('quality.proof.method')
|
||||
>>> qtproof = Proof(name='Quantitative Proof', type='quantitative')
|
||||
>>> method2 = Method(name='Method 2')
|
||||
>>> qtproof.methods.append(method2)
|
||||
>>> qtproof.save()
|
||||
|
||||
Look For Values::
|
||||
|
||||
>>> method1, = Method.find([('name', '=', 'Method 1')])
|
||||
>>> method2, = Method.find([('name', '=', 'Method 2')])
|
||||
>>> val1, = QualityValue.find([('name','=','Val1')])
|
||||
>>> val2, = QualityValue.find([('name','=','Val2')])
|
||||
|
||||
Create Template::
|
||||
|
||||
>>> Template = Model.get('quality.template')
|
||||
>>> template=Template()
|
||||
>>> template.name = 'Template 1'
|
||||
>>> template.document = product
|
||||
>>> template.internal_description='Internal description'
|
||||
>>> template.external_description='External description'
|
||||
>>> _ = template.environments.new(name='High Temperature')
|
||||
>>> _ = template.environments.new(name='Low Temperature')
|
||||
>>> template.save()
|
||||
>>> high_temperature, low_temperature = template.environments
|
||||
>>> ql_line = template.qualitative_lines.new()
|
||||
>>> ql_line.name = 'Line1'
|
||||
>>> ql_line.proof = qlproof
|
||||
>>> ql_line.method = method1
|
||||
>>> ql_line.environment = high_temperature
|
||||
>>> ql_line.valid_value = val1
|
||||
>>> ql_line.internal_description = 'quality line intenal description'
|
||||
>>> ql_line.external_description = 'quality line external description'
|
||||
>>> qt_line = template.quantitative_lines.new()
|
||||
>>> qt_line.name = 'Quantitative Line'
|
||||
>>> qt_line.proof = qtproof
|
||||
>>> qt_line.method = method2
|
||||
>>> qt_line.environment = low_temperature
|
||||
>>> qt_line.unit = unit
|
||||
>>> qt_line.unit_range = unit
|
||||
>>> qt_line.internal_description = 'quality line intenal description'
|
||||
>>> qt_line.external_description = 'quality line external description'
|
||||
>>> qt_line.min_value = Decimal('1.00')
|
||||
>>> qt_line.max_value = Decimal('2.00')
|
||||
>>> template.save()
|
||||
>>> template.reload()
|
||||
|
||||
Create And assing template to Test::
|
||||
|
||||
>>> Test = Model.get('quality.test')
|
||||
>>> test=Test()
|
||||
>>> test.name = 'TEST/'
|
||||
>>> test.document = product
|
||||
>>> test.template = template
|
||||
>>> test.click('set_template')
|
||||
|
||||
Test values are assigned corretly::
|
||||
|
||||
>>> high_stress_test, low_stress_test = test.stress_tests
|
||||
>>> high_stress_test.environment == high_temperature
|
||||
True
|
||||
>>> high_stress_test.start
|
||||
>>> high_stress_test.end
|
||||
>>> low_stress_test.environment == low_temperature
|
||||
True
|
||||
>>> low_stress_test.start
|
||||
>>> low_stress_test.end
|
||||
>>> ql_line, = test.qualitative_lines
|
||||
>>> ql_line.stress_test == high_stress_test
|
||||
True
|
||||
>>> qt_line, = test.quantitative_lines
|
||||
>>> qt_line.stress_test == low_stress_test
|
||||
True
|
|
@ -1,32 +1,158 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains the full
|
||||
# copyright notices and license terms.
|
||||
import unittest
|
||||
import doctest
|
||||
from decimal import Decimal
|
||||
|
||||
import trytond.tests.test_tryton
|
||||
from trytond.tests.test_tryton import test_view, test_depends
|
||||
from trytond.tests.test_tryton import doctest_setup, doctest_teardown
|
||||
from trytond.pool import Pool
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
|
||||
from trytond.modules.company.tests import create_company, set_company
|
||||
|
||||
|
||||
class TestCase(unittest.TestCase):
|
||||
class TestCase(ModuleTestCase):
|
||||
'Test module'
|
||||
module = 'quality_control_stress_test'
|
||||
|
||||
def setUp(self):
|
||||
trytond.tests.test_tryton.install_module('quality_control_stress_test')
|
||||
@with_transaction()
|
||||
def test_account_debit_credit(self):
|
||||
'Test account debit/credit'
|
||||
pool = Pool()
|
||||
Uom = pool.get('product.uom')
|
||||
Template = pool.get('product.template')
|
||||
Product = pool.get('product.product')
|
||||
Model = pool.get('ir.model')
|
||||
Sequence = pool.get('ir.sequence')
|
||||
CualityConfiguration = pool.get('quality.configuration')
|
||||
QualityProof = pool.get('quality.proof')
|
||||
QualityValue = pool.get('quality.qualitative.value')
|
||||
QualityMethod = pool.get('quality.proof.method')
|
||||
QualityValue = pool.get('quality.qualitative.value')
|
||||
QualityTemplate = pool.get('quality.template')
|
||||
QualitytTest = pool.get('quality.test')
|
||||
|
||||
def test0005views(self):
|
||||
'Test views'
|
||||
test_view('quality_control_stress_test')
|
||||
# Create Company
|
||||
company = create_company()
|
||||
with set_company(company):
|
||||
|
||||
def test0006depends(self):
|
||||
'Test depends'
|
||||
test_depends()
|
||||
# Create Product
|
||||
unit, = Uom.search([
|
||||
('name', '=', 'Unit'),
|
||||
])
|
||||
template, = Template.create([{
|
||||
'name': 'Product',
|
||||
'default_uom': unit.id,
|
||||
'type': 'goods',
|
||||
'list_price': Decimal(30),
|
||||
'cost_price': Decimal(20),
|
||||
}])
|
||||
product, = Product.create([{
|
||||
'template': template.id,
|
||||
}])
|
||||
|
||||
# Configure Quality Control
|
||||
sequence, = Sequence.search([('code', '=', 'quality.test')])
|
||||
allowed_doc, = Model.search([('model', '=', 'product.product')])
|
||||
CualityConfiguration.create([{
|
||||
'allowed_documents': [('create', [{
|
||||
'quality_sequence': sequence.id,
|
||||
'document': allowed_doc.id,
|
||||
}])],
|
||||
}])
|
||||
|
||||
# Create Qualitative Proof
|
||||
qlproof, = QualityProof.create([{
|
||||
'name': 'Qualitative Proof',
|
||||
'type': 'qualitative',
|
||||
'methods': [('create', [{
|
||||
'name': 'Method 1',
|
||||
'possible_values': [('create', [{
|
||||
'name': 'Val 1',
|
||||
}, {
|
||||
'name': 'Val 2',
|
||||
}])]
|
||||
}])],
|
||||
}])
|
||||
|
||||
# Create Quantitative Proof
|
||||
qtproof, = QualityProof.create([{
|
||||
'name': 'Quantitative Proof',
|
||||
'type': 'quantitative',
|
||||
'methods': [('create', [{
|
||||
'name': 'Method 2',
|
||||
}])],
|
||||
}])
|
||||
|
||||
# Look For Values
|
||||
method1, = QualityMethod.search([('name', '=', 'Method 1')])
|
||||
method2, = QualityMethod.search([('name', '=', 'Method 2')])
|
||||
val1, = QualityValue.search([('name', '=', 'Val 1')])
|
||||
val2, = QualityValue.search([('name', '=', 'Val 2')])
|
||||
|
||||
# Create Quality Template
|
||||
quality_template, = QualityTemplate.create([{
|
||||
'name': 'Template 1',
|
||||
'document': str(product),
|
||||
'internal_description': u'Internal description',
|
||||
'external_description': u'External description',
|
||||
'environments': [('create', [{
|
||||
'name': 'High Temperature',
|
||||
}, {
|
||||
'name': 'Low Temperature',
|
||||
}])],
|
||||
}])
|
||||
|
||||
high_temperature, low_temperature = quality_template.environments
|
||||
QualityTemplate.write([quality_template], {
|
||||
'qualitative_lines': [('create', [{
|
||||
'name': 'Line1',
|
||||
'proof': qlproof.id,
|
||||
'method': method1.id,
|
||||
'environment': high_temperature.id,
|
||||
'valid_value': val1.id,
|
||||
'internal_description':
|
||||
'quality line intenal description',
|
||||
'external_description':
|
||||
'quality line external description',
|
||||
}])],
|
||||
'quantitative_lines': [('create', [{
|
||||
'name': 'Quantitative Line',
|
||||
'proof': qtproof.id,
|
||||
'method': method2.id,
|
||||
'environment': low_temperature.id,
|
||||
'unit': unit.id,
|
||||
'internal_description':
|
||||
'quality line intenal description',
|
||||
'external_description':
|
||||
'quality line external description',
|
||||
'min_value': Decimal('1.00'),
|
||||
'max_value': Decimal('2.00'),
|
||||
}])],
|
||||
})
|
||||
|
||||
# Create And assing template to Test
|
||||
test, = QualitytTest.create([{
|
||||
'number': 'TEST/',
|
||||
'document': str(product),
|
||||
'templates': [('add', [quality_template.id])],
|
||||
}])
|
||||
test.apply_template_values()
|
||||
|
||||
# Test that values are assigned corretly::
|
||||
high_stress_test, low_stress_test = test.stress_tests
|
||||
self.assertEqual(high_stress_test.environment, high_temperature)
|
||||
high_stress_test.start
|
||||
high_stress_test.end
|
||||
self.assertEqual(low_stress_test.environment, low_temperature)
|
||||
low_stress_test.start
|
||||
low_stress_test.end
|
||||
ql_line, = test.qualitative_lines
|
||||
self.assertEqual(ql_line.stress_test, high_stress_test)
|
||||
qt_line, = test.quantitative_lines
|
||||
self.assertEqual(qt_line.stress_test, low_stress_test)
|
||||
|
||||
|
||||
def suite():
|
||||
suite = trytond.tests.test_tryton.suite()
|
||||
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestCase))
|
||||
suite.addTests(doctest.DocFileSuite(
|
||||
'scenario_quality_control_stress_test.rst',
|
||||
setUp=doctest_setup, tearDown=doctest_teardown, encoding='utf-8',
|
||||
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
|
||||
return suite
|
||||
|
|
Loading…
Reference in New Issue