diff --git a/onadata/apps/api/tests/viewsets/test_briefcase_viewset.py b/onadata/apps/api/tests/viewsets/test_briefcase_viewset.py index 57e32af397..e133e32004 100644 --- a/onadata/apps/api/tests/viewsets/test_briefcase_viewset.py +++ b/onadata/apps/api/tests/viewsets/test_briefcase_viewset.py @@ -1,23 +1,23 @@ +import codecs import os import shutil -import codecs -import mock -from django.utils import timezone -from django.core.urlresolvers import reverse +import mock from django.core.files.storage import get_storage_class +from django.core.urlresolvers import reverse +from django.utils import timezone from django_digest.test import DigestAuth from rest_framework.test import APIRequestFactory from onadata.apps.api.tests.viewsets import test_abstract_viewset from onadata.apps.api.viewsets.briefcase_viewset import BriefcaseViewset -from onadata.apps.api.viewsets.xform_submission_viewset import\ +from onadata.apps.api.viewsets.xform_submission_viewset import \ XFormSubmissionViewSet +from onadata.apps.api.viewsets.xform_viewset import XFormViewSet from onadata.apps.logger.models import Instance from onadata.apps.logger.models import XForm -from onadata.apps.api.viewsets.xform_viewset import XFormViewSet -NUM_INSTANCES = 4 +NUM_INSTANCES = 5 storage = get_storage_class()() @@ -139,7 +139,7 @@ def test_view_submission_list_w_deleted_submission(self): self.assertEqual(response.status_code, 200) submission_list_path = os.path.join( self.main_directory, 'fixtures', 'transportation', - 'view', 'submissionList-4.xml') + 'view', 'submissionList-5.xml') instances = ordered_instances(self.xform) self.assertEqual(instances.count(), NUM_INSTANCES - 1) @@ -208,7 +208,7 @@ def get_last_index(xform, last_index=None): last_index = instances[:2][1].pk last_expected_submission_list = "" - for index in range(1, 5): + for index in range(1, 6): auth = DigestAuth(self.login_username, self.login_password) request = self.factory.get( self._submission_list_url, @@ -221,7 +221,7 @@ def get_last_index(xform, last_index=None): if index > 2: last_index = get_last_index(self.xform, last_index) filename = 'submissionList-%s.xml' % index - if index == 4: + if index == 5: self.assertContains(response, last_expected_submission_list) continue # set cursor for second request diff --git a/onadata/apps/api/tests/viewsets/test_xform_viewset.py b/onadata/apps/api/tests/viewsets/test_xform_viewset.py index 53149f9772..8b7edd30c2 100644 --- a/onadata/apps/api/tests/viewsets/test_xform_viewset.py +++ b/onadata/apps/api/tests/viewsets/test_xform_viewset.py @@ -4142,8 +4142,10 @@ def test_xform_version_count(self): self.assertIn("form_versions", response.data) self.assertEqual(response.data['form_versions'][0].get('total'), 4) + version = response.data['form_versions'][0].get('version') + # soft delete an instance - instance = self.xform.instances.last() + instance = self.xform.instances.filter(version=version).last() instance.set_deleted() # delete cache diff --git a/onadata/apps/logger/management/commands/create_image_thumbnails.py b/onadata/apps/logger/management/commands/create_image_thumbnails.py index a03718f33b..42cf3a7e1b 100644 --- a/onadata/apps/logger/management/commands/create_image_thumbnails.py +++ b/onadata/apps/logger/management/commands/create_image_thumbnails.py @@ -67,9 +67,11 @@ def handle(self, *args, **options): if not default_storage.exists(full_path): try: if default_storage.__class__ != fs.__class__: - resize(filename, att.extension) + resize(filename, + att.extension if att.extension != "non" else settings.DEFAULT_IMG_FILE_TYPE) else: - resize_local_env(filename, att.extension) + resize_local_env(filename, + att.extension if att.extension != "non" else settings.DEFAULT_IMG_FILE_TYPE) path = get_path( filename, '%s' % THUMB_CONF['small']['suffix']) if default_storage.exists(path): diff --git a/onadata/apps/main/tests/fixtures/transportation/instances/transport_2011-07-25_19-05-49_1/transport_2011-07-25_19-05-49_1.xml b/onadata/apps/main/tests/fixtures/transportation/instances/transport_2011-07-25_19-05-49_1/transport_2011-07-25_19-05-49_1.xml index 89c9134440..8f1f6fb27d 100644 --- a/onadata/apps/main/tests/fixtures/transportation/instances/transport_2011-07-25_19-05-49_1/transport_2011-07-25_19-05-49_1.xml +++ b/onadata/apps/main/tests/fixtures/transportation/instances/transport_2011-07-25_19-05-49_1/transport_2011-07-25_19-05-49_1.xml @@ -1,5 +1,5 @@ - + none diff --git a/onadata/apps/main/tests/fixtures/transportation/view/submissionList-3.xml b/onadata/apps/main/tests/fixtures/transportation/view/submissionList-3.xml index 3f750d9848..f5bffc7de0 100644 --- a/onadata/apps/main/tests/fixtures/transportation/view/submissionList-3.xml +++ b/onadata/apps/main/tests/fixtures/transportation/view/submissionList-3.xml @@ -1,5 +1,6 @@ + uuid:5b2cc313-fc09-437e-8149-fcd32f695d42 {{resumptionCursor}} diff --git a/onadata/apps/main/tests/fixtures/transportation/view/submissionList-4.xml b/onadata/apps/main/tests/fixtures/transportation/view/submissionList-4.xml index f8bc469949..3f750d9848 100644 --- a/onadata/apps/main/tests/fixtures/transportation/view/submissionList-4.xml +++ b/onadata/apps/main/tests/fixtures/transportation/view/submissionList-4.xml @@ -1,8 +1,5 @@ - uuid:5b2cc313-fc09-437e-8149-fcd32f695d41 - uuid:9c6f3468-cfda-46e8-84c1-75458e72805d - uuid:9f0a1508-c3b7-4c99-be00-9b237c26bcbf {{resumptionCursor}} diff --git a/onadata/apps/main/tests/fixtures/transportation/view/submissionList-5.xml b/onadata/apps/main/tests/fixtures/transportation/view/submissionList-5.xml new file mode 100644 index 0000000000..ecfa33fdc6 --- /dev/null +++ b/onadata/apps/main/tests/fixtures/transportation/view/submissionList-5.xml @@ -0,0 +1,9 @@ + + + uuid:5b2cc313-fc09-437e-8149-fcd32f695d41 + uuid:9c6f3468-cfda-46e8-84c1-75458e72805d + uuid:9f0a1508-c3b7-4c99-be00-9b237c26bcbf + uuid:5b2cc313-fc09-437e-8149-fcd32f695d42 + + {{resumptionCursor}} + diff --git a/onadata/apps/main/tests/fixtures/transportation/view/submissionList.xml b/onadata/apps/main/tests/fixtures/transportation/view/submissionList.xml index 9b61b76d73..9e727a8ad6 100644 --- a/onadata/apps/main/tests/fixtures/transportation/view/submissionList.xml +++ b/onadata/apps/main/tests/fixtures/transportation/view/submissionList.xml @@ -4,6 +4,7 @@ uuid:f3d8dc65-91a6-4d0f-9e97-802128083390 uuid:9c6f3468-cfda-46e8-84c1-75458e72805d uuid:9f0a1508-c3b7-4c99-be00-9b237c26bcbf + uuid:5b2cc313-fc09-437e-8149-fcd32f695d42 {{resumptionCursor}} diff --git a/onadata/libs/utils/image_tools.py b/onadata/libs/utils/image_tools.py index 710f0af2f6..e0fdc5c867 100644 --- a/onadata/libs/utils/image_tools.py +++ b/onadata/libs/utils/image_tools.py @@ -102,10 +102,11 @@ def image_url(attachment, suffix): get_path(filename, size)) else: if default_storage.__class__ != fs.__class__: - resize(filename, extension=attachment.extension) + resize(filename, + attachment.extension if attachment.extension != "non" else settings.DEFAULT_IMG_FILE_TYPE) else: resize_local_env(filename, - extension=attachment.extension) + attachment.extension if attachment.extension != "non" else settings.DEFAULT_IMG_FILE_TYPE) return image_url(attachment, suffix) else: diff --git a/onadata/settings/common.py b/onadata/settings/common.py index 92586a66d3..4cdfbb871c 100644 --- a/onadata/settings/common.py +++ b/onadata/settings/common.py @@ -9,22 +9,15 @@ # imports this one. # The local files should be used as the value for your DJANGO_SETTINGS_MODULE # environment variable as needed. -import logging import os import socket -import subprocess # noqa, used by included files import sys from imp import reload +from celery.signals import after_setup_logger from future.moves.urllib.parse import urljoin - from past.builtins import basestring -from django.core.exceptions import SuspiciousOperation -from django.utils.log import AdminEmailHandler - -from celery.signals import after_setup_logger - # setting default encoding to utf-8 if sys.version[0] == '2': reload(sys) @@ -426,6 +419,7 @@ def configure_logging(logger, **kwargs): } # order of thumbnails from largest to smallest THUMB_ORDER = ['large', 'medium', 'small'] +DEFAULT_IMG_FILE_TYPE = 'jpg' # celery CELERY_RESULT_BACKEND = 'django-db'