GOLEM/golem_season/tests/test_golem_season.py

90 lines
3.9 KiB
Python
Raw Permalink Normal View History

2016-08-03 16:33:26 +02:00
# -*- coding: utf-8 -*-
2017-06-20 07:35:02 +02:00
# Copyright 2017 Fabien Bourgeois <fabien@yaltik.com>
2016-08-03 16:33:26 +02:00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2017-06-20 07:35:02 +02:00
""" GOLEM season testing """
2016-08-03 16:33:26 +02:00
2017-06-20 07:35:02 +02:00
from odoo.tests.common import TransactionCase
from odoo.models import ValidationError
2016-08-03 16:33:26 +02:00
2017-06-20 07:35:02 +02:00
class TestGolemSeason(TransactionCase):
""" GOLEM season testing """
2016-08-03 16:33:26 +02:00
2017-06-20 07:35:02 +02:00
def setUp(self, *args, **kwargs):
""" Bootstrap res partner sale sector """
super(TestGolemSeason, self).setUp(*args, **kwargs)
2016-08-03 16:33:26 +02:00
self.season_model = self.env['golem.season'].sudo()
def test_season_default(self):
""" Test uniqueness of default season """
first = self.season_model.create({'name': u'First'})
self.assertTrue(first.is_default)
second = self.season_model.create({'name': u'Second'})
self.assertFalse(second.is_default)
second.do_default_season()
self.assertTrue(second.is_default)
self.assertFalse(first.is_default)
def test_check_period(self):
""" Tests constraints on periods """
old = self.season_model.create({'name': 'Valid',
'date_start': '2010-01-01',
'date_end': '2010-12-31'})
self.assertTrue(old.date_end > old.date_start)
with self.assertRaises(ValidationError):
old.write({'date_start': '2011-01-01'})
with self.assertRaises(ValidationError):
self.season_model.create({'name': 'Conflict for start',
'date_start': '2010-11-01',
'date_end': '2011-12-31'})
with self.assertRaises(ValidationError):
self.season_model.create({'name': 'Conflict : include existing',
'date_start': '2009-11-01',
'date_end': '2011-12-31'})
2018-01-15 12:00:50 +01:00
with self.assertRaises(ValidationError):
self.season_model.create({'name': 'date_end is empty',
'date_start': '2009-11-01',
'date_end': False})
with self.assertRaises(ValidationError):
self.season_model.create({'name': 'date_start is empty',
'date_start' : False,
'date_end': '2009-11-01'})
2018-02-28 08:54:46 +01:00
def test_membership(self):
2018-01-18 15:27:35 +01:00
""" Test if membership """
2018-02-28 08:54:46 +01:00
new_season = self.env['golem.season'].create({'name': 'Name'})
membership = self.env['product.template'].create({
'name': 'Name',
'season_id': new_season.id,
'membership': True,
'membership_date_from': '2017-11-01',
'membership_date_to': '2018-11-01'
})
self.assertEqual(new_season.membership_ids[0], membership)
2018-02-28 08:54:46 +01:00
self.assertEqual(membership.season_id, new_season)
membership2 = self.env['product.template'].create({
'name': 'Name2',
'membership': True,
'membership_date_from': '2017-11-01',
'membership_date_to': '2018-11-01'
})
new_season.membership_ids = [(4, membership2.id, False)]
self.assertEqual(len(new_season.membership_ids), 2)
self.assertEqual(new_season.membership_ids[1], membership2)
self.assertEqual(membership2.season_id, new_season)