def test_sheet_save_to_django_model(self):
     model = FakeDjangoModel()
     adapter = DjangoModelImportAdapter(model)
     adapter.column_names = self.data[0]
     writer = DjangoModelWriter(adapter)
     writer.write_array(self.data[1:])
     writer.close()
     eq_(model.objects.objs, self.result)
Beispiel #2
0
 def test_sheet_save_to_django_model(self):
     model=FakeExceptionDjangoModel()
     writer = DjangoModelWriter([model, self.data[0], None, None])
     writer.write_array(self.data[1:])
     writer.close()
     # now raise excpetion
     model=FakeExceptionDjangoModel(raiseException=True)
     writer = DjangoModelWriter([model, self.data[0], None, None])
     writer.write_array(self.data[1:])
     writer.close()
Beispiel #3
0
 def test_mapping_array(self):
     data2 = [
         ["A", "B", "C"],
         [1, 2, 3],
         [4, 5, 6]
     ]
     mapdict = ["X", "Y", "Z"]
     model=FakeDjangoModel()
     writer = DjangoModelWriter([model, data2[0], mapdict, None])
     writer.write_array(data2[1:])
     writer.close()
     assert model.objects.objs == self.result
Beispiel #4
0
 def test_sheet_save_to_django_model_3(self):
     model=FakeDjangoModel()
     def wrapper(row):
         row[0] = row[0] + 1
         return row
     writer = DjangoModelWriter([model, self.data[0], None, wrapper])
     writer.write_array(self.data[1:])
     writer.close()
     assert model.objects.objs == [
         {'Y': 2, 'X': 2, 'Z': 3},
         {'Y': 5, 'X': 5, 'Z': 6}
     ]
Beispiel #5
0
 def test_sheet_save_to_django_model_with_empty_array(self):
     model=FakeDjangoModel()
     data  = [
         ["X", "Y", "Z"],
         ['', '', ''],
         [1, 2, 3],
         [4, 5, 6]
     ]
     writer = DjangoModelWriter([model, data[0], None, None])
     writer.write_array(data[1:])
     writer.close()
     assert model.objects.objs == self.result
Beispiel #6
0
 def test_sheet_save_to_django_model_skip_me(self):
     model=FakeDjangoModel()
     def wrapper(row):
         if row[0] == 4:
             return None
         else:
             return row
     writer = DjangoModelWriter([model, self.data[0], None, wrapper])
     writer.write_array(self.data[1:])
     writer.close()
     assert model.objects.objs == [
         {'Y': 2, 'X': 1, 'Z': 3}
     ]
 def test_mapping_array(self):
     data2 = [
         ["A", "B", "C"],
         [1, 2, 3],
         [4, 5, 6]
     ]
     model = FakeDjangoModel()
     adapter = DjangoModelImportAdapter(model)
     adapter.column_names = data2[0]
     adapter.column_name_mapping_dict = ["X", "Y", "Z"]
     writer = DjangoModelWriter(adapter)
     writer.write_array(data2[1:])
     writer.close()
     eq_(model.objects.objs, self.result)
 def test_sheet_save_to_django_model_with_empty_array(self):
     model = FakeDjangoModel()
     data = [
         ["X", "Y", "Z"],
         ['', '', ''],
         [1, 2, 3],
         [4, 5, 6]
     ]
     adapter = DjangoModelImportAdapter(model)
     adapter.column_names = self.data[0]
     writer = DjangoModelWriter(adapter)
     writer.write_array(data[1:])
     writer.close()
     assert model.objects.objs == self.result
 def test_sheet_save_to_django_model(self):
     model = FakeExceptionDjangoModel()
     adapter = DjangoModelImportAdapter(model)
     adapter.column_names = self.data[0]
     writer = DjangoModelWriter(adapter)
     writer.write_array(self.data[1:])
     writer.close()
     # now raise excpetion
     model = FakeExceptionDjangoModel(raiseException=True)
     adapter = DjangoModelImportAdapter(model)
     adapter.column_names = self.data[0]
     writer = DjangoModelWriter(adapter)
     writer.write_array(self.data[1:])
     writer.close()
    def test_sheet_save_to_django_model_3(self):
        model = FakeDjangoModel()

        def wrapper(row):
            row[0] = row[0] + 1
            return row
        adapter = DjangoModelImportAdapter(model)
        adapter.column_names = self.data[0]
        adapter.row_initializer = wrapper
        writer = DjangoModelWriter(adapter)
        writer.write_array(self.data[1:])
        writer.close()
        assert model.objects.objs == [
            {'Y': 2, 'X': 2, 'Z': 3},
            {'Y': 5, 'X': 5, 'Z': 6}
        ]
 def test_mapping_dict(self):
     data2 = [["A", "B", "C"], [1, 2, 3], [4, 5, 6]]
     mapdict = {"C": "Z", "A": "X", "B": "Y"}
     model = FakeDjangoModel()
     adapter = DjangoModelImportAdapter(model)
     adapter.column_names = data2[0]
     adapter.column_name_mapping_dict = mapdict
     writer = DjangoModelWriter(adapter)
     writer.write_array(data2[1:])
     writer.close()
     eq_(model.objects.objs, self.result)
 def test_sheet_save_to_django_model_with_empty_array(self):
     model = FakeDjangoModel()
     data = [
         ["X", "Y", "Z"],
         ['', '', ''],
         [1, 2, 3],
         [4, 5, 6]
     ]
     adapter = DjangoModelImportAdapter(model)
     adapter.column_names = self.data[0]
     writer = DjangoModelWriter(adapter)
     writer.write_array(data[1:])
     writer.close()
     assert model.objects.objs == self.result
    def test_sheet_save_to_django_model_skip_me(self):
        model = FakeDjangoModel()

        def wrapper(row):
            if row[0] == 4:
                return None
            else:
                return row

        adapter = DjangoModelImportAdapter(model)
        adapter.column_names = self.data[0]
        adapter.row_initializer = wrapper
        writer = DjangoModelWriter(adapter)
        writer.write_array(self.data[1:])
        writer.close()
        assert model.objects.objs == [{'Y': 2, 'X': 1, 'Z': 3}]
 def test_sheet_save_to_django_model(self):
     model = FakeExceptionDjangoModel()
     adapter = DjangoModelImportAdapter(model)
     adapter.column_names = self.data[0]
     writer = DjangoModelWriter(adapter)
     writer.write_array(self.data[1:])
     writer.close()
     # now raise excpetion
     model = FakeExceptionDjangoModel(raiseException=True)
     adapter = DjangoModelImportAdapter(model)
     adapter.column_names = self.data[0]
     writer = DjangoModelWriter(adapter)
     writer.write_array(self.data[1:])
     writer.close()
Beispiel #15
0
 def test_sheet_save_to_django_model(self):
     model=FakeDjangoModel()
     writer = DjangoModelWriter([model, self.data[0], None, None])
     writer.write_array(self.data[1:])
     writer.close()
     assert model.objects.objs == self.result