OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved |
| 3 # |
| 4 # Permission is hereby granted, free of charge, to any person obtaining a |
| 5 # copy of this software and associated documentation files (the |
| 6 # "Software"), to deal in the Software without restriction, including |
| 7 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 8 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 9 # persons to whom the Software is furnished to do so, subject to the fol- |
| 10 # lowing conditions: |
| 11 # |
| 12 # The above copyright notice and this permission notice shall be included |
| 13 # in all copies or substantial portions of the Software. |
| 14 # |
| 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
| 17 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
| 18 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 # IN THE SOFTWARE. |
| 22 # |
| 23 |
| 24 from tests.unit import unittest |
| 25 from tests.unit import AWSMockServiceTestCase |
| 26 |
| 27 from boto.s3.connection import S3Connection |
| 28 from boto.s3.bucket import Bucket |
| 29 |
| 30 |
| 31 class TestS3Key(AWSMockServiceTestCase): |
| 32 connection_class = S3Connection |
| 33 |
| 34 def setUp(self): |
| 35 super(TestS3Key, self).setUp() |
| 36 |
| 37 def default_body(self): |
| 38 return "default body" |
| 39 |
| 40 def test_when_no_restore_header_present(self): |
| 41 self.set_http_response(status_code=200) |
| 42 b = Bucket(self.service_connection, 'mybucket') |
| 43 k = b.get_key('myglacierkey') |
| 44 self.assertIsNone(k.ongoing_restore) |
| 45 self.assertIsNone(k.expiry_date) |
| 46 |
| 47 def test_restore_header_with_ongoing_restore(self): |
| 48 self.set_http_response( |
| 49 status_code=200, |
| 50 header=[('x-amz-restore', 'ongoing-request="true"')]) |
| 51 b = Bucket(self.service_connection, 'mybucket') |
| 52 k = b.get_key('myglacierkey') |
| 53 self.assertTrue(k.ongoing_restore) |
| 54 self.assertIsNone(k.expiry_date) |
| 55 |
| 56 def test_restore_completed(self): |
| 57 self.set_http_response( |
| 58 status_code=200, |
| 59 header=[('x-amz-restore', |
| 60 'ongoing-request="false", ' |
| 61 'expiry-date="Fri, 21 Dec 2012 00:00:00 GMT"')]) |
| 62 b = Bucket(self.service_connection, 'mybucket') |
| 63 k = b.get_key('myglacierkey') |
| 64 self.assertFalse(k.ongoing_restore) |
| 65 self.assertEqual(k.expiry_date, 'Fri, 21 Dec 2012 00:00:00 GMT') |
| 66 |
| 67 def test_delete_key_return_key(self): |
| 68 self.set_http_response(status_code=204, body='') |
| 69 b = Bucket(self.service_connection, 'mybucket') |
| 70 key = b.delete_key('fookey') |
| 71 self.assertIsNotNone(key) |
| 72 |
| 73 |
| 74 if __name__ == '__main__': |
| 75 unittest.main() |
OLD | NEW |