-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] estate: Tutorial - unit tests, with the exception of the form-r…
…elated one
- Loading branch information
Showing
5 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import test_estate_property | ||
from . import test_estate_property_offer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from odoo.tests.common import TransactionCase | ||
from odoo.exceptions import UserError | ||
from odoo.tests import tagged | ||
|
||
@tagged('post_install', '-at_install') | ||
class EstatePropertyTestCase(TransactionCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
super(EstatePropertyTestCase, cls).setUpClass() | ||
cls.property = cls.env['estate.property'].create({ | ||
'name': 'Test', | ||
'expected_price': '1', | ||
}) | ||
|
||
def test_sell_no_offers(self): | ||
"""Test that a property cannot be sold when there are no accepted offers: no offers at all.""" | ||
self.property.offer_ids = [] | ||
with self.assertRaises(UserError): | ||
self.property.action_set_sold() | ||
|
||
def test_sell_no_accepted_offers(self): | ||
"""Test that a property cannot be sold when there are no accepted offers: some unaccepted offers are present.""" | ||
offers = [ | ||
self.env['estate.property.offer'].create({ | ||
'property_id': self.property.id, | ||
'partner_id': 1, # Trying to avoid having to create a new (irrelevant) res.partner record, appears to work | ||
'price': 1, | ||
}), | ||
self.env['estate.property.offer'].create({ | ||
'property_id': self.property.id, | ||
'partner_id': 1, | ||
'price': 1, | ||
'state': 'refused' | ||
}), | ||
] | ||
self.property.offer_ids = [offer.id for offer in offers] | ||
with self.assertRaises(UserError): | ||
self.property.action_set_sold() | ||
|
||
def test_sell_sets_sold(self): | ||
"""Test that selling a property sets it to 'Sold'.""" | ||
offers = [ | ||
self.env['estate.property.offer'].create({ | ||
'property_id': self.property.id, | ||
'partner_id': 1, | ||
'price': 1, | ||
}), | ||
] | ||
self.property.offer_ids = [offer.id for offer in offers] | ||
offers[0].action_accept() | ||
self.property.action_set_sold() | ||
self.assertEqual(self.property.state, 'sold') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from odoo.tests.common import TransactionCase | ||
from odoo.exceptions import UserError | ||
from odoo.tests import tagged | ||
|
||
@tagged('post_install', '-at_install') | ||
class EstatePropertyOfferTestCase(TransactionCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
super(EstatePropertyOfferTestCase, cls).setUpClass() | ||
cls.property = cls.env['estate.property'].create({ | ||
'name': 'Test', | ||
'expected_price': '1', | ||
}) | ||
|
||
def test_create_offer_for_cancelled(self): | ||
"""Test that an offer cannot be created for a cancelled property.""" | ||
self.property.state = 'cancelled' | ||
with self.assertRaises(UserError): | ||
self.env['estate.property.offer'].create({ | ||
'property_id': self.property.id, | ||
'partner_id': 1, | ||
'price': 1, | ||
}) | ||
|
||
def test_create_offer_for_sold(self): | ||
"""Test that an offer cannot be created for a sold property.""" | ||
self.property.state = 'sold' | ||
with self.assertRaises(UserError): | ||
self.env['estate.property.offer'].create({ | ||
'property_id': self.property.id, | ||
'partner_id': 1, | ||
'price': 1, | ||
}) |