diff --git a/esi_leap/api/controllers/v1/lease.py b/esi_leap/api/controllers/v1/lease.py index cf9c95f..b5b2fd7 100644 --- a/esi_leap/api/controllers/v1/lease.py +++ b/esi_leap/api/controllers/v1/lease.py @@ -88,7 +88,7 @@ def get_one(self, lease_id): request, "esi_leap:lease:get", lease_id ) - return Lease(**utils.lease_get_dict_with_added_info(lease)) + return Lease(**self._lease_get_dict_with_added_info(lease)) @wsme_pecan.wsexpose( LeaseCollection, @@ -162,7 +162,7 @@ def get_all( leases_with_added_info = [ Lease( - **utils.lease_get_dict_with_added_info( + **self._lease_get_dict_with_added_info( lease, project_list, node_list ) ) @@ -231,7 +231,7 @@ def post(self, new_lease): lease = lease_obj.Lease(**lease_dict) lease.create(request) - return Lease(**utils.lease_get_dict_with_added_info(lease)) + return Lease(**self._lease_get_dict_with_added_info(lease)) @wsme_pecan.wsexpose(Lease, wtypes.text, body={wtypes.text: wtypes.text}) def patch(self, lease_uuid, patch=None): @@ -252,7 +252,7 @@ def patch(self, lease_uuid, patch=None): updates = {"end_time": new_end_time} lease.update(updates, request) - return Lease(**utils.lease_get_dict_with_added_info(lease)) + return Lease(**self._lease_get_dict_with_added_info(lease)) @wsme_pecan.wsexpose(Lease, wtypes.text) def delete(self, lease_id): @@ -339,3 +339,15 @@ def _lease_get_all_authorize_filters( del filters[k] return filters + + @staticmethod + def _lease_get_dict_with_added_info(lease, project_list=None, node_list=None): + resource = lease.resource_object() + + lease_dict = lease.to_dict() + lease_dict["project"] = idp.get_project_name(lease.project_id, project_list) + lease_dict["owner"] = idp.get_project_name(lease.owner_id, project_list) + lease_dict["resource"] = resource.get_name(node_list) + lease_dict["resource_class"] = resource.get_resource_class(node_list) + lease_dict["resource_properties"] = resource.get_properties(node_list) + return lease_dict diff --git a/esi_leap/api/controllers/v1/offer.py b/esi_leap/api/controllers/v1/offer.py index 50ab2fb..6547e27 100644 --- a/esi_leap/api/controllers/v1/offer.py +++ b/esi_leap/api/controllers/v1/offer.py @@ -91,7 +91,7 @@ def get_one(self, offer_id): ) utils.check_offer_lessee(cdict, offer) - o = utils.offer_get_dict_with_added_info(offer) + o = self._offer_get_dict_with_added_info(offer) return Offer(**o) @@ -199,7 +199,7 @@ def get_all( offers_with_added_info = [ Offer( - **utils.offer_get_dict_with_added_info(o, project_list, node_list) + **self._offer_get_dict_with_added_info(o, project_list, node_list) ) for o in offers ] @@ -263,7 +263,7 @@ def post(self, new_offer): o = offer_obj.Offer(**offer_dict) o.create() - return Offer(**utils.offer_get_dict_with_added_info(o)) + return Offer(**self._offer_get_dict_with_added_info(o)) @wsme_pecan.wsexpose(Offer, wtypes.text) def delete(self, offer_id): @@ -321,4 +321,19 @@ def claim(self, offer_uuid, new_lease): new_lease = lease_obj.Lease(**lease_dict) new_lease.create(request) - return lease.Lease(**utils.lease_get_dict_with_added_info(new_lease)) + return lease.Lease( + **lease.LeasesController._lease_get_dict_with_added_info(new_lease) + ) + + @staticmethod + def _offer_get_dict_with_added_info(offer, project_list=None, node_list=None): + resource = offer.resource_object() + + o = offer.to_dict() + o["availabilities"] = offer.get_availabilities() + o["project"] = idp.get_project_name(offer.project_id, project_list) + o["lessee"] = idp.get_project_name(offer.lessee_id, project_list) + o["resource"] = resource.get_name(node_list) + o["resource_class"] = resource.get_resource_class(node_list) + o["resource_properties"] = resource.get_properties(node_list) + return o diff --git a/esi_leap/api/controllers/v1/utils.py b/esi_leap/api/controllers/v1/utils.py index ec7f107..9eb0102 100644 --- a/esi_leap/api/controllers/v1/utils.py +++ b/esi_leap/api/controllers/v1/utils.py @@ -154,31 +154,6 @@ def check_offer_lessee(cdict, offer): ) -def offer_get_dict_with_added_info(offer, project_list=None, node_list=None): - resource = offer.resource_object() - - o = offer.to_dict() - o["availabilities"] = offer.get_availabilities() - o["project"] = idp.get_project_name(offer.project_id, project_list) - o["lessee"] = idp.get_project_name(offer.lessee_id, project_list) - o["resource"] = resource.get_name(node_list) - o["resource_class"] = resource.get_resource_class(node_list) - o["resource_properties"] = resource.get_properties(node_list) - return o - - -def lease_get_dict_with_added_info(lease, project_list=None, node_list=None): - resource = lease.resource_object() - - lease_dict = lease.to_dict() - lease_dict["project"] = idp.get_project_name(lease.project_id, project_list) - lease_dict["owner"] = idp.get_project_name(lease.owner_id, project_list) - lease_dict["resource"] = resource.get_name(node_list) - lease_dict["resource_class"] = resource.get_resource_class(node_list) - lease_dict["resource_properties"] = resource.get_properties(node_list) - return lease_dict - - def check_lease_length(cdict, start_time, end_time, max_time): if (end_time - start_time) > datetime.timedelta(days=max_time): # Check if the current project is admin diff --git a/esi_leap/tests/api/controllers/v1/test_lease.py b/esi_leap/tests/api/controllers/v1/test_lease.py index ea08728..c5e7a69 100644 --- a/esi_leap/tests/api/controllers/v1/test_lease.py +++ b/esi_leap/tests/api/controllers/v1/test_lease.py @@ -25,6 +25,7 @@ from esi_leap.resource_objects.ironic_node import IronicNode from esi_leap.resource_objects.fake_node import FakeNode from esi_leap.tests.api import base as test_api_base +from esi_leap.conf import CONF class TestLeasesController(test_api_base.APITestCase): @@ -68,7 +69,9 @@ def test_empty(self): @mock.patch("esi_leap.common.ironic.get_node_list") @mock.patch("esi_leap.common.idp.get_project_list") - @mock.patch("esi_leap.api.controllers.v1.utils." "lease_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info" + ) @mock.patch("esi_leap.objects.lease.Lease.get_all") def test_one(self, mock_ga, mock_lgdwai, mock_gpl, mock_gnl): mock_ga.return_value = [self.test_lease] @@ -83,7 +86,9 @@ def test_one(self, mock_ga, mock_lgdwai, mock_gpl, mock_gnl): mock_gnl.assert_called_once() mock_lgdwai.assert_called_once() - @mock.patch("esi_leap.api.controllers.v1.utils." "lease_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info" + ) @mock.patch("esi_leap.api.controllers.v1.lease.get_resource_object") @mock.patch("esi_leap.common.idp.get_project_uuid_from_ident") @mock.patch("oslo_utils.uuidutils.generate_uuid") @@ -131,7 +136,9 @@ def test_post( self.assertEqual(return_data, request.json) self.assertEqual(http_client.CREATED, request.status_int) - @mock.patch("esi_leap.api.controllers.v1.utils." "lease_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info" + ) @mock.patch("esi_leap.api.controllers.v1.lease.get_resource_object") @mock.patch("esi_leap.common.idp.get_project_uuid_from_ident") @mock.patch("oslo_utils.uuidutils.generate_uuid") @@ -178,7 +185,9 @@ def test_post_default_resource_type( self.assertEqual(return_data, request.json) self.assertEqual(http_client.CREATED, request.status_int) - @mock.patch("esi_leap.api.controllers.v1.utils." "lease_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info" + ) @mock.patch("esi_leap.api.controllers.v1.utils." "check_resource_lease_admin") @mock.patch("esi_leap.api.controllers.v1.lease.get_resource_object") @mock.patch("esi_leap.common.idp.get_project_uuid_from_ident") @@ -281,7 +290,9 @@ def test_post_non_admin_no_parent_lease( mock_create.assert_not_called() self.assertEqual(http_client.FORBIDDEN, request.status_int) - @mock.patch("esi_leap.api.controllers.v1.utils." "lease_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info" + ) @mock.patch("esi_leap.objects.lease.Lease.update") @mock.patch("esi_leap.api.controllers.v1.utils." "check_lease_policy_and_retrieve") def test_patch(self, mock_clpar, mock_lease_update, mock_lgdwai): @@ -297,7 +308,9 @@ def test_patch(self, mock_clpar, mock_lease_update, mock_lgdwai): mock_lgdwai.assert_called_once() self.assertEqual(http_client.OK, request.status_int) - @mock.patch("esi_leap.api.controllers.v1.utils." "lease_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info" + ) @mock.patch("esi_leap.objects.lease.Lease.update") @mock.patch("esi_leap.api.controllers.v1.utils." "check_lease_policy_and_retrieve") def test_patch_no_end_time(self, mock_clpar, mock_lease_update, mock_lgdwai): @@ -315,7 +328,9 @@ def test_patch_no_end_time(self, mock_clpar, mock_lease_update, mock_lgdwai): mock_lgdwai.assert_not_called() self.assertEqual(http_client.INTERNAL_SERVER_ERROR, request.status_int) - @mock.patch("esi_leap.api.controllers.v1.utils." "lease_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info" + ) @mock.patch("esi_leap.objects.lease.Lease.update") @mock.patch("esi_leap.api.controllers.v1.utils." "check_lease_policy_and_retrieve") def test_patch_end_time_and_more(self, mock_clpar, mock_lease_update, mock_lgdwai): @@ -335,7 +350,9 @@ def test_patch_end_time_and_more(self, mock_clpar, mock_lease_update, mock_lgdwa @mock.patch("esi_leap.common.ironic.get_node_list") @mock.patch("esi_leap.common.idp.get_project_list") - @mock.patch("esi_leap.api.controllers.v1.utils." "lease_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info" + ) @mock.patch( "esi_leap.api.controllers.v1.lease.LeasesController." "_lease_get_all_authorize_filters" @@ -369,7 +386,9 @@ def test_get_nofilters( @mock.patch("esi_leap.common.ironic.get_node_list") @mock.patch("esi_leap.common.idp.get_project_list") - @mock.patch("esi_leap.api.controllers.v1.utils." "lease_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info" + ) @mock.patch("esi_leap.common.idp.get_project_uuid_from_ident") @mock.patch( "esi_leap.api.controllers.v1.lease.LeasesController." @@ -405,7 +424,9 @@ def test_get_project_filter( @mock.patch("esi_leap.common.ironic.get_node_list") @mock.patch("esi_leap.common.idp.get_project_list") - @mock.patch("esi_leap.api.controllers.v1.utils." "lease_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info" + ) @mock.patch("esi_leap.common.idp.get_project_uuid_from_ident") @mock.patch( "esi_leap.api.controllers.v1.lease.LeasesController." @@ -443,7 +464,9 @@ def test_get_owner_filter( @mock.patch("esi_leap.common.ironic.get_node_list") @mock.patch("esi_leap.common.idp.get_project_list") - @mock.patch("esi_leap.api.controllers.v1.utils." "lease_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info" + ) @mock.patch("esi_leap.api.controllers.v1.lease.get_resource_object") @mock.patch( "esi_leap.api.controllers.v1.lease.LeasesController." @@ -481,7 +504,9 @@ def test_get_resource_filter( @mock.patch("esi_leap.common.ironic.get_node_list") @mock.patch("esi_leap.common.idp.get_project_list") - @mock.patch("esi_leap.api.controllers.v1.utils." "lease_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info" + ) @mock.patch( "esi_leap.api.controllers.v1.lease.LeasesController." "_lease_get_all_authorize_filters" @@ -547,7 +572,9 @@ def _get_lease_response(lease, use_datetime=False): @mock.patch("esi_leap.common.ironic.get_node_list") @mock.patch("esi_leap.common.idp.get_project_list") - @mock.patch("esi_leap.api.controllers.v1.utils." "lease_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info" + ) @mock.patch("esi_leap.api.controllers.v1.lease.get_resource_object") @mock.patch( "esi_leap.api.controllers.v1.lease.LeasesController." @@ -604,6 +631,7 @@ class TestLeaseControllersGetAllFilters(testtools.TestCase): def setUp(self): super(TestLeaseControllersGetAllFilters, self).setUp() + CONF.set_override("auth_enable", True, group="pecan") self.admin_ctx = ctx.RequestContext(project_id="adminid", roles=["admin"]) self.owner_ctx = ctx.RequestContext(project_id="ownerid", roles=["owner"]) self.lessee_ctx = ctx.RequestContext(project_id="lesseeid", roles=["lessee"]) diff --git a/esi_leap/tests/api/controllers/v1/test_offer.py b/esi_leap/tests/api/controllers/v1/test_offer.py index e6c0037..73c0faf 100644 --- a/esi_leap/tests/api/controllers/v1/test_offer.py +++ b/esi_leap/tests/api/controllers/v1/test_offer.py @@ -120,7 +120,9 @@ def test_empty(self): @mock.patch("oslo_utils.uuidutils.generate_uuid") @mock.patch("esi_leap.api.controllers.v1.utils.check_resource_admin") @mock.patch("esi_leap.objects.offer.Offer.create") - @mock.patch("esi_leap.api.controllers.v1.utils." "offer_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info" + ) def test_post( self, mock_ogdwai, mock_create, mock_cra, mock_generate_uuid, mock_gro ): @@ -160,7 +162,9 @@ def test_post( @mock.patch("oslo_utils.uuidutils.generate_uuid") @mock.patch("esi_leap.api.controllers.v1.utils.check_resource_admin") @mock.patch("esi_leap.objects.offer.Offer.create") - @mock.patch("esi_leap.api.controllers.v1.utils." "offer_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info" + ) def test_post_default_resource_type( self, mock_ogdwai, mock_create, mock_cra, mock_generate_uuid, mock_gro ): @@ -200,7 +204,9 @@ def test_post_default_resource_type( @mock.patch("oslo_utils.uuidutils.generate_uuid") @mock.patch("esi_leap.api.controllers.v1.utils.check_resource_admin") @mock.patch("esi_leap.objects.offer.Offer.create") - @mock.patch("esi_leap.api.controllers.v1.utils." "offer_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info" + ) def test_post_lessee( self, mock_ogdwai, @@ -250,7 +256,9 @@ def test_post_lessee( @mock.patch("oslo_utils.uuidutils.generate_uuid") @mock.patch("esi_leap.api.controllers.v1.utils.check_resource_admin") @mock.patch("esi_leap.objects.offer.Offer.create") - @mock.patch("esi_leap.api.controllers.v1.utils." "offer_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info" + ) def test_post_non_admin_parent_lease( self, mock_ogdwai, @@ -310,7 +318,9 @@ def test_post_non_admin_parent_lease( @mock.patch("oslo_utils.uuidutils.generate_uuid") @mock.patch("esi_leap.api.controllers.v1.utils.check_resource_admin") @mock.patch("esi_leap.objects.offer.Offer.create") - @mock.patch("esi_leap.api.controllers.v1.utils." "offer_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info" + ) def test_post_non_admin_no_parent_lease( self, mock_ogdwai, @@ -361,7 +371,9 @@ def test_post_non_admin_no_parent_lease( @mock.patch("esi_leap.common.ironic.get_node_list") @mock.patch("esi_leap.common.idp.get_project_list") - @mock.patch("esi_leap.api.controllers.v1.utils." "offer_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info" + ) @mock.patch("esi_leap.objects.offer.Offer.get_all") def test_get_nofilters(self, mock_get_all, mock_ogdwai, mock_gpl, mock_gnl): mock_get_all.return_value = [self.test_offer, self.test_offer_2] @@ -390,7 +402,9 @@ def test_get_nofilters(self, mock_get_all, mock_ogdwai, mock_gpl, mock_gnl): @mock.patch("esi_leap.common.ironic.get_node_list") @mock.patch("esi_leap.common.idp.get_project_list") - @mock.patch("esi_leap.api.controllers.v1.utils." "offer_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info" + ) @mock.patch("esi_leap.objects.offer.Offer.get_all") def test_get_any_status(self, mock_get_all, mock_ogdwai, mock_gpl, mock_gnl): mock_get_all.return_value = [self.test_offer, self.test_offer_2] @@ -419,7 +433,9 @@ def test_get_any_status(self, mock_get_all, mock_ogdwai, mock_gpl, mock_gnl): @mock.patch("esi_leap.common.ironic.get_node_list") @mock.patch("esi_leap.common.idp.get_project_list") - @mock.patch("esi_leap.api.controllers.v1.utils." "offer_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info" + ) @mock.patch("esi_leap.objects.offer.Offer.get_all") def test_get_status_filter(self, mock_get_all, mock_ogdwai, mock_gpl, mock_gnl): mock_get_all.return_value = [self.test_offer, self.test_offer_2] @@ -449,7 +465,9 @@ def test_get_status_filter(self, mock_get_all, mock_ogdwai, mock_gpl, mock_gnl): @mock.patch("esi_leap.common.ironic.get_node_list") @mock.patch("esi_leap.common.idp.get_project_list") @mock.patch("esi_leap.common.idp.get_project_uuid_from_ident") - @mock.patch("esi_leap.api.controllers.v1.utils." "offer_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info" + ) @mock.patch("esi_leap.objects.offer.Offer.get_all") def test_get_project_filter( self, mock_get_all, mock_ogdwai, mock_gpufi, mock_gpl, mock_gnl @@ -486,7 +504,9 @@ def test_get_project_filter( @mock.patch("esi_leap.common.ironic.get_node_list") @mock.patch("esi_leap.common.idp.get_project_list") @mock.patch("esi_leap.api.controllers.v1.offer.get_resource_object") - @mock.patch("esi_leap.api.controllers.v1.utils." "offer_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info" + ) @mock.patch("esi_leap.objects.offer.Offer.get_all") def test_get_resource_filter( self, mock_get_all, mock_ogdwai, mock_gro, mock_gpl, mock_gnl @@ -525,7 +545,9 @@ def test_get_resource_filter( @mock.patch("esi_leap.common.ironic.get_node_list") @mock.patch("esi_leap.common.idp.get_project_list") - @mock.patch("esi_leap.api.controllers.v1.utils." "offer_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info" + ) @mock.patch("esi_leap.objects.offer.Offer.get_all") def test_get_resource_class_filter( self, mock_get_all, mock_ogdwai, mock_gpl, mock_gnl @@ -560,7 +582,9 @@ def test_get_resource_class_filter( @mock.patch("esi_leap.common.ironic.get_node_list") @mock.patch("esi_leap.common.idp.get_project_list") @mock.patch("esi_leap.api.controllers.v1.offer.get_resource_object") - @mock.patch("esi_leap.api.controllers.v1.utils." "offer_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info" + ) @mock.patch("esi_leap.objects.offer.Offer.get_all") def test_get_resource_filter_default_resource_type( self, mock_get_all, mock_ogdwai, mock_gro, mock_gpl, mock_gnl @@ -597,7 +621,9 @@ def test_get_resource_filter_default_resource_type( @mock.patch("esi_leap.common.ironic.get_node_list") @mock.patch("esi_leap.common.idp.get_project_list") - @mock.patch("esi_leap.api.controllers.v1.utils." "offer_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info" + ) @mock.patch("esi_leap.objects.offer.Offer.get_all") @mock.patch("esi_leap.api.controllers.v1.utils.policy_authorize") def test_get_lessee_filter( @@ -636,7 +662,9 @@ def test_get_lessee_filter( @mock.patch("esi_leap.api.controllers.v1.utils.check_offer_lessee") @mock.patch("esi_leap.api.controllers.v1.utils." "check_offer_policy_and_retrieve") - @mock.patch("esi_leap.api.controllers.v1.utils." "offer_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info" + ) def test_get_one(self, mock_ogdwai, mock_copar, mock_col): mock_copar.return_value = self.test_offer mock_ogdwai.return_value = self.test_offer.to_dict() @@ -654,7 +682,9 @@ def test_get_one(self, mock_ogdwai, mock_copar, mock_col): @mock.patch("esi_leap.objects.lease.Lease.create") @mock.patch("esi_leap.api.controllers.v1.utils.check_offer_lessee") @mock.patch("esi_leap.api.controllers.v1.utils." "check_offer_policy_and_retrieve") - @mock.patch("esi_leap.api.controllers.v1.utils." "lease_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info" + ) def test_claim(self, mock_lgdwai, mock_copar, mock_col, mock_lease_create): lease_uuid = uuidutils.generate_uuid() @@ -685,7 +715,9 @@ def test_claim(self, mock_lgdwai, mock_copar, mock_col, mock_lease_create): @mock.patch("esi_leap.objects.lease.Lease.create") @mock.patch("esi_leap.api.controllers.v1.utils.check_offer_lessee") @mock.patch("esi_leap.api.controllers.v1.utils." "check_offer_policy_and_retrieve") - @mock.patch("esi_leap.api.controllers.v1.utils." "lease_get_dict_with_added_info") + @mock.patch( + "esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info" + ) def test_claim_parent_lease( self, mock_lgdwai, mock_copar, mock_col, mock_lease_create ): diff --git a/esi_leap/tests/api/controllers/v1/test_utils.py b/esi_leap/tests/api/controllers/v1/test_utils.py index d383bfe..802636b 100644 --- a/esi_leap/tests/api/controllers/v1/test_utils.py +++ b/esi_leap/tests/api/controllers/v1/test_utils.py @@ -19,6 +19,8 @@ import testtools from esi_leap.api.controllers.v1 import utils +from esi_leap.api.controllers.v1 import lease as lease_controller +from esi_leap.api.controllers.v1 import offer as offer_controller from esi_leap.common import exception from esi_leap.common import policy from esi_leap.common import statuses @@ -650,7 +652,7 @@ def test_offer_get_dict_with_added_info(self, mock_get_availabilities, mock_gpn) lessee_id=None, ) - o_dict = utils.offer_get_dict_with_added_info(o) + o_dict = offer_controller.OffersController._offer_get_dict_with_added_info(o) expected_offer_dict = { "resource_type": o.resource_type, @@ -696,7 +698,9 @@ def test_lease_get_dict_with_added_info(self, mock_gro, mock_gpn, mock_gn): mock_gpn.return_value = "project-name" mock_gn.return_value = "resource-name" - output_dict = utils.lease_get_dict_with_added_info(self.test_lease) + output_dict = lease_controller.LeasesController._lease_get_dict_with_added_info( + self.test_lease + ) expected_output_dict = self.test_lease.to_dict() expected_output_dict["resource"] = "resource-name"