From ebf8e63717c2c4c55582087d96edd30f6813d26c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Opa=C5=82czy=C5=84ski?= Date: Mon, 26 Sep 2016 22:20:15 +0200 Subject: [PATCH 01/18] [HOTFIX] handling serialization/desrialization of the files properly; --- syncano/models/fields.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/syncano/models/fields.py b/syncano/models/fields.py index 8e4087e..967fd64 100644 --- a/syncano/models/fields.py +++ b/syncano/models/fields.py @@ -547,6 +547,8 @@ class FileField(WritableField): param_name = 'files' def to_native(self, value): + if isinstance(value, six.string_types): + return None return {self.name: value} From 697932bca75a09883c838d22f153f50050cacfca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Opa=C5=82czy=C5=84ski?= Date: Tue, 27 Sep 2016 11:50:19 +0200 Subject: [PATCH 02/18] [HOT-FIX] files hot fix: create tests; --- tests/integration_test_data_objects.py | 126 +++++++++++++++++++++++++ tests/test_files/python-logo.png | Bin 0 -> 11155 bytes 2 files changed, 126 insertions(+) create mode 100644 tests/integration_test_data_objects.py create mode 100644 tests/test_files/python-logo.png diff --git a/tests/integration_test_data_objects.py b/tests/integration_test_data_objects.py new file mode 100644 index 0000000..9254645 --- /dev/null +++ b/tests/integration_test_data_objects.py @@ -0,0 +1,126 @@ +# -*- coding: utf-8 -*- +from hashlib import md5 +from StringIO import StringIO + +import requests +from syncano.models import Object +from tests.integration_test import InstanceMixin, IntegrationTest + + +class DataObjectFileTest(InstanceMixin, IntegrationTest): + + @classmethod + def setUpClass(cls): + super(DataObjectFileTest, cls).setUpClass() + + cls.schema = [ + {'name': 'test_field_a', 'type': 'string'}, + {'name': 'test_field_file', 'type': 'file'}, + ] + cls.class_name = 'test_object_file' + cls.initial_field_a = 'some_string' + cls.file_path = 'tests/test_files/python-logo.png' + cls.instance.classes.create( + name=cls.class_name, + schema=cls.schema + ) + with open(cls.file_path, 'rb') as f: + cls.file_md5 = cls.get_file_md5(f.read()) + + def test_creating_file_object(self): + data_object = self._create_object_with_file() + self.assertEqual(data_object.test_field_a, self.initial_field_a) + self.assert_file_md5(data_object) + + def test_updating_another_field(self): + data_object = self._create_object_with_file() + file_url = data_object.test_field_file + + # no changes made to the file; + update_string = 'some_other_string' + data_object.test_field_a = update_string + data_object.save() + + self.assertEqual(data_object.test_field_file, file_url) + self.assertEqual(data_object.test_field_a, update_string) + self.assert_file_md5(data_object) + + def test_updating_file_field(self): + data_object = self._create_object_with_file() + file_url = data_object.test_field_file + + update_string = 'updating also field a' + 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 + data_object.save() + + self.assertEqual(data_object.test_field_a, update_string) + self.assertNotEqual(data_object.test_field_file, file_url) + + # check file content; + file_content_s3 = requests.get(data_object.test_field_file).text + self.assertEqual(file_content_s3, file_content) + + def test_manager_update(self): + data_object = self._create_object_with_file() + file_url = data_object.test_field_file + # update only string field; + update_string = 'manager updating' + Object.please.update( + id=data_object.id, + class_name=self.class_name, + test_field_a=update_string + ) + + data_object = Object.please.get(id=data_object.id) + self.assertEqual(data_object.test_field_a, update_string) + # shouldn't change; + self.assertEqual(data_object.test_field_file, file_url) + + # update also a file; + new_update_string = 'manager with file update' + file_content = 'manager file update' + new_file = StringIO() + Object.please.update( + id=data_object.id, + class_name=self.class_name, + test_field_a=new_update_string, + test_field_file=new_file + ) + + data_object = Object.please.get(id=data_object.id) + 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).text + self.assertEqual(file_content_s3, file_content) + + def test_manager_create(self): + create_string = 'manager create' + with open(self.file_path, 'rb') as f: + data_object = Object.please.create( + test_field_a=create_string, + test_field_file=f + ) + + self.assertEqual(data_object.test_field_a, create_string) + self.assert_file_md5(data_object) + + @classmethod + def get_file_md5(cls, file_content): + return md5(file_content).hexdigest() + + def assert_file_md5(self, data_object): + file_content = requests.get(data_object.test_field_file).text + file_md5 = self.get_file_md5(file_content) + self.assertEqual(self.file_md5, file_md5) + + def _create_object_with_file(self): + with open('tests/test_files/python-logo.png', 'rb') as f: + object = Object.please.create( + test_field_a=self.initial_field_a, + test_field_file=f + ) + return object diff --git a/tests/test_files/python-logo.png b/tests/test_files/python-logo.png new file mode 100644 index 0000000000000000000000000000000000000000..738f6ed41f499d1f57fd4db356dc1d64769bf725 GIT binary patch literal 11155 zcmdUVWn5IzyDmd_NQaal2t$J+ol*jVbf+L4(%q$k_$O4P6i{-=p&38~1f+zaLz)mfY@00XQM~#e_i5LqDi%dgZMIQ?b+Z22sAjAis zmi_Vf!5>^-B@F{Y@Cqe#NCdx$ywpv7v9O2_{=Fee<>J}kB;6}jlUK?0TYDc*cSnbpw(L({`Zxx7`ndYC zYn!l(3JZ%T_?Hi3VX(%->L@DUDIuIY)C`>CCbyk_-T<}6^)I*C_H@QqdIY1*i>j@X(n9|*#px% zxcYZq+^^6(T%6O_J8ke+2j`4c&-7?jhPr8u#C44H+_G1AD~D4&%N_=2YL#@cHE7OK zpyP7k(<5fmZeax#@G6*@+Q+A)qM{xhK7TKgZV~f=$6MSsIlVkN0Et% zT?Hs9z6@e$he33Oa=hAq-Vxh^)RKw0WgQ9I&5eHcPSa z2n^f&Ex<7Up(}Uv?o?(o_s;+zEAc6Yn)s0qzWkEcM?pE^Ycjuc%sa<=g3WEPM~DsL zn}#<-$ug0df`6)CExWk39F2J*f0a+R3HXsLNCZo>w(frpJPX)YT+hAxu2mj9E-srs zraMl*E0(s{ZkRHR1#PyJa5f2b1tA06p-rs&qqFs6jc?mAIMdd&0JN=s3MJZ%5=r(#P zs14&N0d&CYtM&Z9aW6V<`Ij+I!6=n~qpBjRrm0uy?4AV7#U~|%6MPumooWuE&J=uj zaN;Ypa-!9&9F!I57(sTB`<~WINrn{1`g&6L@L+$hYxAx-PBH=C6l;zcYD}nnodc#+Y2{I zi)?l+dgfhM8&mAb$=Qc~xX>~+%&)USwNpvbLsPiGFb*CR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k_t^)p9^(my1eN4Fu)2DfhkVY7 z-z(n`n{N$z9=Ml28w!OZV>c{_2K#-acx0lPR%ofH&^SEpYD3`?9MRh0aJl_#m`9_~ zJiCvCE!>zPS+Ig~)kXPT5liE196*-?wfxho=-18&pScanKhd$@t-^7yGW8E;dG1tN z3`jhhJiT!-QN{-Ep}gP-jQdxWbq19ylM6a+l{a=eUej z`3{TZ`gC4IM%eEE_=(KQlUUwYMuf3~aQhhia&~#*aM>sA#yHJ8zR>Z|&Hy%GM4*wx zWT3PB%T<0(Ieif>S)R17_^UCFtLorKfdZhQ-T6lhA~eaZ!h1k{rz5v`lHVih*G3>v z5yjp#2~w5r_d!LrvD$|ux_8$YzXD5D2k4$H%r@qrbbWq-SvWCY5l| Date: Tue, 27 Sep 2016 11:58:00 +0200 Subject: [PATCH 03/18] [HOT-FIX] files hot fix: create tests; --- tests/integration_test_data_objects.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/integration_test_data_objects.py b/tests/integration_test_data_objects.py index 9254645..ddf054f 100644 --- a/tests/integration_test_data_objects.py +++ b/tests/integration_test_data_objects.py @@ -1,6 +1,12 @@ # -*- coding: utf-8 -*- from hashlib import md5 -from StringIO import StringIO + +try: + # python2 + from StringIO import StringIO +except ImportError: + # python3 + from io import StringIO import requests from syncano.models import Object @@ -101,6 +107,7 @@ def test_manager_create(self): create_string = 'manager create' with open(self.file_path, 'rb') as f: data_object = Object.please.create( + class_name=self.class_name, test_field_a=create_string, test_field_file=f ) @@ -120,7 +127,8 @@ def assert_file_md5(self, data_object): def _create_object_with_file(self): with open('tests/test_files/python-logo.png', 'rb') as f: object = Object.please.create( + class_name=self.class_name, test_field_a=self.initial_field_a, - test_field_file=f + test_field_file=f, ) return object From 4d0188ea1ef13375efdf65dfeaa2e97ae6a0a628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Opa=C5=82czy=C5=84ski?= Date: Tue, 27 Sep 2016 12:00:55 +0200 Subject: [PATCH 04/18] [HOT-FIX] files hot fix: create tests; --- tests/integration_test_data_objects.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/integration_test_data_objects.py b/tests/integration_test_data_objects.py index ddf054f..7428563 100644 --- a/tests/integration_test_data_objects.py +++ b/tests/integration_test_data_objects.py @@ -1,6 +1,10 @@ # -*- coding: utf-8 -*- from hashlib import md5 +import requests +from syncano.models import Object +from tests.integration_test import InstanceMixin, IntegrationTest + try: # python2 from StringIO import StringIO @@ -8,9 +12,6 @@ # python3 from io import StringIO -import requests -from syncano.models import Object -from tests.integration_test import InstanceMixin, IntegrationTest class DataObjectFileTest(InstanceMixin, IntegrationTest): From f23984c4a1364bd88802c2bd715794138a760936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Opa=C5=82czy=C5=84ski?= Date: Tue, 27 Sep 2016 12:01:27 +0200 Subject: [PATCH 05/18] [HOT-FIX] files hot fix: create tests; --- tests/integration_test_data_objects.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration_test_data_objects.py b/tests/integration_test_data_objects.py index 7428563..862647c 100644 --- a/tests/integration_test_data_objects.py +++ b/tests/integration_test_data_objects.py @@ -13,7 +13,6 @@ from io import StringIO - class DataObjectFileTest(InstanceMixin, IntegrationTest): @classmethod From d6253837e1202a7f48807f6391f6e7501eb15fbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Opa=C5=82czy=C5=84ski?= Date: Tue, 27 Sep 2016 12:13:08 +0200 Subject: [PATCH 06/18] [HOT-FIX] correct tests; --- tests/integration_test_data_objects.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integration_test_data_objects.py b/tests/integration_test_data_objects.py index 862647c..3ddd485 100644 --- a/tests/integration_test_data_objects.py +++ b/tests/integration_test_data_objects.py @@ -80,7 +80,7 @@ def test_manager_update(self): test_field_a=update_string ) - data_object = Object.please.get(id=data_object.id) + data_object = Object.please.get(id=data_object.id, class_name=self.class_name) self.assertEqual(data_object.test_field_a, update_string) # shouldn't change; self.assertEqual(data_object.test_field_file, file_url) @@ -96,7 +96,7 @@ def test_manager_update(self): test_field_file=new_file ) - data_object = Object.please.get(id=data_object.id) + data_object = Object.please.get(id=data_object.id, class_name=self.class_name) self.assertEqual(data_object.test_field_a, new_update_string) # should change; self.assertNotEqual(data_object.test_field_file, file_url) @@ -117,7 +117,7 @@ def test_manager_create(self): @classmethod def get_file_md5(cls, file_content): - return md5(file_content).hexdigest() + return md5(file_content.encode('utf-8')).hexdigest() def assert_file_md5(self, data_object): file_content = requests.get(data_object.test_field_file).text From 98b7a1de686d9575d82251010859d5d90ee2317f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Opa=C5=82czy=C5=84ski?= Date: Tue, 27 Sep 2016 12:21:36 +0200 Subject: [PATCH 07/18] [HOT-FIX] correct tests; --- tests/integration_test_data_objects.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/integration_test_data_objects.py b/tests/integration_test_data_objects.py index 3ddd485..a4b113c 100644 --- a/tests/integration_test_data_objects.py +++ b/tests/integration_test_data_objects.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import six from hashlib import md5 import requests @@ -117,7 +118,9 @@ def test_manager_create(self): @classmethod def get_file_md5(cls, file_content): - return md5(file_content.encode('utf-8')).hexdigest() + if isinstance(file_content, six.string_types): + file_content = file_content.encode('utf-8') + return md5(file_content).hexdigest() def assert_file_md5(self, data_object): file_content = requests.get(data_object.test_field_file).text From 6115f2528b401fd3a221bc80d06416629be6e417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Opa=C5=82czy=C5=84ski?= Date: Tue, 27 Sep 2016 12:27:19 +0200 Subject: [PATCH 08/18] [HOT-FIX] correct isort; --- tests/integration_test_data_objects.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration_test_data_objects.py b/tests/integration_test_data_objects.py index a4b113c..33465b4 100644 --- a/tests/integration_test_data_objects.py +++ b/tests/integration_test_data_objects.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- -import six from hashlib import md5 import requests +import six from syncano.models import Object from tests.integration_test import InstanceMixin, IntegrationTest From 20d6d79710c3905d5e4f353eedc5f552dc60b12b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Opa=C5=82czy=C5=84ski?= Date: Tue, 27 Sep 2016 12:36:01 +0200 Subject: [PATCH 09/18] [HOT-FIX] correct isort; --- tests/integration_test_data_objects.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/integration_test_data_objects.py b/tests/integration_test_data_objects.py index 33465b4..b308ae6 100644 --- a/tests/integration_test_data_objects.py +++ b/tests/integration_test_data_objects.py @@ -89,7 +89,7 @@ def test_manager_update(self): # update also a file; new_update_string = 'manager with file update' file_content = 'manager file update' - new_file = StringIO() + new_file = StringIO(file_content) Object.please.update( id=data_object.id, class_name=self.class_name, @@ -117,9 +117,11 @@ def test_manager_create(self): self.assert_file_md5(data_object) @classmethod - def get_file_md5(cls, file_content): - if isinstance(file_content, six.string_types): - file_content = file_content.encode('utf-8') + def get_file_md5(cls, file_object): + if isinstance(file_object, six.string_types): + file_content = file_object.encode('utf-8') + else: + file_content = file_object.read() return md5(file_content).hexdigest() def assert_file_md5(self, data_object): From 473eb460d3745f96268f7b7145f1ef333dfaa9e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Opa=C5=82czy=C5=84ski?= Date: Tue, 27 Sep 2016 12:42:33 +0200 Subject: [PATCH 10/18] [HOT-FIX] correct isort; --- tests/integration_test_data_objects.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration_test_data_objects.py b/tests/integration_test_data_objects.py index b308ae6..bdab5dc 100644 --- a/tests/integration_test_data_objects.py +++ b/tests/integration_test_data_objects.py @@ -32,7 +32,7 @@ def setUpClass(cls): schema=cls.schema ) with open(cls.file_path, 'rb') as f: - cls.file_md5 = cls.get_file_md5(f.read()) + cls.file_md5 = cls.get_file_md5(f) def test_creating_file_object(self): data_object = self._create_object_with_file() From 5d8271d66f85e7ee5c99c13f7670ff54056ef667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Opa=C5=82czy=C5=84ski?= Date: Tue, 27 Sep 2016 13:06:50 +0200 Subject: [PATCH 11/18] [HOT-FIX] correct isort; --- tests/integration_test_data_objects.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration_test_data_objects.py b/tests/integration_test_data_objects.py index bdab5dc..ecf3123 100644 --- a/tests/integration_test_data_objects.py +++ b/tests/integration_test_data_objects.py @@ -31,7 +31,7 @@ def setUpClass(cls): name=cls.class_name, schema=cls.schema ) - with open(cls.file_path, 'rb') as f: + with open(cls.file_path, 'rt') as f: cls.file_md5 = cls.get_file_md5(f) def test_creating_file_object(self): @@ -125,7 +125,7 @@ def get_file_md5(cls, file_object): return md5(file_content).hexdigest() def assert_file_md5(self, data_object): - file_content = requests.get(data_object.test_field_file).text + 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) From cfca799768807e75f651b370d37018dce5c6883f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Opa=C5=82czy=C5=84ski?= Date: Tue, 27 Sep 2016 13:18:02 +0200 Subject: [PATCH 12/18] [HOT-FIX] correct get_md5 method; --- tests/integration_test_data_objects.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/integration_test_data_objects.py b/tests/integration_test_data_objects.py index ecf3123..c59d582 100644 --- a/tests/integration_test_data_objects.py +++ b/tests/integration_test_data_objects.py @@ -118,9 +118,7 @@ def test_manager_create(self): @classmethod def get_file_md5(cls, file_object): - if isinstance(file_object, six.string_types): - file_content = file_object.encode('utf-8') - else: + if not isinstance(file_object, six.string_types): file_content = file_object.read() return md5(file_content).hexdigest() From e4dd76502d06a5b99c4207c72f390536cae589fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Opa=C5=82czy=C5=84ski?= Date: Tue, 27 Sep 2016 13:18:48 +0200 Subject: [PATCH 13/18] [HOT-FIX] correct content get; --- tests/integration_test_data_objects.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration_test_data_objects.py b/tests/integration_test_data_objects.py index c59d582..05b106b 100644 --- a/tests/integration_test_data_objects.py +++ b/tests/integration_test_data_objects.py @@ -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).text + file_content_s3 = requests.get(data_object.test_field_file).content self.assertEqual(file_content_s3, file_content) def test_manager_update(self): @@ -101,7 +101,7 @@ 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).text + file_content_s3 = requests.get(data_object.test_field_file).content self.assertEqual(file_content_s3, file_content) def test_manager_create(self): From 95ebb90a99a79bbc97c37420347b051df4e5d854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Opa=C5=82czy=C5=84ski?= Date: Tue, 27 Sep 2016 13:29:00 +0200 Subject: [PATCH 14/18] [HOT FIX] correct open mode in class setup; --- tests/integration_test_data_objects.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration_test_data_objects.py b/tests/integration_test_data_objects.py index 05b106b..412920b 100644 --- a/tests/integration_test_data_objects.py +++ b/tests/integration_test_data_objects.py @@ -31,7 +31,7 @@ def setUpClass(cls): name=cls.class_name, schema=cls.schema ) - with open(cls.file_path, 'rt') as f: + with open(cls.file_path, 'rb') as f: cls.file_md5 = cls.get_file_md5(f) def test_creating_file_object(self): From 5c69f72e02424dbd5f5fb7152f414acf37cf7397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Opa=C5=82czy=C5=84ski?= Date: Tue, 27 Sep 2016 14:00:27 +0200 Subject: [PATCH 15/18] [HOT-FIX] correct method which get files from s3 - if byte type in py3 - decode to utf-8; --- tests/integration_test_data_objects.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/integration_test_data_objects.py b/tests/integration_test_data_objects.py index 412920b..a03cd22 100644 --- a/tests/integration_test_data_objects.py +++ b/tests/integration_test_data_objects.py @@ -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 @@ -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): @@ -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): @@ -117,9 +119,9 @@ 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): @@ -127,6 +129,13 @@ def assert_file_md5(self, data_object): 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( From f564a04f132fab4b743e5212e13ba460091d27d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Opa=C5=82czy=C5=84ski?= Date: Tue, 27 Sep 2016 14:49:21 +0200 Subject: [PATCH 16/18] [HOT-FIX] use cStringIO instead of StringIO; --- tests/integration_test_data_objects.py | 2 +- tests/integration_tests_hosting.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration_test_data_objects.py b/tests/integration_test_data_objects.py index a03cd22..0c6b4e8 100644 --- a/tests/integration_test_data_objects.py +++ b/tests/integration_test_data_objects.py @@ -8,7 +8,7 @@ try: # python2 - from StringIO import StringIO + from cStringIO import StringIO except ImportError: # python3 from io import StringIO diff --git a/tests/integration_tests_hosting.py b/tests/integration_tests_hosting.py index 1be56a5..bdb7c5d 100644 --- a/tests/integration_tests_hosting.py +++ b/tests/integration_tests_hosting.py @@ -5,7 +5,7 @@ try: # python2 - from StringIO import StringIO + from cStringIO import StringIO except ImportError: # python3 from io import StringIO From fab97e19883d743bb63cece6d2a0487b7f738ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Opa=C5=82czy=C5=84ski?= Date: Tue, 27 Sep 2016 15:06:29 +0200 Subject: [PATCH 17/18] [HOT-FIX] back to StringIO; --- tests/integration_test_data_objects.py | 6 +++--- tests/integration_tests_hosting.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/integration_test_data_objects.py b/tests/integration_test_data_objects.py index 0c6b4e8..cc7ca06 100644 --- a/tests/integration_test_data_objects.py +++ b/tests/integration_test_data_objects.py @@ -8,7 +8,7 @@ try: # python2 - from cStringIO import StringIO + from StringIO import StringIO except ImportError: # python3 from io import StringIO @@ -138,9 +138,9 @@ def get_s3_file(cls, url): def _create_object_with_file(self): with open('tests/test_files/python-logo.png', 'rb') as f: - object = Object.please.create( + data_object = Object.please.create( class_name=self.class_name, test_field_a=self.initial_field_a, test_field_file=f, ) - return object + return data_object diff --git a/tests/integration_tests_hosting.py b/tests/integration_tests_hosting.py index bdb7c5d..1be56a5 100644 --- a/tests/integration_tests_hosting.py +++ b/tests/integration_tests_hosting.py @@ -5,7 +5,7 @@ try: # python2 - from cStringIO import StringIO + from StringIO import StringIO except ImportError: # python3 from io import StringIO From 70313a39615fbb011ac8d4332fae6949c967c19e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Opa=C5=82czy=C5=84ski?= Date: Tue, 27 Sep 2016 15:14:15 +0200 Subject: [PATCH 18/18] [RELEASE v5.4.4] bump the version; --- syncano/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syncano/__init__.py b/syncano/__init__.py index 31d3523..77b9198 100644 --- a/syncano/__init__.py +++ b/syncano/__init__.py @@ -2,7 +2,7 @@ import os __title__ = 'Syncano Python' -__version__ = '5.4.3' +__version__ = '5.4.4' __author__ = "Daniel Kopka, Michal Kobus and Sebastian Opalczynski" __credits__ = ["Daniel Kopka", "Michal Kobus",