| OLD | NEW |
| 1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
| 2 | 2 |
| 3 # Copyright (c) 2011 Mitch Garnaat http://garnaat.org/ | 3 # Copyright (c) 2011 Mitch Garnaat http://garnaat.org/ |
| 4 # All rights reserved. | 4 # All rights reserved. |
| 5 # | 5 # |
| 6 # Permission is hereby granted, free of charge, to any person obtaining a | 6 # Permission is hereby granted, free of charge, to any person obtaining a |
| 7 # copy of this software and associated documentation files (the | 7 # copy of this software and associated documentation files (the |
| 8 # "Software"), to deal in the Software without restriction, including | 8 # "Software"), to deal in the Software without restriction, including |
| 9 # without limitation the rights to use, copy, modify, merge, publish, dis- | 9 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 10 # tribute, sublicense, and/or sell copies of the Software, and to permit | 10 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 """ | 27 """ |
| 28 | 28 |
| 29 import unittest | 29 import unittest |
| 30 import time | 30 import time |
| 31 | 31 |
| 32 from boto.exception import S3ResponseError | 32 from boto.exception import S3ResponseError |
| 33 from boto.s3.connection import S3Connection | 33 from boto.s3.connection import S3Connection |
| 34 from boto.s3.bucketlogging import BucketLogging | 34 from boto.s3.bucketlogging import BucketLogging |
| 35 from boto.s3.lifecycle import Lifecycle | 35 from boto.s3.lifecycle import Lifecycle |
| 36 from boto.s3.lifecycle import Transition | 36 from boto.s3.lifecycle import Transition |
| 37 from boto.s3.lifecycle import Expiration |
| 37 from boto.s3.lifecycle import Rule | 38 from boto.s3.lifecycle import Rule |
| 38 from boto.s3.acl import Grant | 39 from boto.s3.acl import Grant |
| 39 from boto.s3.tagging import Tags, TagSet | 40 from boto.s3.tagging import Tags, TagSet |
| 40 from boto.s3.lifecycle import Lifecycle, Expiration, Transition | |
| 41 from boto.s3.website import RedirectLocation | 41 from boto.s3.website import RedirectLocation |
| 42 | 42 |
| 43 | 43 |
| 44 class S3BucketTest (unittest.TestCase): | 44 class S3BucketTest (unittest.TestCase): |
| 45 s3 = True | 45 s3 = True |
| 46 | 46 |
| 47 def setUp(self): | 47 def setUp(self): |
| 48 self.conn = S3Connection() | 48 self.conn = S3Connection() |
| 49 self.bucket_name = 'bucket-%d' % int(time.time()) | 49 self.bucket_name = 'bucket-%d' % int(time.time()) |
| 50 self.bucket = self.conn.create_bucket(self.bucket_name) | 50 self.bucket = self.conn.create_bucket(self.bucket_name) |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 lifecycle.add_rule(name, prefix, "Enabled", days) | 254 lifecycle.add_rule(name, prefix, "Enabled", days) |
| 255 # set the lifecycle | 255 # set the lifecycle |
| 256 self.bucket.configure_lifecycle(lifecycle) | 256 self.bucket.configure_lifecycle(lifecycle) |
| 257 # read the lifecycle back | 257 # read the lifecycle back |
| 258 readlifecycle = self.bucket.get_lifecycle_config(); | 258 readlifecycle = self.bucket.get_lifecycle_config(); |
| 259 for rule in readlifecycle: | 259 for rule in readlifecycle: |
| 260 self.assertEqual(rule.id, name) | 260 self.assertEqual(rule.id, name) |
| 261 self.assertEqual(rule.expiration.days, days) | 261 self.assertEqual(rule.expiration.days, days) |
| 262 #Note: Boto seems correct? AWS seems broken? | 262 #Note: Boto seems correct? AWS seems broken? |
| 263 #self.assertEqual(rule.prefix, prefix) | 263 #self.assertEqual(rule.prefix, prefix) |
| 264 |
| 265 def test_lifecycle_with_defaults(self): |
| 266 lifecycle = Lifecycle() |
| 267 lifecycle.add_rule(expiration=30) |
| 268 self.assertTrue(self.bucket.configure_lifecycle(lifecycle)) |
| 269 response = self.bucket.get_lifecycle_config() |
| 270 self.assertEqual(len(response), 1) |
| 271 actual_lifecycle = response[0] |
| 272 self.assertNotEqual(len(actual_lifecycle.id), 0) |
| 273 self.assertEqual(actual_lifecycle.prefix, '') |
| 274 |
| 275 def test_lifecycle_rule_xml(self): |
| 276 # create a rule directly with id, prefix defaults |
| 277 rule = Rule(status='Enabled', expiration=30) |
| 278 s = rule.to_xml() |
| 279 # Confirm no ID is set in the rule. |
| 280 self.assertEqual(s.find("<ID>"), -1) |
| 281 # Confirm Prefix is '' and not set to 'None' |
| 282 self.assertNotEqual(s.find("<Prefix></Prefix>"), -1) |
| OLD | NEW |