Skip to content

Commit 3134811

Browse files
Merge pull request #489 from OpenSPP/test-cases-for-code-coverage
Added test cases for code coverage
2 parents 1ec829e + 8a0718c commit 3134811

34 files changed

+963
-23
lines changed

spp_area/tests/common.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,22 @@
55

66

77
class AreaImportTestMixin(TransactionCase):
8+
@staticmethod
9+
def get_file_path_1():
10+
return f"{os.path.dirname(os.path.abspath(__file__))}/irq_adminboundaries_tabulardata.xlsx"
11+
12+
@staticmethod
13+
def get_file_path_2():
14+
return f"{os.path.dirname(os.path.abspath(__file__))}/pse_adminboundaries_tabulardata.xlsx"
15+
816
@classmethod
917
def setUpClass(cls):
1018
super().setUpClass()
1119
# Greater than or equal to 400 rows
1220
xls_file = None
1321
xls_file_name = None
1422

15-
file_path = f"{os.path.dirname(os.path.abspath(__file__))}/irq_adminboundaries_tabulardata.xlsx"
23+
file_path = cls.get_file_path_1()
1624
with open(file_path, "rb") as f:
1725
xls_file_name = f.name
1826
xls_file = base64.b64encode(f.read())
@@ -29,7 +37,7 @@ def setUpClass(cls):
2937
xls_file_2 = None
3038
xls_file_name_2 = None
3139

32-
file_path_2 = f"{os.path.dirname(os.path.abspath(__file__))}/pse_adminboundaries_tabulardata.xlsx"
40+
file_path_2 = cls.get_file_path_2()
3341
with open(file_path_2, "rb") as f:
3442
xls_file_name_2 = f.name
3543
xls_file_2 = base64.b64encode(f.read())

spp_area_gis/tests/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import test_area_import
2+
from . import test_area_import_raw
60.5 KB
Binary file not shown.
18.4 KB
Binary file not shown.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from odoo.addons.spp_area.tests.test_area_import import AreaImportTest as AreaImportTestMixin
2+
3+
4+
class AreaImportTest(AreaImportTestMixin):
5+
def test_get_column_indexes(self):
6+
columns = {
7+
"ADM2_EN": 0,
8+
"ADM2_PCODE": 1,
9+
"ADM1_EN": 2,
10+
"ADM1_PCODE": 3,
11+
"ADM0_EN": 4,
12+
"ADM0_PCODE": 5,
13+
"date": 6,
14+
"validOn": 7,
15+
"validTo": 8,
16+
"AREA_SQKM": 9,
17+
"longitude": 10,
18+
"latitude": 11,
19+
}
20+
area_level = 1
21+
column_indexes = self.area_import_id_2.get_column_indexes(list(columns.keys()), area_level)
22+
23+
self.assertIn("latitude_index", column_indexes)
24+
self.assertIn("longitude_index", column_indexes)
25+
self.assertEqual(column_indexes["latitude_index"], columns["latitude"])
26+
self.assertEqual(column_indexes["longitude_index"], columns["longitude"])
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from odoo.addons.spp_area.tests.test_area_import_raw import AreaImportRawTest as AreaImportRawTestMixin
2+
3+
4+
class AreaImportRawTest(AreaImportRawTestMixin):
5+
@classmethod
6+
def setUpClass(cls):
7+
super().setUpClass()
8+
cls.area_import_raw_id.latitude = 13.0
9+
cls.area_import_raw_id.longitude = 122.0
10+
11+
def test_check_errors(self):
12+
self.area_import_raw_id.latitude = 91
13+
self.area_import_raw_id.longitude = 181
14+
15+
self.area_import_raw_id.validate_raw_data()
16+
17+
self.assertEqual(self.area_import_raw_id.state, "Error")
18+
self.assertIn("Latitude must be between -90 and 90", self.area_import_raw_id.remarks)
19+
self.assertIn("Longitude must be between -180 and 180", self.area_import_raw_id.remarks)
20+
21+
def test_get_area_vals(self):
22+
area_vals = self.area_import_raw_id.get_area_vals()
23+
24+
self.assertIn("coordinates", area_vals)
25+
self.assertEqual(area_vals["coordinates"], '{"type": "Point", "coordinates": [122.0, 13.0]}')
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

0 commit comments

Comments
 (0)