Example #1
0
    def test_diff_command_valid_usage_with_separator(self):
        result = self.csvdiff_cmd('--sep', '\t', 'id', self.a_file_tsv,
                                  self.b_file_tsv)
        self.assertEqual(result.exit_code, 1)
        diff = result.diff
        patch.validate(diff)
        assert patch.is_valid(diff)

        expected = {
            '_index': ['id'],
            'added': [{
                'id': '5',
                'name': 'mira',
                'amount': '81'
            }],
            'removed': [{
                'id': '2',
                'name': 'eva',
                'amount': '63'
            }],
            'changed': [
                {
                    'key': ['1'],
                    'fields': {
                        'amount': {
                            'from': '20',
                            'to': '23'
                        }
                    }
                },
                {
                    'key': ['6'],
                    'fields': {
                        'amount': {
                            'from': '10',
                            'to': '13'
                        }
                    }
                },
            ],
        }

        self.assertPatchesEqual(diff, expected)
Example #2
0
    def test_diff_command_valid_usage_with_difference(self):
        result = self.csvdiff_cmd('id', self.a_file, self.b_file)
        self.assertEqual(result.exit_code, 1)
        diff = result.diff
        patch.validate(diff)
        assert patch.is_valid(diff)

        expected = {
            '_index': ['id'],
            'added': [{'id': '5', 'name': 'mira', 'amount': '81'}],
            'removed': [{'id': '2', 'name': 'eva', 'amount': '63'}],
            'changed': [
                {'key': ['1'],
                 'fields': {'amount': {'from': '20', 'to': '23'}}},
                {'key': ['6'],
                 'fields': {'amount': {'from': '10', 'to': '13'}}},
            ],
        }

        self.assertPatchesEqual(diff, expected)