Skip to content

Commit

Permalink
Merge pull request #117 from tzumainn/offer-filter-fix
Browse files Browse the repository at this point in the history
Fix for offer status filters
  • Loading branch information
tzumainn authored Jul 26, 2022
2 parents 2d3df7b + 610484d commit 5585b0c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion esi_leap/api/controllers/v1/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]},
Expand Down
2 changes: 2 additions & 0 deletions esi_leap/api/controllers/v1/offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions esi_leap/common/statuses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
27 changes: 27 additions & 0 deletions esi_leap/tests/api/controllers/v1/test_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 5585b0c

Please sign in to comment.