Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Lincoln Simba <[email protected]>
  • Loading branch information
lincmba committed Dec 28, 2018
1 parent 83039df commit 8008520
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 19 deletions.
20 changes: 10 additions & 10 deletions onadata/apps/api/tests/viewsets/test_briefcase_viewset.py
Original file line number Diff line number Diff line change
@@ -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()()


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion onadata/apps/api/tests/viewsets/test_xform_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' ?>
<transportation id="transportation_2011_07_25" version="2014111">
<transportation id="transportation_2011_07_25" version="2018111">
<transport>
<available_transportation_types_to_referral_facility>none
</available_transportation_types_to_referral_facility>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<idChunk xmlns="http://opendatakit.org/submissions">
<idList>
<id>uuid:5b2cc313-fc09-437e-8149-fcd32f695d42</id>
</idList>
<resumptionCursor>{{resumptionCursor}}</resumptionCursor>
</idChunk>
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<idChunk xmlns="http://opendatakit.org/submissions">
<idList>
<id>uuid:5b2cc313-fc09-437e-8149-fcd32f695d41</id>
<id>uuid:9c6f3468-cfda-46e8-84c1-75458e72805d</id>
<id>uuid:9f0a1508-c3b7-4c99-be00-9b237c26bcbf</id>
</idList>
<resumptionCursor>{{resumptionCursor}}</resumptionCursor>
</idChunk>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<idChunk xmlns="http://opendatakit.org/submissions">
<idList>
<id>uuid:5b2cc313-fc09-437e-8149-fcd32f695d41</id>
<id>uuid:9c6f3468-cfda-46e8-84c1-75458e72805d</id>
<id>uuid:9f0a1508-c3b7-4c99-be00-9b237c26bcbf</id>
<id>uuid:5b2cc313-fc09-437e-8149-fcd32f695d42</id>
</idList>
<resumptionCursor>{{resumptionCursor}}</resumptionCursor>
</idChunk>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<id>uuid:f3d8dc65-91a6-4d0f-9e97-802128083390</id>
<id>uuid:9c6f3468-cfda-46e8-84c1-75458e72805d</id>
<id>uuid:9f0a1508-c3b7-4c99-be00-9b237c26bcbf</id>
<id>uuid:5b2cc313-fc09-437e-8149-fcd32f695d42</id>
</idList>
<resumptionCursor>{{resumptionCursor}}</resumptionCursor>
</idChunk>
5 changes: 3 additions & 2 deletions onadata/libs/utils/image_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions onadata/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,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'
Expand Down

0 comments on commit 8008520

Please sign in to comment.