def test_render_to_csv_response(self): response = djqscsv.render_to_csv_response(self.qs, filename="test_csv", use_verbose_names=False) self.assertEqual(response['Content-Type'], 'text/csv') self.assertMatchesCsv(response.content.split('\n'), self.FULL_PERSON_CSV_NO_VERBOSE)
def test_render_to_csv_response(self): response = djqscsv.render_to_csv_response(self.qs, filename="test_csv", use_verbose_names=False) self.assertEqual(response['Content-Type'], 'text/csv') self.assertMatchesCsv( b''.join(response.streaming_content).splitlines(), self.FULL_PERSON_CSV_NO_VERBOSE)
def test_render_to_csv_response_no_filename(self): response = djqscsv.render_to_csv_response(self.qs, use_verbose_names=False) self.assertEqual(response['Content-Type'], 'text/csv') self.assertMatchesCsv(response.content.split('\n'), self.FULL_PERSON_CSV_NO_VERBOSE) self.assertRegexpMatches(response['Content-Disposition'], r'attachment; filename=person_export.csv;')
def test_render_to_csv_fails_on_delimiter_mismatch(self): response = djqscsv.render_to_csv_response(self.qs, filename="test_csv", use_verbose_names=False, delimiter='|') self.assertEqual(response['Content-Type'], 'text/csv') self.assertNotMatchesCsv(response.content.splitlines(), self.FULL_PERSON_CSV_NO_VERBOSE)
def test_render_to_csv_fails_on_delimiter_mismatch(self): response = djqscsv.render_to_csv_response(self.qs, filename="test_csv", use_verbose_names=False, delimiter='|') self.assertEqual(response['Content-Type'], 'text/csv') self.assertNotMatchesCsv(response.content.decode('utf-8').split('\n'), self.FULL_PERSON_CSV_NO_VERBOSE)
def test_render_to_csv_response_with_filename_and_datestamp(self): filename = "the_reach.csv" response = djqscsv.render_to_csv_response(self.qs, filename=filename, append_datestamp=True) self.assertRegexpMatches( response['Content-Disposition'], r'attachment; filename=the_reach_[0-9]{8}.csv;')
def get_csv(request): qs = create_people_and_get_queryset() return djqscsv.render_to_csv_response(qs)