def assert_all(session, query, expected, cl=None, ignore_order=False, timeout=None): """ Assert query returns all expected items optionally in the correct order @param session Session in use @param query Query to run @param expected Expected results from query @param cl Optional Consistency Level setting. Default ONE @param ignore_order Optional boolean flag determining whether response is ordered @param timeout Optional query timeout, in seconds Examples: assert_all(session, "LIST USERS", [['aleksey', False], ['cassandra', True]]) assert_all(self.session1, "SELECT * FROM ttl_table;", [[1, 42, 1, 1]]) """ simple_query = SimpleStatement(query, consistency_level=cl) res = session.execute( simple_query) if timeout is None else session.execute(simple_query, timeout=timeout) list_res = _rows_to_list(res) if ignore_order: expected = list_to_hashed_dict(expected) list_res = list_to_hashed_dict(list_res) assert list_res == expected, "Expected {} from {}, but got {}".format( expected, query, list_res)
def assertEqualIgnoreOrder(self, actual, expected): hashed_expected = list_to_hashed_dict(expected) hashed_actual = list_to_hashed_dict(actual) for key, expected in hashed_expected.items(): assert key in hashed_actual, "expected %s not in actual" % str(expected) actual = hashed_actual[key] assert actual == expected, "actual %s not same as expected %s" % (str(actual), str(expected)) for key, actual in hashed_actual.items(): assert key in hashed_expected, "actual %s not in expected" % str(actual) expected = hashed_expected[key] assert expected == actual, "expected %s not same as actual %s" % (str(expected), str(actual)) assert hashed_expected == hashed_actual
def assert_all(session, query, expected, cl=None, ignore_order=False, timeout=None): """ Assert query returns all expected items optionally in the correct order @param session Session in use @param query Query to run @param expected Expected results from query @param cl Optional Consistency Level setting. Default ONE @param ignore_order Optional boolean flag determining whether response is ordered @param timeout Optional query timeout, in seconds Examples: assert_all(session, "LIST USERS", [['aleksey', False], ['cassandra', True]]) assert_all(self.session1, "SELECT * FROM ttl_table;", [[1, 42, 1, 1]]) """ simple_query = SimpleStatement(query, consistency_level=cl) res = session.execute(simple_query) if timeout is None else session.execute(simple_query, timeout=timeout) list_res = _rows_to_list(res) if ignore_order: expected = list_to_hashed_dict(expected) list_res = list_to_hashed_dict(list_res) assert list_res == expected, "Expected {} from {}, but got {}".format(expected, query, list_res)
def assertEqualIgnoreOrder(self, actual, expected): assert list_to_hashed_dict(actual) == list_to_hashed_dict(expected)