Skip to content

Commit 4eeab76

Browse files
committed
add test cases
1 parent 80d16ae commit 4eeab76

File tree

6 files changed

+135
-0
lines changed

6 files changed

+135
-0
lines changed

spp_oauth/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_rsa_encode_decode
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from unittest.mock import patch
2+
3+
from odoo.tests.common import TransactionCase
4+
5+
from ..tools.rsa_encode_decode import calculate_signature, verify_and_decode_signature
6+
7+
8+
class TestRSA(TransactionCase):
9+
@patch("odoo.addons.spp_oauth.tools.rsa_encode_decode.jwt.encode")
10+
def test_calculate_signature(self, mock_encode):
11+
mock_encode.return_value = "mocked_signature"
12+
13+
header = {"typ": "JWT"}
14+
payload = {"data": "test"}
15+
signature = calculate_signature(header, payload)
16+
17+
self.assertEqual(signature, "mocked_signature")
18+
mock_encode.assert_called_once_with(headers=header, payload=payload, key="", algorithm="RS256")
19+
20+
@patch("odoo.addons.spp_oauth.tools.rsa_encode_decode.jwt.decode")
21+
def test_verify_and_decode_signature(self, mock_decode):
22+
mock_decode.return_value = {"data": "test"}
23+
24+
access_token = "mocked_access_token"
25+
26+
success, decoded = verify_and_decode_signature(access_token)
27+
28+
self.assertTrue(success)
29+
self.assertEqual(decoded, {"data": "test"})
30+
mock_decode.assert_called_once_with(access_token, key="", algorithms=["RS256"])

spp_pmt/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_pmt

spp_pmt/tests/test_pmt.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
from unittest.mock import MagicMock, patch
2+
3+
from odoo import fields
4+
from odoo.tests.common import TransactionCase
5+
6+
7+
class PMTTest(TransactionCase):
8+
@classmethod
9+
def setUpClass(cls):
10+
super().setUpClass()
11+
cls.area_1 = cls.env["spp.area"].create(
12+
{
13+
"draft_name": "Area 1",
14+
}
15+
)
16+
cls.registrant_1 = cls.env["res.partner"].create(
17+
{
18+
"family_name": "Butay",
19+
"given_name": "Red",
20+
"name": "Red Butay",
21+
"is_group": False,
22+
"is_registrant": True,
23+
"area_id": cls.area_1.id,
24+
}
25+
)
26+
cls.group_1 = cls.env["res.partner"].create(
27+
{
28+
"name": "Group 1",
29+
"is_group": True,
30+
"is_registrant": True,
31+
"area_id": cls.area_1.id,
32+
}
33+
)
34+
cls.group_membership_1 = cls.env["g2p.group.membership"].create(
35+
{
36+
"group": cls.group_1.id,
37+
"individual": cls.registrant_1.id,
38+
"start_date": fields.Datetime.now(),
39+
}
40+
)
41+
42+
def test_compute_area(self):
43+
self.registrant_1._compute_area()
44+
self.assertFalse(self.registrant_1.area_calc.id)
45+
46+
self.group_1._compute_area()
47+
self.assertEqual(self.group_1.area_calc.id, self.area_1.id)
48+
49+
def test_compute_score(self):
50+
self.group_1.compute_score("z_ind_grp_pmt_score")
51+
self.assertEqual(self.group_1.z_ind_grp_pmt_score, 0)
52+
53+
@patch("odoo.addons.base.models.ir_model.IrModelFields.search")
54+
def test_compute_score_with_weight(self, mock_search):
55+
area_id = self.env["spp.fields.area"].create(
56+
{
57+
"name": self.area_1.id,
58+
"weight": 1.0,
59+
}
60+
)
61+
self.registrant_1.z_ind_grp_num_individuals = 1
62+
63+
mock_fields = MagicMock()
64+
mock_fields.name = "z_ind_grp_num_individuals"
65+
mock_fields.with_weight = True
66+
mock_fields.target_type = "indv"
67+
mock_fields.area_ids = area_id
68+
mock_search.return_value = [mock_fields]
69+
70+
self.group_1.compute_score("z_ind_grp_pmt_score")
71+
self.assertEqual(self.group_1.z_ind_grp_pmt_score, 1)

spp_user_roles/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_res_partner
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from unittest.mock import MagicMock, patch
2+
3+
from odoo.tests.common import TransactionCase
4+
5+
6+
class ResPartnerTest(TransactionCase):
7+
@classmethod
8+
def setUpClass(cls):
9+
super().setUpClass()
10+
cls.center_area_1 = cls.env["spp.area"].create({"draft_name": "Center Area 1"})
11+
cls.center_area_2 = cls.env["spp.area"].create({"draft_name": "Center Area 1"})
12+
cls.partner_1 = cls.env["res.partner"].create({"name": "Partner 1", "area_id": cls.center_area_1.id})
13+
cls.partner_2 = cls.env["res.partner"].create({"name": "Partner 2", "area_id": cls.center_area_2.id})
14+
15+
def test_search_read(self):
16+
result = self.env["res.partner"].search_read(domain=[], fields=["id", "name", "area_id"])
17+
self.assertEqual(len(result), self.env["res.partner"].search_count([]))
18+
19+
center_area_ids_mock = MagicMock()
20+
center_area_ids_mock.ids = self.center_area_1.ids
21+
22+
with patch(
23+
"odoo.addons.spp_user_roles.models.user.ResUsersCustomSPP.center_area_ids", new=center_area_ids_mock
24+
):
25+
result = self.env["res.partner"].search_read(domain=[], fields=["id", "name", "area_id"])
26+
27+
self.assertEqual(len(result), 1)
28+
self.assertEqual(
29+
result,
30+
[{"id": self.partner_1.id, "name": "Partner 1", "area_id": (self.center_area_1.id, "Center Area 1")}],
31+
)

0 commit comments

Comments
 (0)