changeset ecb3518b054e in modules/stock_forecast:default
details:
https://hg.tryton.org/modules/stock_forecast?cmd=changeset&node=ecb3518b054e
description:
Replace test setuptools command by unittest discover
issue9215
review389851002
diffstat:
setup.py | 2 -
tests/__init__.py | 7 -
tests/test_module.py | 321 ++++++++++++++++++++++++++++++++++++++++++
tests/test_stock_forecast.py | 326 -------------------------------------------
tox.ini | 2 +-
5 files changed, 322 insertions(+), 336 deletions(-)
diffs (690 lines):
diff -r 64853bd07070 -r ecb3518b054e setup.py
--- a/setup.py Mon Apr 11 23:24:21 2022 +0200
+++ b/setup.py Sat Apr 16 18:30:19 2022 +0200
@@ -142,6 +142,4 @@
[trytond.modules]
stock_forecast = trytond.modules.stock_forecast
""",
- test_suite='tests',
- test_loader='trytond.test_loader:Loader',
)
diff -r 64853bd07070 -r ecb3518b054e tests/__init__.py
--- a/tests/__init__.py Mon Apr 11 23:24:21 2022 +0200
+++ b/tests/__init__.py Sat Apr 16 18:30:19 2022 +0200
@@ -1,9 +1,2 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
-
-try:
- from trytond.modules.stock_forecast.tests.test_stock_forecast import suite
-except ImportError:
- from .test_stock_forecast import suite
-
-__all__ = ['suite']
diff -r 64853bd07070 -r ecb3518b054e tests/test_module.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_module.py Sat Apr 16 18:30:19 2022 +0200
@@ -0,0 +1,321 @@
+# This file is part of Tryton. The COPYRIGHT file at the top level of
+# this repository contains the full copyright notices and license terms.
+
+import datetime
+from decimal import Decimal
+
+from dateutil.relativedelta import relativedelta
+
+from trytond.modules.company.tests import (
+ CompanyTestMixin, create_company, set_company)
+from trytond.pool import Pool
+from trytond.tests.test_tryton import ModuleTestCase, with_transaction
+from trytond.transaction import Transaction
+
+
+class StockForecastTestCase(CompanyTestMixin, ModuleTestCase):
+ 'Test StockForecast module'
+ module = 'stock_forecast'
+
+ @with_transaction()
+ def test_distribute(self):
+ 'Test distribute'
+ pool = Pool()
+ Line = pool.get('stock.forecast.line')
+ line = Line()
+ for values, result in (
+ ((1, 5), {0: 5}),
+ ((4, 8), {0: 2, 1: 2, 2: 2, 3: 2}),
+ ((2, 5), {0: 2, 1: 3}),
+ ((10, 4), {0: 0, 1: 1, 2: 0, 3: 1, 4: 0,
+ 5: 0, 6: 1, 7: 0, 8: 1, 9: 0}),
+ ):
+ self.assertEqual(line.distribute(*values), result)
+
+ @with_transaction()
+ def test_create_moves_before(self):
+ "Test create moves before start date"
+ pool = Pool()
+ Uom = pool.get('product.uom')
+ Template = pool.get('product.template')
+ Product = pool.get('product.product')
+ Location = pool.get('stock.location')
+ Forecast = pool.get('stock.forecast')
+ Move = pool.get('stock.move')
+
+ unit, = Uom.search([('name', '=', 'Unit')])
+ template, = Template.create([{
+ 'name': 'Test create_moves',
+ 'type': 'goods',
+ 'default_uom': unit.id,
+ }])
+ product, = Product.create([{
+ 'template': template.id,
+ }])
+ customer, = Location.search([('code', '=', 'CUS')])
+ warehouse, = Location.search([('code', '=', 'WH')])
+ storage, = Location.search([('code', '=', 'STO')])
+ company = create_company()
+ with set_company(company):
+ today = datetime.date.today()
+
+ forecast, = Forecast.create([{
+ 'warehouse': warehouse.id,
+ 'destination': customer.id,
+ 'from_date': today + relativedelta(months=1, day=1),
+ 'to_date': today + relativedelta(months=1, day=20),
+ 'company': company.id,
+ 'lines': [
+ ('create', [{
+ 'product': product.id,
+ 'quantity': 10,
+ 'uom': unit.id,
+ 'minimal_quantity': 2,
+ }],
+ ),
+ ],
+ }])
+ Forecast.confirm([forecast])
+
+ Forecast.create_moves([forecast])
+ line, = forecast.lines
+ self.assertEqual(line.quantity_executed, 0)
+ self.assertEqual(len(line.moves), 5)
+ self.assertEqual(sum(move.quantity for move in line.moves), 10)
+ self.assertGreaterEqual(
+ min(m.planned_date for m in line.moves), forecast.from_date)
+
+ Forecast.delete_moves([forecast])
+ line, = forecast.lines
+ self.assertEqual(len(line.moves), 0)
+
+ Move.create([{
+ 'from_location': storage.id,
+ 'to_location': customer.id,
+ 'product': product.id,
+ 'uom': unit.id,
+ 'quantity': 2,
+ 'planned_date': today + relativedelta(months=1, day=5),
+ 'company': company.id,
+ 'currency': company.currency.id,
+ 'unit_price': Decimal('1'),
+ }])
+ line, = forecast.lines
+ self.assertEqual(line.quantity_executed, 2)
+
+ Forecast.create_moves([forecast])
+ line, = forecast.lines
+ self.assertEqual(line.quantity_executed, 2)
+ self.assertEqual(len(line.moves), 4)
+ self.assertEqual(sum(move.quantity for move in line.moves), 8)
+ self.assertGreaterEqual(
+ min(m.planned_date for m in line.moves), forecast.from_date)
+
+ @with_transaction()
+ def test_create_moves_during(self):
+ "Test create moves during the period"
+ pool = Pool()
+ Uom = pool.get('product.uom')
+ Template = pool.get('product.template')
+ Product = pool.get('product.product')
+ Location = pool.get('stock.location')
+ Forecast = pool.get('stock.forecast')
+ Move = pool.get('stock.move')
+
+ unit, = Uom.search([('name', '=', 'Unit')])
+ template, = Template.create([{
+ 'name': 'Test create_moves',
+ 'type': 'goods',
+ 'default_uom': unit.id,
+ }])
+ product, = Product.create([{
+ 'template': template.id,
+ }])
+ customer, = Location.search([('code', '=', 'CUS')])
+ warehouse, = Location.search([('code', '=', 'WH')])
+ storage, = Location.search([('code', '=', 'STO')])
+ company = create_company()
+ with set_company(company):
+ today = datetime.date.today()
+
+ forecast, = Forecast.create([{
+ 'warehouse': warehouse.id,
+ 'destination': customer.id,
+ 'from_date': today - relativedelta(days=20),
+ 'to_date': today + relativedelta(days=10),
+ 'company': company.id,
+ 'lines': [
+ ('create', [{
+ 'product': product.id,
+ 'quantity': 20,
+ 'uom': unit.id,
+ 'minimal_quantity': 2,
+ }],
+ ),
+ ],
+ }])
+ Forecast.confirm([forecast])
+
+ Forecast.create_moves([forecast])
+ line, = forecast.lines
+ self.assertEqual(line.quantity_executed, 0)
+ self.assertEqual(len(line.moves), 10)
+ self.assertEqual(sum(move.quantity for move in line.moves), 20)
+ self.assertGreaterEqual(
+ min(m.planned_date for m in line.moves), today)
+
+ Forecast.delete_moves([forecast])
+ line, = forecast.lines
+ self.assertEqual(len(line.moves), 0)
+
+ Move.create([{
+ 'from_location': storage.id,
+ 'to_location': customer.id,
+ 'product': product.id,
+ 'uom': unit.id,
+ 'quantity': 10,
+ 'planned_date': today - relativedelta(days=5),
+ 'company': company.id,
+ 'currency': company.currency.id,
+ 'unit_price': Decimal('1'),
+ }])
+ line, = forecast.lines
+ self.assertEqual(line.quantity_executed, 10)
+
+ Forecast.create_moves([forecast])
+ line, = forecast.lines
+ self.assertEqual(line.quantity_executed, 10)
+ self.assertEqual(len(line.moves), 5)
+ self.assertEqual(sum(move.quantity for move in line.moves), 10)
+ self.assertGreaterEqual(
+ min(m.planned_date for m in line.moves), today)
+
+ @with_transaction()
+ def test_create_moves_after(self):
+ "Test create not moves after end date"
+ pool = Pool()
+ Uom = pool.get('product.uom')
+ Template = pool.get('product.template')
+ Product = pool.get('product.product')
+ Location = pool.get('stock.location')
+ Forecast = pool.get('stock.forecast')
+
+ unit, = Uom.search([('name', '=', 'Unit')])
+ template, = Template.create([{
+ 'name': 'Test create_moves',
+ 'type': 'goods',
+ 'default_uom': unit.id,
+ }])
+ product, = Product.create([{
+ 'template': template.id,
+ }])
+ customer, = Location.search([('code', '=', 'CUS')])
+ warehouse, = Location.search([('code', '=', 'WH')])
+ storage, = Location.search([('code', '=', 'STO')])
+ company = create_company()
+ with set_company(company):
+ today = datetime.date.today()
+
+ forecast, = Forecast.create([{
+ 'warehouse': warehouse.id,
+ 'destination': customer.id,
+ 'from_date': today - relativedelta(days=20),
+ 'to_date': today - relativedelta(days=10),
+ 'company': company.id,
+ 'lines': [
+ ('create', [{
+ 'product': product.id,
+ 'quantity': 20,
+ 'uom': unit.id,
+ 'minimal_quantity': 2,
+ }],
+ ),
+ ],
+ }])
+ Forecast.confirm([forecast])
+
+ Forecast.create_moves([forecast])
+ line, = forecast.lines
+ self.assertEqual(len(line.moves), 0)
+
+ @with_transaction()
+ def test_complete(self):
+ 'Test complete'
+ pool = Pool()
+ Uom = pool.get('product.uom')
+ Template = pool.get('product.template')
+ Product = pool.get('product.product')
+ Location = pool.get('stock.location')
+ Forecast = pool.get('stock.forecast')
+ Move = pool.get('stock.move')
+ ForecastComplete = pool.get('stock.forecast.complete', type='wizard')
+
+ unit, = Uom.search([('name', '=', 'Unit')])
+ template, = Template.create([{
+ 'name': 'Test complete',
+ 'type': 'goods',
+ 'default_uom': unit.id,
+ }])
+ product, = Product.create([{
+ 'template': template.id,
+ }])
+ customer, = Location.search([('code', '=', 'CUS')])
+ supplier, = Location.search([('code', '=', 'SUP')])
+ warehouse, = Location.search([('code', '=', 'WH')])
+ storage, = Location.search([('code', '=', 'STO')])
+ company = create_company()
+ with set_company(company):
+ today = datetime.date.today()
+
+ moves = Move.create([{
+ 'from_location': supplier.id,
+ 'to_location': storage.id,
+ 'product': product.id,
+ 'uom': unit.id,
+ 'quantity': 10,
+ 'effective_date': (today
+ + relativedelta(months=-1, day=1)),
+ 'company': company.id,
+ 'currency': company.currency.id,
+ 'unit_price': Decimal('1'),
+ }, {
+ 'from_location': storage.id,
+ 'to_location': customer.id,
+ 'product': product.id,
+ 'uom': unit.id,
+ 'quantity': 5,
+ 'effective_date': (today
+ + relativedelta(months=-1, day=15)),
+ 'company': company.id,
+ 'currency': company.currency.id,
+ 'unit_price': Decimal('1'),
+ }])
+ Move.do(moves)
+
+ forecast, = Forecast.create([{
+ 'warehouse': warehouse.id,
+ 'destination': customer.id,
+ 'from_date': today + relativedelta(months=1, day=1),
+ 'to_date': today + relativedelta(months=1, day=20),
+ 'company': company.id,
+ }])
+
+ with Transaction().set_context(
+ active_model=Forecast.__name__, active_id=forecast.id):
+ session_id, _, _ = ForecastComplete.create()
+ forecast_complete = ForecastComplete(session_id)
+ forecast_complete.ask.from_date = (
+ today + relativedelta(months=-1, day=1))
+ forecast_complete.ask.to_date = (
+ today + relativedelta(months=-1, day=20))
+ forecast_complete.transition_complete()
+
+ self.assertEqual(len(forecast.lines), 1)
+ forecast_line, = forecast.lines
+ self.assertEqual(forecast_line.product, product)
+ self.assertEqual(forecast_line.uom, unit)
+ self.assertEqual(forecast_line.quantity, 5)
+ self.assertEqual(forecast_line.minimal_quantity, 1)
+
+
+del ModuleTestCase
diff -r 64853bd07070 -r ecb3518b054e tests/test_stock_forecast.py
--- a/tests/test_stock_forecast.py Mon Apr 11 23:24:21 2022 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,326 +0,0 @@
-# This file is part of Tryton. The COPYRIGHT file at the top level of
-# this repository contains the full copyright notices and license terms.
-import datetime
-import unittest
-from decimal import Decimal
-
-from dateutil.relativedelta import relativedelta
-
-import trytond.tests.test_tryton
-from trytond.modules.company.tests import (
- CompanyTestMixin, create_company, set_company)
-from trytond.pool import Pool
-from trytond.tests.test_tryton import ModuleTestCase, with_transaction
-from trytond.transaction import Transaction
-
-
-class StockForecastTestCase(CompanyTestMixin, ModuleTestCase):
- 'Test StockForecast module'
- module = 'stock_forecast'
-
- @with_transaction()
- def test_distribute(self):
- 'Test distribute'
- pool = Pool()
- Line = pool.get('stock.forecast.line')
- line = Line()
- for values, result in (
- ((1, 5), {0: 5}),
- ((4, 8), {0: 2, 1: 2, 2: 2, 3: 2}),
- ((2, 5), {0: 2, 1: 3}),
- ((10, 4), {0: 0, 1: 1, 2: 0, 3: 1, 4: 0,
- 5: 0, 6: 1, 7: 0, 8: 1, 9: 0}),
- ):
- self.assertEqual(line.distribute(*values), result)
-
- @with_transaction()
- def test_create_moves_before(self):
- "Test create moves before start date"
- pool = Pool()
- Uom = pool.get('product.uom')
- Template = pool.get('product.template')
- Product = pool.get('product.product')
- Location = pool.get('stock.location')
- Forecast = pool.get('stock.forecast')
- Move = pool.get('stock.move')
-
- unit, = Uom.search([('name', '=', 'Unit')])
- template, = Template.create([{
- 'name': 'Test create_moves',
- 'type': 'goods',
- 'default_uom': unit.id,
- }])
- product, = Product.create([{
- 'template': template.id,
- }])
- customer, = Location.search([('code', '=', 'CUS')])
- warehouse, = Location.search([('code', '=', 'WH')])
- storage, = Location.search([('code', '=', 'STO')])
- company = create_company()
- with set_company(company):
- today = datetime.date.today()
-
- forecast, = Forecast.create([{
- 'warehouse': warehouse.id,
- 'destination': customer.id,
- 'from_date': today + relativedelta(months=1, day=1),
- 'to_date': today + relativedelta(months=1, day=20),
- 'company': company.id,
- 'lines': [
- ('create', [{
- 'product': product.id,
- 'quantity': 10,
- 'uom': unit.id,
- 'minimal_quantity': 2,
- }],
- ),
- ],
- }])
- Forecast.confirm([forecast])
-
- Forecast.create_moves([forecast])
- line, = forecast.lines
- self.assertEqual(line.quantity_executed, 0)
- self.assertEqual(len(line.moves), 5)
- self.assertEqual(sum(move.quantity for move in line.moves), 10)
- self.assertGreaterEqual(
- min(m.planned_date for m in line.moves), forecast.from_date)
-
- Forecast.delete_moves([forecast])
- line, = forecast.lines
- self.assertEqual(len(line.moves), 0)
-
- Move.create([{
- 'from_location': storage.id,
- 'to_location': customer.id,
- 'product': product.id,
- 'uom': unit.id,
- 'quantity': 2,
- 'planned_date': today + relativedelta(months=1, day=5),
- 'company': company.id,
- 'currency': company.currency.id,
- 'unit_price': Decimal('1'),
- }])
- line, = forecast.lines
- self.assertEqual(line.quantity_executed, 2)
-
- Forecast.create_moves([forecast])
- line, = forecast.lines
- self.assertEqual(line.quantity_executed, 2)
- self.assertEqual(len(line.moves), 4)
- self.assertEqual(sum(move.quantity for move in line.moves), 8)
- self.assertGreaterEqual(
- min(m.planned_date for m in line.moves), forecast.from_date)
-
- @with_transaction()
- def test_create_moves_during(self):
- "Test create moves during the period"
- pool = Pool()
- Uom = pool.get('product.uom')
- Template = pool.get('product.template')
- Product = pool.get('product.product')
- Location = pool.get('stock.location')
- Forecast = pool.get('stock.forecast')
- Move = pool.get('stock.move')
-
- unit, = Uom.search([('name', '=', 'Unit')])
- template, = Template.create([{
- 'name': 'Test create_moves',
- 'type': 'goods',
- 'default_uom': unit.id,
- }])
- product, = Product.create([{
- 'template': template.id,
- }])
- customer, = Location.search([('code', '=', 'CUS')])
- warehouse, = Location.search([('code', '=', 'WH')])
- storage, = Location.search([('code', '=', 'STO')])
- company = create_company()
- with set_company(company):
- today = datetime.date.today()
-
- forecast, = Forecast.create([{
- 'warehouse': warehouse.id,
- 'destination': customer.id,
- 'from_date': today - relativedelta(days=20),
- 'to_date': today + relativedelta(days=10),
- 'company': company.id,
- 'lines': [
- ('create', [{
- 'product': product.id,
- 'quantity': 20,
- 'uom': unit.id,
- 'minimal_quantity': 2,
- }],
- ),
- ],
- }])
- Forecast.confirm([forecast])
-
- Forecast.create_moves([forecast])
- line, = forecast.lines
- self.assertEqual(line.quantity_executed, 0)
- self.assertEqual(len(line.moves), 10)
- self.assertEqual(sum(move.quantity for move in line.moves), 20)
- self.assertGreaterEqual(
- min(m.planned_date for m in line.moves), today)
-
- Forecast.delete_moves([forecast])
- line, = forecast.lines
- self.assertEqual(len(line.moves), 0)
-
- Move.create([{
- 'from_location': storage.id,
- 'to_location': customer.id,
- 'product': product.id,
- 'uom': unit.id,
- 'quantity': 10,
- 'planned_date': today - relativedelta(days=5),
- 'company': company.id,
- 'currency': company.currency.id,
- 'unit_price': Decimal('1'),
- }])
- line, = forecast.lines
- self.assertEqual(line.quantity_executed, 10)
-
- Forecast.create_moves([forecast])
- line, = forecast.lines
- self.assertEqual(line.quantity_executed, 10)
- self.assertEqual(len(line.moves), 5)
- self.assertEqual(sum(move.quantity for move in line.moves), 10)
- self.assertGreaterEqual(
- min(m.planned_date for m in line.moves), today)
-
- @with_transaction()
- def test_create_moves_after(self):
- "Test create not moves after end date"
- pool = Pool()
- Uom = pool.get('product.uom')
- Template = pool.get('product.template')
- Product = pool.get('product.product')
- Location = pool.get('stock.location')
- Forecast = pool.get('stock.forecast')
-
- unit, = Uom.search([('name', '=', 'Unit')])
- template, = Template.create([{
- 'name': 'Test create_moves',
- 'type': 'goods',
- 'default_uom': unit.id,
- }])
- product, = Product.create([{
- 'template': template.id,
- }])
- customer, = Location.search([('code', '=', 'CUS')])
- warehouse, = Location.search([('code', '=', 'WH')])
- storage, = Location.search([('code', '=', 'STO')])
- company = create_company()
- with set_company(company):
- today = datetime.date.today()
-
- forecast, = Forecast.create([{
- 'warehouse': warehouse.id,
- 'destination': customer.id,
- 'from_date': today - relativedelta(days=20),
- 'to_date': today - relativedelta(days=10),
- 'company': company.id,
- 'lines': [
- ('create', [{
- 'product': product.id,
- 'quantity': 20,
- 'uom': unit.id,
- 'minimal_quantity': 2,
- }],
- ),
- ],
- }])
- Forecast.confirm([forecast])
-
- Forecast.create_moves([forecast])
- line, = forecast.lines
- self.assertEqual(len(line.moves), 0)
-
- @with_transaction()
- def test_complete(self):
- 'Test complete'
- pool = Pool()
- Uom = pool.get('product.uom')
- Template = pool.get('product.template')
- Product = pool.get('product.product')
- Location = pool.get('stock.location')
- Forecast = pool.get('stock.forecast')
- Move = pool.get('stock.move')
- ForecastComplete = pool.get('stock.forecast.complete', type='wizard')
-
- unit, = Uom.search([('name', '=', 'Unit')])
- template, = Template.create([{
- 'name': 'Test complete',
- 'type': 'goods',
- 'default_uom': unit.id,
- }])
- product, = Product.create([{
- 'template': template.id,
- }])
- customer, = Location.search([('code', '=', 'CUS')])
- supplier, = Location.search([('code', '=', 'SUP')])
- warehouse, = Location.search([('code', '=', 'WH')])
- storage, = Location.search([('code', '=', 'STO')])
- company = create_company()
- with set_company(company):
- today = datetime.date.today()
-
- moves = Move.create([{
- 'from_location': supplier.id,
- 'to_location': storage.id,
- 'product': product.id,
- 'uom': unit.id,
- 'quantity': 10,
- 'effective_date': (today
- + relativedelta(months=-1, day=1)),
- 'company': company.id,
- 'currency': company.currency.id,
- 'unit_price': Decimal('1'),
- }, {
- 'from_location': storage.id,
- 'to_location': customer.id,
- 'product': product.id,
- 'uom': unit.id,
- 'quantity': 5,
- 'effective_date': (today
- + relativedelta(months=-1, day=15)),
- 'company': company.id,
- 'currency': company.currency.id,
- 'unit_price': Decimal('1'),
- }])
- Move.do(moves)
-
- forecast, = Forecast.create([{
- 'warehouse': warehouse.id,
- 'destination': customer.id,
- 'from_date': today + relativedelta(months=1, day=1),
- 'to_date': today + relativedelta(months=1, day=20),
- 'company': company.id,
- }])
-
- with Transaction().set_context(
- active_model=Forecast.__name__, active_id=forecast.id):
- session_id, _, _ = ForecastComplete.create()
- forecast_complete = ForecastComplete(session_id)
- forecast_complete.ask.from_date = (
- today + relativedelta(months=-1, day=1))
- forecast_complete.ask.to_date = (
- today + relativedelta(months=-1, day=20))
- forecast_complete.transition_complete()
-
- self.assertEqual(len(forecast.lines), 1)
- forecast_line, = forecast.lines
- self.assertEqual(forecast_line.product, product)
- self.assertEqual(forecast_line.uom, unit)
- self.assertEqual(forecast_line.quantity, 5)
- self.assertEqual(forecast_line.minimal_quantity, 1)
-
-
-def suite():
- suite = trytond.tests.test_tryton.suite()
- suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
- StockForecastTestCase))
- return suite
diff -r 64853bd07070 -r ecb3518b054e tox.ini
--- a/tox.ini Mon Apr 11 23:24:21 2022 +0200
+++ b/tox.ini Sat Apr 16 18:30:19 2022 +0200
@@ -3,7 +3,7 @@
[testenv]
commands =
- coverage run --include=.*/stock_forecast/* setup.py test
+ coverage run --include=.*/stock_forecast/* -m unittest discover -s tests
coverage report --include=.*/stock_forecast/* --omit=*/tests/*
deps =
coverage