mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[FIX] pms: fix tests (#24)
This commit is contained in:
@@ -68,7 +68,12 @@ class TestPmsReservations(TestHotel):
|
||||
)
|
||||
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()
|
||||
checkin = today + datetime.timedelta(days=8)
|
||||
checkout = checkin + datetime.timedelta(days=11)
|
||||
@@ -80,6 +85,8 @@ class TestPmsReservations(TestHotel):
|
||||
"partner_id": customer.id,
|
||||
"pms_property_id": self.main_hotel_property.id,
|
||||
}
|
||||
|
||||
# ACT
|
||||
reservation = self.env["pms.reservation"].create(reservation_vals)
|
||||
|
||||
self.assertEqual(
|
||||
@@ -87,6 +94,28 @@ class TestPmsReservations(TestHotel):
|
||||
checkin,
|
||||
"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(
|
||||
reservation.reservation_line_ids[-1].date,
|
||||
checkout - datetime.timedelta(1),
|
||||
@@ -96,6 +125,7 @@ class TestPmsReservations(TestHotel):
|
||||
@freeze_time("1980-11-01")
|
||||
def test_split_reservation01(self):
|
||||
"""
|
||||
# TEST CASE
|
||||
The reservation shouldn't be splitted
|
||||
preferred_room_id with availability provided
|
||||
+------------+------+------+------+----+----+----+
|
||||
@@ -106,9 +136,10 @@ class TestPmsReservations(TestHotel):
|
||||
| Double 103 | | | | | | |
|
||||
+------------+------+------+------+----+----+----+
|
||||
"""
|
||||
|
||||
# ARRANGE
|
||||
self.create_common_scenario()
|
||||
|
||||
# ACT
|
||||
r_test = self.env["pms.reservation"].create(
|
||||
{
|
||||
"pms_property_id": self.property.id,
|
||||
@@ -119,17 +150,20 @@ class TestPmsReservations(TestHotel):
|
||||
}
|
||||
)
|
||||
r_test.flush()
|
||||
obtained = all(
|
||||
elem.room_id.id == r_test.reservation_line_ids[0].room_id.id
|
||||
for elem in r_test.reservation_line_ids
|
||||
)
|
||||
|
||||
# ASSERT
|
||||
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")
|
||||
def test_split_reservation02(self):
|
||||
"""
|
||||
# TEST CASE
|
||||
The reservation shouldn't be splitted
|
||||
room_type_id with availability provided
|
||||
+------------+------+------+------+----+----+----+
|
||||
@@ -140,8 +174,10 @@ class TestPmsReservations(TestHotel):
|
||||
| Double 103 | | | | | | |
|
||||
+------------+------+------+------+----+----+----+
|
||||
"""
|
||||
# ARRANGE
|
||||
self.create_common_scenario()
|
||||
|
||||
# ACT
|
||||
r_test = self.env["pms.reservation"].create(
|
||||
{
|
||||
"pms_property_id": self.property.id,
|
||||
@@ -152,11 +188,14 @@ class TestPmsReservations(TestHotel):
|
||||
}
|
||||
)
|
||||
r_test.flush()
|
||||
|
||||
# ASSERT
|
||||
self.assertFalse(r_test.splitted, "The reservation shouldn't be splitted")
|
||||
|
||||
@freeze_time("1980-11-01")
|
||||
def test_split_reservation03(self):
|
||||
"""
|
||||
# TEST CASE
|
||||
The reservation should be splitted in 2 rooms
|
||||
(there is only one better option on day 02 and a draw the next day.
|
||||
The night before should be prioritized)
|
||||
@@ -168,7 +207,7 @@ class TestPmsReservations(TestHotel):
|
||||
| Double 103 | r2 | r4 | | | | |
|
||||
+------------+------+------+------+------+----+----+
|
||||
"""
|
||||
|
||||
# ARRANGE
|
||||
self.create_common_scenario()
|
||||
|
||||
r1 = self.env["pms.reservation"].create(
|
||||
@@ -218,7 +257,9 @@ class TestPmsReservations(TestHotel):
|
||||
)
|
||||
r4.reservation_line_ids[0].room_id = self.room3.id
|
||||
r4.flush()
|
||||
expected_num_changes = 2
|
||||
|
||||
# ACT
|
||||
r_test = self.env["pms.reservation"].create(
|
||||
{
|
||||
"pms_property_id": self.property.id,
|
||||
@@ -229,21 +270,18 @@ class TestPmsReservations(TestHotel):
|
||||
}
|
||||
)
|
||||
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(
|
||||
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")
|
||||
def test_split_reservation04(self):
|
||||
"""
|
||||
# TEST CASE
|
||||
The reservation should be splitted in 3 rooms
|
||||
(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 | | | | |
|
||||
+------------+------+------+------+------+----+----+
|
||||
"""
|
||||
|
||||
# ARRANGE
|
||||
self.create_common_scenario()
|
||||
|
||||
r1 = self.env["pms.reservation"].create(
|
||||
@@ -317,6 +355,7 @@ class TestPmsReservations(TestHotel):
|
||||
r5.reservation_line_ids[0].room_id = self.room2.id
|
||||
r5.flush()
|
||||
|
||||
# ACT
|
||||
r_test = self.env["pms.reservation"].create(
|
||||
{
|
||||
"pms_property_id": self.property.id,
|
||||
@@ -328,20 +367,22 @@ class TestPmsReservations(TestHotel):
|
||||
)
|
||||
r_test.flush()
|
||||
|
||||
changes = 0
|
||||
rooms = 0
|
||||
last_room = None
|
||||
for line in r_test.reservation_line_ids:
|
||||
if line.room_id != last_room:
|
||||
last_room = line.room_id
|
||||
changes += 1
|
||||
rooms += 1
|
||||
|
||||
# ASSERT
|
||||
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")
|
||||
def test_split_reservation05(self):
|
||||
"""
|
||||
# TEST CASE
|
||||
The preferred room_id is not available
|
||||
+------------+------+------+------+----+----+----+
|
||||
| room/date | 01 | 02 | 03 | 04 | 05 | 06 |
|
||||
@@ -351,7 +392,7 @@ class TestPmsReservations(TestHotel):
|
||||
| Double 103 | | | | | | |
|
||||
+------------+------+------+------+----+----+----+
|
||||
"""
|
||||
|
||||
# ARRANGE
|
||||
self.create_common_scenario()
|
||||
|
||||
r1 = self.env["pms.reservation"].create(
|
||||
@@ -366,6 +407,7 @@ class TestPmsReservations(TestHotel):
|
||||
r1.reservation_line_ids[0].room_id = self.room1
|
||||
r1.flush()
|
||||
|
||||
# ACT & ASSERT
|
||||
with self.assertRaises(ValidationError):
|
||||
r_test = self.env["pms.reservation"].create(
|
||||
{
|
||||
@@ -381,6 +423,7 @@ class TestPmsReservations(TestHotel):
|
||||
@freeze_time("1980-11-01")
|
||||
def test_split_reservation06(self):
|
||||
"""
|
||||
# TEST CASE
|
||||
There's no availability in the preferred_room_id provided
|
||||
+------------+------+------+------+----+----+----+
|
||||
| room/date | 01 | 02 | 03 | 04 | 05 | 06 |
|
||||
@@ -390,7 +433,7 @@ class TestPmsReservations(TestHotel):
|
||||
| Double 103 | | | | | | |
|
||||
+------------+------+------+------+----+----+----+
|
||||
"""
|
||||
|
||||
# ARRANGE
|
||||
self.create_common_scenario()
|
||||
|
||||
r1 = self.env["pms.reservation"].create(
|
||||
@@ -406,6 +449,7 @@ class TestPmsReservations(TestHotel):
|
||||
r1.reservation_line_ids[1].room_id = self.room1
|
||||
r1.flush()
|
||||
|
||||
# ACT & ASSERT
|
||||
with self.assertRaises(ValidationError):
|
||||
r_test = self.env["pms.reservation"].create(
|
||||
{
|
||||
@@ -421,6 +465,7 @@ class TestPmsReservations(TestHotel):
|
||||
@freeze_time("1980-11-01")
|
||||
def test_split_reservation07(self):
|
||||
"""
|
||||
# TEST CASE
|
||||
There's no availability
|
||||
+------------+------+------+------+----+----+----+
|
||||
| room/date | 01 | 02 | 03 | 04 | 05 | 06 |
|
||||
@@ -430,7 +475,7 @@ class TestPmsReservations(TestHotel):
|
||||
| Double 103 | r3 | r3 | r3 | | | |
|
||||
+------------+------+------+------+----+----+----+
|
||||
"""
|
||||
|
||||
# ARRANGE
|
||||
self.create_common_scenario()
|
||||
|
||||
r1 = self.env["pms.reservation"].create(
|
||||
@@ -475,8 +520,9 @@ class TestPmsReservations(TestHotel):
|
||||
r3.reservation_line_ids[2].room_id = self.room3
|
||||
r3.flush()
|
||||
|
||||
# ACT & ASSERT
|
||||
with self.assertRaises(ValidationError):
|
||||
r_test = self.env["pms.reservation"].create(
|
||||
self.env["pms.reservation"].create(
|
||||
{
|
||||
"pms_property_id": self.property.id,
|
||||
"checkin": datetime.datetime.now(),
|
||||
@@ -485,17 +531,16 @@ class TestPmsReservations(TestHotel):
|
||||
"room_type_id": self.room_type_double.id,
|
||||
}
|
||||
)
|
||||
r_test.flush()
|
||||
|
||||
def test_manage_children_raise(self):
|
||||
|
||||
# ARRANGE
|
||||
PmsReservation = self.env["pms.reservation"]
|
||||
|
||||
# TEST CASE
|
||||
# reservation with 2 adults and 1 children occupyin
|
||||
# shouldn be higher than room capacity
|
||||
# the capacity for xid pms.pms_room_type_0 is 2 in demo data
|
||||
# NO ARRANGE
|
||||
# ACT & ASSERT
|
||||
with self.assertRaises(ValidationError), self.cr.savepoint():
|
||||
|
||||
PmsReservation.create(
|
||||
self.env["pms.reservation"].create(
|
||||
{
|
||||
"adults": 2,
|
||||
"children_occupying": 1,
|
||||
|
||||
Reference in New Issue
Block a user