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: handle case sensitivity for "Settings" sheet name with explicit error TASK-1353 #5417

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions kpi/mixins/xls_exportable.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@


class XlsExportableMixin:
def ordered_xlsform_content(self,
kobo_specific_types=False,
append=None):
def ordered_xlsform_content(self, kobo_specific_types=False, append=None):
# currently, this method depends on "FormpackXLSFormUtilsMixin"
content = copy.deepcopy(self.content)
if append:
Expand Down
11 changes: 6 additions & 5 deletions kpi/serializers/v2/deployment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8
from django.conf import settings
from pyxform.errors import PyXFormError
from rest_framework import serializers
from xlsxwriter.exceptions import DuplicateWorksheetName

from .asset import AssetSerializer

Expand All @@ -16,8 +16,9 @@ class DeploymentSerializer(serializers.Serializer):
def _raise_unless_current_version(asset, validated_data):
# Stop if the requester attempts to deploy any version of the asset
# except the current one
if 'version_id' in validated_data and \
validated_data['version_id'] != str(asset.version_id):
if 'version_id' in validated_data and validated_data[
'version_id'
] != str(asset.version_id):
raise NotImplementedError(
'Only the current version_id can be deployed')

Expand All @@ -35,8 +36,8 @@ def create(self, validated_data):
# 'deployed' boolean value
try:
asset.deploy(backend=backend_id, active=validated_data.get('active', False))
except PyXFormError as e:
raise serializers.ValidationError({'error': (f'ODK Validation Error: {e}')})
except (DuplicateWorksheetName, PyXFormError) as e:
raise serializers.ValidationError({'error': str(e)})
return asset.deployment

def update(self, instance, validated_data):
Expand Down
46 changes: 42 additions & 4 deletions kpi/tests/api/v2/test_api_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1862,10 +1862,48 @@ def test_asset_deployment_validation_error(self):
self.assertEqual(deploy_response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
deploy_response.data['error'],
(
'ODK Validation Error: '
"The survey element named 'Enter_an_int_number' has no label or hint."
),
"The survey element named 'Enter_an_int_number' has no label or hint.",
)

def test_asset_deployment_with_sheet_name_Settings(self): # noqa
content = {
'schema': '1',
'survey': [
{
'name': 'Enter_a_float_number',
'type': 'decimal',
'label': ['Enter a float number'],
'required': False,
},
],
'choices': [],
'settings': {},
'Settings': [], # simulate sheet name called `Settings` on import
}
assets_url = reverse(self._get_endpoint('asset-list'))
asset_response = self.client.post(
assets_url,
{'content': content, 'asset_type': 'survey'},
format='json',
)
asset = Asset.objects.get(uid=asset_response.data.get('uid'))

deployment_url = reverse(
self._get_endpoint('asset-deployment'), kwargs={'uid': asset.uid}
)

deploy_response = self.client.post(
deployment_url,
{
'backend': 'mock',
'active': True,
},
)

assert deploy_response.status_code == status.HTTP_400_BAD_REQUEST
assert (
"Sheetname 'Settings', with case ignored, is already in use"
in deploy_response.data['error']
)

@patch('kpi.views.v2.asset.ProjectHistoryLog.create_from_deployment_request')
Expand Down
Loading