|
| 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([]) |
0 commit comments