Ejemplo n.º 1
0
 def test_csv_import_4(self):
     """
     Test the import of file with empty field that should be passed
     """
     self.assertEqual(Part.query.count(), 0)
     csv = io.StringIO(
         "name,barcode\nhello,world\nfoo,\n,456\n,433,\nfoo,bar\n")
     Part._import_csv_content(csv)
     self.assertEqual(Part.query.count(), 2)
Ejemplo n.º 2
0
 def test_csv_import_3(self):
     """
     Test the import doesn't fail when importing the same data and erase the data
     """
     self.assertEqual(Part.query.count(), 0)
     csv_content = "name,barcode\nhello,world\nfoo,bar\n123,456\n"
     Part._import_csv_content(io.StringIO(csv_content))
     self.assertEqual(Part.query.count(), 3)
     csv_content = "name,barcode\nfoo,bar\n123,456\nfoo2,bar2\n324,561\n"
     Part._import_csv_content(io.StringIO(csv_content))
     self.assertEqual(Part.query.filter(Part.hidden == False).count(), 4)
Ejemplo n.º 3
0
 def test_csv_re_import(self):
     """
     Test to import a CSV StringIO in the DB
     """
     self.assertEqual(Part.query.count(), 0)
     csv1 = io.StringIO("name,barcode\nhello,world\nfoo,bar\n123,456\n")
     Part._import_csv_content(csv1)
     self.assertEqual(Part.query.count(), 3)
     csv2 = io.StringIO("name,barcode\nhello,world\nfoo,bar\n")
     Part._import_csv_content(csv2)
     self.assertEqual(Part.query.filter(Part.hidden == False).count(), 2)
     self.assertEqual(Part.query.count(), 3)
Ejemplo n.º 4
0
 def test_csv_import_with_csv_map_1(self):
     """
     Test to import a CSV StringIO in the DB
     """
     self.assertEqual(Part.query.count(), 0)
     csv = io.StringIO(
         "default_name,barcode\nhello,world\nfoo,bar\n123,456\n")
     Part._import_csv_content(csv, {
         "name": "default_name",
         "barcode": "barcode"
     })
     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")
Ejemplo n.º 5
0
 def test_csv_import_with_csv_map_2(self):
     """
     Test to import a CSV StringIO in the DB with a CSV map
     """
     self.assertEqual(Part.query.count(), 0)
     csv = io.StringIO(
         '"Référence interne","Code Barre"\n"hello","world"\n"foo","bar"\n"123","456"\n'
     )
     Part._import_csv_content(csv, {
         "name": "Référence interne",
         "barcode": "Code Barre"
     })
     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")