This repository was archived by the owner on Mar 13, 2022. It is now read-only.
File tree 2 files changed +20
-1
lines changed
2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -100,8 +100,12 @@ def as_file(self):
100
100
use_data_if_no_file = not self ._file and self ._data
101
101
if use_data_if_no_file :
102
102
if self ._base64_file_content :
103
+ if isinstance (self ._data , str ):
104
+ content = self ._data .encode ()
105
+ else :
106
+ content = self ._data
103
107
self ._file = _create_temp_file_with_content (
104
- base64 .decodestring (self . _data . encode () ))
108
+ base64 .decodestring (content ))
105
109
else :
106
110
self ._file = _create_temp_file_with_content (self ._data )
107
111
if self ._file and not os .path .isfile (self ._file ):
Original file line number Diff line number Diff line change @@ -65,6 +65,9 @@ def _raise_exception(st):
65
65
TEST_DATA = "test-data"
66
66
TEST_DATA_BASE64 = _base64 (TEST_DATA )
67
67
68
+ TEST_DATA_BYTES = b"test-data"
69
+ TEST_DATA_BASE64_BYTES = b"dGVzdC1kYXRh"
70
+
68
71
TEST_ANOTHER_DATA = "another-test-data"
69
72
TEST_ANOTHER_DATA_BASE64 = _base64 (TEST_ANOTHER_DATA )
70
73
@@ -201,6 +204,18 @@ def test_create_temp_file_with_content(self):
201
204
_create_temp_file_with_content (TEST_DATA )))
202
205
_cleanup_temp_files ()
203
206
207
+ def test_file_given_data_bytes (self ):
208
+ obj = {TEST_DATA_KEY : TEST_DATA_BASE64_BYTES }
209
+ t = FileOrData (obj = obj , file_key_name = TEST_FILE_KEY ,
210
+ data_key_name = TEST_DATA_KEY )
211
+ self .assertEqual (TEST_DATA , self .get_file_content (t .as_file ()))
212
+
213
+ def test_file_given_data_bytes_no_base64 (self ):
214
+ obj = {TEST_DATA_KEY : TEST_DATA_BYTES }
215
+ t = FileOrData (obj = obj , file_key_name = TEST_FILE_KEY ,
216
+ data_key_name = TEST_DATA_KEY , base64_file_content = False )
217
+ self .assertEqual (TEST_DATA , self .get_file_content (t .as_file ()))
218
+
204
219
205
220
class TestConfigNode (BaseTestCase ):
206
221
You can’t perform that action at this time.
0 commit comments