Skip to content

Commit

Permalink
Merge 6a72a65 into 62d30f6
Browse files Browse the repository at this point in the history
  • Loading branch information
LePetitTim authored Mar 14, 2019
2 parents 62d30f6 + 6a72a65 commit aa0515e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion geotrek/common/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,11 @@ def start(self):
if settings.PAPERCLIP_ENABLE_LINK is False and self.download_attachments is False:
raise Exception(u'You need to enable PAPERCLIP_ENABLE_LINK to use this function')
try:
self.filetype = FileType.objects.get(type=self.filetype_name, structure=self.structure)
file_types = FileType.objects.filter(type=self.filetype_name, structure=None)
if file_types.exists():
self.filetype = file_types.first()
else:
self.filetype = FileType.objects.get(type=self.filetype_name, structure=self.structure)
except FileType.DoesNotExist:
raise GlobalImportError(_(u"FileType '{name}' does not exists in Geotrek-Admin. Please add it").format(name=self.filetype_name))
self.creator, created = get_user_model().objects.get_or_create(username='import', defaults={'is_active': False})
Expand Down
16 changes: 16 additions & 0 deletions geotrek/tourism/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ def mocked_json():
self.assertEqual(Attachment.objects.count(), 3)
self.assertEqual(Attachment.objects.first().content_object, content)

@mock.patch('requests.get')
def test_filetype_structure_none(self, mocked):
def mocked_json():
filename = os.path.join(os.path.dirname(__file__), 'data', 'apidaeContent.json')
with io.open(filename, 'r', encoding='utf8') as f:
return json.load(f)

mocked.return_value.status_code = 200
mocked.return_value.json = mocked_json
FileType.objects.create(type=u"Photographie", structure=None)
TouristicContentCategoryFactory(label=u"Eau vive")
TouristicContentTypeFactory(label=u"Type A", in_list=1)
TouristicContentTypeFactory(label=u"Type B", in_list=1)
call_command('import', 'geotrek.tourism.tests.test_parsers.EauViveParser', verbosity=0)
self.assertEqual(TouristicContent.objects.count(), 1)

@mock.patch('requests.get')
def test_create_event_apidae(self, mocked):
def mocked_json():
Expand Down

0 comments on commit aa0515e

Please sign in to comment.