Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
[HOT-FIX] correct method which get files from s3 - if byte type in py…
…3 - decode to utf-8;
  • Loading branch information
opalczynski committed Sep 27, 2016
commit 5c69f72e02424dbd5f5fb7152f414acf37cf7397
21 changes: 15 additions & 6 deletions tests/integration_test_data_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_updating_file_field(self):
file_url = data_object.test_field_file

update_string = 'updating also field a'
file_content = 'some example text file;'
file_content = 'some example text file'
new_file = StringIO(file_content)
data_object.test_field_file = new_file
data_object.test_field_a = update_string
Expand All @@ -67,7 +67,7 @@ def test_updating_file_field(self):
self.assertNotEqual(data_object.test_field_file, file_url)

# check file content;
file_content_s3 = requests.get(data_object.test_field_file).content
file_content_s3 = self.get_s3_file(data_object.test_field_file)
self.assertEqual(file_content_s3, file_content)

def test_manager_update(self):
Expand Down Expand Up @@ -101,7 +101,9 @@ def test_manager_update(self):
self.assertEqual(data_object.test_field_a, new_update_string)
# should change;
self.assertNotEqual(data_object.test_field_file, file_url)
file_content_s3 = requests.get(data_object.test_field_file).content

# check file content;
file_content_s3 = self.get_s3_file(data_object.test_field_file)
self.assertEqual(file_content_s3, file_content)

def test_manager_create(self):
Expand All @@ -117,16 +119,23 @@ def test_manager_create(self):
self.assert_file_md5(data_object)

@classmethod
def get_file_md5(cls, file_object):
if not isinstance(file_object, six.string_types):
file_content = file_object.read()
def get_file_md5(cls, file_content):
if not isinstance(file_content, (six.string_types, six.binary_type)):
file_content = file_content.read()
return md5(file_content).hexdigest()

def assert_file_md5(self, data_object):
file_content = requests.get(data_object.test_field_file).content
file_md5 = self.get_file_md5(file_content)
self.assertEqual(self.file_md5, file_md5)

@classmethod
def get_s3_file(cls, url):
file_content_s3 = requests.get(url).content
if hasattr(file_content_s3, 'decode'):
file_content_s3 = file_content_s3.decode('utf-8')
return file_content_s3

def _create_object_with_file(self):
with open('tests/test_files/python-logo.png', 'rb') as f:
object = Object.please.create(
Expand Down