def json_at_path(context): if 'response' in context: actual = context.response data = context.text or context.data expected = json.loads(data.decode('utf-8')) eq_(traverse_compare(expected, actual), []) else: context.scenario.skip()
def test_actual_bigger_than_expected(self): actual = [{"key1": "value1"}, {"key2": "value2"}, {"key3": "value3"}] expected = [{"key1": "value1"}, {"key2": "value2"}] result = traverse_compare(actual, expected, ignoreIndexErrors=True, ignoreKeyErrors=True) self.assertEqual(result, [])
def test_compare_not_identical_dictionaries(self): actual = {"top": {"middle": {"nested": "value"}}} expected = {"top": {"middle": {"nested": "wrong value"}}} self.assertEqual(traverse_compare(actual, expected), [{ 'expected_value': 'wrong value', 'path': 'top.middle.nested', 'actual_value': 'value' }])
def test_compare_not_identical_list_of_dicts(self): actual = [{"key3": "value3"}, {"key2": "value2"}, {"key1": "value1"}] expected = [{ "key3": "value3" }, { "key2": "value2" }, { "key1": "value-1" }] result = traverse_compare(actual, expected) self.assertEqual(result, [{ 'expected_value': 'value-1', 'path': '[2].key1', 'actual_value': 'value1' }])
def json_at_path(context): actual = context.response data = context.text or context.data expected = json.loads(data.decode('utf-8')) eq_(traverse_compare(expected, actual), [])
def test_compare_identical_dictionaries(self): actual = {"top": {"middle": {"nested": "value"}}} expected = {"top": {"middle": {"nested": "value"}}} self.assertEqual(traverse_compare(actual, expected), [])
def test_compare_identical_list_of_dicts(self): actual = [{"key3": "value3"}, {"key2": "value2"}, {"key1": "value1"}] expected = [{"key3": "value3"}, {"key2": "value2"}, {"key1": "value1"}] result = traverse_compare(actual, expected) self.assertEqual(result, [])
def test_actual_bigger_than_expected_primitives(self): actual = ['a', 'b', 'c'] expected = ['a', 'b'] result = traverse_compare(actual, expected, ignoreIndexErrors=True) self.assertEqual(result, [])