trytond-stock_product_categ.../tests/test_stock_product_category_location.py
Sergio Morillo ac5e2fc1cf Migrate to 4.0
This commit refs #1277
2016-08-19 14:11:05 +02:00

65 lines
2.4 KiB
Python

# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
import unittest
import trytond.tests.test_tryton
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
from trytond.transaction import Transaction
from trytond.pool import Pool
from trytond.exceptions import UserError
import doctest
from trytond.tests.test_tryton import doctest_setup, doctest_teardown
class StockProductCategoryLocationTestCase(ModuleTestCase):
"""Test Stock Product Category Location module"""
module = 'stock_product_category_location'
@with_transaction()
def test0010_add_category_default_location(self):
"""Add the category default location for a warehouse"""
pool = Pool()
Location = pool.get('stock.location')
Category = pool.get('product.category')
CatLoc = pool.get('stock.product.category.location')
transaction = Transaction()
storage, = Location.search([('code', '=', 'STO')])
new_cat, = Category.create([{'name': 'CAT1'}])
cat_loc_rec = {
'category': new_cat.id,
'warehouse': storage.parent.id,
'location': storage.id
}
CatLoc.create([cat_loc_rec])
transaction.commit()
@with_transaction()
def test0020category_location_unique(self):
"""Check unique error"""
pool = Pool()
Location = pool.get('stock.location')
Category = pool.get('product.category')
CatLoc = pool.get('stock.product.category.location')
storage, = Location.search([('code', '=', 'STO')])
new_cat, = Category.search([('name', '=', 'CAT1')])
cat_loc_rec = {
'category': new_cat.id,
'warehouse': storage.parent.id,
'location': storage.id
}
with self.assertRaises(UserError) as cm:
CatLoc.create([cat_loc_rec])
self.assertEqual(
cm.exception.message, 'Category and location must be unique.')
def suite():
suite = trytond.tests.test_tryton.suite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
StockProductCategoryLocationTestCase))
suite.addTests(doctest.DocFileSuite('scenario_stock_product_category_location.rst',
setUp=doctest_setup, tearDown=doctest_teardown, encoding='utf-8',
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
return suite