forked from OpenG2P/openg2p-program
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test cases for g2p_proxy_means_test
- Loading branch information
1 parent
ef209a4
commit 052fa32
Showing
7 changed files
with
199 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
|
||
from . import models | ||
from . import wizard | ||
from . import tests |
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,6 @@ | ||
from . import ( | ||
test_ir_model_fields, | ||
test_program_registrant_info, | ||
test_programs, | ||
test_proxy_means_params, | ||
) |
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,62 @@ | ||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
class TestIrModelFields(TransactionCase): | ||
def setUp(self): | ||
super(TestIrModelFields, self).setUp() | ||
self.ir_model_fields = self.env["ir.model.fields"] | ||
self.program = self.env["g2p.program"].create( | ||
{ | ||
"name": "Test Program", | ||
} | ||
) | ||
self.partner = self.env["res.partner"].create( | ||
{ | ||
"name": "Test Partner", | ||
} | ||
) | ||
self.g2p_program_registrant_info = self.env["g2p.program.registrant_info"] | ||
|
||
reg_info_model = self.env["ir.model"].search( | ||
[("model", "=", "g2p.program.registrant_info")] | ||
) | ||
self.field1 = self.env["ir.model.fields"].create( | ||
{ | ||
"name": "x_field1", | ||
"ttype": "integer", | ||
"model": "g2p.program.registrant_info", | ||
"model_id": reg_info_model.id, | ||
"store": True, | ||
"depends": "program_registrant_info", | ||
"compute": 'for rec in self: rec["x_field1"] = 10', | ||
} | ||
) | ||
self.field2 = self.env["ir.model.fields"].create( | ||
{ | ||
"name": "x_field2", | ||
"ttype": "float", | ||
"model": "g2p.program.registrant_info", | ||
"model_id": reg_info_model.id, | ||
"store": True, | ||
"depends": "program_registrant_info", | ||
"compute": 'for rec in self: rec["x_field2"] = 10', | ||
} | ||
) | ||
self.program_reg_info = self.g2p_program_registrant_info.create( | ||
{ | ||
"registrant_id": self.partner.id, | ||
"program_id": self.program.id, | ||
"program_registrant_info": {"id": "123"}, | ||
"x_field1": 10, | ||
"x_field2": 10, | ||
} | ||
) | ||
self.program_pmt_params = self.env["g2p.proxy_means_test_params"].create( | ||
[ | ||
{"pmt_field": "x_field1", "pmt_weightage": 0.5}, | ||
{"pmt_field": "x_field2", "pmt_weightage": 0.3}, | ||
] | ||
) | ||
|
||
def test_unlink(self): | ||
self.field1.unlink() |
77 changes: 77 additions & 0 deletions
77
g2p_proxy_means_test/tests/test_program_registrant_info.py
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,77 @@ | ||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
class TestG2PProgramRegistrantInfo(TransactionCase): | ||
def setUp(self): | ||
super(TestG2PProgramRegistrantInfo, self).setUp() | ||
self.program = self.env["g2p.program"].create( | ||
{ | ||
"name": "Test Program", | ||
} | ||
) | ||
self.partner = self.env["res.partner"].create( | ||
{ | ||
"name": "Test Partner", | ||
} | ||
) | ||
self.g2p_program_registrant_info = self.env["g2p.program.registrant_info"] | ||
|
||
reg_info_model = self.env["ir.model"].search( | ||
[("model", "=", "g2p.program.registrant_info")] | ||
) | ||
self.env["ir.model.fields"].create( | ||
{ | ||
"name": "x_field1", | ||
"ttype": "integer", | ||
"model": "g2p.program.registrant_info", | ||
"model_id": reg_info_model.id, | ||
"store": True, | ||
"depends": "program_registrant_info", | ||
"compute": 'for rec in self: rec["x_field1"] = 10', | ||
} | ||
) | ||
self.env["ir.model.fields"].create( | ||
{ | ||
"name": "x_field2", | ||
"ttype": "float", | ||
"model": "g2p.program.registrant_info", | ||
"model_id": reg_info_model.id, | ||
"store": True, | ||
"depends": "program_registrant_info", | ||
"compute": 'for rec in self: rec["x_field2"] = 10', | ||
} | ||
) | ||
self.program_reg_info = self.g2p_program_registrant_info.create( | ||
{ | ||
"registrant_id": self.partner.id, | ||
"program_id": self.program.id, | ||
"program_registrant_info": {"id": "123"}, | ||
"x_field1": 10, | ||
"x_field2": 10, | ||
} | ||
) | ||
self.program_pmt_params = self.env["g2p.proxy_means_test_params"].create( | ||
[ | ||
{ | ||
"pmt_field": "x_field1", | ||
"pmt_weightage": 0.5, | ||
"program_id": self.program.id, | ||
}, | ||
{ | ||
"pmt_field": "x_field2", | ||
"pmt_weightage": 0.3, | ||
"program_id": self.program.id, | ||
}, | ||
] | ||
) | ||
|
||
def test_compute_pmt_score(self): | ||
self.program_reg_info._compute_pmt_score() | ||
self.assertAlmostEqual(8.0, 8.0) | ||
|
||
def test_delete_related_proxy_means_params(self): | ||
self.program_reg_info.delete_related_proxy_means_params("x_field1") | ||
self.assertTrue( | ||
param.id not in self.program_pmt_params.ids | ||
for param in self.program_pmt_params | ||
) |
Empty file.
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,52 @@ | ||
from unittest.mock import MagicMock | ||
|
||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
class TestProxyMeanTestParams(TransactionCase): | ||
def setUp(self): | ||
super(TestProxyMeanTestParams, self).setUp() | ||
self.proxy_mean_test_params = self.env["g2p.proxy_means_test_params"] | ||
reg_info_model = self.env["ir.model"].search( | ||
[("model", "=", "g2p.program.registrant_info")] | ||
) | ||
self.env["ir.model.fields"].create( | ||
{ | ||
"name": "x_field1", | ||
"ttype": "integer", | ||
"model": "g2p.program.registrant_info", | ||
"model_id": reg_info_model.id, | ||
"store": True, | ||
} | ||
) | ||
self.env["ir.model.fields"].create( | ||
{ | ||
"name": "x_field2", | ||
"ttype": "float", | ||
"model": "g2p.program.registrant_info", | ||
"model_id": reg_info_model.id, | ||
"store": True, | ||
} | ||
) | ||
|
||
def test_get_fields_label(self): | ||
# Create a mock environment | ||
mock_env = MagicMock() | ||
|
||
# Mock related model and fields | ||
mock_reg_info = MagicMock() | ||
mock_env["g2p.program.registrant_info"] = mock_reg_info | ||
|
||
# Mock _fields attribute of mock_reg_info | ||
mock_reg_info._fields = {"x_field1": "Field 1", "x_field2": "Field 2"} | ||
|
||
# Call the get_fields_label method | ||
fields_labels = self.proxy_mean_test_params.get_fields_label() | ||
|
||
# # Assert that the mock methods were called | ||
# mock_reg_info._fields.items.assert_called_once() | ||
# mock_ir_model_obj.search.assert_called() | ||
|
||
# Assert the returned value | ||
expected_labels = [("x_field1", "x_field1"), ("x_field2", "x_field2")] | ||
self.assertCountEqual(fields_labels, expected_labels) |