Skip to content

Commit 92eefca

Browse files
committed
[IMP] estate: adding tests
1 parent 7ba0a24 commit 92eefca

4 files changed

Lines changed: 132 additions & 0 deletions

File tree

estate/tests/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from . import common
2+
from . import test_estate_property
3+
from . import test_estate_property_offer

estate/tests/common.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import datetime
2+
3+
from odoo.addons.base.tests.common import BaseCommon
4+
5+
6+
class EstateTestCommon(BaseCommon):
7+
@classmethod
8+
def setUpClass(cls):
9+
super().setUpClass()
10+
11+
cls.partner_a = cls.env['res.partner'].create({
12+
'name': 'Test Partner A',
13+
})
14+
15+
cls.property_type_house = cls.env['estate.property.type'].create({
16+
'name': 'House',
17+
})
18+
cls.property_type_apartment = cls.env['estate.property.type'].create({
19+
'name': 'Apartment',
20+
})
21+
22+
def create_property(self, state, **kwargs):
23+
vals = {
24+
'name': 'Property ' + str(datetime.datetime.now()),
25+
'postcode': '12345',
26+
'date_availability': datetime.datetime.now() + datetime.timedelta(days=7),
27+
'expected_price': 100000,
28+
'bedrooms': 2,
29+
'living_area': 120,
30+
'facades': 2,
31+
'property_type_id': self.property_type_house.id,
32+
'state': 'new'
33+
}
34+
35+
vals.update(kwargs)
36+
37+
estate_property = self.env['estate.property'].create(vals)
38+
39+
if state in {'offer_received', 'offer_accepted', 'sold', 'canceled'}:
40+
offer_a = self.create_offer(estate_property, 5000, partner_id=self.partner.id, validity=7)
41+
offer_b = self.create_offer(estate_property, 10000, partner_id=self.partner_a.id, validity=14)
42+
43+
if state in {'offer_accepted', 'sold'}:
44+
offer_a.action_mark_as_refused()
45+
offer_b.action_mark_as_accepted()
46+
47+
if state == 'sold':
48+
estate_property.action_mark_as_sold()
49+
elif state == 'canceled':
50+
estate_property.action_mark_as_canceled()
51+
52+
return estate_property
53+
54+
def create_offer(self, estate_property, price_increase=0, **kwargs):
55+
vals = {
56+
'price': estate_property.expected_price + price_increase,
57+
'partner_id': self.partner.id,
58+
'property_id': estate_property.id,
59+
'validity': 7,
60+
}
61+
62+
vals.update(kwargs)
63+
64+
return self.env['estate.property.offer'].create(vals)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from odoo.addons.estate.tests.common import EstateTestCommon
2+
from odoo.exceptions import UserError
3+
from odoo.tests import tagged, Form
4+
5+
6+
@tagged('post_install', '-at_install')
7+
class EstatePropertyTestCase(EstateTestCommon):
8+
def test_sell_property_with_no_offers(self):
9+
estate_property = self.create_property('offer_received')
10+
11+
with self.assertRaises(UserError):
12+
estate_property.action_mark_as_sold()
13+
14+
def test_sell_property_on_state_new(self):
15+
estate_property = self.create_property('new')
16+
17+
with self.assertRaises(UserError):
18+
estate_property.action_mark_as_sold()
19+
20+
def test_garden_reactivity(self):
21+
estate_property = self.create_property('new')
22+
23+
with Form(estate_property) as form_estate_property:
24+
form_estate_property.garden = True
25+
form_estate_property.save()
26+
self.assertEqual(estate_property.garden_area, 10)
27+
self.assertEqual(estate_property.garden_orientation, 'north')
28+
29+
form_estate_property.garden = False
30+
form_estate_property.save()
31+
self.assertEqual(estate_property.garden_area, 0)
32+
self.assertEqual(estate_property.garden_orientation, False)
33+
34+
form_estate_property.garden = True
35+
form_estate_property.garden_area = 100
36+
form_estate_property.garden_orientation = 'south'
37+
form_estate_property.save()
38+
self.assertEqual(estate_property.garden_area, 100)
39+
self.assertEqual(estate_property.garden_orientation, 'south')
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from odoo.addons.estate.tests.common import EstateTestCommon
2+
from odoo.exceptions import UserError
3+
from odoo.tests import tagged
4+
5+
6+
@tagged('post_install', '-at_install')
7+
class EstatePropertyOfferTestCase(EstateTestCommon):
8+
def test_stop_offer_creation_on_sold_property(self):
9+
estate_property = self.create_property('sold')
10+
11+
with self.assertRaises(UserError):
12+
self.create_offer(estate_property, 50000)
13+
14+
def test_offer_price_too_low_compared_to_other_offers(self):
15+
estate_property = self.create_property('offer_received')
16+
17+
with self.assertRaises(UserError):
18+
self.create_offer(estate_property, 0)
19+
20+
def test_offer_price_too_low_compared_to_expected_price(self):
21+
estate_property = self.create_property('new')
22+
offer = self.create_offer(estate_property, -estate_property.expected_price / 2)
23+
24+
with self.assertRaises(UserError):
25+
offer.action_mark_as_accepted()
26+
estate_property.action_mark_as_sold()

0 commit comments

Comments
 (0)