Skip to content

Commit

Permalink
Fixing test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
QuanMPhm committed Jul 22, 2024
1 parent fbfe0db commit 1ebdde0
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 39 deletions.
6 changes: 3 additions & 3 deletions esi_leap/tests/api/controllers/v1/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def setUp(self):
super(TestEventsController, self).setUp()

@mock.patch("esi_leap.api.controllers.v1.utils.policy_authorize")
@mock.patch("esi_leap.common.keystone.get_project_uuid_from_ident")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_uuid_from_ident")
@mock.patch("esi_leap.api.controllers.v1.event.get_resource_object")
@mock.patch("esi_leap.objects.event.Event.get_all")
def test_get_all(self, mock_ega, mock_gro, mock_gpufi, mock_pa):
Expand All @@ -55,7 +55,7 @@ def test_get_all(self, mock_ega, mock_gro, mock_gpufi, mock_pa):
self.assertEqual(data["events"][0]["id"], 1)

@mock.patch("esi_leap.api.controllers.v1.utils.policy_authorize")
@mock.patch("esi_leap.common.keystone.get_project_uuid_from_ident")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_uuid_from_ident")
@mock.patch("esi_leap.api.controllers.v1.event.get_resource_object")
@mock.patch("esi_leap.objects.event.Event.get_all")
def test_get_all_not_admin(self, mock_ega, mock_gro, mock_gpufi, mock_pa):
Expand All @@ -75,7 +75,7 @@ def test_get_all_not_admin(self, mock_ega, mock_gro, mock_gpufi, mock_pa):
self.assertEqual(data["events"][0]["id"], 1)

@mock.patch("esi_leap.api.controllers.v1.utils.policy_authorize")
@mock.patch("esi_leap.common.keystone.get_project_uuid_from_ident")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_uuid_from_ident")
@mock.patch("esi_leap.api.controllers.v1.event.get_resource_object")
@mock.patch("esi_leap.objects.event.Event.get_all")
def test_get_all_resource_filter(self, mock_ega, mock_gro, mock_gpufi, mock_pa):
Expand Down
26 changes: 13 additions & 13 deletions esi_leap/tests/api/controllers/v1/test_lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_empty(self):
self.assertEqual([], data["leases"])

@mock.patch("esi_leap.common.ironic.get_node_list")
@mock.patch("esi_leap.common.keystone.get_project_list")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_list")
@mock.patch(
"esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info"
)
Expand All @@ -89,7 +89,7 @@ def test_one(self, mock_ga, mock_lgdwai, mock_gpl, mock_gnl):
"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.keystone.get_project_uuid_from_ident")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_uuid_from_ident")
@mock.patch("oslo_utils.uuidutils.generate_uuid")
@mock.patch("esi_leap.api.controllers.v1.utils.check_resource_admin")
@mock.patch("esi_leap.objects.lease.Lease.create")
Expand Down Expand Up @@ -139,7 +139,7 @@ def test_post(
"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.keystone.get_project_uuid_from_ident")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_uuid_from_ident")
@mock.patch("oslo_utils.uuidutils.generate_uuid")
@mock.patch("esi_leap.api.controllers.v1.utils.check_resource_admin")
@mock.patch("esi_leap.objects.lease.Lease.create")
Expand Down Expand Up @@ -189,7 +189,7 @@ def test_post_default_resource_type(
)
@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.keystone.get_project_uuid_from_ident")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_uuid_from_ident")
@mock.patch("oslo_utils.uuidutils.generate_uuid")
@mock.patch("esi_leap.api.controllers.v1.utils.check_resource_admin")
@mock.patch("esi_leap.objects.lease.Lease.create")
Expand Down Expand Up @@ -249,7 +249,7 @@ def test_post_non_admin_parent_lease(

@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.keystone.get_project_uuid_from_ident")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_uuid_from_ident")
@mock.patch("oslo_utils.uuidutils.generate_uuid")
@mock.patch("esi_leap.api.controllers.v1.utils.check_resource_admin")
@mock.patch("esi_leap.objects.lease.Lease.create")
Expand Down Expand Up @@ -348,7 +348,7 @@ def test_patch_end_time_and_more(self, mock_clpar, mock_lease_update, mock_lgdwa
self.assertEqual(http_client.INTERNAL_SERVER_ERROR, request.status_int)

@mock.patch("esi_leap.common.ironic.get_node_list")
@mock.patch("esi_leap.common.keystone.get_project_list")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_list")
@mock.patch(
"esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info"
)
Expand Down Expand Up @@ -384,11 +384,11 @@ def test_get_nofilters(
self.assertEqual(2, mock_lgdwai.call_count)

@mock.patch("esi_leap.common.ironic.get_node_list")
@mock.patch("esi_leap.common.keystone.get_project_list")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_list")
@mock.patch(
"esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info"
)
@mock.patch("esi_leap.common.keystone.get_project_uuid_from_ident")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_uuid_from_ident")
@mock.patch(
"esi_leap.api.controllers.v1.lease.LeasesController."
"_lease_get_all_authorize_filters"
Expand Down Expand Up @@ -422,11 +422,11 @@ def test_get_project_filter(
self.assertEqual(2, mock_lgdwai.call_count)

@mock.patch("esi_leap.common.ironic.get_node_list")
@mock.patch("esi_leap.common.keystone.get_project_list")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_list")
@mock.patch(
"esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info"
)
@mock.patch("esi_leap.common.keystone.get_project_uuid_from_ident")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_uuid_from_ident")
@mock.patch(
"esi_leap.api.controllers.v1.lease.LeasesController."
"_lease_get_all_authorize_filters"
Expand Down Expand Up @@ -462,7 +462,7 @@ def test_get_owner_filter(
self.assertEqual(2, mock_lgdwai.call_count)

@mock.patch("esi_leap.common.ironic.get_node_list")
@mock.patch("esi_leap.common.keystone.get_project_list")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_list")
@mock.patch(
"esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info"
)
Expand Down Expand Up @@ -502,7 +502,7 @@ def test_get_resource_filter(
self.assertEqual(2, mock_lgdwai.call_count)

@mock.patch("esi_leap.common.ironic.get_node_list")
@mock.patch("esi_leap.common.keystone.get_project_list")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_list")
@mock.patch(
"esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info"
)
Expand Down Expand Up @@ -570,7 +570,7 @@ def _get_lease_response(lease, use_datetime=False):
self.assertEqual(response, expected_resp)

@mock.patch("esi_leap.common.ironic.get_node_list")
@mock.patch("esi_leap.common.keystone.get_project_list")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_list")
@mock.patch(
"esi_leap.api.controllers.v1.lease.LeasesController._lease_get_dict_with_added_info"
)
Expand Down
12 changes: 6 additions & 6 deletions esi_leap/tests/api/controllers/v1/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def setUp(self):
@mock.patch("esi_leap.common.ironic.get_node_list")
@mock.patch("esi_leap.objects.offer.Offer.get_all")
@mock.patch("esi_leap.objects.lease.Lease.get_all")
@mock.patch("esi_leap.common.keystone.get_project_list")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_list")
def test_get_all(self, mock_gpl, mock_lga, mock_oga, mock_gnl):
fake_node = FakeIronicNode()
fake_project = FakeProject()
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_get_all(self, mock_gpl, mock_lga, mock_oga, mock_gnl):
self.assertEqual(data["nodes"][0]["future_leases"], ["fake-future-lease-uuid"])

@mock.patch("esi_leap.common.ironic.get_node_list")
@mock.patch("esi_leap.common.keystone.get_project_list")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_list")
def test_get_all_resource_class_filter(self, mock_gpl, mock_gnl):
fake_node = FakeIronicNode()
fake_project = FakeProject()
Expand All @@ -109,8 +109,8 @@ def test_get_all_resource_class_filter(self, mock_gpl, mock_gnl):
self.assertEqual(data["nodes"][0]["resource_class"], "baremetal")

@mock.patch("esi_leap.common.ironic.get_node_list")
@mock.patch("esi_leap.common.keystone.get_project_list")
@mock.patch("esi_leap.common.keystone.get_project_uuid_from_ident")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_list")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_uuid_from_ident")
def test_get_all_owner_filter(self, mock_get_project_uuid, mock_gpl, mock_gnl):
fake_node = FakeIronicNode()
fake_project = FakeProject()
Expand All @@ -127,8 +127,8 @@ def test_get_all_owner_filter(self, mock_get_project_uuid, mock_gpl, mock_gnl):
self.assertEqual(data["nodes"][0]["owner"], fake_project.name)

@mock.patch("esi_leap.common.ironic.get_node_list")
@mock.patch("esi_leap.common.keystone.get_project_list")
@mock.patch("esi_leap.common.keystone.get_project_uuid_from_ident")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_list")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_uuid_from_ident")
def test_get_all_lesse_filter(self, mock_get_project_uuid, mock_gpl, mock_gnl):
fake_node = FakeIronicNode()
fake_project = FakeProject()
Expand Down
20 changes: 10 additions & 10 deletions esi_leap/tests/api/controllers/v1/test_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def test_post_default_resource_type(
self.assertEqual(http_client.CREATED, request.status_int)

@mock.patch("esi_leap.api.controllers.v1.offer.get_resource_object")
@mock.patch("esi_leap.common.keystone.get_project_uuid_from_ident")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_uuid_from_ident")
@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")
Expand Down Expand Up @@ -370,7 +370,7 @@ def test_post_non_admin_no_parent_lease(
self.assertEqual(http_client.FORBIDDEN, request.status_int)

@mock.patch("esi_leap.common.ironic.get_node_list")
@mock.patch("esi_leap.common.keystone.get_project_list")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_list")
@mock.patch(
"esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info"
)
Expand Down Expand Up @@ -401,7 +401,7 @@ def test_get_nofilters(self, mock_get_all, mock_ogdwai, mock_gpl, mock_gnl):
self.assertEqual(request, expected_resp)

@mock.patch("esi_leap.common.ironic.get_node_list")
@mock.patch("esi_leap.common.keystone.get_project_list")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_list")
@mock.patch(
"esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info"
)
Expand Down Expand Up @@ -432,7 +432,7 @@ def test_get_any_status(self, mock_get_all, mock_ogdwai, mock_gpl, mock_gnl):
self.assertEqual(request, expected_resp)

@mock.patch("esi_leap.common.ironic.get_node_list")
@mock.patch("esi_leap.common.keystone.get_project_list")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_list")
@mock.patch(
"esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info"
)
Expand Down Expand Up @@ -463,8 +463,8 @@ def test_get_status_filter(self, mock_get_all, mock_ogdwai, mock_gpl, mock_gnl):
self.assertEqual(request, expected_resp)

@mock.patch("esi_leap.common.ironic.get_node_list")
@mock.patch("esi_leap.common.keystone.get_project_list")
@mock.patch("esi_leap.common.keystone.get_project_uuid_from_ident")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_list")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_uuid_from_ident")
@mock.patch(
"esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info"
)
Expand Down Expand Up @@ -502,7 +502,7 @@ def test_get_project_filter(
self.assertEqual(request, expected_resp)

@mock.patch("esi_leap.common.ironic.get_node_list")
@mock.patch("esi_leap.common.keystone.get_project_list")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_list")
@mock.patch("esi_leap.api.controllers.v1.offer.get_resource_object")
@mock.patch(
"esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info"
Expand Down Expand Up @@ -544,7 +544,7 @@ def test_get_resource_filter(
self.assertEqual(request, expected_resp)

@mock.patch("esi_leap.common.ironic.get_node_list")
@mock.patch("esi_leap.common.keystone.get_project_list")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_list")
@mock.patch(
"esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info"
)
Expand Down Expand Up @@ -580,7 +580,7 @@ def test_get_resource_class_filter(
self.assertEqual(request, expected_resp)

@mock.patch("esi_leap.common.ironic.get_node_list")
@mock.patch("esi_leap.common.keystone.get_project_list")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_list")
@mock.patch("esi_leap.api.controllers.v1.offer.get_resource_object")
@mock.patch(
"esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info"
Expand Down Expand Up @@ -620,7 +620,7 @@ def test_get_resource_filter_default_resource_type(
self.assertEqual(request, expected_resp)

@mock.patch("esi_leap.common.ironic.get_node_list")
@mock.patch("esi_leap.common.keystone.get_project_list")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_list")
@mock.patch(
"esi_leap.api.controllers.v1.offer.OffersController._offer_get_dict_with_added_info"
)
Expand Down
20 changes: 13 additions & 7 deletions esi_leap/tests/api/controllers/v1/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
from esi_leap.objects import lease
from esi_leap.objects import offer
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"])
Expand Down Expand Up @@ -490,15 +496,15 @@ def test_check_lease_policy(self, mock_get_lease, mock_authorize):

class TestOfferLesseeUtils(testtools.TestCase):
@mock.patch("esi_leap.api.controllers.v1.utils.policy_authorize")
@mock.patch("esi_leap.common.keystone.get_parent_project_id_tree")
@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):
utils.check_offer_lessee(lessee_ctx.to_policy_values(), test_offer)

assert not mock_authorize.called
assert not mock_gppit.called

@mock.patch.object(policy, "authorize", spec=True)
@mock.patch("esi_leap.common.keystone.get_parent_project_id_tree")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_parent_project_id_tree")
def test_check_offer_lessee_owner_match(self, mock_gppit, mock_authorize):
utils.check_offer_lessee(
owner_ctx.to_policy_values(), test_offer_lessee_no_match
Expand All @@ -508,7 +514,7 @@ def test_check_offer_lessee_owner_match(self, mock_gppit, mock_authorize):
assert not mock_gppit.called

@mock.patch("esi_leap.api.controllers.v1.utils.policy_authorize")
@mock.patch("esi_leap.common.keystone.get_parent_project_id_tree")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_parent_project_id_tree")
def test_check_offer_lessee_admin(self, mock_gppit, mock_authorize):
mock_authorize.return_value = True
mock_gppit.return_value = [admin_ctx.project_id]
Expand All @@ -525,7 +531,7 @@ def test_check_offer_lessee_admin(self, mock_gppit, mock_authorize):
mock_gppit.assert_called_once_with(admin_ctx.project_id)

@mock.patch("esi_leap.api.controllers.v1.utils.policy_authorize")
@mock.patch("esi_leap.common.keystone.get_parent_project_id_tree")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_parent_project_id_tree")
def test_check_offer_lessee_non_admin_match(self, mock_gppit, mock_authorize):
mock_gppit.return_value = [lessee_ctx.project_id, "lesseeidparent"]

Expand All @@ -535,7 +541,7 @@ def test_check_offer_lessee_non_admin_match(self, mock_gppit, mock_authorize):
mock_gppit.assert_called_once_with(lessee_ctx.project_id)

@mock.patch("esi_leap.api.controllers.v1.utils.policy_authorize")
@mock.patch("esi_leap.common.keystone.get_parent_project_id_tree")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_parent_project_id_tree")
def test_check_offer_lessee_non_admin_no_match(self, mock_gppit, mock_authorize):
mock_authorize.side_effect = exception.HTTPResourceForbidden(
resource_type="offer", resource=test_offer_lessee_no_match.uuid
Expand Down Expand Up @@ -629,7 +635,7 @@ def test_resource_policy_authorize_exception(self, mock_authorize):


class TestOfferGetDictWithAddedInfoUtils(testtools.TestCase):
@mock.patch("esi_leap.common.keystone.get_project_name")
@mock.patch("esi_leap.common.idp.dummyIDP.DummyIDP.get_project_name")
@mock.patch("esi_leap.objects.offer.Offer.get_availabilities")
def test_offer_get_dict_with_added_info(self, mock_get_availabilities, mock_gpn):
mock_get_availabilities.return_value = []
Expand Down Expand Up @@ -686,7 +692,7 @@ def setUp(self):
)

@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.get_name")
@mock.patch("esi_leap.common.keystone.get_project_name")
@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):
mock_gro.return_value = FakeNode("111")
Expand Down

0 comments on commit 1ebdde0

Please sign in to comment.