-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_area.py
More file actions
76 lines (62 loc) · 2.38 KB
/
test_area.py
File metadata and controls
76 lines (62 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Part of OpenSPP. See LICENSE file for full copyright and licensing details.
import logging
from odoo.tests.common import TransactionCase
_logger = logging.getLogger(__name__)
class BaseAreaTest(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# Set context to avoid job queue delay for faster tests
# Note: job_worker module uses 'queue_job__no_delay' (double underscore)
cls.env = cls.env(
context=dict(
cls.env.context,
queue_job__no_delay=True,
)
)
# Initial Setup of Variables
cls.area_1 = cls.env["spp.area"].create(
{
"draft_name": "Testing Area",
}
)
cls.area_1_child = cls.env["spp.area"].create(
{
"draft_name": "Testing Area Child",
"parent_id": cls.area_1.id,
}
)
def test_01_check_childs(self):
"""Test that parent area correctly computes child areas"""
self.area_1._compute_get_childs()
self.assertEqual(len(self.area_1.child_ids), 1)
def test_02_check_area_creation(self):
"""Test basic area creation"""
area = self.env["spp.area"].create(
{
"draft_name": "Test Area 2",
}
)
self.assertTrue(area)
self.assertEqual(area.draft_name, "Test Area 2")
def test_03_check_parent_child_relationship(self):
"""Test parent-child relationship in areas"""
# Check parent has child
self.assertIn(self.area_1_child, self.area_1.child_ids)
# Check child has parent
self.assertEqual(self.area_1_child.parent_id, self.area_1)
def test_04_create_multi_level_hierarchy(self):
"""Test creating multiple levels of area hierarchy"""
# Create level 2 child
area_grandchild = self.env["spp.area"].create(
{
"draft_name": "Testing Area Grandchild",
"parent_id": self.area_1_child.id,
}
)
# Verify hierarchy
self.assertEqual(area_grandchild.parent_id, self.area_1_child)
self.assertEqual(area_grandchild.parent_id.parent_id, self.area_1)
# Check parent has grandchild in descendants
self.area_1._compute_get_childs()
self.assertIn(self.area_1_child, self.area_1.child_ids)