2018-02-28 23:31:30 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
|
|
|
|
# Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
|
|
|
""" GOLEM Activity Queue testing """
|
|
|
|
|
|
|
|
from odoo.tests.common import TransactionCase
|
|
|
|
from odoo.exceptions import ValidationError
|
|
|
|
|
|
|
|
|
|
|
|
class TestGolemActivityQueue(TransactionCase):
|
|
|
|
""" GOLEM Activity Queue testing """
|
|
|
|
|
|
|
|
def setUp(self, *args, **kwargs):
|
2018-03-02 14:37:08 +01:00
|
|
|
""" Bootstrap ActivityQueue """
|
2018-02-28 23:31:30 +01:00
|
|
|
super(TestGolemActivityQueue, self).setUp(*args, **kwargs)
|
|
|
|
|
2018-03-07 11:07:25 +01:00
|
|
|
self.season = self.env['golem.season'].create({'name': u'Season 1'})
|
2018-03-02 23:41:19 +01:00
|
|
|
self.data_member_1 = {'lastname': u'LAST1',
|
|
|
|
'firstname': u'First1',
|
2018-03-07 11:07:25 +01:00
|
|
|
'season_ids':[(4, self.season.id, False)]}
|
2018-03-02 23:41:19 +01:00
|
|
|
self.data_member_2 = {'lastname': u'LAST2',
|
|
|
|
'firstname': u'First2',
|
2018-03-07 11:07:25 +01:00
|
|
|
'season_ids':[(4, self.season.id, False)]}
|
|
|
|
self.member = self.env['golem.member']
|
|
|
|
type_id = self.env.ref('golem_activity.golem_activity_type_activity')
|
2018-03-02 23:41:19 +01:00
|
|
|
self.data_activity = {
|
|
|
|
'name': u'Activity 1',
|
|
|
|
'season_id': self.season.id,
|
2018-03-07 11:07:25 +01:00
|
|
|
'type_id': type_id.id
|
|
|
|
}
|
2018-03-02 23:41:19 +01:00
|
|
|
self.activity = self.env['golem.activity']
|
|
|
|
self.activity_queue = self.env['golem.activity.queue']
|
2018-03-07 11:07:25 +01:00
|
|
|
self.activity_registration = self.env['golem.activity.registration']
|
2018-02-28 23:31:30 +01:00
|
|
|
|
|
|
|
def test_activity_queue_basic(self):
|
2018-03-07 11:07:25 +01:00
|
|
|
""" Test activity queue basics """
|
|
|
|
member1 = self.member.create(self.data_member_1)
|
2018-03-02 23:41:19 +01:00
|
|
|
activity = self.activity.create(self.data_activity)
|
2018-03-07 09:36:06 +01:00
|
|
|
activity.auto_registration_from_queue = False
|
2018-03-02 23:41:19 +01:00
|
|
|
activity_queue = self.activity_queue.create({'activity_id': activity.id,
|
|
|
|
'member_id': member1.id})
|
|
|
|
self.assertEqual(activity.activity_queue_ids[0], activity_queue)
|
|
|
|
self.assertEqual(member1.activity_queue_ids[0], activity_queue)
|
|
|
|
|
|
|
|
def test_check_member_registration(self):
|
2018-03-07 11:07:25 +01:00
|
|
|
""" Test activity queue fordib if already in activity """
|
|
|
|
member1 = self.member.create(self.data_member_1)
|
2018-03-02 23:41:19 +01:00
|
|
|
activity = self.activity.create(self.data_activity)
|
2018-03-07 11:07:25 +01:00
|
|
|
self.activity_registration.create({'activity_id': activity.id,
|
|
|
|
'member_id': member1.id})
|
2018-03-02 23:41:19 +01:00
|
|
|
self.assertEqual(activity.activity_registration_ids[0].member_id, member1)
|
2018-03-07 11:07:25 +01:00
|
|
|
with self.assertRaises(ValidationError) as err:
|
2018-03-06 07:31:41 +01:00
|
|
|
self.activity_queue.create({'activity_id': activity.id,
|
|
|
|
'member_id': member1.id})
|
2018-03-07 11:07:25 +01:00
|
|
|
self.assertIn('already registered for this activity', err.exception.args[0])
|