def test_validate_lifecycle_missing_exp_or_trans(self):
     bucket = 'test'
     module = Mock()
     lifecycle = [{
         "rule_id": "rule1",
         "status": "enabled",
         "state": "present"
     }]
     module.fail_json = Mock(return_value=True)
     validate_lifecycle(module, bucket, lifecycle)
     module.fail_json.assert_called_once_with(
         msg='missing expiration or transition rule for rule_id: rule1')
 def test_validate_lifecycle_invalid_transition(self):
     bucket = 'test'
     module = Mock()
     lifecycle = [{
         "rule_id": "rule1",
         "transition": {},
         "status": "enabled",
         "state": "present"
     }]
     module.fail_json = Mock(return_value=True)
     validate_lifecycle(module, bucket, lifecycle)
     module.fail_json.assert_called_once_with(
         msg='missing days or date in transition rule for rule_id: rule1')
 def test_validate_missing_rule_id(self):
     bucket = 'test'
     module = Mock()
     lifecycle = [{
         "transition": {
             "storage_class": "frozen",
             "days": 90
         },
         "state": "present"
     }]
     module.fail_json = Mock(return_value=True)
     validate_lifecycle(module, bucket, lifecycle)
     module.fail_json.assert_called_once_with(
         msg='rule_id required for bucket test')
 def test_validate_missing_state(self):
     bucket = 'test'
     module = Mock()
     lifecycle = [{
         "rule_id": "rule1",
         "status": "enabled",
         "transition": {
             "storage_class": "frozen",
             "days": 90
         }
     }]
     module.fail_json = Mock(return_value=True)
     validate_lifecycle(module, bucket, lifecycle)
     module.fail_json.assert_called_once_with(
         msg='state needed for rule_id: rule1')
 def test_validate_lifecycle_transition_missing_storage(self):
     bucket = 'test'
     module = Mock()
     lifecycle = [{
         "rule_id": "rule1",
         "transition": {
             "days": 90
         },
         "status": "enabled",
         "state": "present"
     }]
     module.fail_json = Mock(return_value=True)
     validate_lifecycle(module, bucket, lifecycle)
     module.fail_json.assert_called_once_with(
         msg='missing storage_class in rule_id: rule1')
 def test_validate_lifecycle_transition_glacier(self):
     bucket = 'test'
     module = Mock()
     lifecycle = [{
         "rule_id": "rule1",
         "transition": {
             "storage_class": "glacier",
             "days": 90
         },
         "status": "enabled",
         "state": "present"
     }]
     module.fail_json = Mock(return_value=True)
     validate_lifecycle(module, bucket, lifecycle)
     module.fail_json.assert_has_calls(calls=[])
 def test_validate_lifecycle_expiration(self):
     bucket = 'test'
     module = Mock()
     lifecycle = [{
         "rule_id": "rule1",
         "prefix": "/f1",
         "expiration": {
             "days": 31
         },
         "status": "enabled",
         "state": "present"
     }]
     module.fail_json = Mock(return_value=True)
     validate_lifecycle(module, bucket, lifecycle)
     module.fail_json.assert_has_calls(calls=[])
 def test_validate_lifecycle_expiration_both_days_and_date(self):
     bucket = 'test'
     module = Mock()
     lifecycle = [{
         "rule_id": "rule1",
         "expiration": {
             "days": 90,
             "date": "2020-01-30"
         },
         "status": "enabled",
         "state": "present"
     }]
     module.fail_json = Mock(return_value=True)
     validate_lifecycle(module, bucket, lifecycle)
     module.fail_json.assert_called_once_with(
         msg=
         'can only have date or days, not both in expiration rule_id: rule1'
     )