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 }, ]
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}]
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}]
def test_django_model_import_adapter(): adapter = DjangoModelImportAdapter(FakeDjangoModel) adapter.column_names = ["a"] adapter.row_initializer = "abc" eq_(adapter.row_initializer, "abc")
def test_django_model_import_adapter(): adapter = DjangoModelImportAdapter(FakeDjangoModel) adapter.column_names = ["a"] adapter.row_initializer = "abc" eq_(adapter.row_initializer, "abc")