from django.test import TestCase

from django_tablib import ModelDataset, Field

from .models import TestModel


class DjangoTablibTestCase(TestCase):
    def test_declarative_fields(self):
        class TestModelDataset(ModelDataset):
            field1 = Field()
            field2 = Field(attribute='field1')

            class Meta:
                model = TestModel

        data = TestModelDataset()

        self.assertEqual(len(data.headers), 2)
        self.assertTrue('id' not in data.headers)
        self.assertTrue('field1' in data.headers)
        self.assertTrue('field2' in data.headers)

from django.test import TestCase

from django_tablib import ModelDataset, Field

from .models import TestModel


class DjangoTablibTestCase(TestCase):
    def setUp(self):
        TestModel.objects.create(field1='value')

    def test_declarative_fields(self):
        class TestModelDataset(ModelDataset):
            field1 = Field()
            field2 = Field(attribute='field1')

            class Meta:
                model = TestModel

        data = TestModelDataset()

        self.assertEqual(len(data.headers), 2)
        self.assertTrue('id' not in data.headers)
        self.assertTrue('field1' in data.headers)
        self.assertTrue('field2' in data.headers)

        self.assertEqual(data[0][0], data[0][1])

Test that declarative fields actually work.