OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved |
| 2 # |
| 3 # Permission is hereby granted, free of charge, to any person obtaining a |
| 4 # copy of this software and associated documentation files (the |
| 5 # "Software"), to deal in the Software without restriction, including |
| 6 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 7 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 8 # persons to whom the Software is furnished to do so, subject to the fol- |
| 9 # lowing conditions: |
| 10 # |
| 11 # The above copyright notice and this permission notice shall be included |
| 12 # in all copies or substantial portions of the Software. |
| 13 # |
| 14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
| 16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
| 17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 20 # IN THE SOFTWARE. |
| 21 # |
| 22 from tests.unit import unittest |
| 23 import mock |
| 24 |
| 25 from boto.glacier.job import Job |
| 26 from boto.glacier.layer1 import Layer1 |
| 27 from boto.glacier.response import GlacierResponse |
| 28 from boto.glacier.exceptions import TreeHashDoesNotMatchError |
| 29 |
| 30 |
| 31 class TestJob(unittest.TestCase): |
| 32 def setUp(self): |
| 33 self.api = mock.Mock(spec=Layer1) |
| 34 self.vault = mock.Mock() |
| 35 self.vault.layer1 = self.api |
| 36 self.job = Job(self.vault) |
| 37 |
| 38 def test_get_job_validate_checksum_success(self): |
| 39 response = GlacierResponse(mock.Mock(), None) |
| 40 response['TreeHash'] = 'tree_hash' |
| 41 self.api.get_job_output.return_value = response |
| 42 with mock.patch('boto.glacier.job.tree_hash_from_str') as t: |
| 43 t.return_value = 'tree_hash' |
| 44 self.job.get_output(byte_range=(1, 1024), validate_checksum=True) |
| 45 |
| 46 def test_get_job_validation_fails(self): |
| 47 response = GlacierResponse(mock.Mock(), None) |
| 48 response['TreeHash'] = 'tree_hash' |
| 49 self.api.get_job_output.return_value = response |
| 50 with mock.patch('boto.glacier.job.tree_hash_from_str') as t: |
| 51 t.return_value = 'BAD_TREE_HASH_VALUE' |
| 52 with self.assertRaises(TreeHashDoesNotMatchError): |
| 53 # With validate_checksum set to True, this call fails. |
| 54 self.job.get_output(byte_range=(1, 1024), validate_checksum=True
) |
| 55 # With validate_checksum set to False, this call succeeds. |
| 56 self.job.get_output(byte_range=(1, 1024), validate_checksum=False) |
| 57 |
| 58 |
| 59 if __name__ == '__main__': |
| 60 unittest.main() |
OLD | NEW |