Skip to content

Commit

Permalink
Merge pull request #43 from samuel-zuk/interface-cleanup
Browse files Browse the repository at this point in the history
Cleaned up functional test interface code, fixed broken test
  • Loading branch information
tzumainn authored Jul 12, 2022
2 parents 20418a0 + 995de90 commit 709c011
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 40 deletions.
71 changes: 32 additions & 39 deletions esileapclient/tests/functional/utils/esi_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@
import esileapclient.tests.functional.utils.output_utils as utils


def _execute(client, cmd, valid_flags, kwargs, args, parse, fail_ok):
flag_str = utils.kwargs_to_flags(valid_flags, kwargs) if kwargs else ''
arg_str = '' if not len(args) else ' '.join(args)
if parse:
flag_str = ' '.join((flag_str, '-f json'))
return json.loads(client.esi(cmd, flag_str, arg_str, fail_ok))
else:
return client.esi(cmd, flag_str, arg_str, fail_ok)


def offer_create(client, node_uuid, parse=True, fail_ok=False, **kwargs):
valid_flags = ('resource_type', 'start_time', 'end_time',
'lessee', 'name', 'properties')
flags = utils.kwargs_to_flags(valid_flags, kwargs)
flags += ' -f json' if parse else ''

output = client.esi('offer create', flags, node_uuid, fail_ok)
return json.loads(output) if parse else output
return _execute(client, cmd='offer create', valid_flags=valid_flags,
kwargs=kwargs, args=(node_uuid,), parse=parse,
fail_ok=fail_ok)


def offer_delete(client, offer_uuid, fail_ok=False):
Expand All @@ -18,58 +26,43 @@ def offer_delete(client, offer_uuid, fail_ok=False):

def offer_list(client, parse=True, fail_ok=False, **kwargs):
valid_flags = ('long', 'status', 'project', 'resource_uuid',
'resource_type', 'time_range', 'availability_range',
'resource_class')
flags = utils.kwargs_to_flags(valid_flags, kwargs)
flags += ' -f json' if parse else ''

output = client.esi('offer list', flags, '', fail_ok)
return json.loads(output) if parse else output
'resource_type', 'time_range', 'availability_range')
return _execute(client, cmd='offer list', valid_flags=valid_flags,
kwargs=kwargs, args=(), parse=parse, fail_ok=fail_ok)


def offer_show(client, offer_uuid, parse=True, fail_ok=False, **kwargs):
flags = '-f json' if parse else ''
output = client.esi('offer show', flags, offer_uuid, fail_ok)
return json.loads(output) if parse else output
def offer_show(client, offer_uuid, parse=True, fail_ok=False):
return _execute(client, cmd='offer show', valid_flags=None, kwargs=None,
args=(offer_uuid,), parse=parse, fail_ok=fail_ok)


def offer_claim(client, offer_uuid, parse=True, fail_ok=False, **kwargs):
valid_flags = ('start_time', 'end_time', 'properties')
flags = utils.kwargs_to_flags(valid_flags, kwargs)
flags += ' -f json' if parse else ''
return _execute(client, cmd='offer claim', valid_flags=valid_flags,
kwargs=kwargs, args=(offer_uuid,), parse=parse,
fail_ok=fail_ok)

output = client.esi('offer claim', flags, offer_uuid, fail_ok)
return json.loads(output) if parse else output


def lease_create(client, node_uuid, lessee, parse=True,
fail_ok=False, **kwargs):
def lease_create(client, node_uuid, lessee, parse=True, fail_ok=False,
**kwargs):
valid_flags = ('resource_type', 'start_time', 'end_time',
'name', 'properties')
flags = utils.kwargs_to_flags(valid_flags, kwargs)
flags += ' -f json' if parse else ''

output = client.esi('lease create', flags, '%s %s' %
(node_uuid, lessee), fail_ok)
return json.loads(output) if parse else output
return _execute(client, cmd='lease create', valid_flags=valid_flags,
kwargs=kwargs, args=(node_uuid, lessee), parse=parse,
fail_ok=fail_ok)


def lease_list(client, parse=True, fail_ok=False, **kwargs):
valid_flags = ('long', 'all', 'status', 'offer_uuid', 'time_range',
'project', 'owner', 'resource_type', 'resource_uuid',
'resource_class')
flags = utils.kwargs_to_flags(valid_flags, kwargs)
flags += ' -f json' if parse else ''

output = client.esi('lease list', flags, '', fail_ok)
return json.loads(output) if parse else output
'project', 'owner', 'resource_type', 'resource_uuid')
return _execute(client, cmd='lease list', valid_flags=valid_flags,
kwargs=kwargs, args=(), parse=parse, fail_ok=fail_ok)


def lease_delete(client, lease_uuid, fail_ok=False):
return client.esi('lease delete', '', lease_uuid, fail_ok)


def lease_show(client, lease_uuid, parse=True, fail_ok=False):
flags = '-f json' if parse else ''
output = client.esi('lease show', flags, lease_uuid, fail_ok)
return json.loads(output) if parse else output
return _execute(client, cmd='lease show', valid_flags=None, kwargs=None,
args=(lease_uuid,), parse=parse, fail_ok=fail_ok)
3 changes: 2 additions & 1 deletion esileapclient/tests/functional/v1/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def test_offer_show_basic(self):
offer = esi.offer_create(self.clients['parent-owner'],
self.dummy_node.uuid,
resource_type='dummy_node',
lessee=self.projects['child']['name'])
lessee=self.projects['child']['name'],
start_time='9999-01-01')
self.assertNotEqual(offer, {})
self.addCleanup(esi.offer_delete,
self.clients['parent-owner'],
Expand Down

0 comments on commit 709c011

Please sign in to comment.