class CSVSerializerTests(TransactionTestCase): def setUp(self): self.point = MushroomSpot.objects.create() self.point.tags.add(Tag.objects.create(label="Tag1")) self.point.tags.add(Tag.objects.create(label="Tag2")) self.serializer = CSVSerializer() self.stream = StringIO() def tearDown(self): self.stream.close() def test_content(self): self.serializer.serialize(MushroomSpot.objects.all(), stream=self.stream, fields=['id', 'name', 'number', 'size', 'boolean', 'tags'], delete=False) self.assertEquals(self.stream.getvalue(), ('ID,name,number,size,boolean,tags\r\n{},' 'Empty,42,3.14159,yes,"Tag1,Tag2"\r\n').format(self.point.pk)) @override_settings(USE_L10N=True) def test_content_fr(self): translation.activate('fr-fr') self.serializer.serialize(MushroomSpot.objects.all(), stream=self.stream, fields=['id', 'name', 'number', 'size', 'boolean', 'tags'], delete=False) self.assertEquals(self.stream.getvalue(), ('ID,name,number,size,boolean,tags\r\n{},' 'Empty,42,"3,14159",oui,"Tag1,Tag2"\r\n').format(self.point.pk)) translation.deactivate()
class CSVSerializerTests(TransactionTestCase): def setUp(self): self.point = MushroomSpot.objects.create() self.point.tags.add(Tag.objects.create(label="Tag1")) self.point.tags.add(Tag.objects.create(label="Tag2")) self.serializer = CSVSerializer() self.stream = StringIO() def tearDown(self): self.stream.close() def test_content(self): self.serializer.serialize( MushroomSpot.objects.all(), stream=self.stream, fields=['id', 'name', 'number', 'size', 'boolean', 'tags'], delete=False) self.assertEquals(self.stream.getvalue(), ('ID,name,number,size,boolean,tags\r\n{},' 'Empty,42,3.14159,yes,"Tag1,Tag2"\r\n').format( self.point.pk)) @override_settings(USE_L10N=True) def test_content_fr(self): translation.activate('fr-fr') self.serializer.serialize( MushroomSpot.objects.all(), stream=self.stream, fields=['id', 'name', 'number', 'size', 'boolean', 'tags'], delete=False) self.assertEquals(self.stream.getvalue(), ('ID,name,number,size,boolean,tags\r\n{},' 'Empty,42,"3,14159",oui,"Tag1,Tag2"\r\n').format( self.point.pk)) translation.deactivate()
class CSVSerializerTests(TestCase): def setUp(self): self.point = DiveFactory.create(name="Test") self.point.themes.add(ThemeFactory.create(label="Tag1")) self.point.themes.add(ThemeFactory.create(label="Tag2")) self.serializer = CSVSerializer() self.stream = StringIO() def tearDown(self): self.stream.close() def test_content(self): self.serializer.serialize(Dive.objects.all(), stream=self.stream, fields=['id', 'name'], delete=False) self.assertEqual(self.stream.getvalue(), ('ID,Name\r\n{},' 'Test\r\n').format(self.point.pk)) @override_settings(USE_L10N=True) def test_content_fr(self): translation.activate('fr') self.serializer.serialize(Dive.objects.all(), stream=self.stream, fields=['id', 'name'], delete=False) self.assertEqual(self.stream.getvalue(), ('ID,Nom\r\n{},' 'Test\r\n').format(self.point.pk)) translation.deactivate()
class CSVSerializerTests(TestCase): def setUp(self): self.point = MushroomSpot.objects.create() self.serializer = CSVSerializer() self.stream = StringIO() def tearDown(self): self.stream.close() def test_content(self): self.serializer.serialize( MushroomSpot.objects.all(), stream=self.stream, fields=['id', 'name', 'number', 'size', 'boolean'], delete=False) self.assertEquals( self.stream.getvalue(), 'ID,name,number,size,boolean\r\n1,Empty,42,3.14159,yes\r\n') @override_settings(USE_L10N=True) def test_content_fr(self): translation.activate('fr-fr') self.serializer.serialize( MushroomSpot.objects.all(), stream=self.stream, fields=['id', 'name', 'number', 'size', 'boolean'], delete=False) self.assertEquals( self.stream.getvalue(), 'ID,name,number,size,boolean\r\n1,Empty,42,"3,14159",oui\r\n') translation.deactivate()
class CSVSerializerTests(TestCase): def setUp(self): self.point = MushroomSpot.objects.create() self.serializer = CSVSerializer() self.stream = StringIO() def tearDown(self): self.stream.close() def test_content(self): self.serializer.serialize(MushroomSpot.objects.all(), stream=self.stream, fields=['id', 'name', 'number', 'size', 'boolean'], delete=False) self.assertEquals(self.stream.getvalue(), 'ID,name,number,size,boolean\r\n1,Empty,42,3.14159,yes\r\n') @override_settings(USE_L10N=True) def test_content_fr(self): translation.activate('fr-fr') self.serializer.serialize(MushroomSpot.objects.all(), stream=self.stream, fields=['id', 'name', 'number', 'size', 'boolean'], delete=False) self.assertEquals(self.stream.getvalue(), 'ID,name,number,size,boolean\r\n1,Empty,42,"3,14159",oui\r\n') translation.deactivate()