[REF] pms: refactor room type tests

This commit is contained in:
miguelpadin
2021-06-15 02:34:49 +02:00
parent 8c50359f96
commit 0afeba30c8
2 changed files with 214 additions and 177 deletions

View File

@@ -2,66 +2,6 @@ from .common import TestPms
class TestPmsBoardServiceRoomType(TestPms):
# def _create_common_scenario(self):
# self.company1 = self.env["res.company"].create(
# {
# "name": "Pms_Company_Test",
# }
# )
# self.folio_sequence = self.env["ir.sequence"].create(
# {
# "name": "PMS Folio",
# "code": "pms.folio",
# "padding": 4,
# "company_id": self.company1.id,
# }
# )
# self.reservation_sequence = self.env["ir.sequence"].create(
# {
# "name": "PMS Reservation",
# "code": "pms.reservation",
# "padding": 4,
# "company_id": self.company1.id,
# }
# )
# self.checkin_sequence = self.env["ir.sequence"].create(
# {
# "name": "PMS Checkin",
# "code": "pms.checkin.partner",
# "padding": 4,
# "company_id": self.company1.id,
# }
# )
# self.property1 = self.env["pms.property"].create(
# {
# "name": "Pms_property_test1",
# "company_id": self.company1.id,
# "default_pricelist_id": self.env.ref("product.list0").id,
# "folio_sequence_id": self.folio_sequence.id,
# "reservation_sequence_id": self.reservation_sequence.id,
# "checkin_sequence_id": self.checkin_sequence.id,
# }
# )
# self.property2 = self.env["pms.property"].create(
# {
# "name": "Pms_property_test2",
# "company_id": self.company1.id,
# "default_pricelist_id": self.env.ref("product.list0").id,
# "folio_sequence_id": self.folio_sequence.id,
# "reservation_sequence_id": self.reservation_sequence.id,
# "checkin_sequence_id": self.checkin_sequence.id,
# }
# )
# self.room_type_availability = self.env["pms.availability.plan"].create(
# {"name": "Availability plan for TEST"}
# )
#
# # create room type class
# self.room_type_class = self.env["pms.room.type.class"].create(
# {"name": "Room", "default_code": "ROOM"}
# )
def test_create_rt_props_gt_bs_props(self):
"""
Create board service for a room type and the room type

View File

@@ -30,8 +30,11 @@ class TestRoomType(TestPms):
}
)
def test_internal_case_01(self):
def test_create_room_type_consistency_company(self):
"""
Create a room type with a company (1) consistent with the company property (1).
Creation should be successful.
PRE: - room_type1 does not exists
ACT: - create a new room_type1 room
- room_type1 has code c1
@@ -40,23 +43,25 @@ class TestRoomType(TestPms):
- room_type1 has company company1
POST: - room_type1 created
"""
# ARRANGE & ACT & ASSERT
try:
# room_type1
self.env["pms.room.type"].create(
{
"name": "Room type 1",
"default_code": "c1",
"pms_property_ids": [(6, 0, [self.pms_property1.id])],
"company_id": self.company1.id,
"class_id": self.room_type_class1.id,
}
)
except ValidationError:
self.fail("Room type not created when it should")
# ARRANGE & ACT
new_room_type = self.env["pms.room.type"].create(
{
"name": "Room type 1",
"default_code": "c1",
"pms_property_ids": [(6, 0, [self.pms_property1.id])],
"company_id": self.company1.id,
"class_id": self.room_type_class1.id,
}
)
# ASSERT
self.assertTrue(new_room_type.id, "Room type not created when it should")
def test_internal_case_02(self):
def test_create_room_type_inconsistency_company(self):
"""
Create a room type with inconsistency between company (1)
and company property (1).
The creation should fail.
PRE: - room_type1 does not exists
ACT: - create a new room_type1 room
- room_type1 has code c1
@@ -81,8 +86,12 @@ class TestRoomType(TestPms):
}
)
def test_internal_case_03(self):
def test_create_room_type_inconsistency_companies(self):
"""
Create a room type with inconsistency between company (1)
and company properties (several).
The creation should fail.
PRE: - room_type1 does not exists
ACT: - create a new room_type1 room
- room_type1 has code c1
@@ -110,10 +119,14 @@ class TestRoomType(TestPms):
}
)
def test_internal_case_04(self):
def test_create_room_type_consistency_companies(self):
"""
Create a room type with consistency between companies (all)
and company properties (2).
Creation should be successful.
PRE: - room_type1 does not exists
ACT: - create a new room_type1 room
ACT: - create a new room_type1
- room_type1 has code c1
- room_type1 has property pms_property1 and pms_property3
- pms_property1 has company company1
@@ -121,26 +134,28 @@ class TestRoomType(TestPms):
- room_type1 has no company
POST: - room_type1 created
"""
# ARRANGE & ACT & ASSERT
try:
# room_type1
self.env["pms.room.type"].create(
{
"name": "Room type 1",
"default_code": "c1",
"pms_property_ids": [
(6, 0, [self.pms_property1.id, self.pms_property3.id])
],
"company_id": False,
"class_id": self.room_type_class1.id,
}
)
except ValidationError:
self.fail("Room type not created when it should")
# ARRANGE & ACT
new_room_type = self.env["pms.room.type"].create(
{
"name": "Room type 1",
"default_code": "c1",
"pms_property_ids": [
(6, 0, [self.pms_property1.id, self.pms_property3.id])
],
"company_id": False,
"class_id": self.room_type_class1.id,
}
)
# ASSERT
self.assertTrue(new_room_type.id, "Room type not created when it should")
# external integrity
def test_external_case_01(self):
def test_create_room_type_inconsistency_all_companies(self):
"""
Create a room type for 1 company and 1 property.
Try to create a room type for all the companies.
The creation should fail.
PRE: - room type room_type1 exists
- room_type1 has code c1
- room_type1 has property pms_property1
@@ -165,7 +180,6 @@ class TestRoomType(TestPms):
"class_id": self.room_type_class1.id,
}
)
# ACT & ASSERT
with self.assertRaises(
ValidationError, msg="The room type has been created and it shouldn't"
@@ -181,8 +195,13 @@ class TestRoomType(TestPms):
}
)
def test_external_case_02(self):
def test_create_room_type_inconsistency_code_company(self):
"""
Create a room type for all the companies and for one property.
Try to create a room type with same code and same property but
for all companies.
The creation should fail.
PRE: - room type room_type1 exists
- room_type1 has code c1
- room_type1 has property pms_property1
@@ -223,8 +242,13 @@ class TestRoomType(TestPms):
}
)
def test_external_case_03(self):
def test_create_room_type_inconsistency_code_companies(self):
"""
Create a room type for 1 property and 1 company.
Try to create a room type with same code and 3 propertys
belonging to 2 different companies.
The creation should fail.
PRE: - room type room_type1 exists
- room_type1 has code c1
- room_type1 has property pms_property1
@@ -250,7 +274,6 @@ class TestRoomType(TestPms):
"class_id": self.room_type_class1.id,
}
)
# ACT & ASSERT
with self.assertRaises(
ValidationError, msg="The room type has been created and it shouldn't"
@@ -276,8 +299,12 @@ class TestRoomType(TestPms):
}
)
def test_single_case_01(self):
def test_get_room_type_by_property_first(self):
"""
Room type exists for all the companies and 2 properties.
Search for property of existing room type.
The method should return the existing room type.
PRE: - room type room_type1 exists
- room_type1 has code c1
- room_type1 with 2 properties pms_property1 and pms_property2
@@ -299,50 +326,19 @@ class TestRoomType(TestPms):
"class_id": self.room_type_class1.id,
}
)
# ACT
room_types = self.env["pms.room.type"].get_room_types_by_property(
self.pms_property1.id, "c1"
)
# ASSERT
self.assertEqual(room_types.id, room_type1.id, "Expected room type not found")
def test_single_case_02(self):
def test_get_room_type_by_property_second(self):
"""
PRE: - room type room_type1 exists
- room_type1 has code c1
- room_type1 with 2 properties pms_property1 and pms_property3
- pms_property1 and pms_property2 have different companies
- pms_property1 have company company1 and pms_property3 have company2
- room_type1 has no company
ACT: - search room type with code c1 and property pms_property1
- pms_property1 has company company1
POST: - only room_type1 room type found
"""
# ARRANGE
room_type1 = self.env["pms.room.type"].create(
{
"name": "Room type 1",
"default_code": "c1",
"pms_property_ids": [
(6, 0, [self.pms_property1.id, self.pms_property3.id])
],
"company_id": False,
"class_id": self.room_type_class1.id,
}
)
Room type exists for all the companies and 2 properties.
Search for 2nd property of existing room type.
The method should return existing room type.
# ACT
room_types = self.env["pms.room.type"].get_room_types_by_property(
self.pms_property1.id, "c1"
)
# ASSERT
self.assertEqual(room_types.id, room_type1.id, "Expected room type not found")
def test_single_case_03(self):
"""
PRE: - room type room_type1 exists
- room_type1 has code c1
- room_type1 with 2 properties pms_property1 and pms_property2
@@ -374,8 +370,13 @@ class TestRoomType(TestPms):
# ASSERT
self.assertFalse(room_types, "Room type found but it should have not found any")
def test_single_case_04(self):
def test_get_room_type_by_property_existing_all_same_company(self):
"""
Room type exists for 1 company and for all properties.
Search for one specific property belonging to same company
as the existing room type.
The method should return existing room type.
PRE: - room type r1 exists
- room_type1 has code c1
- room_type1 properties are null
@@ -394,17 +395,19 @@ class TestRoomType(TestPms):
"class_id": self.room_type_class1.id,
}
)
# ACT
room_types = self.env["pms.room.type"].get_room_types_by_property(
self.pms_property1.id, "c1"
)
# ASSERT
self.assertEqual(room_types.id, room_type1.id, "Expected room type not found")
def test_single_case_05(self):
def test_get_room_type_by_property_existing_all_diff_company(self):
"""
Room type exists for 1 company and all the properties.
Search for property different than existing room type.
The method shouldn't return results.
PRE: - room type room_type1 exists
- room_type1 has code c1
- room_type1 properties are null
@@ -434,8 +437,13 @@ class TestRoomType(TestPms):
self.assertFalse(room_types, "Room type found but it should have not found any")
# tests with more than one room type
def test_multiple_case_01(self):
def test_get_room_type_by_property_existing_several_match_prop(self):
"""
Room type 1 exists for all companies and 2 properties.
Room type 2 exists for all companies and properties.
Search for same property as one of the 1st room type created.
The method should return the 1st room type created.
PRE: - room type room_type1 exists
- room_type1 has code c1
- room_type1 with 2 properties pms_property1 and pms_property2
@@ -480,8 +488,14 @@ class TestRoomType(TestPms):
# ASSERT
self.assertEqual(room_types.id, room_type1.id, "Expected room type not found")
def test_multiple_case_02(self):
def test_get_room_type_by_property_diff_company(self):
"""
Room type 1 exists for all companies and one property.
Room type 2 exists for all companies and properties.
Search for property different than the 1st room type created
and belonging to different company.
The method should return the 2nd room type created.
PRE: - room type r1 exists
- room_type1 has code c1
- room_type1 has property pms_property1
@@ -524,8 +538,14 @@ class TestRoomType(TestPms):
# ASSERT
self.assertEqual(room_types.id, room_type2.id, "Expected room type not found")
def test_multiple_case_03(self):
def test_get_room_type_by_property_same_company(self):
"""
Room type 1 exists for all companies and one property.
Room type 2 exists for all companies and properties.
Search for property different than the 1st room type created
and belonging to same company.
The method should return the 2nd room type created.
PRE: - room type room_type1 exists
- room_type1 has code c1
- room_type1 has property pms_property1
@@ -568,8 +588,14 @@ class TestRoomType(TestPms):
# ASSERT
self.assertEqual(room_types.id, room_type2.id, "Expected room type not found")
def test_multiple_case_04(self):
def test_get_room_type_by_property_same_company_prop_not_found(self):
"""
Room type 1 exists for all companies and one property.
Room type 2 exists for one company and for all properties.
Search for property different than the
1st room type created but belonging to same company.
The method shouldn't return results.
PRE: - room_type1 exists
- room_type1 has code c1
- room_type1 has property pms_property1
@@ -613,8 +639,14 @@ class TestRoomType(TestPms):
# ASSERT
self.assertFalse(room_types, "Room type found but it should have not found any")
def test_multiple_case_05(self):
def test_get_room_type_by_property_same_company_prop(self):
"""
Room type 1 exists for all companies and for one property.
Room type 2 exists for one company and for all properties.
Search for property belonging to the same company as
2nd room type created.
The method should return 2nd existing room type.
PRE: - room_type1 exists
- room_type1 has code c1
- room_type1 has property pms_property1
@@ -648,7 +680,6 @@ class TestRoomType(TestPms):
"class_id": self.room_type_class1.id,
}
)
# ACT
room_types = self.env["pms.room.type"].get_room_types_by_property(
self.pms_property3.id, "c1"
@@ -657,8 +688,15 @@ class TestRoomType(TestPms):
# ASSERT
self.assertEqual(room_types.id, room_type2.id, "Expected room type not found")
def test_multiple_case_06(self):
def test_get_room_type_by_property_diff_company_prop(self):
"""
Room type 1 exists for all companies and for one property.
Room type 2 exists for one company and for all properties.
Room type 3 exists for all companies and for all properties.
Search for property belonging to a different company than
the 2nd room type created.
The method should return 3rd room type.
PRE: - room type r1 exists
- room_type1 has code c1
- room_type1 has property pms_property1
@@ -715,7 +753,12 @@ class TestRoomType(TestPms):
# ASSERT
self.assertEqual(room_types.id, room_type3.id, "Expected room type not found")
def test_check_property_room_type_class(self):
def test_rooom_type_creation_inconsistency_class(self):
"""
Create a rooom type class belonging to one property.
Create a room type belonging to another property.
Room type creation should fail.
"""
# ARRANGE
room_type_class = self.env["pms.room.type.class"].create(
{
@@ -742,41 +785,72 @@ class TestRoomType(TestPms):
)
room_type1.pms_property_ids = [(4, self.pms_property1.id)]
# TODO: pending multi property PR
def test_rooom_type_creation_consistency_class(self):
"""
Create a rooom type class belonging to one property.
Create a room type belonging to same property.
Room type creation should be successful.
"""
# ARRANGE
room_type_class = self.env["pms.room.type.class"].create(
{
"name": "Room Type Class",
"default_code": "ROOM",
"pms_property_ids": [
(4, self.pms_property2.id),
],
},
)
# ACT
new_room_type = self.env["pms.room.type"].create(
{
"name": "Room Type",
"default_code": "c1",
"class_id": room_type_class.id,
"pms_property_ids": [
(4, self.pms_property2.id),
],
}
)
# ASSERT
self.assertTrue(new_room_type.id, "Room type creation should be successful.")
# def test_check_board_service_property_integrity(self):
#
# self.room_type_class = self.env["pms.room.type.class"].create(
# {"name": "Room Type Class", "default_code": "SIN1"}
# )
# self.room_type = self.env["pms.room.type"].create(
# {
# "name": "Room Type",
# "default_code": "Type1",
# "pms_property_ids": self.p3,
# "class_id": self.room_type_class.id,
# }
# )
# self.board_service = self.env["pms.board.service"].create(
# {
# "name": "Board Service",
# }
# )
# with self.assertRaises(ValidationError):
# self.env["pms.board.service.room.type"].create(
# {
# "pms_board_service_id": self.board_service.id,
# "pms_room_type_id": self.room_type.id,
# "pricelist_id": self.env.ref("product.list0").id,
# "pms_property_ids": self.p4,
# }
# )
def test_check_board_service_property_integrity(self):
# ARRANGE
room_type = self.env["pms.room.type"].create(
{
"name": "Room Type",
"default_code": "Type1",
"pms_property_ids": self.pms_property1,
"class_id": self.room_type_class1.id,
}
)
board_service = self.env["pms.board.service"].create(
{
"name": "Board service 1",
"default_code": "c1",
"pms_property_ids": self.pms_property1,
}
)
# ACT & ASSERT
with self.assertRaises(UserError, msg="Board service created and shouldn't."):
self.env["pms.board.service.room.type"].create(
{
"pms_board_service_id": board_service.id,
"pms_room_type_id": room_type.id,
"pms_property_ids": self.pms_property2,
}
)
def test_check_amenities_property_integrity(self):
self.amenity1 = self.env["pms.amenity"].create(
{"name": "Amenity", "pms_property_ids": self.pms_property1}
)
with self.assertRaises(UserError):
# ACT & ASSERT
with self.assertRaises(
UserError,
msg="Shouldn't create room type with amenities belonging to other properties",
):
self.env["pms.room.type"].create(
{
"name": "Room Type",
@@ -786,3 +860,26 @@ class TestRoomType(TestPms):
"room_amenity_ids": [self.amenity1.id],
}
)
def test_rooom_type_creation_consistency_amenity(self):
"""
Create an amenity belonging to one property.
Create a room type belonging to same property.
Room type creation should be successful.
"""
# ARRANGE
self.amenity1 = self.env["pms.amenity"].create(
{"name": "Amenity", "pms_property_ids": self.pms_property1}
)
# ACT
new_room_type = self.env["pms.room.type"].create(
{
"name": "Room Type",
"default_code": "Type1",
"class_id": self.room_type_class1.id,
"pms_property_ids": [self.pms_property1.id],
"room_amenity_ids": [self.amenity1.id],
}
)
# ASSERT
self.assertTrue(new_room_type.id, "Room type creation should be successful.")