Skip to content

Commit c76da53

Browse files
Santhosh EdukullaGirish Shilamkar
authored andcommitted
CLOUDSTACK-5032 Provides custom assert facility to test features
Added assertElementInList to cloudstackTestCase. Users can use this new custom addition to add assertions, thus replacing current multiple assertions Signed-off-by: Santhosh Edukulla <Santhosh.Edukulla@citrix.com>
1 parent 87983e0 commit c76da53

2 files changed

Lines changed: 58 additions & 36 deletions

File tree

‎tools/marvin/marvin/cloudstackTestCase.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
# under the License.
1717

1818
import unittest
19+
from marvin.integration.lib.utils import verifyElementInList
20+
from marvin.codes import PASS
1921

2022

2123
def user(Name, DomainName, AcctType):
@@ -35,6 +37,18 @@ def __init__(self, *args, **kws):
3537
class cloudstackTestCase(unittest.case.TestCase):
3638
clstestclient = None
3739

40+
def assertElementInList(inp, toverify, responsevar=None, pos=0,
41+
assertmsg="TC Failed for reason"):
42+
'''
43+
@Name: assertElementInList
44+
@desc:Uses the utility function verifyElementInList and
45+
asserts based upon PASS\FAIL value of the output.
46+
Takes one additional argument of what message to assert with
47+
when failed
48+
'''
49+
out = verifyElementInList(inp, toverify, responsevar, pos)
50+
unittest.TestCase.assertEquals(out[0], PASS, "msg:%s" % out[1])
51+
3852
@classmethod
3953
def getClsTestClient(cls):
4054
return cls.clstestclient

‎tools/marvin/marvin/integration/lib/utils.py‎

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -353,42 +353,50 @@ def validateList(inp):
353353
return ret
354354
return [PASS, inp[0], None]
355355

356-
def verifyElementInList(inp, toverify, pos = 0):
357-
'''
358-
@name: verifyElementInList
359-
@Description:
360-
1. A utility function to validate
361-
whether the input passed is a list.
362-
The list is empty or not.
363-
If it is list and not empty, verify
364-
whether a given element is there in that list or not
365-
at a given pos
366-
@Input:
367-
I : Input to be verified whether its a list or not
356+
def verifyElementInList(inp, toverify, responsevar=None, pos=0):
357+
'''
358+
@name: verifyElementInList
359+
@Description:
360+
1. A utility function to validate
361+
whether the input passed is a list.
362+
The list is empty or not.
363+
If it is list and not empty, verify
364+
whether a given element is there in that list or not
365+
at a given pos
366+
@Input:
367+
I : Input to be verified whether its a list or not
368368
II : Element to verify whether it exists in the list
369-
III : Position in the list at which the input element to verify
370-
default to 0
371-
@output: List, containing [ Result,Reason ]
372-
Ist Argument('Result') : FAIL : If it is not a list
373-
If it is list but empty
374-
PASS : If it is list and not empty
369+
III : variable name in response object to verify
370+
default to None, if None, we will verify for the complete
371+
first element EX: state of response object object
372+
IV : Position in the list at which the input element to verify
373+
default to 0
374+
@output: List, containing [ Result,Reason ]
375+
Ist Argument('Result') : FAIL : If it is not a list
376+
If it is list but empty
377+
PASS : If it is list and not empty
375378
and matching element was found
376-
IIrd Argument( 'Reason' ): Reason for failure ( FAIL ),
377-
default to None.
378-
INVALID_INPUT
379-
EMPTY_LIST
380-
MATCH_NOT_FOUND
381-
'''
382-
if toverify is None or toverify == '' \
383-
or pos is None or pos < -1 or pos == '':
384-
return [FAIL, INVALID_INPUT]
385-
out = validateList(inp)
386-
if out[0] == FAIL:
387-
return [FAIL, out[2]]
388-
if out[0] == PASS:
389-
if len(inp) > pos and inp[pos] == toverify:
390-
return [PASS, None]
391-
else:
392-
return [FAIL, MATCH_NOT_FOUND]
393-
379+
IIrd Argument( 'Reason' ): Reason for failure ( FAIL ),
380+
default to None.
381+
INVALID_INPUT
382+
EMPTY_LIST
383+
MATCH_NOT_FOUND
384+
'''
385+
if toverify is None or toverify == '' \
386+
or pos is None or pos < -1 or pos == '':
387+
return [FAIL, INVALID_INPUT]
388+
out = validateList(inp)
389+
if out[0] == FAIL:
390+
return [FAIL, out[2]]
391+
if len(inp) > pos:
392+
if responsevar is None:
393+
if inp[pos] == toverify:
394+
return [PASS, None]
395+
else:
396+
if responsevar in inp[pos].__dict__ and getattr(inp[pos], responsevar) == toverify:
397+
return [PASS, None]
398+
else:
399+
return [FAIL, MATCH_NOT_FOUND]
400+
else:
401+
return [FAIL, MATCH_NOT_FOUND]
394402

0 commit comments

Comments
 (0)