fix: read config data with bytes (python3)
This commit is contained in:
parent
d68e456190
commit
9d78cd794c
@ -100,8 +100,12 @@ class FileOrData(object):
|
||||
use_data_if_no_file = not self._file and self._data
|
||||
if use_data_if_no_file:
|
||||
if self._base64_file_content:
|
||||
if isinstance(self._data, str):
|
||||
content = self._data.encode()
|
||||
else:
|
||||
content = self._data
|
||||
self._file = _create_temp_file_with_content(
|
||||
base64.decodestring(self._data.encode()))
|
||||
base64.decodestring(content))
|
||||
else:
|
||||
self._file = _create_temp_file_with_content(self._data)
|
||||
if self._file and not os.path.isfile(self._file):
|
||||
|
||||
@ -201,6 +201,18 @@ class TestFileOrData(BaseTestCase):
|
||||
_create_temp_file_with_content(TEST_DATA)))
|
||||
_cleanup_temp_files()
|
||||
|
||||
def test_file_given_data_bytes(self):
|
||||
obj = {TEST_DATA_KEY: TEST_DATA_BASE64.encode()}
|
||||
t = FileOrData(obj=obj, file_key_name=TEST_FILE_KEY,
|
||||
data_key_name=TEST_DATA_KEY)
|
||||
self.assertEqual(TEST_DATA, self.get_file_content(t.as_file()))
|
||||
|
||||
def test_file_given_data_bytes_no_base64(self):
|
||||
obj = {TEST_DATA_KEY: TEST_DATA.encode()}
|
||||
t = FileOrData(obj=obj, file_key_name=TEST_FILE_KEY,
|
||||
data_key_name=TEST_DATA_KEY, base64_file_content=False)
|
||||
self.assertEqual(TEST_DATA, self.get_file_content(t.as_file()))
|
||||
|
||||
|
||||
class TestConfigNode(BaseTestCase):
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user