Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix XLSX bulk library import, broken by #3765 #4779

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 16 additions & 5 deletions kpi/tests/api/v2/test_api_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ def test_import_locking_xls_as_question(self):
assert expected_content_settings == created_asset.content['settings']
assert not created_asset.content['kobo--locking-profiles']

def test_import_library_bulk_xls(self):
def _test_import_library_bulk(self, filetype='xlsx'):
library_sheet_content = [
['block', 'name', 'type', 'label', 'tag:subject:fungus', 'tag:subject:useless'],
['mushroom', 'cap', 'text', 'Describe the cap', '1', None],
Expand All @@ -785,14 +785,19 @@ def test_import_library_bulk_xls(self):
['seasons', 'fall', 'Fall'],
['seasons', 'winter', 'Winter'],
]

content = (
('library', library_sheet_content),
('choices', choices_sheet_content),
)
task_data = self._construct_xls_for_import(
content, name='Collection created from bulk library import'
)
name='Collection created from bulk library import'

if filetype == 'xls':
task_data = self._construct_xls_for_import(content, name=name)
elif filetype == 'xlsx':
task_data = self._construct_xlsx_for_import(content, name=name)
else:
raise NotImplementedError(f'{filetype} must be either xls or xlsx')

post_url = reverse('api_v2:importtask-list')
response = self.client.post(post_url, task_data)
assert response.status_code == status.HTTP_201_CREATED
Expand Down Expand Up @@ -888,6 +893,12 @@ def test_import_library_bulk_xls(self):
tagged_as_useless[1], non_block_assets[1]
)

def test_import_library_bulk_xls(self):
self._test_import_library_bulk('xls')

def test_import_library_bulk_xlsx(self):
self._test_import_library_bulk('xlsx')

def test_import_asset_xls(self):
xlsx_io = self.asset.to_xlsx_io()
task_data = {
Expand Down
2 changes: 1 addition & 1 deletion kpi/utils/rename_xls_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ def rename_xlsx_sheet(
raise NoFromSheetError(from_sheet)
book[from_sheet].title = to_sheet
stream = BytesIO()
writable.save(stream)
book.save(stream)
jnm marked this conversation as resolved.
Show resolved Hide resolved
stream.seek(0)
return stream