Beispiel #1
0
    def test_json_export(self):

        def deep_sort(obj):
            """
            Recursively sort list or dict nested lists
            Taken from https://stackoverflow.com/questions/18464095/how-to-achieve-assertdictequal-with-assertsequenceequal-applied-to-values
            """

            if isinstance(obj, dict):
                _sorted = {}
                for key in sorted(obj):
                    _sorted[key] = deep_sort(obj[key])

            elif isinstance(obj, list):
                new_list = []
                for val in obj:
                    new_list.append(deep_sort(val))
                _sorted = sorted(new_list)

            else:
                _sorted = obj

            return _sorted

        BusinessDataImporter('tests/fixtures/data/json/resource_export_business_data_truth.json').import_business_data()

        export = BusinessDataExporter('json').export('ab74af76-fa0e-11e6-9e3e-026d961c88e6')
        json_export = deep_sort(json.loads(export[0]['outputfile'].getvalue()))

        json_truth = deep_sort(json.loads(open('tests/fixtures/data/json/resource_export_business_data_truth.json').read()))

        self.assertDictEqual(json_export, json_truth)
    def test_csv_export(self):
        BusinessDataImporter("tests/fixtures/data/csv/resource_export_test.csv").import_business_data()

        export = BusinessDataExporter("csv", configs="tests/fixtures/data/csv/resource_export_test.mapping", single_file=True).export()

        csv_output = list(csv.DictReader(export[0]["outputfile"].getvalue().split("\r\n")))[0]
        csvinputfile = "tests/fixtures/data/csv/resource_export_test.csv"
        csv_input = list(csv.DictReader(open(csvinputfile, "rU", encoding="utf-8"), restkey="ADDITIONAL", restval="MISSING"))[0]

        self.assertDictEqual(dict(csv_input), dict(csv_output))
Beispiel #3
0
    def test_csv_export(self):
        BusinessDataImporter('tests/fixtures/data/csv/resource_export_test.csv').import_business_data()

        export = BusinessDataExporter('csv', configs='tests/fixtures/data/csv/resource_export_test.mapping', single_file=True).export()
        csv_export = filter(lambda export: 'csv' in export['name'], export)[0]['outputfile'].getvalue().split('\r')
        csv_output = list(unicodecsv.DictReader(BytesIO(export[0]['outputfile'].getvalue()), encoding='utf-8-sig'))[0]

        csvinputfile = 'tests/fixtures/data/csv/resource_export_test.csv'
        csv_input = list(unicodecsv.DictReader(open(csvinputfile, 'rU'), encoding='utf-8-sig', restkey='ADDITIONAL', restval='MISSING'))[0]

        self.assertDictEqual(csv_input, csv_output)
Beispiel #4
0
    def test_csv_export(self):
        BusinessDataImporter('tests/fixtures/data/csv/resource_export_test.csv'
                             ).import_business_data()

        export = BusinessDataExporter(
            'csv',
            configs='tests/fixtures/data/csv/resource_export_test.mapping',
            single_file=True).export()

        csv_output = list(
            csv.DictReader(
                export[0]['outputfile'].getvalue().split('\r\n')))[0]
        csvinputfile = 'tests/fixtures/data/csv/resource_export_test.csv'
        csv_input = list(
            csv.DictReader(open(csvinputfile, 'rU', encoding="utf-8"),
                           restkey='ADDITIONAL',
                           restval='MISSING'))[0]

        self.assertDictEqual(dict(csv_input), dict(csv_output))
Beispiel #5
0
 def test_json_export(self):
     export = BusinessDataExporter('json').export(
         'ab74af76-fa0e-11e6-9e3e-026d961c88e6')
     json_export = json.loads(export[0]['outputfile'].getvalue())
     number_of_resources = len(json_export['business_data']['resources'])
     self.assertEqual(number_of_resources, 2)