-
Notifications
You must be signed in to change notification settings - Fork 86
Migrate "test/unit/test_streaming_client_stream_decryptor.py" from unittest to pytest #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mattsb42-aws
merged 10 commits into
aws:master
from
ansanper:unit/test_streaming_client_stream_decryptor.py
Dec 17, 2018
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3e3e701
Migrating unit/test_deserialize.py from unittest from pytest
a070cb6
Migrate unit/test_provides_kms_master_key.py from unittest to pytest
cba6995
Migrated unit/test/_providers_kms_master_key_provider.py from unittes…
fdb3b5a
unit/test_providers_raw_master_key.py
1d2b654
Migrate unit/test_providers_raw_master_key_provider.py from unittest …
aa3df87
Migrate unit/test_serialize.py from unittest to pytest
437c391
Migrate unit/test_streaming_client_stream_decryptor.py from unittest …
5c0acfb
Autoformat
8dc8804
Removed unit tests not corresponding to this branch
2e8110b
Removed unused import and added yield and tearDown to apply_fixture f…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
# language governing permissions and limitations under the License. | ||
"""Unit test suite for aws_encryption_sdk.streaming_client.StreamDecryptor""" | ||
import io | ||
import unittest | ||
|
||
import pytest | ||
import six | ||
|
@@ -29,8 +28,9 @@ | |
pytestmark = [pytest.mark.unit, pytest.mark.local] | ||
|
||
|
||
class TestStreamDecryptor(unittest.TestCase): | ||
def setUp(self): | ||
class TestStreamDecryptor(object): | ||
@pytest.fixture(autouse=True) | ||
def apply_fixtures(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as #127 : need to run teardown actions. |
||
self.mock_key_provider = MagicMock(__class__=MasterKeyProvider) | ||
self.mock_materials_manager = MagicMock(__class__=CryptoMaterialsManager) | ||
self.mock_materials_manager.decrypt_materials.return_value = MagicMock( | ||
|
@@ -186,12 +186,11 @@ def test_read_header_frame_too_large(self, mock_derive_datakey): | |
test_decryptor.key_provider = self.mock_key_provider | ||
test_decryptor.source_stream = ct_stream | ||
test_decryptor._stream_length = len(VALUES["data_128"]) | ||
with six.assertRaisesRegex( | ||
self, | ||
CustomMaximumValueExceeded, | ||
"Frame Size in header found larger than custom value: {found} > {custom}".format(found=1024, custom=10), | ||
): | ||
with pytest.raises(CustomMaximumValueExceeded) as excinfo: | ||
test_decryptor._read_header() | ||
excinfo.match( | ||
"Frame Size in header found larger than custom value: {found} > {custom}".format(found=1024, custom=10) | ||
) | ||
|
||
@patch("aws_encryption_sdk.streaming_client.Verifier") | ||
@patch("aws_encryption_sdk.streaming_client.DecryptionMaterialsRequest") | ||
|
@@ -220,14 +219,13 @@ def test_prep_non_framed_content_length_too_large(self): | |
mock_data_key = MagicMock() | ||
test_decryptor.data_key = mock_data_key | ||
|
||
with six.assertRaisesRegex( | ||
self, | ||
CustomMaximumValueExceeded, | ||
with pytest.raises(CustomMaximumValueExceeded) as excinfo: | ||
test_decryptor._prep_non_framed() | ||
excinfo.match( | ||
"Non-framed message content length found larger than custom value: {found} > {custom}".format( | ||
found=len(VALUES["data_128"]), custom=len(VALUES["data_128"]) // 2 | ||
), | ||
): | ||
test_decryptor._prep_non_framed() | ||
) | ||
) | ||
|
||
def test_prep_non_framed(self): | ||
test_decryptor = StreamDecryptor(key_provider=self.mock_key_provider, source=self.mock_input_stream) | ||
|
@@ -288,10 +286,9 @@ def test_read_bytes_from_non_framed_message_body_too_small(self): | |
test_decryptor = StreamDecryptor(key_provider=self.mock_key_provider, source=ct_stream) | ||
test_decryptor.body_length = len(VALUES["data_128"] * 2) | ||
test_decryptor._header = self.mock_header | ||
with six.assertRaisesRegex( | ||
self, SerializationError, "Total message body contents less than specified in body description" | ||
): | ||
with pytest.raises(SerializationError) as excinfo: | ||
test_decryptor._read_bytes_from_non_framed_body(1) | ||
excinfo.match("Total message body contents less than specified in body description") | ||
|
||
def test_read_bytes_from_non_framed_no_verifier(self): | ||
ct_stream = io.BytesIO(VALUES["data_128"]) | ||
|
@@ -497,8 +494,9 @@ def test_read_bytes_from_framed_body_bad_sequence_number(self): | |
frame_data.final_frame = False | ||
frame_data.ciphertext = b"asdfzxcv" | ||
self.mock_deserialize_frame.return_value = (frame_data, False) | ||
with six.assertRaisesRegex(self, SerializationError, "Malformed message: frames out of order"): | ||
with pytest.raises(SerializationError) as excinfo: | ||
test_decryptor._read_bytes_from_framed_body(4) | ||
excinfo.match("Malformed message: frames out of order") | ||
|
||
@patch("aws_encryption_sdk.streaming_client.StreamDecryptor._read_bytes_from_non_framed_body") | ||
@patch("aws_encryption_sdk.streaming_client.StreamDecryptor._read_bytes_from_framed_body") | ||
|
@@ -549,8 +547,9 @@ def test_read_bytes_unknown(self, mock_read_frame, mock_read_block): | |
test_decryptor = StreamDecryptor(key_provider=self.mock_key_provider, source=ct_stream) | ||
test_decryptor._header = MagicMock() | ||
test_decryptor._header.content_type = None | ||
with six.assertRaisesRegex(self, NotSupportedError, "Unsupported content type"): | ||
with pytest.raises(NotSupportedError) as excinfo: | ||
test_decryptor._read_bytes(5) | ||
excinfo.match("Unsupported content type") | ||
|
||
@patch("aws_encryption_sdk.streaming_client._EncryptionStream.close") | ||
def test_close(self, mock_close): | ||
|
@@ -565,5 +564,6 @@ def test_close(self, mock_close): | |
def test_close_no_footer(self, mock_close): | ||
self.mock_header.content_type = ContentType.FRAMED_DATA | ||
test_decryptor = StreamDecryptor(key_provider=self.mock_key_provider, source=self.mock_input_stream) | ||
with six.assertRaisesRegex(self, SerializationError, "Footer not read"): | ||
with pytest.raises(SerializationError) as excinfo: | ||
test_decryptor.close() | ||
excinfo.match("Footer not read") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to remove the now-unused import.