示例#1
0
 def test_load_sheet_from_django_model(self):
     model = FakeDjangoModel()
     importer = DjangoModelImporter()
     adapter = DjangoModelImportAdapter(model)
     adapter.column_names = self.data[0]
     importer.append(adapter)
     save_data(importer, {adapter.get_name(): self.data[1:]},
               file_type=DB_DJANGO)
     assert model.objects.objs == self.result
     model._meta.update(["X", "Y", "Z"])
     reader = DjangoModelReader(model)
     data = reader.to_array()
     assert list(data) == self.data
示例#2
0
 def test_load_sheet_from_django_model(self):
     model = FakeDjangoModel()
     importer = DjangoModelImporter()
     adapter = DjangoModelImportAdapter(model)
     adapter.column_names = self.data[0]
     importer.append(adapter)
     save_data(
         importer, {adapter.get_name(): self.data[1:]}, file_type=DB_DJANGO
     )
     assert model.objects.objs == self.result
     model._meta.update(["X", "Y", "Z"])
     reader = DjangoModelReader(model)
     data = reader.to_array()
     assert list(data) == self.data
示例#3
0
    def test_load_and_format_sheet_from_django_model(self):
        model = FakeDjangoModel()
        importer = DjangoModelImporter()
        adapter = DjangoModelImportAdapter(model)
        adapter.column_names = self.data[0]
        importer.append(adapter)
        save_data(importer, {adapter.get_name(): self.data[1:]},
                  file_type=DB_DJANGO)
        assert model.objects.objs == self.result
        model._meta.update(["X", "Y", "Z"])

        def row_renderer(row):
            return [str(element) for element in row]

        # the key point of this test case
        reader = DjangoModelReader(model, row_renderer=row_renderer)
        data = reader.to_array()
        expected = [["X", "Y", "Z"], ["1", "2", "3"], ["4", "5", "6"]]
        eq_(list(data), expected)
示例#4
0
    def test_load_and_format_sheet_from_django_model(self):
        model = FakeDjangoModel()
        importer = DjangoModelImporter()
        adapter = DjangoModelImportAdapter(model)
        adapter.column_names = self.data[0]
        importer.append(adapter)
        save_data(
            importer, {adapter.get_name(): self.data[1:]}, file_type=DB_DJANGO
        )
        assert model.objects.objs == self.result
        model._meta.update(["X", "Y", "Z"])

        def row_renderer(row):
            return [str(element) for element in row]

        # the key point of this test case
        reader = DjangoModelReader(model, row_renderer=row_renderer)
        data = reader.to_array()
        expected = [["X", "Y", "Z"], ["1", "2", "3"], ["4", "5", "6"]]
        eq_(list(data), expected)
示例#5
0
 def test_load_sheet_from_django_model_with_filter_3(self):
     reader = DjangoModelReader(self.model, start_column=1, column_limit=1)
     data = reader.to_array()
     expected = [["Y"], [2], [5]]
     eq_(list(data), expected)
示例#6
0
 def test_load_sheet_from_django_model_with_filter_1(self):
     reader = DjangoModelReader(self.model, start_row=1, row_limit=3)
     data = reader.to_array()
     expected = [[1, 2, 3], [4, 5, 6]]
     eq_(list(data), expected)
示例#7
0
 def test_load_sheet_from_django_model_with_filter(self):
     reader = DjangoModelReader(self.model, start_row=0, row_limit=2)
     data = reader.to_array()
     expected = [["X", "Y", "Z"], [1, 2, 3]]
     eq_(list(data), expected)
示例#8
0
 def test_empty_model(self):
     model = FakeDjangoModel()
     reader = DjangoModelReader(model)
     data = reader.to_array()
     eq_(list(data), [[], []])
 def test_load_sheet_from_django_model_with_filter_2(self):
     reader = DjangoModelReader(self.model, start_column=1)
     data = reader.to_array()
     expected = [['Y', 'Z'], [2, 3], [5, 6]]
     eq_(list(data), expected)
示例#10
0
 def test_load_sheet_from_django_model_with_filter_3(self):
     reader = DjangoModelReader(self.model, start_column=1, column_limit=1)
     data = reader.to_array()
     expected = [["Y"], [2], [5]]
     eq_(list(data), expected)
示例#11
0
 def test_load_sheet_from_django_model_with_filter_1(self):
     reader = DjangoModelReader(self.model, start_row=1, row_limit=3)
     data = reader.to_array()
     expected = [[1, 2, 3], [4, 5, 6]]
     eq_(list(data), expected)
示例#12
0
 def test_load_sheet_from_django_model_with_filter(self):
     reader = DjangoModelReader(self.model, start_row=0, row_limit=2)
     data = reader.to_array()
     expected = [["X", "Y", "Z"], [1, 2, 3]]
     eq_(list(data), expected)
示例#13
0
 def test_empty_model(self):
     model = FakeDjangoModel()
     reader = DjangoModelReader(model)
     data = reader.to_array()
     eq_(list(data), [[], []])