Skip to content

Commit 5c69f72

Browse files
committed
[HOT-FIX] correct method which get files from s3 - if byte type in py3 - decode to utf-8;
1 parent 95ebb90 commit 5c69f72

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

tests/integration_test_data_objects.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_updating_file_field(self):
5757
file_url = data_object.test_field_file
5858

5959
update_string = 'updating also field a'
60-
file_content = 'some example text file;'
60+
file_content = 'some example text file'
6161
new_file = StringIO(file_content)
6262
data_object.test_field_file = new_file
6363
data_object.test_field_a = update_string
@@ -67,7 +67,7 @@ def test_updating_file_field(self):
6767
self.assertNotEqual(data_object.test_field_file, file_url)
6868

6969
# check file content;
70-
file_content_s3 = requests.get(data_object.test_field_file).content
70+
file_content_s3 = self.get_s3_file(data_object.test_field_file)
7171
self.assertEqual(file_content_s3, file_content)
7272

7373
def test_manager_update(self):
@@ -101,7 +101,9 @@ def test_manager_update(self):
101101
self.assertEqual(data_object.test_field_a, new_update_string)
102102
# should change;
103103
self.assertNotEqual(data_object.test_field_file, file_url)
104-
file_content_s3 = requests.get(data_object.test_field_file).content
104+
105+
# check file content;
106+
file_content_s3 = self.get_s3_file(data_object.test_field_file)
105107
self.assertEqual(file_content_s3, file_content)
106108

107109
def test_manager_create(self):
@@ -117,16 +119,23 @@ def test_manager_create(self):
117119
self.assert_file_md5(data_object)
118120

119121
@classmethod
120-
def get_file_md5(cls, file_object):
121-
if not isinstance(file_object, six.string_types):
122-
file_content = file_object.read()
122+
def get_file_md5(cls, file_content):
123+
if not isinstance(file_content, (six.string_types, six.binary_type)):
124+
file_content = file_content.read()
123125
return md5(file_content).hexdigest()
124126

125127
def assert_file_md5(self, data_object):
126128
file_content = requests.get(data_object.test_field_file).content
127129
file_md5 = self.get_file_md5(file_content)
128130
self.assertEqual(self.file_md5, file_md5)
129131

132+
@classmethod
133+
def get_s3_file(cls, url):
134+
file_content_s3 = requests.get(url).content
135+
if hasattr(file_content_s3, 'decode'):
136+
file_content_s3 = file_content_s3.decode('utf-8')
137+
return file_content_s3
138+
130139
def _create_object_with_file(self):
131140
with open('tests/test_files/python-logo.png', 'rb') as f:
132141
object = Object.please.create(

0 commit comments

Comments
 (0)