GOLEM/golem_season/tests/test_golem_season.py

79 lines
3.6 KiB
Python
Raw 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-01-15 12:00:50 +01:00
def test__onchange_season_dates(self):
2018-01-18 15:27:35 +01:00
""" Test if membership """
2018-01-15 17:03:12 +01:00
membership = self.env['product.template'].create({'name': 'Name',
'membership': True,
2018-01-15 17:03:12 +01:00
'membership_date_from': '2017-11-01',
'membership_date_to': '2018-11-01'})
2018-01-15 12:00:50 +01:00
2018-01-15 14:13:22 +01:00
new_season = self.env['golem.season'].create({'name': 'Name',
2018-01-19 07:54:47 +01:00
'membership_id': membership.id})
2018-01-18 15:27:35 +01:00
self.assertEqual(new_season.membership_id, membership)