From 0ec6068829ccedbd6f724c96cdf7e0d08aafe3d6 Mon Sep 17 00:00:00 2001 From: Fabien Bourgeois Date: Thu, 4 Aug 2016 11:33:44 +0200 Subject: [PATCH] [ADD]GOLEM Activity Session Place unit tests --- .../tests/__init__.py | 18 ++++++ .../tests/test_golem_activity_session.py | 56 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 golem_activity_session_place/tests/__init__.py create mode 100644 golem_activity_session_place/tests/test_golem_activity_session.py diff --git a/golem_activity_session_place/tests/__init__.py b/golem_activity_session_place/tests/__init__.py new file mode 100644 index 0000000..bb8537f --- /dev/null +++ b/golem_activity_session_place/tests/__init__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 Fabien Bourgeois +# +# 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 . + +from . import test_golem_activity_session diff --git a/golem_activity_session_place/tests/test_golem_activity_session.py b/golem_activity_session_place/tests/test_golem_activity_session.py new file mode 100644 index 0000000..98f1773 --- /dev/null +++ b/golem_activity_session_place/tests/test_golem_activity_session.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 Fabien Bourgeois +# +# 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 . + +from openerp.tests.common import TransactionCase +from openerp.models import ValidationError + + +class GolemActivitySessionTestCase(TransactionCase): + + def setUp(self): + super(GolemActivitySessionTestCase, self).setUp() + season_model = self.env['golem.season'].sudo() + season_data = {'name': u'Current', 'date_start': '2010-01-01', + 'date_end': '2010-12-31'} + season1 = season_model.create(season_data) + activity_model = self.env['golem.activity'].sudo() + categ = self.ref('golem_activity.golem_product_category_activities') + self.activity1 = activity_model.create({'name': 'activity1', + 'default_code': 'A1', + 'categ_id': categ, + 'season_id': season1.id}) + self.activity1.onchange_season_dates() + self.session_model = self.env['golem.activity.session'].sudo() + sdata = {'name': 's1', 'activity_id': self.activity1.id} + self.session1 = self.session_model.create(sdata) + self.session1.onchange_activity_id() + + def test_session_places_overbook(self): + """ Test computed places with overbooked on """ + self.session1.places = 4 + self.assertEqual(self.session1.places_used, 0) + self.assertEqual(self.session1.places_remain, 4) + self.session1.is_overbooked = True + self.session1.onchange_is_overbooked() + self.assertEqual(self.session1.places_overbooked, 5) + self.assertEqual(self.session1.places_remain, 5) + self.session1.places_overbooked = 15 + self.assertEqual(self.session1.places_overbooked, 15) + self.assertEqual(self.session1.places_remain, 15) + # Overbooked places cannot be < to places + with self.assertRaises(ValidationError): + self.session1.places_overbooked = 2