Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release/2.024.36'
Browse files Browse the repository at this point in the history
  • Loading branch information
jnm committed Jan 14, 2025
2 parents 89bd9b7 + b4aa1b7 commit d22b8b5
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dependencies/pip/dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# via -r dependencies/pip/requirements.in
-e git+https://github.com/trevoriancox/django-dont-vary-on.git@01a804122b7ddcdc22f50b40993f91c27b03bef6#egg=django-dont-vary-on
# via -r dependencies/pip/requirements.in
-e git+https://github.com/kobotoolbox/formpack.git@5a8cda8cc37a56a2313c98b88fcacc18049ef477#egg=formpack
-e git+https://github.com/kobotoolbox/formpack.git@894d285b1d2955b2990500427158e845af32259d#egg=formpack
# via -r dependencies/pip/requirements.in
-e git+https://github.com/dimagi/python-digest@5c94bb74516b977b60180ee832765c0695ff2b56#egg=python_digest
# via -r dependencies/pip/requirements.in
Expand Down
2 changes: 1 addition & 1 deletion dependencies/pip/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://github.com/bndr/pipreqs is a handy utility, too.

# formpack
-e git+https://github.com/kobotoolbox/formpack.git@5a8cda8cc37a56a2313c98b88fcacc18049ef477#egg=formpack
-e git+https://github.com/kobotoolbox/formpack.git@894d285b1d2955b2990500427158e845af32259d#egg=formpack

# More up-to-date version of django-digest than PyPI seems to have.
# Also, python-digest is an unlisted dependency thereof.
Expand Down
2 changes: 1 addition & 1 deletion dependencies/pip/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# via -r dependencies/pip/requirements.in
-e git+https://github.com/trevoriancox/django-dont-vary-on.git@01a804122b7ddcdc22f50b40993f91c27b03bef6#egg=django-dont-vary-on
# via -r dependencies/pip/requirements.in
-e git+https://github.com/kobotoolbox/formpack.git@5a8cda8cc37a56a2313c98b88fcacc18049ef477#egg=formpack
-e git+https://github.com/kobotoolbox/formpack.git@894d285b1d2955b2990500427158e845af32259d#egg=formpack
# via -r dependencies/pip/requirements.in
-e git+https://github.com/dimagi/python-digest@5c94bb74516b977b60180ee832765c0695ff2b56#egg=python_digest
# via -r dependencies/pip/requirements.in
Expand Down
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
18 changes: 13 additions & 5 deletions kpi/serializers/v2/deployment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# coding: utf-8
from django.conf import settings
from pyxform.errors import PyXFormError
from pyxform.validators.enketo_validate import EnketoValidateError
from pyxform.validators.odk_validate import ODKValidateError
from rest_framework import serializers
from xlsxwriter.exceptions import DuplicateWorksheetName

from .asset import AssetSerializer

Expand All @@ -16,8 +18,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 +38,13 @@ 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,
EnketoValidateError,
PyXFormError,
ODKValidateError,
) 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 @@ -1806,10 +1806,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']
)

def test_asset_redeployment(self):
Expand Down

0 comments on commit d22b8b5

Please sign in to comment.