|
| 1 | +# coding: utf-8 |
1 | 2 | # Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2 | 3 | #
|
3 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
11 | 12 | # ANY KIND, either express or implied. See the License for the specific
|
12 | 13 | # language governing permissions and limitations under the License.
|
13 | 14 | """Test suite for aws_encryption_sdk.internal.utils"""
|
| 15 | +import io |
14 | 16 | import unittest
|
15 | 17 |
|
16 | 18 | import pytest
|
|
28 | 30 | pytestmark = [pytest.mark.unit, pytest.mark.local]
|
29 | 31 |
|
30 | 32 |
|
| 33 | +def test_prep_stream_data_passthrough(): |
| 34 | + test = aws_encryption_sdk.internal.utils.prep_stream_data(sentinel.not_a_string_or_bytes) |
| 35 | + |
| 36 | + assert test is sentinel.not_a_string_or_bytes |
| 37 | + |
| 38 | + |
| 39 | +@pytest.mark.parametrize("source", (u"some unicode data ловие", b"\x00\x01\x02")) |
| 40 | +def test_prep_stream_data_wrap(source): |
| 41 | + test = aws_encryption_sdk.internal.utils.prep_stream_data(source) |
| 42 | + |
| 43 | + assert isinstance(test, io.BytesIO) |
| 44 | + |
| 45 | + |
31 | 46 | class TestUtils(unittest.TestCase):
|
32 | 47 | def setUp(self):
|
33 | 48 | # Set up mock key provider and keys
|
@@ -235,14 +250,6 @@ def test_prepare_data_keys(self):
|
235 | 250 | [mock_encrypted_data_encryption_key, sentinel.encrypted_data_key_1, sentinel.encrypted_data_key_2]
|
236 | 251 | )
|
237 | 252 |
|
238 |
| - @patch("aws_encryption_sdk.internal.utils.to_bytes", return_value=sentinel.bytes) |
239 |
| - @patch("aws_encryption_sdk.internal.utils.io.BytesIO", return_value=sentinel.bytesio) |
240 |
| - def test_prep_stream_data(self, mock_bytesio, mock_to_bytes): |
241 |
| - test = aws_encryption_sdk.internal.utils.prep_stream_data(sentinel.data) |
242 |
| - mock_to_bytes.assert_called_once_with(sentinel.data) |
243 |
| - mock_bytesio.assert_called_once_with(sentinel.bytes) |
244 |
| - assert test is sentinel.bytesio |
245 |
| - |
246 | 253 | def test_source_data_key_length_check_valid(self):
|
247 | 254 | mock_algorithm = MagicMock()
|
248 | 255 | mock_algorithm.kdf_input_len = 5
|
|
0 commit comments