summaryrefslogtreecommitdiff
path: root/addons/lunch/tests
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/lunch/tests
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/lunch/tests')
-rw-r--r--addons/lunch/tests/__init__.py6
-rw-r--r--addons/lunch/tests/common.py75
-rw-r--r--addons/lunch/tests/test_product_report.py21
-rw-r--r--addons/lunch/tests/test_supplier.py124
4 files changed, 226 insertions, 0 deletions
diff --git a/addons/lunch/tests/__init__.py b/addons/lunch/tests/__init__.py
new file mode 100644
index 00000000..368a677b
--- /dev/null
+++ b/addons/lunch/tests/__init__.py
@@ -0,0 +1,6 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import common
+from . import test_product_report
+from . import test_supplier
diff --git a/addons/lunch/tests/common.py b/addons/lunch/tests/common.py
new file mode 100644
index 00000000..61e75d3d
--- /dev/null
+++ b/addons/lunch/tests/common.py
@@ -0,0 +1,75 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo.tests import common
+
+
+class TestsCommon(common.TransactionCase):
+
+ def setUp(self):
+ super(TestsCommon, self).setUp()
+
+ self.location_office_1 = self.env['lunch.location'].create({
+ 'name' : 'Farm 1',
+ })
+
+ self.location_office_2 = self.env['lunch.location'].create({
+ 'name': 'Farm 2',
+ })
+
+ self.partner_pizza_inn = self.env['res.partner'].create({
+ 'name': 'Pizza Inn',
+ })
+
+ self.supplier_pizza_inn = self.env['lunch.supplier'].create({
+ 'partner_id': self.partner_pizza_inn.id,
+ 'send_by': 'mail',
+ 'automatic_email_time': 11,
+ 'available_location_ids': [
+ (6, 0, [self.location_office_1.id, self.location_office_2.id])
+ ],
+ })
+
+ self.partner_coin_gourmand = self.env['res.partner'].create({
+ 'name': 'Coin Gourmand',
+ })
+
+ self.supplier_coin_gourmand = self.env['lunch.supplier'].create({
+ 'partner_id': self.partner_coin_gourmand.id,
+ 'send_by': 'phone',
+ 'available_location_ids': [
+ (6, 0, [self.location_office_1.id, self.location_office_2.id])
+ ],
+ })
+
+ self.category_pizza = self.env['lunch.product.category'].create({
+ 'name': 'Pizza',
+ })
+
+ self.category_sandwich = self.env['lunch.product.category'].create({
+ 'name': 'Sandwich',
+ })
+
+ self.product_pizza = self.env['lunch.product'].create({
+ 'name': 'Pizza',
+ 'category_id': self.category_pizza.id,
+ 'price': 9,
+ 'supplier_id': self.supplier_pizza_inn.id,
+ })
+
+ self.product_sandwich_tuna = self.env['lunch.product'].create({
+ 'name': 'Tuna Sandwich',
+ 'category_id': self.category_sandwich.id,
+ 'price': 3,
+ 'supplier_id': self.supplier_coin_gourmand.id,
+ })
+
+ self.topping_olives = self.env['lunch.topping'].create({
+ 'name': 'Olives',
+ 'price': 0.3,
+ 'category_id': self.category_pizza.id,
+ })
+
+ self.env['lunch.cashmove'].create({
+ 'amount': 100,
+ })
diff --git a/addons/lunch/tests/test_product_report.py b/addons/lunch/tests/test_product_report.py
new file mode 100644
index 00000000..624d6c5e
--- /dev/null
+++ b/addons/lunch/tests/test_product_report.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo.addons.lunch.tests.common import TestsCommon
+
+
+class TestLunchProductReport(TestsCommon):
+ def test_product_available(self):
+ self.assertTrue(self.env['lunch.product.report'].search([]), 'There should be some record on lunch_product_report')
+
+ def test_order_in_report(self):
+ pizza = self.env['lunch.product.report'].search([('product_id', '=', self.product_pizza.id)], limit=1)
+ self.assertEqual(pizza.name, 'Pizza')
+ pizza = pizza.with_user(pizza.user_id)
+ pizza.write({'is_favorite': True})
+ self.assertTrue(pizza.product_id in pizza.user_id.favorite_lunch_product_ids)
+
+ new_pizza = self.env['lunch.product.report'].search([('product_id', '=', self.product_pizza.id), ('user_id', '=', pizza.user_id.id)])
+
+ self.assertEqual(new_pizza.id, pizza.id)
+ self.assertEqual(new_pizza.name, 'Pizza')
diff --git a/addons/lunch/tests/test_supplier.py b/addons/lunch/tests/test_supplier.py
new file mode 100644
index 00000000..3048237d
--- /dev/null
+++ b/addons/lunch/tests/test_supplier.py
@@ -0,0 +1,124 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+import pytz
+
+from datetime import datetime
+from unittest.mock import patch
+
+from odoo import fields
+
+from odoo.addons.lunch.tests.common import TestsCommon
+
+
+class TestSupplier(TestsCommon):
+ def setUp(self):
+ super(TestSupplier, self).setUp()
+
+ self.monday_1am = datetime(2018, 10, 29, 1, 0, 0)
+ self.monday_10am = datetime(2018, 10, 29, 10, 0, 0)
+ self.monday_1pm = datetime(2018, 10, 29, 13, 0, 0)
+ self.monday_8pm = datetime(2018, 10, 29, 20, 0, 0)
+
+ self.saturday_3am = datetime(2018, 11, 3, 3, 0, 0)
+ self.saturday_10am = datetime(2018, 11, 3, 10, 0, 0)
+ self.saturday_1pm = datetime(2018, 11, 3, 13, 0, 0)
+ self.saturday_8pm = datetime(2018, 11, 3, 20, 0, 0)
+
+ def test_compute_available_today(self):
+ tests = [(self.monday_1am, True), (self.monday_10am, True),
+ (self.monday_1pm, True), (self.monday_8pm, True),
+ (self.saturday_3am, False), (self.saturday_10am, False),
+ (self.saturday_1pm, False), (self.saturday_8pm, False)]
+
+ for value, result in tests:
+ with patch.object(fields.Datetime, 'now', return_value=value) as _:
+ assert self.supplier_pizza_inn.available_today == result,\
+ 'supplier pizza inn should %s considered available on %s' % ('be' if result else 'not be', value)
+
+ self.env['lunch.supplier'].invalidate_cache(['available_today'], [self.supplier_pizza_inn.id])
+
+ def test_search_available_today(self):
+ '''
+ This test checks that _search_available_today returns a valid domain
+ '''
+ self.env.user.tz = 'Europe/Brussels'
+ Supplier = self.env['lunch.supplier']
+
+ tests = [(self.monday_1am, 1.0, 'monday'), (self.monday_10am, 10.0, 'monday'),
+ (self.monday_1pm, 13.0, 'monday'), (self.monday_8pm, 20.0, 'monday'),
+ (self.saturday_3am, 3.0, 'saturday'), (self.saturday_10am, 10.0, 'saturday'),
+ (self.saturday_1pm, 13.0, 'saturday'), (self.saturday_8pm, 20.0, 'saturday')]
+
+ # It should return an empty domain if we compare to values other than datetime
+ assert Supplier._search_available_today('>', 7) == []
+ assert Supplier._search_available_today('>', True) == []
+
+ for value, rvalue, dayname in tests:
+ with patch.object(fields.Datetime, 'now', return_value=value) as _:
+ assert Supplier._search_available_today('=', True) == ['&', '|', ('recurrency_end_date', '=', False),
+ ('recurrency_end_date', '>', value.replace(tzinfo=pytz.UTC).astimezone(pytz.timezone(self.env.user.tz))),
+ ('recurrency_%s' % (dayname), '=', True)],\
+ 'Wrong domain generated for values (%s, %s)' % (value, rvalue)
+
+ with patch.object(fields.Datetime, 'now', return_value=self.monday_10am) as _:
+ assert self.supplier_pizza_inn in Supplier.search([('available_today', '=', True)])
+
+ def test_auto_email_send(self):
+ with patch.object(fields.Datetime, 'now', return_value=self.monday_1pm) as _:
+ with patch.object(fields.Date, 'today', return_value=self.monday_1pm.date()) as _:
+ with patch.object(fields.Date, 'context_today', return_value=self.monday_1pm.date()) as _:
+ line = self.env['lunch.order'].create({
+ 'product_id': self.product_pizza.id,
+ 'date': self.monday_1pm.date()
+ })
+
+ line.action_order()
+ assert line.state == 'ordered'
+
+ self.supplier_pizza_inn._auto_email_send()
+
+ assert line.state == 'confirmed'
+
+ line = self.env['lunch.order'].create({
+ 'product_id': self.product_pizza.id,
+ 'topping_ids_1': [(6, 0, [self.topping_olives.id])],
+ 'date': self.monday_1pm.date()
+ })
+ line2 = self.env['lunch.order'].create({
+ 'product_id': self.product_sandwich_tuna.id,
+ 'date': self.monday_1pm.date()
+ })
+
+ (line | line2).action_order()
+ assert line.state == 'ordered'
+ assert line2.state == 'ordered'
+
+ self.supplier_pizza_inn._auto_email_send()
+
+ assert line.state == 'confirmed'
+ assert line2.state == 'ordered'
+
+ line_1 = self.env['lunch.order'].create({
+ 'product_id': self.product_pizza.id,
+ 'quantity': 2,
+ 'date': self.monday_1pm.date()
+ })
+
+ line_2 = self.env['lunch.order'].create({
+ 'product_id': self.product_pizza.id,
+ 'topping_ids_1': [(6, 0, [self.topping_olives.id])],
+ 'date': self.monday_1pm.date()
+ })
+
+ line_3 = self.env['lunch.order'].create({
+ 'product_id': self.product_sandwich_tuna.id,
+ 'quantity': 2,
+ 'date': self.monday_1pm.date()
+ })
+
+ (line_1 | line_2 | line_3).action_order()
+
+ assert all(line.state == 'ordered' for line in [line_1, line_2, line_3])
+
+ self.supplier_pizza_inn._auto_email_send()