diff --git a/esi_leap/api/controllers/v1/node.py b/esi_leap/api/controllers/v1/node.py index 9f2991a6..914ada86 100644 --- a/esi_leap/api/controllers/v1/node.py +++ b/esi_leap/api/controllers/v1/node.py @@ -67,7 +67,7 @@ def get_all(self): project_list = keystone.get_project_list() now = datetime.now() - offers = offer_obj.Offer.get_all({'status': statuses.AVAILABLE}, + offers = offer_obj.Offer.get_all({'status': [statuses.AVAILABLE]}, context) leases = lease_obj.Lease.get_all({'status': [statuses.CREATED]}, diff --git a/esi_leap/api/controllers/v1/offer.py b/esi_leap/api/controllers/v1/offer.py index 848b16a3..0aa91620 100644 --- a/esi_leap/api/controllers/v1/offer.py +++ b/esi_leap/api/controllers/v1/offer.py @@ -137,6 +137,8 @@ def get_all(self, project_id=None, resource_type=None, status = statuses.OFFER_CAN_DELETE elif status == 'any': status = None + else: + status = [status] try: utils.policy_authorize('esi_leap:offer:offer_admin', cdict, cdict) diff --git a/esi_leap/common/statuses.py b/esi_leap/common/statuses.py index a08ccc69..4d346372 100644 --- a/esi_leap/common/statuses.py +++ b/esi_leap/common/statuses.py @@ -20,5 +20,5 @@ WAIT_EXPIRE = 'wait expire' WAIT_FULFILL = 'wait fulfill' -OFFER_CAN_DELETE = (AVAILABLE, ERROR) -LEASE_CAN_DELETE = (ACTIVE, CREATED, ERROR, WAIT_FULFILL) +OFFER_CAN_DELETE = [AVAILABLE, ERROR] +LEASE_CAN_DELETE = [ACTIVE, CREATED, ERROR, WAIT_FULFILL] diff --git a/esi_leap/tests/api/controllers/v1/test_offer.py b/esi_leap/tests/api/controllers/v1/test_offer.py index 2c6314c2..4627560d 100644 --- a/esi_leap/tests/api/controllers/v1/test_offer.py +++ b/esi_leap/tests/api/controllers/v1/test_offer.py @@ -396,6 +396,33 @@ def test_get_any_status(self, mock_get_all, mock_ogdwai, mock_gpl, assert mock_ogdwai.call_count == 2 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.api.controllers.v1.utils.' + '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] + mock_ogdwai.side_effect = [ + _get_offer_response(self.test_offer, use_datetime=True), + _get_offer_response(self.test_offer_2, use_datetime=True)] + mock_gpl.return_value = [] + mock_gnl.return_value = [] + + expected_filters = {'status': [statuses.AVAILABLE]} + expected_resp = {'offers': [_get_offer_response(self.test_offer), + _get_offer_response(self.test_offer_2)]} + + request = self.get_json( + '/offers/?status=available') + + mock_get_all.assert_called_once_with(expected_filters, self.context) + mock_gpl.assert_called_once() + mock_gnl.assert_called_once() + assert mock_ogdwai.call_count == 2 + 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')