Skip to content

Commit

Permalink
improve test cov
Browse files Browse the repository at this point in the history
  • Loading branch information
RPSJR committed Oct 28, 2024
1 parent 3566423 commit 52be3e0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def setUpClass(cls):

cls.item_02 = cls.inspection_item.create({"name": "Mirrors"})

cls.inspection_template = cls.inspection_template.create(
cls.inspection_template_01 = cls.inspection_template.create(
{
"name": "TemplateTest",
"name": "TemplateTest_01",
"inspection_template_line_ids": [
(
0,
Expand All @@ -35,15 +35,69 @@ def setUpClass(cls):
}
)

cls.inspection_template_02 = cls.inspection_template.create(
{
"name": "TemplateTest_02",
"inspection_template_line_ids": [
(
0,
0,
{
"inspection_template_item_id": cls.item_01.id,
"sequence": 11, # Different sequence in the template line
},
),
(
0,
0,
{
"inspection_template_item_id": cls.item_02.id,
"sequence": 10, # Different sequence in the template line
},
),
],
}
)

cls.inspection = cls.inspection.create(
{
"vehicle_id": cls.vehicle,
"inspection_template_id": cls.inspection_template.id,
"inspection_template_id": cls.inspection_template_01.id,
}
)

def test_fleet_vehicle_inspection(self):
# --- Test with an inspection template ---
self.inspection._onchange_inspection_template_id()

self.assertEqual(self.inspection.name, self.inspection_template_01.name)
self.assertTrue(self.inspection.inspection_line_ids)

# --- Change the template ID ---
self.inspection.inspection_template_id = self.inspection_template_02

# Trigger the onchange method again
self.inspection._onchange_inspection_template_id()
self.assertEqual(self.inspection.name, self.inspection_template.name)

self.assertEqual(len(self.inspection.inspection_line_ids), 2)

# Check if the sequence is correctly copied from the template line
line_1 = self.inspection.inspection_line_ids.filtered(
lambda linei: linei.inspection_item_id == self.item_01
)
self.assertEqual(line_1.sequence, 11)

# --- Test without an inspection template ---
self.inspection.inspection_template_id = False # Remove the template

# Trigger the onchange method again
self.inspection._onchange_inspection_template_id()

# Assert that the name and note are not changed
self.assertEqual(self.inspection.name, self.inspection_template_02.name)
# (remains the same as the previous template)
self.assertNotEqual(self.inspection.name, self.inspection_template_01.name)

# Assert that the inspection lines are NOT removed
self.assertTrue(self.inspection.inspection_line_ids)
self.assertEqual(len(self.inspection.inspection_line_ids), 2)

0 comments on commit 52be3e0

Please sign in to comment.