Пример #1
0
    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(None, 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
            },
        ]
Пример #2
0
 def test_single_save_to_django_model_with_exception(self):
     model = FakeExceptionDjangoModel(raiseException=True)
     adapter = DjangoModelImportAdapter(model)
     adapter.column_names = self.data[0]
     writer = DjangoModelWriter(None, adapter)
     writer.write_array(self.data[1:])
     writer.close()
Пример #3
0
 def test_single_save_to_django_model_with_exception(self):
     model = FakeExceptionDjangoModel(raiseException=True)
     adapter = DjangoModelImportAdapter(model)
     adapter.column_names = self.data[0]
     writer = DjangoModelWriter(None, adapter)
     writer.write_array(self.data[1:])
     writer.close()
Пример #4
0
 def test_sheet_save_to_django_model(self):
     model = FakeDjangoModel()
     adapter = DjangoModelImportAdapter(model)
     adapter.column_names = self.data[0]
     writer = DjangoModelWriter(None, adapter)
     writer.write_array(self.data[1:])
     writer.close()
     eq_(model.objects.objs, self.result)
Пример #5
0
 def test_sheet_save_to_django_model(self):
     model = FakeDjangoModel()
     adapter = DjangoModelImportAdapter(model)
     adapter.column_names = self.data[0]
     writer = DjangoModelWriter(None, adapter)
     writer.write_array(self.data[1:])
     writer.close()
     eq_(model.objects.objs, self.result)
Пример #6
0
 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(None, adapter)
     writer.write_array(data[1:])
     writer.close()
     assert model.objects.objs == self.result
Пример #7
0
 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(None, adapter)
     writer.write_array(data[1:])
     writer.close()
     assert model.objects.objs == self.result
Пример #8
0
 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(None, adapter)
     writer.write_array(data2[1:])
     writer.close()
     eq_(model.objects.objs, self.result)
Пример #9
0
 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(None, adapter)
     writer.write_array(data2[1:])
     writer.close()
     eq_(model.objects.objs, self.result)
Пример #10
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

        adapter = DjangoModelImportAdapter(model)
        adapter.column_names = self.data[0]
        adapter.row_initializer = wrapper
        writer = DjangoModelWriter(None, adapter)
        writer.write_array(self.data[1:])
        writer.close()
        assert model.objects.objs == [{'Y': 2, 'X': 1, 'Z': 3}]
Пример #11
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

        adapter = DjangoModelImportAdapter(model)
        adapter.column_names = self.data[0]
        adapter.row_initializer = wrapper
        writer = DjangoModelWriter(None, adapter)
        writer.write_array(self.data[1:])
        writer.close()
        assert model.objects.objs == [{"Y": 2, "X": 1, "Z": 3}]