Esempio n. 1
0
    def test_osm_csv_export(self):
        self._publish_osm_with_submission()
        count = Export.objects.all().count()

        view = XFormViewSet.as_view({
            'get': 'retrieve'
        })

        request = self.factory.get('/', data={'include_images': False},
                                   **self.extra)
        response = view(request, pk=self.xform.pk, format='csv')
        self.assertEqual(response.status_code, 200)

        self.assertEquals(count + 1, Export.objects.all().count())

        headers = dict(response.items())
        self.assertEqual(headers['Content-Type'], 'application/csv')
        content_disposition = headers['Content-Disposition']
        filename = filename_from_disposition(content_disposition)
        basename, ext = os.path.splitext(filename)
        self.assertEqual(ext, '.csv')

        content = get_response_content(response)
        reader = csv.DictReader(StringIO(content))
        data = [_ for _ in reader]
        test_file_path = os.path.join(self.fixtures_dir, 'osm.csv')
        with open(test_file_path, 'r') as test_file:
            expected_csv_reader = csv.DictReader(test_file)
            for index, row in enumerate(expected_csv_reader):
                self.assertDictContainsSubset(row, data[index])

        request = self.factory.get('/', **self.extra)
        response = view(request, pk=self.xform.pk, format='csv')
        self.assertEqual(response.status_code, 200)
Esempio n. 2
0
    def test_osm_csv_export(self):
        self._publish_osm_with_submission()
        count = Export.objects.all().count()

        view = XFormViewSet.as_view({'get': 'retrieve'})

        request = self.factory.get('/',
                                   data={'include_images': False},
                                   **self.extra)
        response = view(request, pk=self.xform.pk, format='csv')
        self.assertEqual(response.status_code, 200)

        self.assertEquals(count + 1, Export.objects.all().count())

        headers = dict(response.items())
        self.assertEqual(headers['Content-Type'], 'application/csv')
        content_disposition = headers['Content-Disposition']
        filename = filename_from_disposition(content_disposition)
        basename, ext = os.path.splitext(filename)
        self.assertEqual(ext, '.csv')

        content = get_response_content(response)
        reader = csv.DictReader(StringIO(content))
        data = [_ for _ in reader]
        test_file_path = os.path.join(self.fixtures_dir, 'osm.csv')
        with open(test_file_path, 'r') as test_file:
            expected_csv_reader = csv.DictReader(test_file)
            for index, row in enumerate(expected_csv_reader):
                self.assertDictContainsSubset(row, data[index])

        request = self.factory.get('/', **self.extra)
        response = view(request, pk=self.xform.pk, format='csv')
        self.assertEqual(response.status_code, 200)
Esempio n. 3
0
    def _test_csv_response(self, response, csv_file_path):
        headers = dict(response.items())
        self.assertEqual(headers['Content-Type'], 'application/csv')
        content_disposition = headers['Content-Disposition']
        filename = filename_from_disposition(content_disposition)
        __, ext = os.path.splitext(filename)
        self.assertEqual(ext, '.csv')

        data = get_response_content(response)
        reader = csv.DictReader(StringIO(data))
        data = [_ for _ in reader]
        with open(csv_file_path, 'r') as test_file:
            expected_csv_reader = csv.DictReader(test_file)
            for index, row in enumerate(expected_csv_reader):
                if None in row:
                    row.pop(None)
                self.assertDictContainsSubset(row, data[index])
Esempio n. 4
0
    def _test_csv_response(self, response, csv_file_path):
        headers = dict(response.items())
        self.assertEqual(headers['Content-Type'], 'application/csv')
        content_disposition = headers['Content-Disposition']
        filename = filename_from_disposition(content_disposition)
        __, ext = os.path.splitext(filename)
        self.assertEqual(ext, '.csv')

        data = get_response_content(response)
        reader = csv.DictReader(StringIO(data))
        data = [_ for _ in reader]
        with open(csv_file_path, encoding='utf-8') as test_file:
            expected_csv_reader = csv.DictReader(test_file)
            for index, row in enumerate(expected_csv_reader):
                if None in row:
                    row.pop(None)
                self.assertDictContainsSubset(row, data[index])