From 4a2643a1296cf2d7c48cc1b28e917a2de48cece1 Mon Sep 17 00:00:00 2001 From: ramakrishnavellala Date: Wed, 20 Mar 2024 16:40:03 +0530 Subject: [PATCH] added unit tests for cycleless and program_documents models --- g2p_program_cycleless/__init__.py | 2 +- g2p_program_cycleless/tests/__init__.py | 3 + .../tests/test_entitlement_manager.py | 88 ++++++++++ .../tests/test_program_manager.py | 66 +++++++ g2p_program_cycleless/tests/test_programs.py | 67 +++++++ g2p_program_documents/__init__.py | 2 +- g2p_program_documents/tests/__init__.py | 6 + .../tests/test_document_file.py | 86 +++++++++ .../tests/test_document_store.py | 59 +++++++ .../tests/test_entitlement.py | 166 ++++++++++++++++++ .../tests/test_entitlement_manager.py | 108 ++++++++++++ g2p_program_documents/tests/test_program.py | 32 ++++ .../tests/test_program_membership.py | 51 ++++++ 13 files changed, 734 insertions(+), 2 deletions(-) create mode 100644 g2p_program_cycleless/tests/__init__.py create mode 100644 g2p_program_cycleless/tests/test_entitlement_manager.py create mode 100644 g2p_program_cycleless/tests/test_program_manager.py create mode 100644 g2p_program_cycleless/tests/test_programs.py create mode 100644 g2p_program_documents/tests/__init__.py create mode 100644 g2p_program_documents/tests/test_document_file.py create mode 100644 g2p_program_documents/tests/test_document_store.py create mode 100644 g2p_program_documents/tests/test_entitlement.py create mode 100644 g2p_program_documents/tests/test_entitlement_manager.py create mode 100644 g2p_program_documents/tests/test_program.py create mode 100644 g2p_program_documents/tests/test_program_membership.py diff --git a/g2p_program_cycleless/__init__.py b/g2p_program_cycleless/__init__.py index 2c0aa80c..4dc66b0d 100644 --- a/g2p_program_cycleless/__init__.py +++ b/g2p_program_cycleless/__init__.py @@ -1,2 +1,2 @@ # Part of OpenG2P. See LICENSE file for full copyright and licensing details. -from . import models +from . import models, tests diff --git a/g2p_program_cycleless/tests/__init__.py b/g2p_program_cycleless/tests/__init__.py new file mode 100644 index 00000000..9d0556a1 --- /dev/null +++ b/g2p_program_cycleless/tests/__init__.py @@ -0,0 +1,3 @@ +from . import test_entitlement_manager +from . import test_program_manager +from . import test_programs diff --git a/g2p_program_cycleless/tests/test_entitlement_manager.py b/g2p_program_cycleless/tests/test_entitlement_manager.py new file mode 100644 index 00000000..233a6dac --- /dev/null +++ b/g2p_program_cycleless/tests/test_entitlement_manager.py @@ -0,0 +1,88 @@ +from datetime import datetime, timedelta + +from odoo.tests.common import TransactionCase + + +class TestG2PEntitlementManagerDefault(TransactionCase): + def setUp(self): + super(TestG2PEntitlementManagerDefault, self).setUp() + self.entitlement_manager = self.env["g2p.program.entitlement.manager.default"] + self.program_model = self.env["g2p.program"] + self.cycle_model = self.env["g2p.cycle"] + + def test_open_entitlements_form_reimbursement(self): + reimbursement_program = self.program_model.create( + {"name": "Reimbursement Program", "is_reimbursement_program": True} + ) + reimbursement_cycle = self.cycle_model.create( + { + "name": "Reimbursement Cycle", + "program_id": reimbursement_program.id, + "start_date": datetime.now(), + "end_date": datetime.now() + timedelta(days=30), + } + ) + + action_reimbursement = self.entitlement_manager.open_entitlements_form( + reimbursement_cycle + ) + + self.assertNotEqual(action_reimbursement["name"], "Reimbursements") + self.assertNotEqual(action_reimbursement["name"], "Entitlements") + + def test_open_entitlements_form_cycleless(self): + program = self.program_model.create( + { + "name": "Cycleless Program", + "is_cycleless": True, + } + ) + + cycle = self.cycle_model.create( + { + "name": "Test Cycle", + "program_id": program.id, + "start_date": datetime.now(), + "end_date": datetime.now() + timedelta(days=30), + } + ) + + manager = self.entitlement_manager.create( + { + "program_id": program.id, + "name": "Test Manager", + } + ) + + result = manager.open_entitlements_form(cycle) + + self.assertEqual(result["name"], "Entitlements") + + def test_open_entitlements_form_default(self): + program = self.program_model.create( + { + "name": "Regular Program", + } + ) + + cycle = self.cycle_model.create( + { + "name": "Test Cycle", + "program_id": program.id, + "start_date": datetime.now(), + "end_date": datetime.now() + timedelta(days=30), + } + ) + + manager = self.entitlement_manager.create( + { + "program_id": program.id, + "name": "Test Manager", + } + ) + + result = manager.open_entitlements_form(cycle) + + # Add assertions for the default behavior, if any + self.assertNotEqual(result["name"], "Reimbursements") + self.assertNotEqual(result["name"], "Entitlements") diff --git a/g2p_program_cycleless/tests/test_program_manager.py b/g2p_program_cycleless/tests/test_program_manager.py new file mode 100644 index 00000000..a853d686 --- /dev/null +++ b/g2p_program_cycleless/tests/test_program_manager.py @@ -0,0 +1,66 @@ +from odoo.exceptions import UserError +from odoo.tests import common + +from odoo.addons.g2p_programs.models import constants + + +class TestDefaultProgramManager(common.TransactionCase): + def setUp(self): + super(TestDefaultProgramManager, self).setUp() + + # Create a program and enroll a registrant (required for create_new_cycle) + self.program = self.env["g2p.program"].create({"name": "Test Program"}) + self.partner = self.env["res.partner"].create({"name": "Test Partner"}) + self.membership = self.env["g2p.program_membership"].create( + { + "program_id": self.program.id, + "partner_id": self.partner.id, + "state": "active", + } + ) + + # Create the default program manager for the program + self.manager = self.program.get_manager(constants.MANAGER_PROGRAM) + + def test_onchange_is_cycless_true(self): + self.manager.is_cycleless = True + + # Assert program's is_cycleless field is also set to True + self.assertEqual(self.program.is_cycleless, True) + + def test_onchange_is_cycless_false(self): + # Create a cycle to test for its removal + self.program.create_new_cycle() + + self.manager.is_cycleless = True # Set cycleless to True to create a cycle + self.manager.onchange_is_cycless() + + self.manager.is_cycleless = False + + # Assert program's is_cycleless field is also set to False + self.assertEqual(self.program.is_cycleless, False) + + # Assert the previously created cycle is removed + with self.assertRaises(AssertionError): + self.program.default_active_cycle + + def test_onchange_is_cycless_not_original_manager(self): + # Create another program manager with a name + new_manager = self.env["g2p.program.manager.default"].create( + { + "program_id": self.program.id, + "name": "Another Manager", + } + ) + + new_manager.is_cycleless = True + new_manager.onchange_is_cycless() + + # Assert changing is_cycleless on a non-original manager has no effect + self.assertFalse(self.program.is_cycleless) + + def test_onchange_is_cycleless_no_enrolled_registrants(self): + # Set manager to cycleless without enrolled registrants + with self.assertRaises(UserError): + self.manager.is_cycleless = True + self.manager.onchange_is_cycless() diff --git a/g2p_program_cycleless/tests/test_programs.py b/g2p_program_cycleless/tests/test_programs.py new file mode 100644 index 00000000..597258b2 --- /dev/null +++ b/g2p_program_cycleless/tests/test_programs.py @@ -0,0 +1,67 @@ +from unittest import mock + +from odoo.tests import common + + +class TestG2PPrograms(common.TransactionCase): + def setUp(self): + super(TestG2PPrograms, self).setUp() + + # Create a cycle-based and a cycleless program + self.cycle_based_program = self.env["g2p.program"].create( + {"name": "Cycle-Based Program"} + ) + self.cycleless_program = self.env["g2p.program"].create( + {"name": "Cycleless Program", "is_cycleless": True} + ) + + def test_default_active_cycle_cycle_based(self): + # Create two cycles with different states + cycle1 = self.cycle_based_program.create_new_cycle() + cycle2 = self.cycle_based_program.create_new_cycle() + cycle1.state = "approved" + cycle2.state = "to_approve" + + # Assert that the most recently approved cycle is the default active cycle + self.assertEqual(self.cycle_based_program.default_active_cycle, cycle1) + + def test_default_active_cycle_cycleless(self): + # Create a cycle for the cycleless program + self.cycleless_program.create_new_cycle() + + # Assert that the cycle is not assigned as the default active cycle (should be None) + self.assertFalse(self.cycleless_program.default_active_cycle) + + def test_show_cycleless_fields_cycle_based(self): + # Assert that cycleless fields are not shown for a cycle-based program + self.assertFalse(self.cycle_based_program.show_prepare_payments_button) + self.assertFalse(self.cycle_based_program.show_send_payments_button) + + def test_show_cycleless_fields_cycleless_active_with_payment_manager(self): + # Assign a payment manager to the cycleless program + self.cycleless_program.write( + {"manager_id": self.env["g2p.program.manager.phee"].create({}).id} + ) + + # Assert that cycleless payment buttons are displayed + self.assertTrue(self.cycleless_program.show_prepare_payments_button) + self.assertTrue(self.cycleless_program.show_send_payments_button) + + def test_show_cycleless_fields_cycleless_inactive(self): + # Change the program state to inactive + self.cycleless_program.state = "inactive" + + # Assert that cycleless payment buttons are not displayed + self.assertFalse(self.cycleless_program.show_prepare_payments_button) + self.assertFalse(self.cycleless_program.show_send_payments_button) + + def test_open_entitlements_form(self): + # Create a cycle for the program + cycle = self.cycle_based_program.create_new_cycle() + + # Call open_entitlements_form and assert that it calls the correct method on the cycle + with mock.patch.object( + cycle, "open_entitlements_form" + ) as mock_open_entitlements: + self.cycle_based_program.open_entitlements_form() + mock_open_entitlements.assert_called_once() diff --git a/g2p_program_documents/__init__.py b/g2p_program_documents/__init__.py index 2c0aa80c..4dc66b0d 100644 --- a/g2p_program_documents/__init__.py +++ b/g2p_program_documents/__init__.py @@ -1,2 +1,2 @@ # Part of OpenG2P. See LICENSE file for full copyright and licensing details. -from . import models +from . import models, tests diff --git a/g2p_program_documents/tests/__init__.py b/g2p_program_documents/tests/__init__.py new file mode 100644 index 00000000..bb1a1eae --- /dev/null +++ b/g2p_program_documents/tests/__init__.py @@ -0,0 +1,6 @@ +from . import test_document_file +from . import test_document_store +from . import test_entitlement +from . import test_entitlement_manager +from . import test_program +from . import test_program_membership diff --git a/g2p_program_documents/tests/test_document_file.py b/g2p_program_documents/tests/test_document_file.py new file mode 100644 index 00000000..6d913625 --- /dev/null +++ b/g2p_program_documents/tests/test_document_file.py @@ -0,0 +1,86 @@ +from datetime import datetime, timedelta + +from odoo.exceptions import AccessError +from odoo.tests.common import TransactionCase + + +class TestG2PDocument(TransactionCase): + def setUp(self): + super(TestG2PDocument, self).setUp() + + # Create necessary records or perform any setup needed for the tests + self.program = self.env["g2p.program"].create({"name": "Test Program"}) + self.partner = self.env["res.partner"].create({"name": "Test Partner"}) + self.g2p_program_membership = self.env["g2p.program_membership"].create( + { + "name": "Test Membership", + "partner_id": self.partner.id, + "program_id": self.program.id, + } + ) + self.cycle = self.env["g2p.cycle"].create( + { + "name": "Test Cycle", + "program_id": self.program.id, + "sequence": 1, + "start_date": datetime.now().strftime("%Y-%m-%d"), + "end_date": (datetime.now() + timedelta(days=30)).strftime("%Y-%m-%d"), + } + ) + + self.g2p_entitlement = self.env["g2p.entitlement"].create( + { + "name": "Test Entitlement", + "partner_id": self.partner.id, + "program_id": self.program.id, + "cycle_id": self.cycle.id, + "initial_amount": 100, + } + ) + + self.storage_file = self.env["storage.file"].create( + { + "name": "Test File", + "program_membership_id": self.g2p_program_membership.id, + "entitlement_id": self.g2p_entitlement.id, + "backend_id": 1, + } + ) + + def test_get_binary(self): + # Ensure that get_binary method creates an attachment and returns the correct result + self.storage_file.get_binary() + + # Check if the attachment is created + self.assertTrue(self.storage_file.attachment_id) + + # Check if the attachment is associated with the correct file + self.assertEqual(self.storage_file.attachment_id.res_id, self.storage_file.id) + + # Check if the attachment type is binary + self.assertEqual(self.storage_file.attachment_id.type, "binary") + + # Check if the method returns a dictionary with expected keys + binary_data = self.storage_file.get_binary() + self.assertIsInstance(binary_data, dict) + self.assertIn("id", binary_data) + self.assertIn("mimetype", binary_data) + self.assertIn("index_content", binary_data) + self.assertIn("url", binary_data) + + def test_get_binary_no_attachment(self): + # Ensure that get_binary method handles the case when no attachment is present + self.storage_file.attachment_id = False + + # Check if the method creates an attachment when there is no attachment + self.storage_file.get_binary() + + # Check if the attachment is created + self.assertTrue(self.storage_file.attachment_id) + + def test_get_binary_no_permission(self): + # Ensure that get_binary method raises AccessError when user has no permission + # For example, you might check if the user has read access to the file + with self.assertRaises(AccessError): + self.env.user.write({"groups_id": [(3, self.ref("base.group_user"))]}) + self.storage_file.get_binary() diff --git a/g2p_program_documents/tests/test_document_store.py b/g2p_program_documents/tests/test_document_store.py new file mode 100644 index 00000000..8362578a --- /dev/null +++ b/g2p_program_documents/tests/test_document_store.py @@ -0,0 +1,59 @@ +from odoo.tests.common import TransactionCase + + +class TestG2PDocumentStore(TransactionCase): + def setUp(self): + super(TestG2PDocumentStore, self).setUp() + self.G2PDocumentStore = self.env["storage.backend"] + self.program = self.env["g2p.program"].create({"name": "Test Program"}) + self.partner = self.env["res.partner"].create({"name": "Test Partner"}) + self.g2p_program_membership = self.env["g2p.program_membership"].create( + { + "name": "Test Membership", + "partner_id": self.partner.id, + "program_id": self.program.id, + } + ) + self.g2p_document_store = self.G2PDocumentStore.create( + { + "name": "Test Document Store", + # Add any other required fields + } + ) + # Create a G2PDocumentStore instance + document_store = self.env["storage.backend"].create( + { + "name": "Test Document Store", + # ... other required fields ... + } + ) + # Call add_file with a program_membership + file = document_store.add_file( + data=b"Some test data", + name="Test File", + extension="txt", + ) + # Assert that the program_membership_id is set + self.assertEqual(file.program_membership_id, self.g2p_program_membership) + + def test_add_file_calls_super_method(self): + """Test that add_file calls the superclass method correctly.""" + with self.mock_with_context( + self.env["storage.backend"]._patch_method("add_file") + ) as mock_add_file: + document_store = self.env["storage.backend"].create( + { + "name": "Test Document Store", + # ... other required fields ... + } + ) + document_store.add_file( + data=b"Some test data", + name="Test File", + extension="txt", + ) + mock_add_file.assert_called_once_with( + data=b"Some test data", + name="Test File", + extension="txt", + ) diff --git a/g2p_program_documents/tests/test_entitlement.py b/g2p_program_documents/tests/test_entitlement.py new file mode 100644 index 00000000..f53d2d40 --- /dev/null +++ b/g2p_program_documents/tests/test_entitlement.py @@ -0,0 +1,166 @@ +from datetime import datetime, timedelta + +from odoo.tests import common + + +class TestG2PEntitlement(common.TransactionCase): + def setUp(self): + super(TestG2PEntitlement, self).setUp() + self.program = self.env["g2p.program"].create({"name": "Test Program"}) + self.partner = self.env["res.partner"].create({"name": "Test Partner"}) + self.g2p_program_membership = self.env["g2p.program_membership"].create( + { + "name": "Test Membership", + "partner_id": self.partner.id, + "program_id": self.program.id, + } + ) + self.cycle = self.env["g2p.cycle"].create( + { + "name": "Test Cycle", + "program_id": self.program.id, + "sequence": 1, + "start_date": datetime.now().strftime("%Y-%m-%d"), + "end_date": (datetime.now() + timedelta(days=30)).strftime("%Y-%m-%d"), + } + ) + + self.entitlement = self.env["g2p.entitlement"].create( + { + "name": "Test Entitlement", + "partner_id": self.partner.id, + "program_id": self.program.id, + "cycle_id": self.cycle.id, + "initial_amount": 100, + } + ) + + def test_one_to_many_relationship(self): + entitlement = self.env["g2p.entitlement"].create( + { + "name": "Test Entitlement", + "partner_id": self.partner.id, + "program_id": self.program.id, + "cycle_id": self.cycle.id, + "initial_amount": 100, + } + ) + document1 = self.env["storage.file"].create( + {"name": "Document 1", "entitlement_id": entitlement.id, "backend_id": 1} + ) + document2 = self.env["storage.file"].create( + {"name": "Document 2", "entitlement_id": entitlement.id, "backend_id": 1} + ) + + self.assertEqual(entitlement.supporting_document_ids, document1 + document2) + self.assertEqual(document1.entitlement_id, entitlement) + self.assertEqual(document2.entitlement_id, entitlement) + + # Remove a document and verify the relationship and count update + document2.unlink() + self.assertEqual(entitlement.supporting_document_ids, document1) + self.assertEqual(entitlement.document_count, 1) + + def test_computed_field(self): + """Verify that the computed field 'document_count' is calculated correctly.""" + entitlement = self.env["g2p.entitlement"].create( + { + "name": "Test Entitlement", + "partner_id": self.partner.id, + "program_id": self.program.id, + "cycle_id": self.cycle.id, + "initial_amount": 100, + } + ) + self.assertEqual(entitlement.document_count, 0) + + # Create multiple documents and check the count + documents = self.env["storage.file"].create( + [ + { + "name": "Document {}".format(i), + "entitlement_id": entitlement.id, + "backend_id": 1, + } + for i in range(5) + ] + ) + self.assertEqual(entitlement.document_count, 5) + + def test_computed_field_dependency(self): + """Ensure that the computed field is correctly invalidated when its dependencies change.""" + entitlement = self.env["g2p.entitlement"].create( + { + "name": "Test Entitlement", + "partner_id": self.partner.id, + "program_id": self.program.id, + "cycle_id": self.cycle.id, + "initial_amount": 100, + } + ) + self.assertEqual(entitlement.document_count, 0) + + # Create a document and check the count + self.env["storage.file"].create( + {"name": "Document 1", "entitlement_id": entitlement.id, "backend_id": 1} + ) + self.assertEqual(entitlement.document_count, 1) + + # Modify a non-related field and check that the count remains unchanged + entitlement.write({"name": "Updated Entitlement"}) + self.assertEqual(entitlement.document_count, 1) + + def test_entitlement_copy_documents(self): + # Create a program, partner, membership, and entitlement + program = self.env["g2p.program"].create({"name": "Test Program"}) + partner = self.env["res.partner"].create({"name": "Test Beneficiary"}) + membership = self.env["g2p.program_membership"].create( + { + "program_id": program.id, + "partner_id": partner.id, + } + ) + entitlement = self.env["g2p.entitlement"].create( + { + "name": "Test Entitlement", + "partner_id": self.partner.id, + "program_id": self.program.id, + "cycle_id": self.cycle.id, + "initial_amount": 100, + } + ) + + # Create supporting documents + documents = self.env["storage.file"].create( + [ + { + "name": "Document 1", + "program_membership_id": membership.id, + "backend_id": 1, + }, + { + "name": "Document 2", + "program_membership_id": membership.id, + "backend_id": 1, + }, + ] + ) + + # Call the method to copy documents + entitlement.copy_documents_from_beneficiary() + + # Fetch updated entitlement record + entitlement = self.env["g2p.entitlement"].browse(entitlement.id) + + # Assert that the documents are not linked to previous entitlements + other_entitlement = self.env["g2p.entitlement"].create( + { + "name": "Test Entitlement", + "partner_id": self.partner.id, + "program_id": self.program.id, + "cycle_id": self.cycle.id, + "initial_amount": 100, + } + ) + self.assertFalse(other_entitlement.supporting_document_ids) + self.assertEqual(other_entitlement.document_count, 0) diff --git a/g2p_program_documents/tests/test_entitlement_manager.py b/g2p_program_documents/tests/test_entitlement_manager.py new file mode 100644 index 00000000..26731d41 --- /dev/null +++ b/g2p_program_documents/tests/test_entitlement_manager.py @@ -0,0 +1,108 @@ +from datetime import datetime, timedelta + +from odoo.exceptions import UserError +from odoo.tests import common + + +class TestDefaultEntitlementManagerForDocument(common.TransactionCase): + def setUp(self): + super(TestDefaultEntitlementManagerForDocument, self).setUp() + + # Create program, partner, membership, and document + self.program = self.env["g2p.program"].create({"name": "Test Program"}) + self.partner = self.env["res.partner"].create({"name": "Test Beneficiary"}) + self.membership = self.env["g2p.program_membership"].create( + { + "program_id": self.program.id, + "partner_id": self.partner.id, + } + ) + self.document = self.env["storage.file"].create( + { + "name": "Test Document", + "program_membership_id": self.membership.id, + "backend_id": 1, + } + ) + + # Create custom manager instance + self.manager = self.env["g2p.program.entitlement.manager.default"].create( + { + "program_id": self.program.id, + "name": "Test Manager", + } + ) + + def test_entitlement_copy_documents(self): + # Create cycle and beneficiaries + cycle = self.env["g2p.cycle"].create( + { + "name": "Test Cycle", + "program_id": self.program.id, + "sequence": 1, + "start_date": datetime.now().strftime("%Y-%m-%d"), + "end_date": (datetime.now() + timedelta(days=30)).strftime("%Y-%m-%d"), + } + ) + beneficiaries = [self.partner.id] # List of partner IDs + + # Call the method with custom manager + ents = self.manager.prepare_entitlements(cycle, beneficiaries) + + # Assert that entitlements are created and documents are copied + self.assertTrue(ents) + for ent in ents: + self.assertEqual(ent.supporting_document_ids, self.document) + + def test_entitlement_copy_documents_no_documents(self): + # No documents linked to membership + self.document.program_membership_id = False + + # Create cycle and beneficiaries + cycle = self.env["g2p.cycle"].create( + { + "name": "Test Cycle", + "program_id": self.program.id, + "sequence": 1, + "start_date": datetime.now().strftime("%Y-%m-%d"), + "end_date": (datetime.now() + timedelta(days=30)).strftime("%Y-%m-%d"), + } + ) + beneficiaries = [self.partner.id] + + # Call the method with custom manager (should not raise error) + ents = self.manager.prepare_entitlements(cycle, beneficiaries) + + # Assert that entitlements are created without documents + self.assertTrue(ents) + for ent in ents: + self.assertFalse(ent.supporting_document_ids) + + def test_entitlement_copy_documents_error(self): + # Mock a method to raise an error during document copying + def mock_copy_documents_from_beneficiary(self): + raise UserError("Test Error") + + # Patch the method with the mock + with self.env.patch.object( + self.env["g2p.entitlement"], + "copy_documents_from_beneficiary", + mock_copy_documents_from_beneficiary, + ): + # Create cycle and beneficiaries + cycle = self.env["g2p.cycle"].create( + { + "name": "Test Cycle", + "program_id": self.program.id, + "sequence": 1, + "start_date": datetime.now().strftime("%Y-%m-%d"), + "end_date": (datetime.now() + timedelta(days=30)).strftime( + "%Y-%m-%d" + ), + } + ) + beneficiaries = [self.partner.id] + + # Call the method with custom manager (should raise UserError) + with self.assertRaises(UserError): + self.manager.prepare_entitlements(cycle, beneficiaries) diff --git a/g2p_program_documents/tests/test_program.py b/g2p_program_documents/tests/test_program.py new file mode 100644 index 00000000..8350ca03 --- /dev/null +++ b/g2p_program_documents/tests/test_program.py @@ -0,0 +1,32 @@ +from odoo.tests import common + + +class TestG2PProgram(common.TransactionCase): + def setUp(self): + super(TestG2PProgram, self).setUp() + self.Program = self.env["g2p.program"] + self.StorageBackend = self.env["storage.backend"] + + def test_supporting_documents_store(self): + # Create a test storage backend + test_storage_backend = self.StorageBackend.create( + { + "name": "Test Storage Backend", + # Add any other required fields + } + ) + + # Create a test program + test_program = self.Program.create( + { + "name": "Test Program", + "supporting_documents_store": test_storage_backend.id, + # Add any other required fields + } + ) + + # Retrieve the supporting documents store for the program + supporting_documents_store = test_program.supporting_documents_store + + # Assert that the supporting documents store is correct + self.assertEqual(supporting_documents_store, test_storage_backend) diff --git a/g2p_program_documents/tests/test_program_membership.py b/g2p_program_documents/tests/test_program_membership.py new file mode 100644 index 00000000..099fe509 --- /dev/null +++ b/g2p_program_documents/tests/test_program_membership.py @@ -0,0 +1,51 @@ +from odoo.tests import common + + +class TestG2PProgramMembership(common.TransactionCase): + def setUp(self): + super(TestG2PProgramMembership, self).setUp() + self.ProgramMembership = self.env["g2p.program_membership"] + self.StorageFile = self.env["storage.file"] + self.g2p_program = self.env["g2p.program"].create( + { + "name": "Test Program", + # Add any other required fields + } + ) + + def test_supporting_documents_ids(self): + # Create a test program membership + test_program_membership = self.ProgramMembership.create( + { + "name": "Test Program Membership", + "program_id": self.g2p_program.id, + # Add any other required fields + } + ) + + # Create test supporting documents + test_document_1 = self.StorageFile.create( + { + "name": "Test Document 1", + "program_membership_id": test_program_membership.id, + "backend_id": 1 + # Add any other required fields + } + ) + + test_document_2 = self.StorageFile.create( + { + "name": "Test Document 2", + "program_membership_id": test_program_membership.id, + "backend_id": 1 + # Add any other required fields + } + ) + + # Retrieve the supporting documents for the program membership + supporting_documents = test_program_membership.supporting_documents_ids + + # Assert that the supporting documents are correct + self.assertEqual(len(supporting_documents), 2) + self.assertIn(test_document_1, supporting_documents) + self.assertIn(test_document_2, supporting_documents)