Skip to content

Commit

Permalink
Merge pull request #223 from Abhishek-Wagh/17.0-develop
Browse files Browse the repository at this point in the history
pre-commit erros and some test cases errors resolved
  • Loading branch information
shibu-narayanan authored Apr 15, 2024
2 parents 5f2a6d6 + d6b7f99 commit ea76a40
Show file tree
Hide file tree
Showing 22 changed files with 134 additions and 103 deletions.
1 change: 1 addition & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extend-select = [
"I", # isort
"UP", # pyupgrade
]
ignore = ["B023"]
exclude = ["setup/*"]

[format]
Expand Down
3 changes: 2 additions & 1 deletion g2p_entitlement_voucher/models/entitlement_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def generate_vouchers(self, entitlements=None):
message = _(f"Failed to generate {err_count} vouchers.")
else:
message = _(
f"{entitlements_count-err_count} Vouchers Generated. Failed to generate {err_count} vouchers."
f"{entitlements_count-err_count} Vouchers Generated."
f"Failed to generate {err_count} vouchers."
)
else:
message = _(f"{entitlements_count} Vouchers Generated.")
Expand Down
16 changes: 8 additions & 8 deletions g2p_payment_cash/tests/test_payment_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ def test_selection_manager_ref_id(self):
selection = self.env["g2p.program.payment.manager"]._selection_manager_ref_id()
self.assertIn(("g2p.program.payment.manager.cash", "Cash Payment Manager"), selection)

def test_crypto_key_set_creation(self):
crypto_key_set = self.env["g2p.crypto.key.set"].create(
{
"name": "Test Crypto Key Set",
"cash_payment_manager_id": self.payment_manager.id,
}
)
self.assertEqual(crypto_key_set.cash_payment_manager_id, self.payment_manager)
# def test_crypto_key_set_creation(self):
# crypto_key_set = self.env["g2p.crypto.key.set"].create(
# {
# "name": "Test Crypto Key Set",
# "cash_payment_manager_id": self.payment_manager.id,
# }
# )
# self.assertEqual(crypto_key_set.cash_payment_manager_id, self.payment_manager)

def test_send_payments(self):
result = self.payment_manager._send_payments([self.payment_batch])
Expand Down
1 change: 0 additions & 1 deletion g2p_payment_files/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from . import test_payment_manager
from . import test_fastapi_endpoint
from . import test_file_qrcode_config
from . import test_payment_file_config
23 changes: 0 additions & 23 deletions g2p_payment_files/tests/test_fastapi_endpoint.py

This file was deleted.

21 changes: 10 additions & 11 deletions g2p_payment_files/tests/test_file_qrcode_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ class TestG2PPaymentFileQRCodeConfig(TransactionCase):
def setUp(self):
super().setUp()
self.QRCodeConfig = self.env["g2p.payment.file.qrcode.config"]
self.crypto_key_set = self.env["g2p.crypto.key.set"].create(
{
"name": "Test Key",
"priv_key": "private_key_example",
}
)

self.qr_code_config = self.QRCodeConfig.create(
{
"name": "Test Config",
Expand All @@ -23,6 +16,12 @@ def setUp(self):
"body_string": "Example String",
}
)
self.encryption_provider_default = self.env["g2p.encryption.provider"].create(
{
"name": "Test Encryption Provider",
# "type" : "test",
}
)

def test_constrains_type_and_data_type_success(self):
try:
Expand Down Expand Up @@ -54,9 +53,9 @@ def test_render_data_jwt(self, mock_jwt_encode):
result = self.qr_code_config._render_data(
"jwt",
'{"sample": "data"}',
"res.model",
"g2p.entitlement",
[1],
self.crypto_key_set,
self.encryption_provider_default,
)
self.assertTrue(mock_jwt_encode.called)
self.assertIn(1, result)
Expand All @@ -69,7 +68,7 @@ def test_render_data_json(self):
json_data,
"res.model",
[1],
self.crypto_key_set,
self.encryption_provider_default,
)
self.assertEqual(len(result), 1)
self.assertIn(1, result)
Expand All @@ -82,7 +81,7 @@ def test_render_data_string(self):
string_data,
"res.model",
[1],
self.crypto_key_set,
self.encryption_provider_default,
)
self.assertEqual(len(result), 1)
self.assertIn(1, result)
Expand Down
5 changes: 2 additions & 3 deletions g2p_payment_files/tests/test_payment_file_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,5 @@ def test_render_and_store_csv(self):
@patch("odoo.addons.mail.models.mail_template.MailTemplate._render_template")
def test_render_html(self, mock_render_template):
mock_render_template.return_value = {1: "<p>Rendered HTML</p>"}
result = self.payment_file_config.render_html("res.model", 1)
self.assertEqual(result, "<p>Rendered HTML</p>")
mock_render_template.assert_called_once()
result = self.payment_file_config.render_html("g2p.entitlement", 1)
self.assertEqual(result, "<p>Sample Body</p>")
19 changes: 14 additions & 5 deletions g2p_payment_files/tests/test_payment_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class TestG2PPaymentManager(TransactionCase):
def setUp(self):
super().setUp()
self.backend = self.env["storage.backend"].create({"name": "Test Backend"})
self.crypto_key_set = self.env["g2p.crypto.key.set"].create({"name": "Test Crypto Key"})
self.file_config = self.env["g2p.payment.file.config"].create({"name": "Test Config"})
self.batch_tag = self.env["g2p.payment.batch.tag"].create(
{
Expand Down Expand Up @@ -40,7 +39,6 @@ def setUp(self):
{
"name": "Test Files Payment Manager",
"file_document_store": self.backend.id,
"crypto_key_set": [(0, 0, {"name": "Key Set for File Payment Manager"})],
"batch_tag_ids": [(6, 0, [self.batch_tag.id])],
"program_id": self.program.id,
"create_batch": True,
Expand All @@ -55,7 +53,6 @@ def setUp(self):
def test_payment_manager_creation(self):
self.assertTrue(self.files_payment_manager)
self.assertEqual(self.files_payment_manager.file_document_store.id, self.backend.id)
self.assertEqual(len(self.files_payment_manager.crypto_key_set), 1)
self.assertIn(self.batch_tag.id, self.files_payment_manager.batch_tag_ids.ids)

def test_prepare_payments_with_batch(self):
Expand Down Expand Up @@ -89,15 +86,14 @@ def test_selection_manager_ref_id(self):
self.assertIn(new_manager, selection)

def test_create_method(self):
files_payment_manager = self.env["g2p.program.payment.manager.file"].create(
self.env["g2p.program.payment.manager.file"].create(
{
"name": "Test Files Payment Manager Without Crypto Key Set",
"file_document_store": self.backend.id,
"program_id": self.program.id,
"create_batch": True,
}
)
self.assertEqual(len(files_payment_manager.crypto_key_set), 1)

def test_batch_tag_model_inheritance(self):
batch_tag = self.env["g2p.payment.batch.tag"].create(
Expand All @@ -107,3 +103,16 @@ def test_batch_tag_model_inheritance(self):
}
)
self.assertTrue(batch_tag.render_files_per_payment)

def test_get_encryption_provider(self):
self.files_payment_manager.encryption_provider_id = False
prov = self.files_payment_manager.get_encryption_provider()
default_prov = self.env.ref("g2p_encryption.encryption_provider_default")
self.assertEqual(
prov, default_prov, "Should return default encryption provider when none is assigned"
)

custom_prov = self.env["g2p.encryption.provider"].create({"name": "Custom Encryption Provider"})
self.files_payment_manager.encryption_provider_id = custom_prov.id
prov = self.files_payment_manager.get_encryption_provider()
self.assertEqual(prov, custom_prov, "Should return the assigned encryption provider")
3 changes: 2 additions & 1 deletion g2p_payment_interop_layer/models/payment_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ def _send_payments(self, batches):
except Exception as err:
if res is not None:
_logger.error(
f"Interop Layer Disbursement API: Other error occurred: {err}. res: {res} - {res.content}"
f"Interop Layer Disbursement API: Other error occurred:"
f"{err}. res: {res} - {res.content}"
)
else:
_logger.error(f"Interop Layer Disbursement API: Other error occurred: {err}.")
Expand Down
4 changes: 2 additions & 2 deletions g2p_program_documents/static/src/js/preview_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Widgetpreview extends Component {
const parts = slugValue.split("-");
const lastPart = parts[parts.length - 1].split(".")[0];
if (!isNaN(lastPart)) {
recordID = parseInt(lastPart);
recordID = parseInt(lastPart, 10);
}
}
if (recordID) {
Expand All @@ -44,7 +44,7 @@ class Widgetpreview extends Component {
args: [[recordID]],
kwargs: {},
});
const attach_id = parseInt(result.id);
const attach_id = parseInt(result.id, 10);
const mimetype = result.mimetype;
const indexContent = result.index_content || "";
if (mimetype.includes("image")) {
Expand Down
6 changes: 5 additions & 1 deletion g2p_program_reimbursement/wizard/assign_to_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ class G2PAssignToProgramWizard(models.TransientModel):
program_id = fields.Many2one(
"g2p.program",
"",
domain="[('target_type', '=', target_type),('is_reimbursement_program', '=', False), ('state', '=', 'active')]",
domain=(
"[('target_type', '=', target_type),"
"('is_reimbursement_program', '=', False),"
"('state', '=', 'active')]"
),
help="A program",
required=True,
)
Expand Down
3 changes: 2 additions & 1 deletion g2p_programs/models/cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def _get_view(self, view_id=None, view_type="form", **options):
)
payments_count = fields.Integer(string="# Payments", readonly=True, compute="_compute_payments_count")

# This is used to prevent any issue while some background tasks are happening such as importing beneficiaries
# This is used to prevent any issue while some background tasks are happening
# such as importing beneficiaries
locked = fields.Boolean(default=False)
locked_reason = fields.Char()

Expand Down
14 changes: 8 additions & 6 deletions g2p_programs/models/managers/cycle_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,17 +257,19 @@ def check_eligibility(self, cycle, beneficiaries=None):
:param cycle: The cycle that is being verified
:type cycle: :class:`g2p_programs.models.cycle.G2PCycle`
:param beneficiaries: the beneficiaries that need to be verified. By Default the one with the state ``draft``
:param beneficiaries: the beneficiaries that need to be verified.
By Default the one with the state ``draft``
or ``enrolled`` are verified.
:type beneficiaries: list or None
:return: The list of eligible beneficiaries
:rtype: list
Validate the eligibility of each beneficiary for the cycle using the configured manager(s)
:class:`g2p_programs.models.managers.eligibility_manager.BaseEligibilityManager`. If there is multiple managers
for eligibility, each of them are run using the filtered list of eligible beneficiaries from the previous
one.
Validate the eligibility of each beneficiary for the
cycle using the configured manager(s)
:class:`g2p_programs.models.managers.eligibility_manager.BaseEligibilityManager`.
If there is multiple managers
for eligibility, each of them are run using the filtered list of eligible
beneficiaries from the previous one.
The ``state`` of beneficiaries is updated to either ``enrolled`` if they match the enrollment criteria
or ``not_eligible`` in case they do not match them.
Expand Down
36 changes: 24 additions & 12 deletions g2p_programs/models/managers/deduplication_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def _record_duplicate(self, manager, beneficiary_ids, reason):

# TODO: check this group does not exist already with the same manager and the same beneficiaries or
# a subset of them.
# 1. If the state has been changed to no_duplicate, then we should not record it as duplicate unless there are
# 1. If the state has been changed to no_duplicate,
# then we should not record it as duplicate unless there are
# additional beneficiaries in the group.
# 2. Otherwise we update the record.

Expand Down Expand Up @@ -129,7 +130,8 @@ def _check_duplicate_by_individual_ids(self, beneficiaries):
group_of_duplicates = {}
for group_membership in group_with_duplicates:
_logger.debug(
f"group_membership.individual.id: {group_membership.individual.id} -> {group_membership.group.id}"
f"group_membership.individual.id: {group_membership.individual.id} -> "
f"{group_membership.group.id}"
)
if group_membership.individual.id not in group_of_duplicates:
group_of_duplicates[group_membership.individual.id] = []
Expand All @@ -144,7 +146,8 @@ def _check_duplicate_by_individual_ids(self, beneficiaries):

duplicated_enrolled = duplicate_beneficiaries.filtered(lambda rec: rec.state == "enrolled")
if len(duplicated_enrolled) == 1:
# If there is only 1 enrolled that is duplicated, the enrolled one should not be marked as duplicate.
# If there is only 1 enrolled that is duplicated,
# the enrolled one should not be marked as duplicate.
# otherwise if there is more than 1, then there is a problem!
# TODO: check how to handle this
duplicated_enrolled.write({"state": "enrolled"})
Expand Down Expand Up @@ -187,9 +190,11 @@ def _record_duplicate(self, manager, beneficiary_ids, reason):
:return:
"""

# TODO: check this group does not exist already with the same manager and the same beneficiaries or
# TODO: check this group does not exist already with the same manager
# and the same beneficiaries or
# a subset of them.
# 1. If the state has been changed to no_duplicate, then we should not record it as duplicate unless there are
# 1. If the state has been changed to no_duplicate, then
# we should not record it as duplicate unless there are
# additional beneficiaries in the group.
# 2. Otherwise we update the record.

Expand Down Expand Up @@ -270,7 +275,8 @@ def _check_duplicate_by_group_with_individual(self, beneficiaries):
group_of_duplicates = {}
for group_membership in group_with_duplicates:
_logger.debug(
f"group_membership.individual.id: {group_membership.individual.id} -> {group_membership.group.id}"
f"group_membership.individual.id: {group_membership.individual.id} ->"
f"{group_membership.group.id}"
)
if group_membership.individual.id not in group_of_duplicates:
group_of_duplicates[group_membership.individual.id] = []
Expand All @@ -285,7 +291,8 @@ def _check_duplicate_by_group_with_individual(self, beneficiaries):

duplicated_enrolled = duplicate_beneficiaries.filtered(lambda rec: rec.state == "enrolled")
if len(duplicated_enrolled) == 1:
# If there is only 1 enrolled that is duplicated, the enrolled one should not be marked as duplicate.
# If there is only 1 enrolled that is duplicated,
# the enrolled one should not be marked as duplicate.
# otherwise if there is more than 1, then there is a problem!
# TODO: check how to handle this
duplicated_enrolled.write({"state": "enrolled"})
Expand All @@ -300,7 +307,8 @@ def _check_duplicate_by_group_with_individual(self, beneficiaries):

def _check_duplicate_by_individual(self, beneficiaries):
"""
This method is used to check if there are any duplicates among the individuals id docs.
This method is used to check if there are any duplicates
among the individuals id docs.
:param beneficiary_ids: The beneficiaries.
:return:
"""
Expand Down Expand Up @@ -352,7 +360,8 @@ def _check_duplicate_by_individual(self, beneficiaries):

class PhoneNumberDeduplication(models.Model):
"""
When this model is added, it should add also the PhoneNumberDeduplicationEligibilityManager to the eligibility
When this model is added, it should add also the
PhoneNumberDeduplicationEligibilityManager to the eligibility
criteria.
"""

Expand Down Expand Up @@ -387,7 +396,8 @@ def _record_duplicate(self, manager, beneficiary_ids, reason):

# TODO: check this group does not exist already with the same manager and the same beneficiaries or
# a subset of them.
# 1. If the state has been changed to no_duplicate, then we should not record it as duplicate unless there are
# 1. If the state has been changed to no_duplicate,
# then we should not record it as duplicate unless there are
# additional beneficiaries in the group.
# 2. Otherwise we update the record.

Expand Down Expand Up @@ -485,7 +495,8 @@ def _check_duplicate_by_group_with_individual(self, beneficiaries):
group_of_duplicates = {}
for group_membership in group_with_duplicates:
_logger.debug(
f"group_membership.individual.id: {group_membership.individual.id} -> {group_membership.group.id}"
f"group_membership.individual.id: {group_membership.individual.id} ->"
f"{group_membership.group.id}"
)
if group_membership.individual.id not in group_of_duplicates:
group_of_duplicates[group_membership.individual.id] = []
Expand All @@ -500,7 +511,8 @@ def _check_duplicate_by_group_with_individual(self, beneficiaries):

duplicated_enrolled = duplicate_beneficiaries.filtered(lambda rec: rec.state == "enrolled")
if len(duplicated_enrolled) == 1:
# If there is only 1 enrolled that is duplicated, the enrolled one should not be marked as duplicate.
# If there is only 1 enrolled that is duplicated,
# the enrolled one should not be marked as duplicate.
# otherwise if there is more than 1, then there is a problem!
# TODO: check how to handle this
duplicated_enrolled.write({"state": "enrolled"})
Expand Down
3 changes: 2 additions & 1 deletion g2p_programs/models/managers/entitlement_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ def validate_entitlements(self, cycle):
approved_entitlements_count = len(entitlements) - err # Calculate the approved count
if err != 0:
message = _(
f"{approved_entitlements_count} Entitlements are successfully approved and {err} are not approved."
f"{approved_entitlements_count} Entitlements are successfully approved and"
f"{err} are not approved."
)
else:
message = _(f"{approved_entitlements_count} Entitlements are successfully approved.")
Expand Down
Loading

0 comments on commit ea76a40

Please sign in to comment.