Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions test_app/djqscsv_tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
from StringIO import StringIO


def create_people_and_get_queryset():
Person.objects.create(name='vetch', address='iffish', info='wizard')
Person.objects.create(name='nemmerle', address='roke',
info='arch mage')

return Person.objects.all()


class ValidateCleanFilenameTests(TestCase):

def assertValidatedEquals(self, filename, expected_value):
Expand Down Expand Up @@ -78,11 +86,7 @@ def test_unclean_extension_raises(self):

class GenerateFilenameTests(TestCase):
def test_generate_filename(self):
Person.objects.create(name='vetch', address='iffish', info='wizard')
Person.objects.create(name='nemmerle', address='roke',
info='arch mage')

qs = Person.objects.all()
qs = create_people_and_get_queryset()

self.assertEqual(djqscsv.generate_filename(qs),
'person_export.csv')
Expand All @@ -94,10 +98,7 @@ def test_generate_filename(self):
class WriteCSVDataTests(TestCase):

def setUp(self):
Person.objects.create(name='vetch', address='iffish', info='wizard')
Person.objects.create(name='nemmerle', address='roke',
info='arch mage')
self.qs = Person.objects.all()
self.qs = create_people_and_get_queryset()

self.full_verbose_csv = [
['\xef\xbb\xbfID', 'Person\'s name', 'address', 'Info on Person'],
Expand Down Expand Up @@ -152,6 +153,27 @@ def test_write_csv_limited_verbose(self):
csv_file = filter(None, obj.getvalue().split('\n'))
self.assertMatchesCsv(csv_file, self.limited_verbose_csv)

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 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_csv)

self.assertRegexpMatches(response['Content-Disposition'],
r'attachment; filename=person_export.csv;')


def test_render_to_csv_response(self):
response = djqscsv.render_to_csv_response(self.qs,
filename="test_csv",
Expand Down