[FIX] pms: fix tests (#24)

This commit is contained in:
Miguel Padin
2020-12-15 15:40:21 +01:00
committed by GitHub
parent 644e276d60
commit 3bf6dd78a6

View File

@@ -68,7 +68,12 @@ class TestPmsReservations(TestHotel):
) )
self.demo_user = self.env.ref("base.user_admin") self.demo_user = self.env.ref("base.user_admin")
def test_create_reservation(self): @freeze_time("1980-11-01")
def test_create_reservation_start_date(self):
# TEST CASE
# reservation should start on checkin day
# ARRANGE
today = fields.date.today() today = fields.date.today()
checkin = today + datetime.timedelta(days=8) checkin = today + datetime.timedelta(days=8)
checkout = checkin + datetime.timedelta(days=11) checkout = checkin + datetime.timedelta(days=11)
@@ -80,6 +85,8 @@ class TestPmsReservations(TestHotel):
"partner_id": customer.id, "partner_id": customer.id,
"pms_property_id": self.main_hotel_property.id, "pms_property_id": self.main_hotel_property.id,
} }
# ACT
reservation = self.env["pms.reservation"].create(reservation_vals) reservation = self.env["pms.reservation"].create(reservation_vals)
self.assertEqual( self.assertEqual(
@@ -87,6 +94,28 @@ class TestPmsReservations(TestHotel):
checkin, checkin,
"Reservation lines don't start in the correct date", "Reservation lines don't start in the correct date",
) )
@freeze_time("1980-11-01")
def test_create_reservation_end_date(self):
# TEST CASE
# reservation should end on checkout day
# ARRANGE
today = fields.date.today()
checkin = today + datetime.timedelta(days=8)
checkout = checkin + datetime.timedelta(days=11)
customer = self.env.ref("base.res_partner_12")
reservation_vals = {
"checkin": checkin,
"checkout": checkout,
"room_type_id": self.room_type_3.id,
"partner_id": customer.id,
"pms_property_id": self.main_hotel_property.id,
}
# ACT
reservation = self.env["pms.reservation"].create(reservation_vals)
self.assertEqual( self.assertEqual(
reservation.reservation_line_ids[-1].date, reservation.reservation_line_ids[-1].date,
checkout - datetime.timedelta(1), checkout - datetime.timedelta(1),
@@ -96,6 +125,7 @@ class TestPmsReservations(TestHotel):
@freeze_time("1980-11-01") @freeze_time("1980-11-01")
def test_split_reservation01(self): def test_split_reservation01(self):
""" """
# TEST CASE
The reservation shouldn't be splitted The reservation shouldn't be splitted
preferred_room_id with availability provided preferred_room_id with availability provided
+------------+------+------+------+----+----+----+ +------------+------+------+------+----+----+----+
@@ -106,9 +136,10 @@ class TestPmsReservations(TestHotel):
| Double 103 | | | | | | | | Double 103 | | | | | | |
+------------+------+------+------+----+----+----+ +------------+------+------+------+----+----+----+
""" """
# ARRANGE
self.create_common_scenario() self.create_common_scenario()
# ACT
r_test = self.env["pms.reservation"].create( r_test = self.env["pms.reservation"].create(
{ {
"pms_property_id": self.property.id, "pms_property_id": self.property.id,
@@ -119,17 +150,20 @@ class TestPmsReservations(TestHotel):
} }
) )
r_test.flush() r_test.flush()
obtained = all(
elem.room_id.id == r_test.reservation_line_ids[0].room_id.id # ASSERT
for elem in r_test.reservation_line_ids
)
self.assertTrue( self.assertTrue(
obtained, "The entire reservation should be allocated in the preferred room" all(
elem.room_id.id == r_test.reservation_line_ids[0].room_id.id
for elem in r_test.reservation_line_ids
),
"The entire reservation should be allocated in the preferred room",
) )
@freeze_time("1980-11-01") @freeze_time("1980-11-01")
def test_split_reservation02(self): def test_split_reservation02(self):
""" """
# TEST CASE
The reservation shouldn't be splitted The reservation shouldn't be splitted
room_type_id with availability provided room_type_id with availability provided
+------------+------+------+------+----+----+----+ +------------+------+------+------+----+----+----+
@@ -140,8 +174,10 @@ class TestPmsReservations(TestHotel):
| Double 103 | | | | | | | | Double 103 | | | | | | |
+------------+------+------+------+----+----+----+ +------------+------+------+------+----+----+----+
""" """
# ARRANGE
self.create_common_scenario() self.create_common_scenario()
# ACT
r_test = self.env["pms.reservation"].create( r_test = self.env["pms.reservation"].create(
{ {
"pms_property_id": self.property.id, "pms_property_id": self.property.id,
@@ -152,11 +188,14 @@ class TestPmsReservations(TestHotel):
} }
) )
r_test.flush() r_test.flush()
# ASSERT
self.assertFalse(r_test.splitted, "The reservation shouldn't be splitted") self.assertFalse(r_test.splitted, "The reservation shouldn't be splitted")
@freeze_time("1980-11-01") @freeze_time("1980-11-01")
def test_split_reservation03(self): def test_split_reservation03(self):
""" """
# TEST CASE
The reservation should be splitted in 2 rooms The reservation should be splitted in 2 rooms
(there is only one better option on day 02 and a draw the next day. (there is only one better option on day 02 and a draw the next day.
The night before should be prioritized) The night before should be prioritized)
@@ -168,7 +207,7 @@ class TestPmsReservations(TestHotel):
| Double 103 | r2 | r4 | | | | | | Double 103 | r2 | r4 | | | | |
+------------+------+------+------+------+----+----+ +------------+------+------+------+------+----+----+
""" """
# ARRANGE
self.create_common_scenario() self.create_common_scenario()
r1 = self.env["pms.reservation"].create( r1 = self.env["pms.reservation"].create(
@@ -218,7 +257,9 @@ class TestPmsReservations(TestHotel):
) )
r4.reservation_line_ids[0].room_id = self.room3.id r4.reservation_line_ids[0].room_id = self.room3.id
r4.flush() r4.flush()
expected_num_changes = 2
# ACT
r_test = self.env["pms.reservation"].create( r_test = self.env["pms.reservation"].create(
{ {
"pms_property_id": self.property.id, "pms_property_id": self.property.id,
@@ -229,21 +270,18 @@ class TestPmsReservations(TestHotel):
} }
) )
r_test.flush() r_test.flush()
changes = 0
last_room = None
for line in r_test.reservation_line_ids:
if last_room != line.room_id.id:
last_room = line.room_id.id
changes += 1
# ASSERT
self.assertEqual( self.assertEqual(
2, changes, "The reservation shouldn't have more than 2 changes" expected_num_changes,
len(r_test.reservation_line_ids.mapped("room_id")),
"The reservation shouldn't have more than 2 changes",
) )
@freeze_time("1980-11-01") @freeze_time("1980-11-01")
def test_split_reservation04(self): def test_split_reservation04(self):
""" """
# TEST CASE
The reservation should be splitted in 3 rooms The reservation should be splitted in 3 rooms
(there are 2 best options on day 03 and room of last night is not available) (there are 2 best options on day 03 and room of last night is not available)
+------------+------+------+------+------+----+----+ +------------+------+------+------+------+----+----+
@@ -254,7 +292,7 @@ class TestPmsReservations(TestHotel):
| Double 103 | r2 | r4 | | | | | | Double 103 | r2 | r4 | | | | |
+------------+------+------+------+------+----+----+ +------------+------+------+------+------+----+----+
""" """
# ARRANGE
self.create_common_scenario() self.create_common_scenario()
r1 = self.env["pms.reservation"].create( r1 = self.env["pms.reservation"].create(
@@ -317,6 +355,7 @@ class TestPmsReservations(TestHotel):
r5.reservation_line_ids[0].room_id = self.room2.id r5.reservation_line_ids[0].room_id = self.room2.id
r5.flush() r5.flush()
# ACT
r_test = self.env["pms.reservation"].create( r_test = self.env["pms.reservation"].create(
{ {
"pms_property_id": self.property.id, "pms_property_id": self.property.id,
@@ -328,20 +367,22 @@ class TestPmsReservations(TestHotel):
) )
r_test.flush() r_test.flush()
changes = 0 rooms = 0
last_room = None last_room = None
for line in r_test.reservation_line_ids: for line in r_test.reservation_line_ids:
if line.room_id != last_room: if line.room_id != last_room:
last_room = line.room_id last_room = line.room_id
changes += 1 rooms += 1
# ASSERT
self.assertEqual( self.assertEqual(
3, changes, "The reservation shouldn't be splitted in more than 3 roomss" 3, rooms, "The reservation shouldn't be splitted in more than 3 roomss"
) )
@freeze_time("1980-11-01") @freeze_time("1980-11-01")
def test_split_reservation05(self): def test_split_reservation05(self):
""" """
# TEST CASE
The preferred room_id is not available The preferred room_id is not available
+------------+------+------+------+----+----+----+ +------------+------+------+------+----+----+----+
| room/date | 01 | 02 | 03 | 04 | 05 | 06 | | room/date | 01 | 02 | 03 | 04 | 05 | 06 |
@@ -351,7 +392,7 @@ class TestPmsReservations(TestHotel):
| Double 103 | | | | | | | | Double 103 | | | | | | |
+------------+------+------+------+----+----+----+ +------------+------+------+------+----+----+----+
""" """
# ARRANGE
self.create_common_scenario() self.create_common_scenario()
r1 = self.env["pms.reservation"].create( r1 = self.env["pms.reservation"].create(
@@ -366,6 +407,7 @@ class TestPmsReservations(TestHotel):
r1.reservation_line_ids[0].room_id = self.room1 r1.reservation_line_ids[0].room_id = self.room1
r1.flush() r1.flush()
# ACT & ASSERT
with self.assertRaises(ValidationError): with self.assertRaises(ValidationError):
r_test = self.env["pms.reservation"].create( r_test = self.env["pms.reservation"].create(
{ {
@@ -381,6 +423,7 @@ class TestPmsReservations(TestHotel):
@freeze_time("1980-11-01") @freeze_time("1980-11-01")
def test_split_reservation06(self): def test_split_reservation06(self):
""" """
# TEST CASE
There's no availability in the preferred_room_id provided There's no availability in the preferred_room_id provided
+------------+------+------+------+----+----+----+ +------------+------+------+------+----+----+----+
| room/date | 01 | 02 | 03 | 04 | 05 | 06 | | room/date | 01 | 02 | 03 | 04 | 05 | 06 |
@@ -390,7 +433,7 @@ class TestPmsReservations(TestHotel):
| Double 103 | | | | | | | | Double 103 | | | | | | |
+------------+------+------+------+----+----+----+ +------------+------+------+------+----+----+----+
""" """
# ARRANGE
self.create_common_scenario() self.create_common_scenario()
r1 = self.env["pms.reservation"].create( r1 = self.env["pms.reservation"].create(
@@ -406,6 +449,7 @@ class TestPmsReservations(TestHotel):
r1.reservation_line_ids[1].room_id = self.room1 r1.reservation_line_ids[1].room_id = self.room1
r1.flush() r1.flush()
# ACT & ASSERT
with self.assertRaises(ValidationError): with self.assertRaises(ValidationError):
r_test = self.env["pms.reservation"].create( r_test = self.env["pms.reservation"].create(
{ {
@@ -421,6 +465,7 @@ class TestPmsReservations(TestHotel):
@freeze_time("1980-11-01") @freeze_time("1980-11-01")
def test_split_reservation07(self): def test_split_reservation07(self):
""" """
# TEST CASE
There's no availability There's no availability
+------------+------+------+------+----+----+----+ +------------+------+------+------+----+----+----+
| room/date | 01 | 02 | 03 | 04 | 05 | 06 | | room/date | 01 | 02 | 03 | 04 | 05 | 06 |
@@ -430,7 +475,7 @@ class TestPmsReservations(TestHotel):
| Double 103 | r3 | r3 | r3 | | | | | Double 103 | r3 | r3 | r3 | | | |
+------------+------+------+------+----+----+----+ +------------+------+------+------+----+----+----+
""" """
# ARRANGE
self.create_common_scenario() self.create_common_scenario()
r1 = self.env["pms.reservation"].create( r1 = self.env["pms.reservation"].create(
@@ -475,8 +520,9 @@ class TestPmsReservations(TestHotel):
r3.reservation_line_ids[2].room_id = self.room3 r3.reservation_line_ids[2].room_id = self.room3
r3.flush() r3.flush()
# ACT & ASSERT
with self.assertRaises(ValidationError): with self.assertRaises(ValidationError):
r_test = self.env["pms.reservation"].create( self.env["pms.reservation"].create(
{ {
"pms_property_id": self.property.id, "pms_property_id": self.property.id,
"checkin": datetime.datetime.now(), "checkin": datetime.datetime.now(),
@@ -485,17 +531,16 @@ class TestPmsReservations(TestHotel):
"room_type_id": self.room_type_double.id, "room_type_id": self.room_type_double.id,
} }
) )
r_test.flush()
def test_manage_children_raise(self): def test_manage_children_raise(self):
# TEST CASE
# ARRANGE # reservation with 2 adults and 1 children occupyin
PmsReservation = self.env["pms.reservation"] # shouldn be higher than room capacity
# the capacity for xid pms.pms_room_type_0 is 2 in demo data
# NO ARRANGE
# ACT & ASSERT # ACT & ASSERT
with self.assertRaises(ValidationError), self.cr.savepoint(): with self.assertRaises(ValidationError), self.cr.savepoint():
self.env["pms.reservation"].create(
PmsReservation.create(
{ {
"adults": 2, "adults": 2,
"children_occupying": 1, "children_occupying": 1,