Skip to content

Commit

Permalink
Added test cases for g2p_proxy_means_test
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek-Wagh committed Mar 21, 2024
1 parent ef209a4 commit 052fa32
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 1 deletion.
2 changes: 1 addition & 1 deletion g2p_payment_interop_layer/tests/test_payment_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def test_get_dfsp_id_and_type(self):
)
partner.update({"bank_ids": [(4, bank_account.id)]})

id_type = self.env["g2p.id.type"].create({"name": "ACCOUNT_ID"})
self.env["g2p.id.type"].create({"name": "ACCOUNT_ID"})

payee_id_type, payee_id_value = payment_manager._get_dfsp_id_and_type(payment)
self.assertEqual(payee_id_type, "ACCOUNT_ID")
Expand Down
1 change: 1 addition & 0 deletions g2p_proxy_means_test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

from . import models
from . import wizard
from . import tests
6 changes: 6 additions & 0 deletions g2p_proxy_means_test/tests/__init__.py
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,
)
62 changes: 62 additions & 0 deletions g2p_proxy_means_test/tests/test_ir_model_fields.py
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 g2p_proxy_means_test/tests/test_program_registrant_info.py
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.
52 changes: 52 additions & 0 deletions g2p_proxy_means_test/tests/test_proxy_means_params.py
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)

0 comments on commit 052fa32

Please sign in to comment.