Skip to content

Commit

Permalink
Bug using tuple in Meta.exclude fields resolved #63
Browse files Browse the repository at this point in the history
  • Loading branch information
valdergallo committed Mar 6, 2015
1 parent 5d79cdc commit a4e3967
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions data_importer/importers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def exclude_fields(self):
self._excluded = True
for exclude in self.Meta.exclude:
if exclude in self.fields:
self.fields = list(self.fields)
self.fields.remove(exclude)

def load_descriptor(self):
Expand Down
24 changes: 24 additions & 0 deletions data_importer/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,30 @@ def clean_test_field(self, value):
(1, {'test_number_field': '1', 'test_field': 'TEST1'}),
importer.cleaned_data[0])

def test_exclude_with_tupla(self):
class TestMeta(CSVImporter):
fields = [
'test_field',
'test_number_field',
'test3_field',
]

class Meta:
exclude = ('test3_field',)
delimiter = ','
raise_errors = True
ignore_first_line = True

def clean_test_field(self, value):
return str(value).upper()

self.source_content.seek(0)
importer = TestMeta(source=self.source_content)
self.assertTrue(importer.is_valid(), importer.errors)
self.assertEquals(importer.cleaned_data[0],
(1, {'test_number_field': '1', 'test_field': 'TEST1'}),
importer.cleaned_data[0])


class TestImporter(BaseImporter):
fields = ('name', 'value')
Expand Down

0 comments on commit a4e3967

Please sign in to comment.