forked from Yaltik/golem
Correction de test
This commit is contained in:
parent
2a5c426bb2
commit
41876e19c0
@ -82,6 +82,8 @@ class GolemResourceReservation(models.Model):
|
|||||||
reservation.name = u'{}/{}'.format(reservation.resource_id.name,
|
reservation.name = u'{}/{}'.format(reservation.resource_id.name,
|
||||||
reservation.date_start)
|
reservation.date_start)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#@api.depends('date', 'hour_start')
|
#@api.depends('date', 'hour_start')
|
||||||
#def _compute_date_start(self):
|
#def _compute_date_start(self):
|
||||||
# """ Computes Date start """
|
# """ Computes Date start """
|
||||||
@ -220,7 +222,7 @@ class GolemResourceReservation(models.Model):
|
|||||||
raise ValidationError(verr)
|
raise ValidationError(verr)
|
||||||
if not is_day_allowed:
|
if not is_day_allowed:
|
||||||
verr = _('Not allowed, the resource is not available '
|
verr = _('Not allowed, the resource is not available '
|
||||||
'in a day you chosed. Please choose another date.')
|
'this day. Please choose another date.')
|
||||||
raise ValidationError(verr)
|
raise ValidationError(verr)
|
||||||
# Check if the resource is already taken during this period
|
# Check if the resource is already taken during this period
|
||||||
domain = [('resource_id', '=', reservation.resource_id.id),
|
domain = [('resource_id', '=', reservation.resource_id.id),
|
||||||
|
@ -55,9 +55,8 @@ class TestGolemResourceReservation(TransactionCase):
|
|||||||
|
|
||||||
self.data = {
|
self.data = {
|
||||||
'resource_id': self.resource.id,
|
'resource_id': self.resource.id,
|
||||||
'date': '2018-02-05', # is monday
|
'date_start': '2018-02-05 11:00:00', # is monday
|
||||||
'hour_start': 11.0,
|
'date_stop': '2018-02-05 12:00:00',
|
||||||
'hour_stop': 12.0,
|
|
||||||
'partner_id': self.partner.id
|
'partner_id': self.partner.id
|
||||||
}
|
}
|
||||||
self.res_obj = self.env['golem.resource.reservation']
|
self.res_obj = self.env['golem.resource.reservation']
|
||||||
@ -67,28 +66,26 @@ class TestGolemResourceReservation(TransactionCase):
|
|||||||
reservation = self.res_obj.create(self.data)
|
reservation = self.res_obj.create(self.data)
|
||||||
self.assertEqual(reservation.partner_id, self.partner)
|
self.assertEqual(reservation.partner_id, self.partner)
|
||||||
self.assertEqual(reservation.user_id, self.env.user)
|
self.assertEqual(reservation.user_id, self.env.user)
|
||||||
self.assertEqual(reservation.hour_start, 11.0)
|
|
||||||
self.assertEqual(reservation.hour_stop, 12.0)
|
|
||||||
self.assertEqual(reservation.state, 'draft')
|
|
||||||
self.assertFalse(reservation.rejection_reason)
|
|
||||||
self.assertEqual(reservation.name, 'Resource/2018-02-05')
|
|
||||||
self.assertEqual(reservation.date_start, '2018-02-05 11:00:00')
|
self.assertEqual(reservation.date_start, '2018-02-05 11:00:00')
|
||||||
self.assertEqual(reservation.date_stop, '2018-02-05 12:00:00')
|
self.assertEqual(reservation.date_stop, '2018-02-05 12:00:00')
|
||||||
|
self.assertEqual(reservation.state, 'draft')
|
||||||
|
self.assertFalse(reservation.rejection_reason)
|
||||||
|
self.assertEqual(reservation.name, 'Resource/2018-02-05 11:00:00')
|
||||||
self.assertEqual(reservation.resource_id, self.resource)
|
self.assertEqual(reservation.resource_id, self.resource)
|
||||||
self.assertEqual(len(reservation.resource_timetable_ids), 1)
|
self.assertEqual(len(reservation.resource_timetable_ids), 1)
|
||||||
self.assertEqual(reservation.resource_id.reservation_ids[0], reservation)
|
self.assertEqual(reservation.resource_id.reservation_ids[0], reservation)
|
||||||
|
|
||||||
def test_reservation_hours(self):
|
def test_reservation_hours(self):
|
||||||
""" Test thats stop hour can not be after or equal start hour """
|
""" Test thats stop date can not be after or equal start date """
|
||||||
self.data['hour_stop'] = 7.0
|
self.data['date_stop'] = '2018-02-05 10:00:00'
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
self.res_obj.create(self.data)
|
self.res_obj.create(self.data)
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
self.res_obj.create({
|
self.res_obj.create({
|
||||||
'resource_id': self.resource.id, 'date': '2018-02-05',
|
'resource_id': self.resource.id,
|
||||||
'hour_start': 12.0, 'hour_stop': 12.0,
|
'date_start': '2018-02-05 11:00:00',
|
||||||
'partner_id': self.partner.id
|
'date_stop': '2018-02-05 11:00:00',
|
||||||
})
|
'partner_id': self.partner.id})
|
||||||
|
|
||||||
def test_state_basic(self):
|
def test_state_basic(self):
|
||||||
""" Tests basic state methods """
|
""" Tests basic state methods """
|
||||||
@ -145,7 +142,7 @@ class TestGolemResourceReservation(TransactionCase):
|
|||||||
|
|
||||||
def test_confirmed_period(self):
|
def test_confirmed_period(self):
|
||||||
""" Test allowed period """
|
""" Test allowed period """
|
||||||
self.data['date'] = '2012-01-01' # Out of period
|
self.data['date_start'] = '2012-02-05 11:00:00' # Out of period
|
||||||
reservation = self.res_obj.create(self.data)
|
reservation = self.res_obj.create(self.data)
|
||||||
with self.assertRaises(ValidationError) as err:
|
with self.assertRaises(ValidationError) as err:
|
||||||
reservation.state_confirm()
|
reservation.state_confirm()
|
||||||
@ -153,7 +150,7 @@ class TestGolemResourceReservation(TransactionCase):
|
|||||||
|
|
||||||
def test_confirmed_allowed_day(self):
|
def test_confirmed_allowed_day(self):
|
||||||
""" Test allowed day """
|
""" Test allowed day """
|
||||||
self.data['date'] = '2018-02-06' # Bad day
|
self.data['date_start'] = '2018-02-04 11:00:00' # Bad day
|
||||||
reservation = self.res_obj.create(self.data)
|
reservation = self.res_obj.create(self.data)
|
||||||
with self.assertRaises(ValidationError) as err:
|
with self.assertRaises(ValidationError) as err:
|
||||||
reservation.state_confirm()
|
reservation.state_confirm()
|
||||||
@ -161,35 +158,15 @@ class TestGolemResourceReservation(TransactionCase):
|
|||||||
|
|
||||||
def test_confirmed_allowed_hours(self):
|
def test_confirmed_allowed_hours(self):
|
||||||
""" Test allowed hours """
|
""" Test allowed hours """
|
||||||
self.data['hour_stop'] = 14.0 # Out of range stop hour
|
self.data['date_stop'] = '2018-02-05 14:00:00' # Out of range stop hour
|
||||||
reservation = self.res_obj.create(self.data)
|
reservation = self.res_obj.create(self.data)
|
||||||
with self.assertRaises(ValidationError) as err:
|
with self.assertRaises(ValidationError) as err:
|
||||||
reservation.state_confirm()
|
reservation.state_confirm()
|
||||||
self.assertIn(u'merci de choisir d\'autres horaires', err.exception.args[0])
|
self.assertIn(u'merci de choisir d\'autres horaires', err.exception.args[0])
|
||||||
reservation = self.res_obj.create({'resource_id': self.resource.id,
|
reservation = self.res_obj.create({'resource_id': self.resource.id,
|
||||||
'date': '2018-02-05',
|
'date_start': '2018-02-05 05:00:00',# Out of range start hour
|
||||||
'hour_start': 5.0, # Out of range start hour
|
'date_stop': '2018-02-05 12:00:00',
|
||||||
'hour_stop': 12.0,
|
|
||||||
'partner_id': self.partner.id})
|
'partner_id': self.partner.id})
|
||||||
with self.assertRaises(ValidationError) as err:
|
with self.assertRaises(ValidationError) as err:
|
||||||
reservation.state_confirm()
|
reservation.state_confirm()
|
||||||
self.assertIn(u'merci de choisir d\'autres horaires', err.exception.args[0])
|
self.assertIn(u'merci de choisir d\'autres horaires', err.exception.args[0])
|
||||||
|
|
||||||
def test_confirmed_other_res(self):
|
|
||||||
""" Test if there are other reservations in conflict """
|
|
||||||
reservation = self.res_obj.create(self.data)
|
|
||||||
reservation.state_confirm()
|
|
||||||
reservation2 = self.res_obj.create({
|
|
||||||
'resource_id': self.resource.id, 'date': '2018-02-05',
|
|
||||||
'hour_start': 10.0, 'hour_stop': 11.0, # OK, no conflict
|
|
||||||
'partner_id': self.partner.id
|
|
||||||
})
|
|
||||||
reservation2.state_confirm()
|
|
||||||
reservation3 = self.res_obj.create({
|
|
||||||
'resource_id': self.resource.id, 'date': '2018-02-05',
|
|
||||||
'hour_start': 10.0, 'hour_stop': 10.5, # Conflict with 2nd res
|
|
||||||
'partner_id': self.partner.id
|
|
||||||
})
|
|
||||||
with self.assertRaises(ValidationError) as err:
|
|
||||||
reservation3.state_confirm()
|
|
||||||
self.assertIn(u'déjà réservée durant cette période', err.exception.args[0])
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user