You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

csv_utils_tests.py 803B

12345678910111213141516171819202122232425262728
  1. # -*- coding: utf-8 -*-
  2. import datetime
  3. import StringIO
  4. from django.test import TestCase
  5. from oscar.apps.dashboard.reports.csv_utils import CsvUnicodeWriter
  6. class TestCsvWriter(TestCase):
  7. def test_(self):
  8. s = u'ünįcodē'
  9. class unicodeobj(object):
  10. def __unicode__(self):
  11. return s
  12. rows = [
  13. [s, s.encode('utf-8'), unicodeobj(), 123, datetime.date.today()]
  14. ]
  15. f = StringIO.StringIO()
  16. CsvUnicodeWriter(f).writerows(rows)
  17. f.seek(0)
  18. self.assertEqual(
  19. f.read().decode('utf-8-sig').strip(),
  20. u','.join((s, s, s, u'123', unicode(datetime.date.today())))
  21. )
  22. f = StringIO.StringIO()
  23. self.assertRaises(TypeError, CsvUnicodeWriter(f).writerows, [object()])