def test_csv_import_latin_char(self): self.assertEqual(Part.query.count(), 0) name = "hèllô" barcode = "wèrld" csv = io.StringIO(("name,barcode\n%s,%s\n" % (name, barcode))) filename = "/tmp/%s" % (uuid.uuid4()) with open(filename, "wb") as f: f.write(csv.getvalue().encode("latin1")) Part.import_csv(filename) self.assertEqual(Part.query.count(), 1) p = Part.query.get(1) self.assertEqual(p.name, name) self.assertEqual(p.barcode, barcode)
def test_csv_import_1(self): """ Test to import a CSV file in the DB """ self.assertEqual(Part.query.count(), 0) csv = io.StringIO("name,barcode\nhello,world\nfoo,bar\n123,456\n") filename = "/tmp/%s" % (uuid.uuid4()) with open(filename, "w") as f: print(csv.getvalue(), file=f) Part.import_csv(filename) self.assertEqual(Part.query.count(), 3) p = Part.query.filter(Part.barcode == "bar").first() self.assertEqual(p.name, "foo") self.assertEqual(p.barcode, "bar") p = Part.query.filter(Part.barcode == "world").first() self.assertEqual(p.name, "hello") self.assertEqual(p.barcode, "world") p = Part.query.filter(Part.barcode == "456").first() self.assertEqual(p.name, "123") self.assertEqual(p.barcode, "456")