From 4cbe1a0038bcd12adbe36e7f3ca9121a1fdd7ad5 Mon Sep 17 00:00:00 2001 From: PSNAppZ Date: Thu, 28 Nov 2024 11:09:46 +0530 Subject: [PATCH 01/10] Remove ref_id to replace with unique_id. --- g2p_social_registry/__init__.py | 6 +- g2p_social_registry/__manifest__.py | 3 - g2p_social_registry/data/cron_job.xml | 17 -- .../data/default_ref_id_config.xml | 9 - .../i18n/g2p_social_registry.pot | 2 +- g2p_social_registry/models/__init__.py | 4 +- .../models/g2p_que_id_generation.py | 70 +++++++ g2p_social_registry/models/pending_ref_id.py | 36 ---- g2p_social_registry/models/ref_id_config.py | 76 ------- g2p_social_registry/models/registrant.py | 37 +--- .../models/res_config_settings.py | 73 ------- g2p_social_registry/tests/__init__.py | 4 +- .../tests/test_g2p_que_id_generation.py | 190 ++++++++++++++++++ .../tests/test_pending_ref_id.py | 47 ----- .../tests/test_ref_id_config.py | 67 ------ .../tests/test_res_config_settings.py | 77 ------- g2p_social_registry/views/registrant_view.xml | 7 - .../views/res_config_settings_view.xml | 51 ----- 18 files changed, 274 insertions(+), 502 deletions(-) delete mode 100644 g2p_social_registry/data/cron_job.xml delete mode 100644 g2p_social_registry/data/default_ref_id_config.xml create mode 100644 g2p_social_registry/models/g2p_que_id_generation.py delete mode 100644 g2p_social_registry/models/pending_ref_id.py delete mode 100644 g2p_social_registry/models/ref_id_config.py delete mode 100644 g2p_social_registry/models/res_config_settings.py create mode 100644 g2p_social_registry/tests/test_g2p_que_id_generation.py delete mode 100644 g2p_social_registry/tests/test_pending_ref_id.py delete mode 100644 g2p_social_registry/tests/test_ref_id_config.py delete mode 100644 g2p_social_registry/tests/test_res_config_settings.py delete mode 100644 g2p_social_registry/views/res_config_settings_view.xml diff --git a/g2p_social_registry/__init__.py b/g2p_social_registry/__init__.py index 9635e7d..bc9454e 100644 --- a/g2p_social_registry/__init__.py +++ b/g2p_social_registry/__init__.py @@ -1,8 +1,8 @@ # Part of OpenG2P Registry. See LICENSE file for full copyright and licensing details. from . import models - def post_init_hook(env): - partners = env["res.partner"].search([("is_registrant", "=", True), ("ref_id", "=", False)]) + partners = env["res.partner"].search([("is_registrant", "=", True), ("unique_id", "=", False)]) for partner in partners: - env["g2p.pending.reference_id"].create({"registrant_id": partner.id, "status": "failed"}) + env["g2p.pending.reference_id"].create({"registrant_id": partner.id, "id_generation_request_status": "pending", + "id_generation_update_status": "not_applicable"}) diff --git a/g2p_social_registry/__manifest__.py b/g2p_social_registry/__manifest__.py index b08dc49..b1abf16 100644 --- a/g2p_social_registry/__manifest__.py +++ b/g2p_social_registry/__manifest__.py @@ -15,12 +15,9 @@ "external_dependencies": {"python": ["python-jose"]}, "data": [ "security/ir.model.access.csv", - "data/cron_job.xml", - "data/default_ref_id_config.xml", "views/main_view.xml", "views/region.xml", "views/registrant_view.xml", - "views/res_config_settings_view.xml", ], "assets": {}, "demo": [], diff --git a/g2p_social_registry/data/cron_job.xml b/g2p_social_registry/data/cron_job.xml deleted file mode 100644 index cd7a0d5..0000000 --- a/g2p_social_registry/data/cron_job.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - Reference ID Generation Cron Job - - code - model.retry_generate_ref_id() - 1 - minutes - -1 - - - - diff --git a/g2p_social_registry/data/default_ref_id_config.xml b/g2p_social_registry/data/default_ref_id_config.xml deleted file mode 100644 index f706f7f..0000000 --- a/g2p_social_registry/data/default_ref_id_config.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - Default Reference ID Config - - diff --git a/g2p_social_registry/i18n/g2p_social_registry.pot b/g2p_social_registry/i18n/g2p_social_registry.pot index ac64499..ac24d6a 100644 --- a/g2p_social_registry/i18n/g2p_social_registry.pot +++ b/g2p_social_registry/i18n/g2p_social_registry.pot @@ -313,5 +313,5 @@ msgstr "" #. module: g2p_social_registry #: model:ir.model.constraint,message:g2p_social_registry.constraint_res_partner_ref_id_uniq -msgid "ref_id is an unique identifier!" +msgid "unique_id is an unique identifier!" msgstr "" diff --git a/g2p_social_registry/models/__init__.py b/g2p_social_registry/models/__init__.py index b27b348..68d4c27 100644 --- a/g2p_social_registry/models/__init__.py +++ b/g2p_social_registry/models/__init__.py @@ -1,7 +1,5 @@ # Part of OpenG2P. See LICENSE file for full copyright and licensing details. from . import region -from . import ref_id_config -from . import res_config_settings from . import registrant -from . import pending_ref_id +from . import g2p_que_id_generation diff --git a/g2p_social_registry/models/g2p_que_id_generation.py b/g2p_social_registry/models/g2p_que_id_generation.py new file mode 100644 index 0000000..c1ad43d --- /dev/null +++ b/g2p_social_registry/models/g2p_que_id_generation.py @@ -0,0 +1,70 @@ +from odoo import models, fields, api +from datetime import datetime + + +class G2PQueIDGeneration(models.Model): + _name = "g2p.que.id.generation" + _description = "G2P Queue ID Generation" + + registrant_id = fields.Char( + string="Registrant ID", + required=True, + unique=True, + ) + + id_generation_request_status = fields.Selection( + selection=[ + ('pending', 'Pending'), + ('approved', 'Approved'), + ('rejected', 'Rejected'), + ], + string="ID Generation Request Status", + required=True, + default='pending', + ) + + id_generation_update_status = fields.Selection( + selection=[ + ('not_applicable', 'Not Applicable'), + ('in_progress', 'In Progress'), + ('completed', 'Completed'), + ], + string="ID Generation Update Status", + required=True, + default='not_applicable', + ) + + queued_datetime = fields.Datetime( + string="Queued Datetime", + required=True, + default=fields.Datetime.now, + ) + + number_of_attempts_request = fields.Integer( + string="Number of Attempts (Request)", + required=True, + default=0, + ) + + number_of_attempts_update = fields.Integer( + string="Number of Attempts (Update)", + required=True, + default=0, + ) + + last_attempt_error_code_request = fields.Char( + string="Last Attempt Error Code (Request)" + ) + + last_attempt_error_code_update = fields.Char( + string="Last Attempt Error Code (Update)" + ) + + last_attempt_datetime_request = fields.Datetime( + string="Last Attempt Datetime (Request)" + ) + + last_attempt_datetime_update = fields.Datetime( + string="Last Attempt Datetime (Update)" + ) + diff --git a/g2p_social_registry/models/pending_ref_id.py b/g2p_social_registry/models/pending_ref_id.py deleted file mode 100644 index e66c015..0000000 --- a/g2p_social_registry/models/pending_ref_id.py +++ /dev/null @@ -1,36 +0,0 @@ -import logging - -from odoo import api, fields, models - -_logger = logging.getLogger(__name__) - - -class FallbackTable(models.Model): - _name = "g2p.pending.reference_id" - - registrant_id = fields.Many2one("res.partner") - ref_id = fields.Char() - status = fields.Selection([("failed", "Failed"), ("success", "Success")], default="failed") - - @api.model - def retry_generate_ref_id(self): - records = self.search([("status", "=", "failed")]) - for record in records: - partner = record.registrant_id - if partner: - partner.generate_ref_id() - if partner.ref_id: - record.status = "success" - record.ref_id = partner.ref_id - - def generate_ref_id_for_selected(self): - for rec in self.env.context.get("active_ids"): - partner = self.env["res.partner"].browse(rec) - registrant = self.env["g2p.pending.reference_id"].search([("registrant_id", "=", rec)], limit=1) - - if not partner.ref_id: - partner.generate_ref_id() - - if partner.ref_id and registrant: - registrant.status = "success" - registrant.ref_id = partner.ref_id diff --git a/g2p_social_registry/models/ref_id_config.py b/g2p_social_registry/models/ref_id_config.py deleted file mode 100644 index c10acc6..0000000 --- a/g2p_social_registry/models/ref_id_config.py +++ /dev/null @@ -1,76 +0,0 @@ -import logging -import os -from datetime import datetime - -import requests -from jose import jwt - -from odoo import _, api, fields, models -from odoo.exceptions import UserError - -_logger = logging.getLogger(__name__) - -ID_GENERATOR_API_BASE_URL = os.getenv( - "ID_GENERATOR_API_BASE_URL", "https://idgenerator.sandbox.net/v1/idgenerator/uin" -) -ID_GENERATOR_AUTH_URL = os.getenv( - "ID_GENERATOR_AUTH_URL", - "https://keycloak.openg2p.org/realms/master/protocol/openid-connect/token", -) -ID_GENERATOR_AUTH_CLIENT_ID = os.getenv("ID_GENERATOR_AUTH_CLIENT_ID", "") -ID_GENERATOR_AUTH_CLIENT_SECRET = os.getenv("ID_GENERATOR_AUTH_CLIENT_SECRET", "") -ID_GENERATOR_AUTH_GRANT_TYPE = os.getenv("ID_GENERATOR_AUTH_GRANT_TYPE", "client_credentials") - - -class G2PReferenceIdconfig(models.Model): - _name = "g2p.reference_id.config" - _description = "G2P Reference ID Configuration" - - name = fields.Char() - base_api_url = fields.Char(default=ID_GENERATOR_API_BASE_URL) - auth_url = fields.Char(default=ID_GENERATOR_AUTH_URL) - auth_client_id = fields.Char(default=ID_GENERATOR_AUTH_CLIENT_ID) - auth_client_secret = fields.Char(default=ID_GENERATOR_AUTH_CLIENT_SECRET) - auth_grant_type = fields.Char(default=ID_GENERATOR_AUTH_GRANT_TYPE) - api_timeout = fields.Integer(default=10) - - access_token = fields.Char() - access_token_expiry = fields.Datetime() - - @api.model - def get_config(self): - return self.search([], limit=1) - - def get_access_token(self): - self.ensure_one() - - if self.access_token and self.access_token_expiry and self.access_token_expiry > datetime.utcnow(): - return self.access_token - - if not self.auth_url: - raise UserError(_("ID Generator Authentication URL is not set")) - - data = { - "grant_type": self.auth_grant_type, - "client_id": self.auth_client_id, - "client_secret": self.auth_client_secret, - } - - response = requests.post(self.auth_url, data=data, timeout=self.api_timeout) - _logger.debug("ID Generator Authentication API response: %s", response.text) - response.raise_for_status() - - access_token = response.json().get("access_token", None) - token_exp = jwt.get_unverified_claims(access_token).get("exp") - - self.write( - { - "access_token": access_token, - "access_token_expiry": datetime.fromtimestamp(token_exp) - if isinstance(token_exp, int) - else datetime.fromisoformat(token_exp) - if isinstance(token_exp, str) - else token_exp, - } - ) - return access_token diff --git a/g2p_social_registry/models/registrant.py b/g2p_social_registry/models/registrant.py index 57f7597..e1144bb 100644 --- a/g2p_social_registry/models/registrant.py +++ b/g2p_social_registry/models/registrant.py @@ -13,43 +13,22 @@ class ResPartner(models.Model): _inherit = "res.partner" region = fields.Many2one("g2p.region") - ref_id = fields.Char(string="Reference ID", index=True) + unique_id = fields.Char(string="Reference ID", index=True) _sql_constraints = [ - ("ref_id_uniq", "UNIQUE(ref_id)", "ref_id is an unique identifier!"), + ("unique_id_uniq", "UNIQUE(unique_id)", "unique_id is an unique identifier!"), ] @api.model def create(self, vals): record = super().create(vals) if vals.get("is_registrant"): - record.generate_ref_id() + record.generate_unique_id_id() return record - def generate_ref_id(self): + def generate_unique_id_id(self): for rec in self: - try: - config = self.env["g2p.reference_id.config"].get_config() - - access_token = config.get_access_token() - headers = {"Cookie": f"Authorization={access_token}"} - - response = requests.get(config.base_api_url, headers=headers, timeout=config.api_timeout) - _logger.debug("ID Generator API response: %s", response.text) - response.raise_for_status() - res = response.json() - - unique_id = res.get("response")["uin"] - rec.ref_id = rec.get_ref_id_prefix() + unique_id if rec.get_ref_id_prefix() else unique_id - - except Exception as e: - _logger.error("Failed to generate ref_id for partner %s: %s", rec.id, str(e)) - - pending_ref_id_model = self.env["g2p.pending.reference_id"] - - if not pending_ref_id_model.search([("registrant_id", "=", rec.id)]): - pending_ref_id_model.create({"registrant_id": rec.id, "status": "failed"}) - - def get_ref_id_prefix(self): - # Override this method for customization - return + g2p_que_id_model = self.env["g2p.que.id.generation"] + if not g2p_que_id_model.search([("registrant_id", "=", rec.id)]): + g2p_que_id_model.create({"registrant_id": rec.id, "id_generation_request_status": "pending", + "id_generation_update_status": "not_applicable"}) diff --git a/g2p_social_registry/models/res_config_settings.py b/g2p_social_registry/models/res_config_settings.py deleted file mode 100644 index 4f9c560..0000000 --- a/g2p_social_registry/models/res_config_settings.py +++ /dev/null @@ -1,73 +0,0 @@ -# Part of OpenG2P. See LICENSE file for full copyright and licensing details. - -import logging - -from odoo import _, api, fields, models -from odoo.exceptions import UserError - -_logger = logging.getLogger(__name__) - - -class RegistryConfig(models.TransientModel): - _inherit = "res.config.settings" - - id_generator_base_api_url = fields.Char() - id_generator_auth_url = fields.Char() - id_generator_auth_client_id = fields.Char() - id_generator_auth_client_secret = fields.Char() - id_generator_auth_grant_type = fields.Char() - id_generator_api_timeout = fields.Integer() - - def set_values(self): - res = super().set_values() - config = self.env["g2p.reference_id.config"].get_config() - - config.write( - { - "base_api_url": self.id_generator_base_api_url, - "auth_url": self.id_generator_auth_url, - "auth_client_id": self.id_generator_auth_client_id, - "auth_client_secret": self.id_generator_auth_client_secret, - "auth_grant_type": self.id_generator_auth_grant_type, - "api_timeout": self.id_generator_api_timeout, - } - ) - - return res - - @api.model - def get_values(self): - res = super().get_values() - config = self.env["g2p.reference_id.config"].get_config() - - res.update( - { - "id_generator_base_api_url": config.base_api_url, - "id_generator_auth_url": config.auth_url, - "id_generator_auth_client_id": config.auth_client_id, - "id_generator_auth_client_secret": config.auth_client_secret, - "id_generator_auth_grant_type": config.auth_grant_type, - "id_generator_api_timeout": config.api_timeout, - } - ) - - return res - - def add_missing_ref_id_to_retry(self): - query = """ - SELECT id FROM res_partner - WHERE is_registrant = TRUE AND ref_id is Null - """ - - pending_ref_id_model = self.env["g2p.pending.reference_id"] - - try: - self._cr.execute(query) # pylint: disable=sql-injection - - for rec in [record[0] for record in (self._cr.fetchall())]: - if not pending_ref_id_model.search([("registrant_id", "=", rec)], limit=1): - pending_ref_id_model.create({"registrant_id": rec, "status": "failed"}) - - except Exception as e: - _logger.error("Database Query Error: %s", e) - raise UserError(_("Database Query Error: %s") % e) from None diff --git a/g2p_social_registry/tests/__init__.py b/g2p_social_registry/tests/__init__.py index 33a66eb..e7f6e91 100644 --- a/g2p_social_registry/tests/__init__.py +++ b/g2p_social_registry/tests/__init__.py @@ -1,5 +1,3 @@ # Part of OpenG2P Social Registry. See LICENSE file for full copyright and licensing details. -from . import test_ref_id_config -from . import test_res_config_settings -from . import test_pending_ref_id +from . import test_g2p_que_id_generation diff --git a/g2p_social_registry/tests/test_g2p_que_id_generation.py b/g2p_social_registry/tests/test_g2p_que_id_generation.py new file mode 100644 index 0000000..d3cd496 --- /dev/null +++ b/g2p_social_registry/tests/test_g2p_que_id_generation.py @@ -0,0 +1,190 @@ +from odoo.tests import TransactionCase +from odoo.exceptions import ValidationError + + +class TestG2PQueIDGeneration(TransactionCase): + def setUp(self): + super().setUp() + # Create test partners to be used as registrants + self.partner1 = self.env["res.partner"].create({"name": "Test Partner 1"}) + self.partner2 = self.env["res.partner"].create({"name": "Test Partner 2"}) + + # Create an instance of the G2PQueIDGeneration model + self.g2p_queue = self.env["g2p.que.id.generation"].create( + { + "registrant_id": self.partner1.id, + "id_generation_request_status": "pending", + "id_generation_update_status": "not_applicable", + # Other fields will take default values + } + ) + + def test_create_g2p_queue_record(self): + """ + Test that a G2PQueIDGeneration record is created successfully with valid data. + """ + self.assertTrue(self.g2p_queue, "G2PQueIDGeneration record was not created.") + self.assertEqual( + self.g2p_queue.registrant_id, self.partner1, + "Registrant ID does not match the expected partner." + ) + self.assertEqual( + self.g2p_queue.id_generation_request_status, "pending", + "Default ID Generation Request Status should be 'pending'." + ) + self.assertEqual( + self.g2p_queue.id_generation_update_status, "not_applicable", + "Default ID Generation Update Status should be 'not_applicable'." + ) + self.assertEqual( + self.g2p_queue.number_of_attempts_request, 0, + "Default number_of_attempts_request should be 0." + ) + self.assertEqual( + self.g2p_queue.number_of_attempts_update, 0, + "Default number_of_attempts_update should be 0." + ) + self.assertFalse( + self.g2p_queue.last_attempt_error_code_request, + "last_attempt_error_code_request should be empty by default." + ) + self.assertFalse( + self.g2p_queue.last_attempt_error_code_update, + "last_attempt_error_code_update should be empty by default." + ) + self.assertFalse( + self.g2p_queue.last_attempt_datetime_request, + "last_attempt_datetime_request should be empty by default." + ) + self.assertFalse( + self.g2p_queue.last_attempt_datetime_update, + "last_attempt_datetime_update should be empty by default." + ) + self.assertTrue( + self.g2p_queue.queued_datetime, + "queued_datetime should be set by default." + ) + + def test_unique_registrant_id_constraint(self): + """ + Test that the registrant_id must be unique across G2PQueIDGeneration records. + Attempting to create a second record with the same registrant_id should raise a ValidationError. + """ + with self.assertRaises(ValidationError, msg="Duplicate registrant_id should raise ValidationError."): + self.env["g2p.que.id.generation"].create( + { + "registrant_id": self.partner1.id, + "id_generation_request_status": "pending", + "id_generation_update_status": "not_applicable", + } + ) + + def test_multiple_g2p_queue_records(self): + """ + Test creating multiple G2PQueIDGeneration records with unique registrant_ids. + """ + record2 = self.env["g2p.que.id.generation"].create( + { + "registrant_id": self.partner2.id, + "id_generation_request_status": "approved", + "id_generation_update_status": "in_progress", + "last_attempt_error_code_request": "ERR001", + "last_attempt_datetime_request": fields.Datetime.now(), + } + ) + + self.assertTrue(record2, "Second G2PQueIDGeneration record was not created.") + self.assertEqual( + record2.registrant_id, self.partner2, + "Registrant ID for the second record does not match the expected partner." + ) + self.assertEqual( + record2.id_generation_request_status, "approved", + "ID Generation Request Status should be 'approved'." + ) + self.assertEqual( + record2.id_generation_update_status, "in_progress", + "ID Generation Update Status should be 'in_progress'." + ) + + self.assertEqual( + record2.last_attempt_error_code_request, "ERR001", + "last_attempt_error_code_request should be 'ERR001'." + ) + self.assertTrue( + record2.last_attempt_datetime_request, + "last_attempt_datetime_request should be set." + ) + + def test_field_assignments(self): + """ + Test that fields can be updated correctly after record creation. + """ + self.g2p_queue.write( + { + "id_generation_request_status": "approved", + "id_generation_update_status": "completed", + "number_of_attempts_request": 1, + } + ) + + self.assertEqual( + self.g2p_queue.id_generation_request_status, "approved", + "ID Generation Request Status should be updated to 'approved'." + ) + self.assertEqual( + self.g2p_queue.id_generation_update_status, "completed", + "ID Generation Update Status should be updated to 'completed'." + ) + self.assertEqual( + self.g2p_queue.number_of_attempts_request, 1, + "number_of_attempts_request should be updated to 1." + ) + + + def test_default_values_on_creation(self): + """ + Test that default values are correctly set when creating a new record without specifying them. + """ + new_record = self.env["g2p.que.id.generation"].create( + { + "registrant_id": self.partner2.id, + } + ) + + self.assertEqual( + new_record.id_generation_request_status, "pending", + "Default ID Generation Request Status should be 'pending'." + ) + self.assertEqual( + new_record.id_generation_update_status, "not_applicable", + "Default ID Generation Update Status should be 'not_applicable'." + ) + self.assertEqual( + new_record.number_of_attempts_request, 0, + "Default number_of_attempts_request should be 0." + ) + self.assertEqual( + new_record.number_of_attempts_update, 0, + "Default number_of_attempts_update should be 0." + ) + self.assertFalse( + new_record.last_attempt_error_code_request, + "last_attempt_error_code_request should be empty by default." + ) + self.assertFalse( + new_record.last_attempt_error_code_update, + "last_attempt_error_code_update should be empty by default." + ) + self.assertFalse( + new_record.last_attempt_datetime_request, + "last_attempt_datetime_request should be empty by default." + ) + self.assertFalse( + new_record.last_attempt_datetime_update, + "last_attempt_datetime_update should be empty by default." + ) + self.assertTrue( + new_record.queued_datetime, + "queued_datetime should be set by default." + ) diff --git a/g2p_social_registry/tests/test_pending_ref_id.py b/g2p_social_registry/tests/test_pending_ref_id.py deleted file mode 100644 index a05f79a..0000000 --- a/g2p_social_registry/tests/test_pending_ref_id.py +++ /dev/null @@ -1,47 +0,0 @@ -from unittest.mock import patch - -from odoo.tests import TransactionCase - - -class TestFallbackTable(TransactionCase): - def setUp(self): - super().setUp() - self.fallback_table = self.env["g2p.pending.reference_id"].create( - { - "registrant_id": self.env["res.partner"].create({"name": "Test Partner"}).id, - "ref_id": "", - "status": "failed", - } - ) - - @patch("odoo.addons.g2p_social_registry.models.registrant.ResPartner.generate_ref_id") - def test_retry_generate_ref_id_success(self, mock_generate_ref_id): - mock_generate_ref_id.return_value = None - self.fallback_table.registrant_id.ref_id = "some_ref_id" - self.fallback_table.retry_generate_ref_id() - self.assertEqual(self.fallback_table.status, "success") - self.assertEqual(self.fallback_table.ref_id, "some_ref_id") - - @patch("odoo.addons.g2p_social_registry.models.registrant.ResPartner.generate_ref_id") - def test_retry_generate_ref_id_failure(self, mock_generate_ref_id): - mock_generate_ref_id.return_value = False - self.fallback_table.retry_generate_ref_id() - self.assertEqual(self.fallback_table.status, "failed") - - @patch("odoo.addons.g2p_social_registry.models.registrant.ResPartner.generate_ref_id") - def test_generate_ref_id_for_selected_failure(self, mock_generate_ref_id): - mock_generate_ref_id.return_value = False - self.env.context = {"active_ids": [self.fallback_table.registrant_id.id]} - self.fallback_table.generate_ref_id_for_selected() - self.assertEqual(self.fallback_table.status, "failed") - - @patch("odoo.addons.g2p_social_registry.models.registrant.ResPartner.generate_ref_id") - @patch("odoo.addons.g2p_social_registry.models.pending_ref_id.FallbackTable.search") - def test_generate_ref_id_for_selected_no_registrant(self, mock_search, mock_generate_ref_id): - mock_search.return_value = False - mock_generate_ref_id.return_value = True - self.env.context = {"active_ids": [self.fallback_table.registrant_id.id]} - self.fallback_table.generate_ref_id_for_selected() - mock_search.assert_called_once_with( - [("registrant_id", "=", self.fallback_table.registrant_id.id)], limit=1 - ) diff --git a/g2p_social_registry/tests/test_ref_id_config.py b/g2p_social_registry/tests/test_ref_id_config.py deleted file mode 100644 index 4b192bb..0000000 --- a/g2p_social_registry/tests/test_ref_id_config.py +++ /dev/null @@ -1,67 +0,0 @@ -from unittest.mock import MagicMock, patch - -import requests - -from odoo.tests import TransactionCase - - -class TestG2PReferenceIdconfig(TransactionCase): - def setUp(self): - super().setUp() - self.config = self.env["g2p.reference_id.config"].create( - { - "name": "Test Config", - "base_api_url": "https://idgenerator.sandbox.net/v1/idgenerator/uin", - "auth_url": "https://keycloak.openg2p.org/realms/master/protocol/openid-connect/token", - "auth_client_id": "client_id", - "auth_client_secret": "client_secret", - "auth_grant_type": "client_credentials", - "api_timeout": 10, - } - ) - - @patch("requests.post") - def test_get_access_token(self, mock_post): - mock_response = MagicMock() - mock_response.json.return_value = { - "access_token": ( - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9." - "eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ." - "SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" - ) - } - mock_response.raise_for_status = lambda: None - mock_post.return_value = mock_response - access_token = self.config.get_access_token() - self.assertEqual( - access_token, - ( - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9." - "eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ." - "SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" - ), - ) - - @patch("requests.post") - def test_get_access_token_error(self, mock_post): - mock_response = MagicMock() - mock_response.raise_for_status.side_effect = requests.exceptions.HTTPError() - mock_post.return_value = mock_response - with self.assertRaises(requests.exceptions.HTTPError): - self.config.get_access_token() - - @patch("requests.post") - def test_write_access_token(self, mock_post): - mock_response = MagicMock() - mock_response.json.return_value = { - "access_token": ( - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9." - "eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ." - "SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" - ) - } - mock_response.raise_for_status = lambda: None - mock_post.return_value = mock_response - self.config.get_access_token() - self.assertIsNotNone(self.config.access_token) - self.assertIsNotNone(self.config.access_token_expiry) diff --git a/g2p_social_registry/tests/test_res_config_settings.py b/g2p_social_registry/tests/test_res_config_settings.py deleted file mode 100644 index 7aa929f..0000000 --- a/g2p_social_registry/tests/test_res_config_settings.py +++ /dev/null @@ -1,77 +0,0 @@ -from unittest.mock import MagicMock, patch - -from odoo.tests import TransactionCase - - -class TestRegistryConfig(TransactionCase): - def setUp(self): - super().setUp() - self.config = self.env["g2p.reference_id.config"].create( - { - "name": "Test Config", - "base_api_url": "https://idgenerator.sandbox.net/v1/idgenerator/uin", - "auth_url": "https://keycloak.openg2p.org/realms/master/protocol/openid-connect/token", - "auth_client_id": "client_id", - "auth_client_secret": "client_secret", - "auth_grant_type": "client_credentials", - "api_timeout": 10, - } - ) - self.registry_config = self.env["res.config.settings"].create({}) - - @patch("requests.post") - def test_set_values(self, mock_post): - mock_response = MagicMock() - mock_response.json.return_value = {"access_token": "test_access_token"} - mock_response.raise_for_status = lambda: None - mock_post.return_value = mock_response - self.registry_config.id_generator_base_api_url = "https://idgenerator.sandbox.net/v1/idgenerator/uin" - self.registry_config.id_generator_auth_url = ( - "https://keycloak.openg2p.org/realms/master/protocol/openid-connect/token" - ) - self.registry_config.id_generator_auth_client_id = "new_client_id" - self.registry_config.id_generator_auth_client_secret = "new_client_secret" - self.registry_config.id_generator_auth_grant_type = "new_grant_type" - self.registry_config.id_generator_api_timeout = 20 - self.registry_config.set_values() - config = self.env["g2p.reference_id.config"].get_config() - self.assertEqual(config.base_api_url, "https://idgenerator.sandbox.net/v1/idgenerator/uin") - self.assertEqual( - config.auth_url, "https://keycloak.openg2p.org/realms/master/protocol/openid-connect/token" - ) - self.assertEqual(config.auth_client_id, "new_client_id") - self.assertEqual(config.auth_client_secret, "new_client_secret") - self.assertEqual(config.auth_grant_type, "new_grant_type") - self.assertEqual(config.api_timeout, 20) - - @patch("requests.post") - def test_get_values(self, mock_post): - mock_response = MagicMock() - mock_response.json.return_value = {"access_token": "test_access_token"} - mock_response.raise_for_status = lambda: None - mock_post.return_value = mock_response - self.registry_config.get_values() - config = self.env["g2p.reference_id.config"].get_config() - self.assertEqual(self.registry_config.id_generator_base_api_url, config.base_api_url) - self.assertEqual(self.registry_config.id_generator_auth_url, config.auth_url) - self.assertEqual(self.registry_config.id_generator_auth_client_id, config.auth_client_id) - self.assertEqual(self.registry_config.id_generator_auth_client_secret, config.auth_client_secret) - self.assertEqual(self.registry_config.id_generator_auth_grant_type, config.auth_grant_type) - self.assertEqual(self.registry_config.id_generator_api_timeout, config.api_timeout) - - @patch("requests.post") - def test_add_missing_ref_id_to_retry(self, mock_post): - mock_response = MagicMock() - mock_response.json.return_value = {"access_token": "test_access_token"} - mock_response.raise_for_status = lambda: None - mock_post.return_value = mock_response - partner_without_ref = self.env["res.partner"].create( - {"name": "Test Partner", "is_registrant": True, "ref_id": False} - ) - self.registry_config.add_missing_ref_id_to_retry() - pending_records = self.env["g2p.pending.reference_id"].search( - [("registrant_id", "=", partner_without_ref.id)] - ) - self.assertEqual(len(pending_records), 1) - self.assertEqual(pending_records.registrant_id.id, partner_without_ref.id) - self.assertEqual(pending_records.status, "failed") diff --git a/g2p_social_registry/views/registrant_view.xml b/g2p_social_registry/views/registrant_view.xml index 8a004bd..40759fb 100644 --- a/g2p_social_registry/views/registrant_view.xml +++ b/g2p_social_registry/views/registrant_view.xml @@ -33,11 +33,4 @@ - - Generate Reference ID - - - code - action = model.generate_ref_id_for_selected() - diff --git a/g2p_social_registry/views/res_config_settings_view.xml b/g2p_social_registry/views/res_config_settings_view.xml deleted file mode 100644 index 699cb93..0000000 --- a/g2p_social_registry/views/res_config_settings_view.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - openg2p.res.config.settings.view.inherit.setup - res.config.settings - - - - - G2P Social Registry Settings - - - - -
-
-
- - - - - - - - - - - - - - - -
-
-
-
-
From afd526ddbdb390f91856d86d18e73308755a4b89 Mon Sep 17 00:00:00 2001 From: PSNAppZ Date: Thu, 28 Nov 2024 11:31:48 +0530 Subject: [PATCH 02/10] Update model.access.csv --- g2p_social_registry/security/ir.model.access.csv | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/g2p_social_registry/security/ir.model.access.csv b/g2p_social_registry/security/ir.model.access.csv index 76b6797..acaaa7e 100644 --- a/g2p_social_registry/security/ir.model.access.csv +++ b/g2p_social_registry/security/ir.model.access.csv @@ -1,7 +1,5 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink g2p_region_admin,Region Admin Access,g2p_social_registry.model_g2p_region,g2p_registry_base.group_g2p_admin,1,1,1,1 g2p_region_registrar,Region Registrar Access,g2p_social_registry.model_g2p_region,,1,0,0,0 -g2p_pending_reference_id_admin,Pending Reference ID Admin Access,g2p_social_registry.model_g2p_pending_reference_id,g2p_registry_base.group_g2p_admin,1,1,1,1 -g2p_pending_reference_id_registrar,Pending Reference ID Registrar Access,g2p_social_registry.model_g2p_pending_reference_id,,1,0,0,0 -g2p_reference_id_config_admin,Reference ID Config Admin Access,g2p_social_registry.model_g2p_reference_id_config,g2p_registry_base.group_g2p_admin,1,1,1,1 -g2p_reference_id_config_registrar,Reference ID Config Registrar Access,g2p_social_registry.model_g2p_reference_id_config,,1,0,0,0 +g2p_que_id_generation_admin,Queue ID Generation Admin Access,g2p_social_registry.model_g2p_que_id_generation,g2p_registry_base.group_g2p_admin,1,1,1,1 +g2p_que_id_generation_registrar,Queue ID Generation Registrar Access,g2p_social_registry.model_g2p_que_id_generation,,1,0,0,0 From e4c23edb7164105966806a19a867df16a638ec30 Mon Sep 17 00:00:00 2001 From: PSNAppZ Date: Thu, 28 Nov 2024 11:42:48 +0530 Subject: [PATCH 03/10] add registrant_id_uniq constraint --- g2p_social_registry/models/g2p_que_id_generation.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/g2p_social_registry/models/g2p_que_id_generation.py b/g2p_social_registry/models/g2p_que_id_generation.py index c1ad43d..c8373aa 100644 --- a/g2p_social_registry/models/g2p_que_id_generation.py +++ b/g2p_social_registry/models/g2p_que_id_generation.py @@ -9,7 +9,6 @@ class G2PQueIDGeneration(models.Model): registrant_id = fields.Char( string="Registrant ID", required=True, - unique=True, ) id_generation_request_status = fields.Selection( @@ -68,3 +67,6 @@ class G2PQueIDGeneration(models.Model): string="Last Attempt Datetime (Update)" ) + _sql_constraints = [ + ("registrant_id_uniq", "UNIQUE(registrant_id)", "registrant_id is an unique identifier!"), + ] From 505cfeae7c934cb290940af46e3d1e32fb2ddf80 Mon Sep 17 00:00:00 2001 From: PSNAppZ Date: Thu, 28 Nov 2024 12:17:23 +0530 Subject: [PATCH 04/10] Fix imports --- g2p_social_registry/tests/test_g2p_que_id_generation.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/g2p_social_registry/tests/test_g2p_que_id_generation.py b/g2p_social_registry/tests/test_g2p_que_id_generation.py index d3cd496..806add7 100644 --- a/g2p_social_registry/tests/test_g2p_que_id_generation.py +++ b/g2p_social_registry/tests/test_g2p_que_id_generation.py @@ -1,5 +1,6 @@ from odoo.tests import TransactionCase from odoo.exceptions import ValidationError +from odoo import fields class TestG2PQueIDGeneration(TransactionCase): @@ -25,7 +26,7 @@ def test_create_g2p_queue_record(self): """ self.assertTrue(self.g2p_queue, "G2PQueIDGeneration record was not created.") self.assertEqual( - self.g2p_queue.registrant_id, self.partner1, + self.g2p_queue.registrant_id, self.partner1.id, "Registrant ID does not match the expected partner." ) self.assertEqual( @@ -95,7 +96,7 @@ def test_multiple_g2p_queue_records(self): self.assertTrue(record2, "Second G2PQueIDGeneration record was not created.") self.assertEqual( - record2.registrant_id, self.partner2, + record2.registrant_id, self.partner2.id, "Registrant ID for the second record does not match the expected partner." ) self.assertEqual( From 022313e089ac06ae9cd6c76067ca3e3ad775ab8a Mon Sep 17 00:00:00 2001 From: PSNAppZ Date: Thu, 28 Nov 2024 13:02:21 +0530 Subject: [PATCH 05/10] Fix test case --- .../tests/test_g2p_que_id_generation.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/g2p_social_registry/tests/test_g2p_que_id_generation.py b/g2p_social_registry/tests/test_g2p_que_id_generation.py index 806add7..a7ced66 100644 --- a/g2p_social_registry/tests/test_g2p_que_id_generation.py +++ b/g2p_social_registry/tests/test_g2p_que_id_generation.py @@ -1,6 +1,7 @@ from odoo.tests import TransactionCase from odoo.exceptions import ValidationError from odoo import fields +from odoo.sql_db import IntegrityError class TestG2PQueIDGeneration(TransactionCase): @@ -26,7 +27,7 @@ def test_create_g2p_queue_record(self): """ self.assertTrue(self.g2p_queue, "G2PQueIDGeneration record was not created.") self.assertEqual( - self.g2p_queue.registrant_id, self.partner1.id, + self.g2p_queue.registrant_id, str(self.partner2.id), "Registrant ID does not match the expected partner." ) self.assertEqual( @@ -69,12 +70,12 @@ def test_create_g2p_queue_record(self): def test_unique_registrant_id_constraint(self): """ Test that the registrant_id must be unique across G2PQueIDGeneration records. - Attempting to create a second record with the same registrant_id should raise a ValidationError. + Attempting to create a second record with the same registrant_id should raise an IntegrityError. """ - with self.assertRaises(ValidationError, msg="Duplicate registrant_id should raise ValidationError."): + with self.assertRaises(IntegrityError, msg="Duplicate registrant_id should raise IntegrityError."): self.env["g2p.que.id.generation"].create( { - "registrant_id": self.partner1.id, + "registrant_id": str(self.partner1.id), # Ensure registrant_id is a string "id_generation_request_status": "pending", "id_generation_update_status": "not_applicable", } @@ -96,7 +97,7 @@ def test_multiple_g2p_queue_records(self): self.assertTrue(record2, "Second G2PQueIDGeneration record was not created.") self.assertEqual( - record2.registrant_id, self.partner2.id, + record2.registrant_id, str(self.partner2.id), "Registrant ID for the second record does not match the expected partner." ) self.assertEqual( From 6c52366e22609979e5b9f7f56f5b5f1b54abe139 Mon Sep 17 00:00:00 2001 From: PSNAppZ Date: Thu, 28 Nov 2024 13:16:45 +0530 Subject: [PATCH 06/10] Fix test case imports --- g2p_social_registry/tests/test_g2p_que_id_generation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g2p_social_registry/tests/test_g2p_que_id_generation.py b/g2p_social_registry/tests/test_g2p_que_id_generation.py index a7ced66..12bf006 100644 --- a/g2p_social_registry/tests/test_g2p_que_id_generation.py +++ b/g2p_social_registry/tests/test_g2p_que_id_generation.py @@ -1,7 +1,7 @@ from odoo.tests import TransactionCase from odoo.exceptions import ValidationError from odoo import fields -from odoo.sql_db import IntegrityError +from psycopg2 import IntegrityError class TestG2PQueIDGeneration(TransactionCase): From 264091768589d7583c41b4b6e592347d165fadc1 Mon Sep 17 00:00:00 2001 From: PSNAppZ Date: Thu, 28 Nov 2024 13:31:45 +0530 Subject: [PATCH 07/10] Fix test case partner_id --- .../tests/test_g2p_que_id_generation.py | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/g2p_social_registry/tests/test_g2p_que_id_generation.py b/g2p_social_registry/tests/test_g2p_que_id_generation.py index 12bf006..78f7d8e 100644 --- a/g2p_social_registry/tests/test_g2p_que_id_generation.py +++ b/g2p_social_registry/tests/test_g2p_que_id_generation.py @@ -17,7 +17,6 @@ def setUp(self): "registrant_id": self.partner1.id, "id_generation_request_status": "pending", "id_generation_update_status": "not_applicable", - # Other fields will take default values } ) @@ -27,7 +26,7 @@ def test_create_g2p_queue_record(self): """ self.assertTrue(self.g2p_queue, "G2PQueIDGeneration record was not created.") self.assertEqual( - self.g2p_queue.registrant_id, str(self.partner2.id), + self.g2p_queue.registrant_id, str(self.partner1.id), "Registrant ID does not match the expected partner." ) self.assertEqual( @@ -67,20 +66,6 @@ def test_create_g2p_queue_record(self): "queued_datetime should be set by default." ) - def test_unique_registrant_id_constraint(self): - """ - Test that the registrant_id must be unique across G2PQueIDGeneration records. - Attempting to create a second record with the same registrant_id should raise an IntegrityError. - """ - with self.assertRaises(IntegrityError, msg="Duplicate registrant_id should raise IntegrityError."): - self.env["g2p.que.id.generation"].create( - { - "registrant_id": str(self.partner1.id), # Ensure registrant_id is a string - "id_generation_request_status": "pending", - "id_generation_update_status": "not_applicable", - } - ) - def test_multiple_g2p_queue_records(self): """ Test creating multiple G2PQueIDGeneration records with unique registrant_ids. From c09e6329ce3e4c71d22534ecddb4d4af0e733523 Mon Sep 17 00:00:00 2001 From: PSNAppZ Date: Thu, 28 Nov 2024 16:37:20 +0530 Subject: [PATCH 08/10] Update model name --- g2p_social_registry/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g2p_social_registry/__init__.py b/g2p_social_registry/__init__.py index bc9454e..0c010e9 100644 --- a/g2p_social_registry/__init__.py +++ b/g2p_social_registry/__init__.py @@ -4,5 +4,5 @@ def post_init_hook(env): partners = env["res.partner"].search([("is_registrant", "=", True), ("unique_id", "=", False)]) for partner in partners: - env["g2p.pending.reference_id"].create({"registrant_id": partner.id, "id_generation_request_status": "pending", + env["g2p.que.id.generation"].create({"registrant_id": partner.id, "id_generation_request_status": "pending", "id_generation_update_status": "not_applicable"}) From 6ae5dfc4c591d508fbbd606353166df886c76d3c Mon Sep 17 00:00:00 2001 From: PSNAppZ Date: Thu, 28 Nov 2024 16:37:25 +0530 Subject: [PATCH 09/10] Update model name --- g2p_social_registry/i18n/g2p_social_registry.pot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g2p_social_registry/i18n/g2p_social_registry.pot b/g2p_social_registry/i18n/g2p_social_registry.pot index ac24d6a..ec1fd2b 100644 --- a/g2p_social_registry/i18n/g2p_social_registry.pot +++ b/g2p_social_registry/i18n/g2p_social_registry.pot @@ -308,7 +308,7 @@ msgstr "" #. module: g2p_social_registry #: model:ir.model,name:g2p_social_registry.model_g2p_pending_reference_id -msgid "g2p.pending.reference_id" +msgid "g2p.que.id.generation" msgstr "" #. module: g2p_social_registry From fe92d7de24b85589d57d07ed46f037120aad449a Mon Sep 17 00:00:00 2001 From: PS Narayanan Date: Thu, 28 Nov 2024 16:49:09 +0530 Subject: [PATCH 10/10] pre-commit fixes --- g2p_social_registry/__init__.py | 10 +- .../models/g2p_que_id_generation.py | 41 +++---- g2p_social_registry/models/registrant.py | 11 +- .../tests/test_g2p_que_id_generation.py | 106 +++++++++--------- 4 files changed, 78 insertions(+), 90 deletions(-) diff --git a/g2p_social_registry/__init__.py b/g2p_social_registry/__init__.py index 0c010e9..7418171 100644 --- a/g2p_social_registry/__init__.py +++ b/g2p_social_registry/__init__.py @@ -1,8 +1,14 @@ # Part of OpenG2P Registry. See LICENSE file for full copyright and licensing details. from . import models + def post_init_hook(env): partners = env["res.partner"].search([("is_registrant", "=", True), ("unique_id", "=", False)]) for partner in partners: - env["g2p.que.id.generation"].create({"registrant_id": partner.id, "id_generation_request_status": "pending", - "id_generation_update_status": "not_applicable"}) + env["g2p.que.id.generation"].create( + { + "registrant_id": partner.id, + "id_generation_request_status": "pending", + "id_generation_update_status": "not_applicable", + } + ) diff --git a/g2p_social_registry/models/g2p_que_id_generation.py b/g2p_social_registry/models/g2p_que_id_generation.py index c8373aa..66d6492 100644 --- a/g2p_social_registry/models/g2p_que_id_generation.py +++ b/g2p_social_registry/models/g2p_que_id_generation.py @@ -1,5 +1,4 @@ -from odoo import models, fields, api -from datetime import datetime +from odoo import fields, models class G2PQueIDGeneration(models.Model): @@ -7,65 +6,51 @@ class G2PQueIDGeneration(models.Model): _description = "G2P Queue ID Generation" registrant_id = fields.Char( - string="Registrant ID", required=True, ) id_generation_request_status = fields.Selection( selection=[ - ('pending', 'Pending'), - ('approved', 'Approved'), - ('rejected', 'Rejected'), + ("pending", "Pending"), + ("approved", "Approved"), + ("rejected", "Rejected"), ], - string="ID Generation Request Status", required=True, - default='pending', + default="pending", ) id_generation_update_status = fields.Selection( selection=[ - ('not_applicable', 'Not Applicable'), - ('in_progress', 'In Progress'), - ('completed', 'Completed'), + ("not_applicable", "Not Applicable"), + ("in_progress", "In Progress"), + ("completed", "Completed"), ], - string="ID Generation Update Status", required=True, - default='not_applicable', + default="not_applicable", ) queued_datetime = fields.Datetime( - string="Queued Datetime", required=True, default=fields.Datetime.now, ) number_of_attempts_request = fields.Integer( - string="Number of Attempts (Request)", required=True, default=0, ) number_of_attempts_update = fields.Integer( - string="Number of Attempts (Update)", required=True, default=0, ) - last_attempt_error_code_request = fields.Char( - string="Last Attempt Error Code (Request)" - ) + last_attempt_error_code_request = fields.Char() - last_attempt_error_code_update = fields.Char( - string="Last Attempt Error Code (Update)" - ) + last_attempt_error_code_update = fields.Char() - last_attempt_datetime_request = fields.Datetime( - string="Last Attempt Datetime (Request)" - ) + last_attempt_datetime_request = fields.Datetime() - last_attempt_datetime_update = fields.Datetime( - string="Last Attempt Datetime (Update)" - ) + last_attempt_datetime_update = fields.Datetime() _sql_constraints = [ ("registrant_id_uniq", "UNIQUE(registrant_id)", "registrant_id is an unique identifier!"), diff --git a/g2p_social_registry/models/registrant.py b/g2p_social_registry/models/registrant.py index e1144bb..c730bca 100644 --- a/g2p_social_registry/models/registrant.py +++ b/g2p_social_registry/models/registrant.py @@ -2,8 +2,6 @@ import logging -import requests - from odoo import api, fields, models _logger = logging.getLogger(__name__) @@ -30,5 +28,10 @@ def generate_unique_id_id(self): for rec in self: g2p_que_id_model = self.env["g2p.que.id.generation"] if not g2p_que_id_model.search([("registrant_id", "=", rec.id)]): - g2p_que_id_model.create({"registrant_id": rec.id, "id_generation_request_status": "pending", - "id_generation_update_status": "not_applicable"}) + g2p_que_id_model.create( + { + "registrant_id": rec.id, + "id_generation_request_status": "pending", + "id_generation_update_status": "not_applicable", + } + ) diff --git a/g2p_social_registry/tests/test_g2p_que_id_generation.py b/g2p_social_registry/tests/test_g2p_que_id_generation.py index 78f7d8e..7219bf6 100644 --- a/g2p_social_registry/tests/test_g2p_que_id_generation.py +++ b/g2p_social_registry/tests/test_g2p_que_id_generation.py @@ -1,7 +1,5 @@ -from odoo.tests import TransactionCase -from odoo.exceptions import ValidationError from odoo import fields -from psycopg2 import IntegrityError +from odoo.tests import TransactionCase class TestG2PQueIDGeneration(TransactionCase): @@ -26,45 +24,43 @@ def test_create_g2p_queue_record(self): """ self.assertTrue(self.g2p_queue, "G2PQueIDGeneration record was not created.") self.assertEqual( - self.g2p_queue.registrant_id, str(self.partner1.id), - "Registrant ID does not match the expected partner." + self.g2p_queue.registrant_id, + str(self.partner1.id), + "Registrant ID does not match the expected partner.", ) self.assertEqual( - self.g2p_queue.id_generation_request_status, "pending", - "Default ID Generation Request Status should be 'pending'." + self.g2p_queue.id_generation_request_status, + "pending", + "Default ID Generation Request Status should be 'pending'.", ) self.assertEqual( - self.g2p_queue.id_generation_update_status, "not_applicable", - "Default ID Generation Update Status should be 'not_applicable'." + self.g2p_queue.id_generation_update_status, + "not_applicable", + "Default ID Generation Update Status should be 'not_applicable'.", ) self.assertEqual( - self.g2p_queue.number_of_attempts_request, 0, - "Default number_of_attempts_request should be 0." + self.g2p_queue.number_of_attempts_request, 0, "Default number_of_attempts_request should be 0." ) self.assertEqual( - self.g2p_queue.number_of_attempts_update, 0, - "Default number_of_attempts_update should be 0." + self.g2p_queue.number_of_attempts_update, 0, "Default number_of_attempts_update should be 0." ) self.assertFalse( self.g2p_queue.last_attempt_error_code_request, - "last_attempt_error_code_request should be empty by default." + "last_attempt_error_code_request should be empty by default.", ) self.assertFalse( self.g2p_queue.last_attempt_error_code_update, - "last_attempt_error_code_update should be empty by default." + "last_attempt_error_code_update should be empty by default.", ) self.assertFalse( self.g2p_queue.last_attempt_datetime_request, - "last_attempt_datetime_request should be empty by default." + "last_attempt_datetime_request should be empty by default.", ) self.assertFalse( self.g2p_queue.last_attempt_datetime_update, - "last_attempt_datetime_update should be empty by default." - ) - self.assertTrue( - self.g2p_queue.queued_datetime, - "queued_datetime should be set by default." + "last_attempt_datetime_update should be empty by default.", ) + self.assertTrue(self.g2p_queue.queued_datetime, "queued_datetime should be set by default.") def test_multiple_g2p_queue_records(self): """ @@ -82,26 +78,27 @@ def test_multiple_g2p_queue_records(self): self.assertTrue(record2, "Second G2PQueIDGeneration record was not created.") self.assertEqual( - record2.registrant_id, str(self.partner2.id), - "Registrant ID for the second record does not match the expected partner." + record2.registrant_id, + str(self.partner2.id), + "Registrant ID for the second record does not match the expected partner.", ) self.assertEqual( - record2.id_generation_request_status, "approved", - "ID Generation Request Status should be 'approved'." + record2.id_generation_request_status, + "approved", + "ID Generation Request Status should be 'approved'.", ) self.assertEqual( - record2.id_generation_update_status, "in_progress", - "ID Generation Update Status should be 'in_progress'." + record2.id_generation_update_status, + "in_progress", + "ID Generation Update Status should be 'in_progress'.", ) self.assertEqual( - record2.last_attempt_error_code_request, "ERR001", - "last_attempt_error_code_request should be 'ERR001'." - ) - self.assertTrue( - record2.last_attempt_datetime_request, - "last_attempt_datetime_request should be set." + record2.last_attempt_error_code_request, + "ERR001", + "last_attempt_error_code_request should be 'ERR001'.", ) + self.assertTrue(record2.last_attempt_datetime_request, "last_attempt_datetime_request should be set.") def test_field_assignments(self): """ @@ -116,19 +113,19 @@ def test_field_assignments(self): ) self.assertEqual( - self.g2p_queue.id_generation_request_status, "approved", - "ID Generation Request Status should be updated to 'approved'." + self.g2p_queue.id_generation_request_status, + "approved", + "ID Generation Request Status should be updated to 'approved'.", ) self.assertEqual( - self.g2p_queue.id_generation_update_status, "completed", - "ID Generation Update Status should be updated to 'completed'." + self.g2p_queue.id_generation_update_status, + "completed", + "ID Generation Update Status should be updated to 'completed'.", ) self.assertEqual( - self.g2p_queue.number_of_attempts_request, 1, - "number_of_attempts_request should be updated to 1." + self.g2p_queue.number_of_attempts_request, 1, "number_of_attempts_request should be updated to 1." ) - def test_default_values_on_creation(self): """ Test that default values are correctly set when creating a new record without specifying them. @@ -140,38 +137,35 @@ def test_default_values_on_creation(self): ) self.assertEqual( - new_record.id_generation_request_status, "pending", - "Default ID Generation Request Status should be 'pending'." + new_record.id_generation_request_status, + "pending", + "Default ID Generation Request Status should be 'pending'.", ) self.assertEqual( - new_record.id_generation_update_status, "not_applicable", - "Default ID Generation Update Status should be 'not_applicable'." + new_record.id_generation_update_status, + "not_applicable", + "Default ID Generation Update Status should be 'not_applicable'.", ) self.assertEqual( - new_record.number_of_attempts_request, 0, - "Default number_of_attempts_request should be 0." + new_record.number_of_attempts_request, 0, "Default number_of_attempts_request should be 0." ) self.assertEqual( - new_record.number_of_attempts_update, 0, - "Default number_of_attempts_update should be 0." + new_record.number_of_attempts_update, 0, "Default number_of_attempts_update should be 0." ) self.assertFalse( new_record.last_attempt_error_code_request, - "last_attempt_error_code_request should be empty by default." + "last_attempt_error_code_request should be empty by default.", ) self.assertFalse( new_record.last_attempt_error_code_update, - "last_attempt_error_code_update should be empty by default." + "last_attempt_error_code_update should be empty by default.", ) self.assertFalse( new_record.last_attempt_datetime_request, - "last_attempt_datetime_request should be empty by default." + "last_attempt_datetime_request should be empty by default.", ) self.assertFalse( new_record.last_attempt_datetime_update, - "last_attempt_datetime_update should be empty by default." - ) - self.assertTrue( - new_record.queued_datetime, - "queued_datetime should be set by default." + "last_attempt_datetime_update should be empty by default.", ) + self.assertTrue(new_record.queued_datetime, "queued_datetime should be set by default.")