mirror of https://github.com/apache/cloudstack.git
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>
This commit is contained in:
parent
87983e09e2
commit
c76da53123
|
|
@ -16,6 +16,8 @@
|
|||
# under the License.
|
||||
|
||||
import unittest
|
||||
from marvin.integration.lib.utils import verifyElementInList
|
||||
from marvin.codes import PASS
|
||||
|
||||
|
||||
def user(Name, DomainName, AcctType):
|
||||
|
|
@ -35,6 +37,18 @@ def user(Name, DomainName, AcctType):
|
|||
class cloudstackTestCase(unittest.case.TestCase):
|
||||
clstestclient = None
|
||||
|
||||
def assertElementInList(inp, toverify, responsevar=None, pos=0,
|
||||
assertmsg="TC Failed for reason"):
|
||||
'''
|
||||
@Name: assertElementInList
|
||||
@desc:Uses the utility function verifyElementInList and
|
||||
asserts based upon PASS\FAIL value of the output.
|
||||
Takes one additional argument of what message to assert with
|
||||
when failed
|
||||
'''
|
||||
out = verifyElementInList(inp, toverify, responsevar, pos)
|
||||
unittest.TestCase.assertEquals(out[0], PASS, "msg:%s" % out[1])
|
||||
|
||||
@classmethod
|
||||
def getClsTestClient(cls):
|
||||
return cls.clstestclient
|
||||
|
|
|
|||
|
|
@ -353,42 +353,50 @@ def validateList(inp):
|
|||
return ret
|
||||
return [PASS, inp[0], None]
|
||||
|
||||
def verifyElementInList(inp, toverify, pos = 0):
|
||||
'''
|
||||
@name: verifyElementInList
|
||||
@Description:
|
||||
1. A utility function to validate
|
||||
whether the input passed is a list.
|
||||
The list is empty or not.
|
||||
If it is list and not empty, verify
|
||||
whether a given element is there in that list or not
|
||||
at a given pos
|
||||
@Input:
|
||||
I : Input to be verified whether its a list or not
|
||||
def verifyElementInList(inp, toverify, responsevar=None, pos=0):
|
||||
'''
|
||||
@name: verifyElementInList
|
||||
@Description:
|
||||
1. A utility function to validate
|
||||
whether the input passed is a list.
|
||||
The list is empty or not.
|
||||
If it is list and not empty, verify
|
||||
whether a given element is there in that list or not
|
||||
at a given pos
|
||||
@Input:
|
||||
I : Input to be verified whether its a list or not
|
||||
II : Element to verify whether it exists in the list
|
||||
III : Position in the list at which the input element to verify
|
||||
default to 0
|
||||
@output: List, containing [ Result,Reason ]
|
||||
Ist Argument('Result') : FAIL : If it is not a list
|
||||
If it is list but empty
|
||||
PASS : If it is list and not empty
|
||||
III : variable name in response object to verify
|
||||
default to None, if None, we will verify for the complete
|
||||
first element EX: state of response object object
|
||||
IV : Position in the list at which the input element to verify
|
||||
default to 0
|
||||
@output: List, containing [ Result,Reason ]
|
||||
Ist Argument('Result') : FAIL : If it is not a list
|
||||
If it is list but empty
|
||||
PASS : If it is list and not empty
|
||||
and matching element was found
|
||||
IIrd Argument( 'Reason' ): Reason for failure ( FAIL ),
|
||||
default to None.
|
||||
INVALID_INPUT
|
||||
EMPTY_LIST
|
||||
MATCH_NOT_FOUND
|
||||
'''
|
||||
if toverify is None or toverify == '' \
|
||||
or pos is None or pos < -1 or pos == '':
|
||||
return [FAIL, INVALID_INPUT]
|
||||
out = validateList(inp)
|
||||
if out[0] == FAIL:
|
||||
return [FAIL, out[2]]
|
||||
if out[0] == PASS:
|
||||
if len(inp) > pos and inp[pos] == toverify:
|
||||
return [PASS, None]
|
||||
else:
|
||||
return [FAIL, MATCH_NOT_FOUND]
|
||||
|
||||
IIrd Argument( 'Reason' ): Reason for failure ( FAIL ),
|
||||
default to None.
|
||||
INVALID_INPUT
|
||||
EMPTY_LIST
|
||||
MATCH_NOT_FOUND
|
||||
'''
|
||||
if toverify is None or toverify == '' \
|
||||
or pos is None or pos < -1 or pos == '':
|
||||
return [FAIL, INVALID_INPUT]
|
||||
out = validateList(inp)
|
||||
if out[0] == FAIL:
|
||||
return [FAIL, out[2]]
|
||||
if len(inp) > pos:
|
||||
if responsevar is None:
|
||||
if inp[pos] == toverify:
|
||||
return [PASS, None]
|
||||
else:
|
||||
if responsevar in inp[pos].__dict__ and getattr(inp[pos], responsevar) == toverify:
|
||||
return [PASS, None]
|
||||
else:
|
||||
return [FAIL, MATCH_NOT_FOUND]
|
||||
else:
|
||||
return [FAIL, MATCH_NOT_FOUND]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue