Updated Branches: refs/heads/master 2f4594049 -> 1058e3049
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 <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/1058e304 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/1058e304 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/1058e304 Branch: refs/heads/master Commit: 1058e3049a2141cad8bfba4cf8afca6916396d77 Parents: 2f45940 Author: Santhosh Edukulla <[email protected]> Authored: Tue Nov 5 03:16:24 2013 +0530 Committer: Daan Hoogland <[email protected]> Committed: Tue Nov 5 11:06:26 2013 +0100 ---------------------------------------------------------------------- tools/marvin/marvin/cloudstackTestCase.py | 14 ++++ tools/marvin/marvin/integration/lib/utils.py | 80 +++++++++++++---------- 2 files changed, 58 insertions(+), 36 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1058e304/tools/marvin/marvin/cloudstackTestCase.py ---------------------------------------------------------------------- diff --git a/tools/marvin/marvin/cloudstackTestCase.py b/tools/marvin/marvin/cloudstackTestCase.py index 85ef542..6456bb1 100644 --- a/tools/marvin/marvin/cloudstackTestCase.py +++ b/tools/marvin/marvin/cloudstackTestCase.py @@ -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 http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1058e304/tools/marvin/marvin/integration/lib/utils.py ---------------------------------------------------------------------- diff --git a/tools/marvin/marvin/integration/lib/utils.py b/tools/marvin/marvin/integration/lib/utils.py index d53c1ae..4d048f0 100644 --- a/tools/marvin/marvin/integration/lib/utils.py +++ b/tools/marvin/marvin/integration/lib/utils.py @@ -354,42 +354,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]
