Skip to content

Commit 212b4a9

Browse files
committed
add test cases for code coverage
1 parent 4eeab76 commit 212b4a9

File tree

8 files changed

+260
-1
lines changed

8 files changed

+260
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_api_client_credentials
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import uuid
2+
3+
from odoo.exceptions import UserError
4+
from odoo.tests.common import TransactionCase
5+
6+
7+
class ApiClientCredentialsTest(TransactionCase):
8+
@classmethod
9+
def setUpClass(cls):
10+
"""
11+
Setup and create necessary records for this test
12+
"""
13+
super().setUpClass()
14+
cls.gis_api_model = cls.env["spp.gis.api.client.credential"]
15+
16+
def test_generate_client_id(self):
17+
client_id = self.gis_api_model._generate_client_id()
18+
self.assertTrue(bool(uuid.UUID(client_id)))
19+
20+
def test_generate_client_secret(self):
21+
client_secret = self.gis_api_model._generate_client_secret()
22+
self.assertTrue(bool(uuid.UUID(client_secret)))
23+
24+
def test_generate_client_token(self):
25+
client_token = self.gis_api_model._generate_client_token()
26+
self.assertTrue(bool(uuid.UUID(client_token)))
27+
28+
def test_show_credentials(self):
29+
api_id = self.gis_api_model.create(
30+
{
31+
"name": "Test API Client",
32+
"auth_type": "bearer",
33+
}
34+
)
35+
36+
self.assertFalse(api_id.show_button_clicked)
37+
action = api_id.show_credentials()
38+
self.assertEqual(action["type"], "ir.actions.act_window")
39+
self.assertEqual(action["res_model"], "spp.gis.api.client.credential")
40+
self.assertEqual(
41+
action["views"][0][0], self.env.ref("spp_base_gis_rest.spp_gis_api_client_credential_view_credentials").id
42+
)
43+
self.assertEqual(action["target"], "new")
44+
self.assertEqual(action["res_id"], api_id.id)
45+
self.assertEqual(action["view_type"], "form")
46+
self.assertEqual(action["view_mode"], "form")
47+
self.assertTrue(api_id.show_button_clicked)
48+
49+
with self.assertRaisesRegex(UserError, "Client ID and Client Secret is already showed once."):
50+
api_id.show_credentials()
51+
52+
def test_export_data(self):
53+
api_id = self.gis_api_model.create(
54+
{
55+
"name": "Test API Client",
56+
"auth_type": "bearer",
57+
}
58+
)
59+
60+
with self.assertRaisesRegex(UserError, "Not allowed to export on this model."):
61+
api_id.export_data([])

spp_custom_fields_ui/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"license": "LGPL-3",
1010
"development_status": "Alpha",
1111
"maintainers": ["jeremi", "gonzalesedwin1123"],
12-
"depends": ["base", "g2p_registry_base"],
12+
"depends": ["base", "g2p_registry_base", "g2p_registry_membership"],
1313
"data": [
1414
"views/custom_fields_ui.xml",
1515
],
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_custom_fields_ui
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
from odoo.exceptions import UserError
2+
from odoo.tests.common import TransactionCase
3+
4+
5+
class CustomFieldsTest(TransactionCase):
6+
@classmethod
7+
def setUpClass(cls):
8+
"""
9+
Setup and create necessary records for this test
10+
"""
11+
super().setUpClass()
12+
cls.model_id = cls.env["ir.model"].search([("model", "=", "res.partner")], limit=1)
13+
cls.kind_id = cls.env.ref("g2p_registry_membership.group_membership_kind_head")
14+
cls.model_field_id = cls.env["ir.model.fields"].create(
15+
{
16+
"name": "x_test_field",
17+
"model_id": cls.model_id.id,
18+
"field_description": "Test Field",
19+
"draft_name": "test_field",
20+
"ttype": "char",
21+
"state": "manual",
22+
"kinds": [(6, 0, [cls.kind_id.id])],
23+
}
24+
)
25+
26+
def test_open_custom_fields_tree(self):
27+
action = self.model_field_id.open_custom_fields_tree()
28+
29+
self.assertEqual(action["name"], "Custom Fields")
30+
self.assertEqual(action["type"], "ir.actions.act_window")
31+
self.assertEqual(action["res_model"], "ir.model.fields")
32+
self.assertEqual(action["context"]["default_model_id"], self.model_id.id)
33+
self.assertEqual(action["context"]["default_model"], self.model_id.model)
34+
self.assertEqual(action["view_mode"], "tree, form")
35+
self.assertEqual(action["views"][0][0], self.env.ref("spp_custom_fields_ui.view_custom_fields_ui_tree").id)
36+
self.assertEqual(action["views"][0][1], "tree")
37+
self.assertEqual(action["views"][1][0], self.env.ref("spp_custom_fields_ui.view_custom_fields_ui_form").id)
38+
self.assertEqual(action["views"][1][1], "form")
39+
self.assertEqual(action["domain"], [("model_id", "=", self.model_id.id), ("state", "=", "manual")])
40+
41+
def test_compute_prefix(self):
42+
self.model_field_id._compute_prefix()
43+
self.assertEqual(self.model_field_id.prefix, "x_cst_grp")
44+
45+
def test_onchange_draft_name(self):
46+
self.model_field_id._onchange_draft_name()
47+
48+
self.assertEqual(self.model_field_id.name, "x_cst_grp_test_field")
49+
50+
def test_onchange_field_category(self):
51+
self.model_field_id._onchange_field_category()
52+
53+
self.assertEqual(self.model_field_id.name, "x_cst_grp_test_field")
54+
self.assertEqual(self.model_field_id.ttype, "char")
55+
self.assertFalse(self.model_field_id.compute)
56+
57+
def test_onchange_kinds(self):
58+
self.model_field_id._onchange_kinds()
59+
60+
self.assertEqual(self.model_field_id.name, "x_cst_grp_test_field")
61+
self.assertEqual(self.model_field_id.ttype, "char")
62+
self.assertFalse(self.model_field_id.compute)
63+
64+
def test_onchange_target_type(self):
65+
self.model_field_id._onchange_target_type()
66+
67+
self.assertEqual(self.model_field_id.name, "x_cst_grp_test_field")
68+
self.assertEqual(self.model_field_id.ttype, "char")
69+
self.assertFalse(self.model_field_id.compute)
70+
71+
def test_onchange_has_presence(self):
72+
self.model_field_id._onchange_has_presence()
73+
74+
self.assertEqual(self.model_field_id.name, "x_cst_grp_test_field")
75+
self.assertEqual(self.model_field_id.ttype, "char")
76+
77+
def test_set_compute(self):
78+
self.model_field_id.field_category = "ind"
79+
with self.assertRaisesRegex(
80+
UserError, "Changing the type of a field is not yet supported. Please drop it and create it again!"
81+
):
82+
self.model_field_id.set_compute()
83+
84+
self.model_field_id.has_presence = True
85+
with self.assertRaisesRegex(
86+
UserError, "Changing the type of a field is not yet supported. Please drop it and create it again!"
87+
):
88+
self.model_field_id.set_compute()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import test_client_credentials
2+
from . import test_individual
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import uuid
2+
3+
from odoo.exceptions import UserError
4+
from odoo.tests.common import TransactionCase
5+
6+
7+
class ClientCredentialsTest(TransactionCase):
8+
@classmethod
9+
def setUpClass(cls):
10+
"""
11+
Setup and create necessary records for this test
12+
"""
13+
super().setUpClass()
14+
15+
cls.dci_api_model = cls.env["spp.dci.api.client.credential"]
16+
17+
def test_generate_client_id(self):
18+
client_id = self.dci_api_model._generate_client_id()
19+
self.assertTrue(bool(uuid.UUID(client_id)))
20+
21+
def test_generate_client_secret(self):
22+
client_secret = self.dci_api_model._generate_client_secret()
23+
self.assertTrue(bool(uuid.UUID(client_secret)))
24+
25+
def test_show_credentials(self):
26+
api_id = self.dci_api_model.create(
27+
{
28+
"name": "Test API Client",
29+
}
30+
)
31+
32+
self.assertFalse(api_id.show_button_clicked)
33+
34+
action = api_id.show_credentials()
35+
36+
self.assertEqual(action["type"], "ir.actions.act_window")
37+
self.assertEqual(action["res_model"], "spp.dci.api.client.credential")
38+
self.assertEqual(
39+
action["views"][0][0], self.env.ref("spp_dci_api_server.spp_dci_api_client_credential_view_credentials").id
40+
)
41+
self.assertEqual(action["target"], "new")
42+
self.assertEqual(action["res_id"], api_id.id)
43+
self.assertEqual(action["view_type"], "form")
44+
self.assertEqual(action["view_mode"], "form")
45+
self.assertTrue(api_id.show_button_clicked)
46+
47+
with self.assertRaisesRegex(UserError, "Client ID and Client Secret is already showed once."):
48+
api_id.show_credentials()
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from odoo.tests.common import TransactionCase
2+
3+
4+
class IndividualTest(TransactionCase):
5+
@classmethod
6+
def setUpClass(cls):
7+
"""
8+
Setup and create necessary records for this test
9+
"""
10+
super().setUpClass()
11+
cls.id_type_id = cls.env["g2p.id.type"].create(
12+
{
13+
"name": "National ID",
14+
}
15+
)
16+
17+
cls.individual_id = cls.env["res.partner"].create(
18+
{
19+
"name": "Chin Franco",
20+
"family_name": "Franco",
21+
"given_name": "Chin",
22+
"addl_name": "Chin",
23+
"is_group": False,
24+
"is_registrant": True,
25+
"phone": "+639266716911",
26+
}
27+
)
28+
29+
cls.individual_2_id = cls.env["res.partner"].create(
30+
{
31+
"name": "Red Butay",
32+
"family_name": "Butay",
33+
"given_name": "Red",
34+
"addl_name": "Red",
35+
"is_group": False,
36+
"is_registrant": True,
37+
"phone": "+639266716912",
38+
}
39+
)
40+
41+
cls.reg_id = cls.env["g2p.reg.id"].create(
42+
{
43+
"partner_id": cls.individual_id.id,
44+
"id_type": cls.id_type_id.id,
45+
"value": "1234567890",
46+
}
47+
)
48+
49+
def test_get_dci_individual_registry_data(self):
50+
reg_records = self.individual_id.get_dci_individual_registry_data()
51+
reg_records_2 = self.individual_2_id.get_dci_individual_registry_data()
52+
self.assertEqual(len(reg_records), 1)
53+
self.assertEqual(len(reg_records_2), 0)
54+
self.assertEqual(reg_records[0]["identifier"][0]["name"], "National ID")
55+
self.assertEqual(reg_records[0]["identifier"][0]["identifier"], "1234567890")
56+
self.assertEqual(reg_records[0]["birthDate"], "False")
57+
self.assertEqual(reg_records[0]["givenName"], "Chin")
58+
self.assertEqual(reg_records[0]["familyName"], "Franco")

0 commit comments

Comments
 (0)