def test_config(self): config = VersioningConfig(ENABLED) xml.marshal(config) config = xml.unmarshal( VersioningConfig, """<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> </VersioningConfiguration>""", ) xml.marshal(config) self.assertEqual(config.status, OFF) config = xml.unmarshal( VersioningConfig, """<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Status>Enabled</Status> </VersioningConfiguration>""", ) xml.marshal(config) self.assertEqual(config.status, ENABLED) config = xml.unmarshal( VersioningConfig, """<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Status>Suspended</Status> <MFADelete>Disabled</MFADelete> </VersioningConfiguration>""", ) xml.marshal(config) self.assertEqual(config.status, SUSPENDED) self.assertEqual(config.mfa_delete, DISABLED)
def test_config(self): config = ReplicationConfig( "REPLACE-WITH-ACTUAL-ROLE", [ Rule( Destination( "REPLACE-WITH-ACTUAL-DESTINATION-BUCKET-ARN", ), ENABLED, delete_marker_replication=DeleteMarkerReplication( DISABLED, ), rule_filter=Filter( AndOperator( "TaxDocs", { "key1": "value1", "key2": "value2" }, ), ), rule_id="rule1", priority=1, ), ], ) xml.marshal(config) config = xml.unmarshal( ReplicationConfig, """<ReplicationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Role>arn:aws:iam::35667example:role/CrossRegionReplicationRoleForS3</Role> <Rule> <ID>rule1</ID> <Status>Enabled</Status> <Priority>1</Priority> <DeleteMarkerReplication> <Status>Disabled</Status> </DeleteMarkerReplication> <Filter> <And> <Prefix>TaxDocs</Prefix> <Tag> <Key>key1</Key> <Value>value1</Value> </Tag> <Tag> <Key>key1</Key> <Value>value1</Value> </Tag> </And> </Filter> <Destination> <Bucket>arn:aws:s3:::exampletargetbucket</Bucket> </Destination> </Rule> </ReplicationConfiguration>""", ) xml.marshal(config)
def test_status(self): config = LegalHold(True) xml.marshal(config) config = xml.unmarshal( LegalHold, """<LegalHold xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Status>OFF</Status> </LegalHold>""", ) xml.marshal(config) self.assertFalse(config.status)
def test_config(self): config = Retention(GOVERNANCE, datetime.now() + timedelta(days=10)) xml.marshal(config) config = xml.unmarshal( Retention, """<Retention xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Mode>COMPLIANCE</Mode> <RetainUntilDate>2020-10-02T00:00:00Z</RetainUntilDate> </Retention>""", ) xml.marshal(config) eq_(config.mode, COMPLIANCE) eq_(config.retain_until_date, datetime(2020, 10, 2, 0, 0, 0))
def test_config(self): config = LifecycleConfig([ Rule( ENABLED, rule_filter=Filter(prefix="documents/"), rule_id="rule1", transition=Transition(days=30, storage_class="GLACIER"), ), Rule( ENABLED, rule_filter=Filter(prefix="logs/"), rule_id="rule2", expiration=Expiration(days=365), ), ], ) xml.marshal(config) config = xml.unmarshal( LifecycleConfig, """<LifeCycleConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Rule> <ID>DeleteAfterBecomingNonCurrent</ID> <Filter> <Prefix>logs/</Prefix> </Filter> <Status>Enabled</Status> <NoncurrentVersionExpiration> <NoncurrentDays>100</NoncurrentDays> </NoncurrentVersionExpiration> </Rule> <Rule> <ID>TransitionAfterBecomingNonCurrent</ID> <Filter> <Prefix>documents/</Prefix> </Filter> <Status>Enabled</Status> <NoncurrentVersionTransition> <NoncurrentDays>30</NoncurrentDays> <StorageClass>GLACIER</StorageClass> </NoncurrentVersionTransition> </Rule> </LifeCycleConfiguration>""", ) xml.marshal(config)
def test_config(self): config = ObjectLockConfig(GOVERNANCE, 15, DAYS) xml.marshal(config) config = xml.unmarshal( ObjectLockConfig, """<ObjectLockConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <ObjectLockEnabled>Enabled</ObjectLockEnabled> <Rule> <DefaultRetention> <Mode>COMPLIANCE</Mode> <Years>3</Years> </DefaultRetention> </Rule> </ObjectLockConfiguration>""", ) xml.marshal(config) eq_(config.mode, COMPLIANCE) eq_(config.duration, (3, YEARS))
def test_config(self): config = NotificationConfig( queue_config_list=[ QueueConfig( "QUEUE-ARN-OF-THIS-BUCKET", ['s3:ObjectCreated:*'], config_id="1", prefix_filter_rule=PrefixFilterRule("abc"), ), ], ) xml.marshal(config) config = xml.unmarshal( NotificationConfig, """<NotificationConfiguration> <CloudFunctionConfiguration> <Id>ObjectCreatedEvents</Id> <CloudFunction>arn:aws:lambda:us-west-2:35667example:function:CreateThumbnail</CloudFunction> <Event>s3:ObjectCreated:*</Event> </CloudFunctionConfiguration> <QueueConfiguration> <Id>1</Id> <Filter> <S3Key> <FilterRule> <Name>prefix</Name> <Value>images/</Value> </FilterRule> <FilterRule> <Name>suffix</Name> <Value>.jpg</Value> </FilterRule> </S3Key> </Filter> <Queue>arn:aws:sqs:us-west-2:444455556666:s3notificationqueue</Queue> <Event>s3:ObjectCreated:Put</Event> </QueueConfiguration> </NotificationConfiguration>""", ) xml.marshal(config)
def test_config(self): config = SSEConfig(Rule.new_sse_s3_rule()) xml.marshal(config) config = xml.unmarshal( SSEConfig, """<ServerSideEncryptionConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Rule> <ApplyServerSideEncryptionByDefault> <SSEAlgorithm>aws:kms</SSEAlgorithm> <KMSMasterKeyID>arn:aws:kms:us-east-1:1234/5678example</KMSMasterKeyID> </ApplyServerSideEncryptionByDefault> </Rule> </ServerSideEncryptionConfiguration> """, ) xml.marshal(config) eq_(config.rule.sse_algorithm, AWS_KMS) eq_( config.rule.kms_master_key_id, "arn:aws:kms:us-east-1:1234/5678example", )
def test_tagging(self): tags = Tags() tags["Project"] = "Project One" tags["User"] = "******" tagging = Tagging(tags) xml.marshal(tagging) config = xml.unmarshal( Tagging, """<Tagging xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <TagSet> <Tag> <Key>key1</Key> <Value>value1</Value> </Tag> <Tag> <Key>key2</Key> <Value>value2</Value> </Tag> </TagSet> </Tagging>""", ) xml.marshal(config)