Skip to content

Commit

Permalink
Testing auth_enable
Browse files Browse the repository at this point in the history
  • Loading branch information
QuanMPhm committed Jul 22, 2024
1 parent 1ebdde0 commit 2dc2d1e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
4 changes: 3 additions & 1 deletion esi_leap/api/controllers/v1/offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ 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):
Expand Down
2 changes: 2 additions & 0 deletions esi_leap/tests/api/controllers/v1/test_lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -630,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"])
Expand Down
4 changes: 3 additions & 1 deletion esi_leap/tests/api/controllers/v1/test_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,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
):
Expand Down
19 changes: 12 additions & 7 deletions esi_leap/tests/api/controllers/v1/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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
Expand All @@ -28,12 +29,6 @@
from esi_leap.resource_objects.fake_node import FakeNode
from esi_leap.conf import CONF


CONF.set_override(
"idp_plugin_class", "esi_leap.common.idp.dummyIDP.DummyIDP", group="esi"
)


admin_ctx = ctx.RequestContext(project_id="adminid", roles=["admin"])

owner_ctx = ctx.RequestContext(project_id="ownerid", roles=["owner"])
Expand Down Expand Up @@ -495,6 +490,12 @@ def test_check_lease_policy(self, mock_get_lease, mock_authorize):


class TestOfferLesseeUtils(testtools.TestCase):
def setUp(self):
super(TestOfferLesseeUtils, self).setUp()
CONF.set_override(
"idp_plugin_class", "esi_leap.common.idp.dummyIDP.DummyIDP", group="esi"
)

@mock.patch("esi_leap.api.controllers.v1.utils.policy_authorize")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_parent_project_id_tree")
def test_check_offer_lessee_no_lessee_id(self, mock_gppit, mock_authorize):
Expand Down Expand Up @@ -695,11 +696,15 @@ def setUp(self):
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_name")
@mock.patch("esi_leap.objects.lease.get_resource_object")
def test_lease_get_dict_with_added_info(self, mock_gro, mock_gpn, mock_gn):
print("--- in test_lease_get_dict_with_added_info")
print("conf idp set as: ", CONF.esi.idp_plugin_class)
mock_gro.return_value = FakeNode("111")
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"
Expand Down

0 comments on commit 2dc2d1e

Please sign in to comment.