diff options
author | Joao Fonseca <jpdf.fonseca@gmail.com> | 2016-04-19 12:22:11 +0100 |
---|---|---|
committer | Joao Fonseca <jpdf.fonseca@gmail.com> | 2016-04-19 12:29:19 +0100 |
commit | fa942c755ab513829dcab27487ba1e7ab5a806ee (patch) | |
tree | 0cc57391104a3c1c1e0aea1a937a8565160a0548 /qa/rpc-tests/test_framework/util.py | |
parent | 187186b0fe039010ea4b81edb671b9bdfc63d29a (diff) |
Move method to check matches within arrays on util.py
Diffstat (limited to 'qa/rpc-tests/test_framework/util.py')
-rw-r--r-- | qa/rpc-tests/test_framework/util.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 8b720b54a1..27891f7f4c 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -478,6 +478,35 @@ def assert_is_hash_string(string, length=64): raise AssertionError( "String %r contains invalid characters for a hash." % string) +def assert_array_result(object_array, to_match, expected, should_not_find = False): + """ + Pass in array of JSON objects, a dictionary with key/value pairs + to match against, and another dictionary with expected key/value + pairs. + If the should_not_find flag is true, to_match should not be found + in object_array + """ + if should_not_find == True: + expected = { } + num_matched = 0 + for item in object_array: + all_match = True + for key,value in to_match.items(): + if item[key] != value: + all_match = False + if not all_match: + continue + elif should_not_find == True: + num_matched = num_matched+1 + for key,value in expected.items(): + if item[key] != value: + raise AssertionError("%s : expected %s=%s"%(str(item), str(key), str(value))) + num_matched = num_matched+1 + if num_matched == 0 and should_not_find != True: + raise AssertionError("No objects matched %s"%(str(to_match))) + if num_matched > 0 and should_not_find == True: + raise AssertionError("Objects were found %s"%(str(to_match))) + def satoshi_round(amount): return Decimal(amount).quantize(Decimal('0.00000001'), rounding=ROUND_DOWN) |