Skip to content

Commit

Permalink
[#1262] fix test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
kindly committed Oct 10, 2013
1 parent 1b62423 commit c4d6733
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
12 changes: 7 additions & 5 deletions ckan/lib/uploader.py
Expand Up @@ -4,10 +4,12 @@
import datetime
import ckan.lib.munge as munge


class Upload(object):
def __init__(self, object_type, old_filename=None):
path = pylons.config.get('ckan.storage_path', '/tmp')
self.storage_path = os.path.join(path, 'storage', 'uploads', object_type)
self.storage_path = os.path.join(path, 'storage',
'uploads', object_type)
try:
os.makedirs(self.storage_path)
except OSError, e:
Expand All @@ -22,7 +24,7 @@ def __init__(self, object_type, old_filename=None):
def update_data_dict(self, data_dict, url_field, file_field, clear_field):
self.url = data_dict.get(url_field, '')
self.clear = data_dict.pop(clear_field, None)
self.upload_field_storage = data_dict.pop(file_field, None)
self.upload_field_storage = data_dict.pop(file_field, None)

if isinstance(self.upload_field_storage, cgi.FieldStorage):
self.filename = self.upload_field_storage.filename
Expand All @@ -39,13 +41,13 @@ def update_data_dict(self, data_dict, url_field, file_field, clear_field):
if self.clear and self.url == self.old_filename:
data_dict[url_field] = ''


def upload(self):
if self.filename:
output_file = open(self.tmp_filepath, 'wb')
self.upload_file.seek(0)
while True:
data = self.upload_file.read(2 ** 20) #mb chuncks
# mb chuncks
data = self.upload_file.read(2 ** 20)
if not data:
break
output_file.write(data)
Expand All @@ -54,7 +56,7 @@ def upload(self):
self.clear = True

if (self.clear and self.old_filename
and not self.old_filename.startswith('http')):
and not self.old_filename.startswith('http')):
try:
os.remove(self.old_filepath)
except OSError, e:
Expand Down
2 changes: 2 additions & 0 deletions ckan/tests/lib/test_dictization.py
Expand Up @@ -923,6 +923,7 @@ def test_16_group_dictized(self):
'capacity' : 'public',
'display_name': u'simple',
'image_url': u'',
'image_display_url': u'',
'name': u'simple',
'packages': 0,
'state': u'active',
Expand All @@ -944,6 +945,7 @@ def test_16_group_dictized(self):
'name': u'help',
'display_name': u'help',
'image_url': u'',
'image_display_url': u'',
'package_count': 2,
'is_organization': False,
'packages': [{'author': None,
Expand Down
1 change: 1 addition & 0 deletions ckan/tests/lib/test_dictization_schema.py
Expand Up @@ -160,6 +160,7 @@ def test_2_group_schema(self):
'is_organization': False,
'type': u'group',
'image_url': u'',
'image_display_url': u'',
'packages': sorted([{'id': group_pack[0].id,
'name': group_pack[0].name,
'title': group_pack[0].title},
Expand Down

0 comments on commit c4d6733

Please sign in to comment.