def test_deploy_error_destroy(self, cfngin_context: MockCFNginContext, monkeypatch: MonkeyPatch) -> None: """Test deploy with errors that result in destroy being called.""" # setup context cfngin_context.add_stubber("acm", "us-east-1") cfngin_context.add_stubber("route53", "us-east-1") cfngin_context.config.namespace = "test" cert_arn = "arn:aws:acm:us-east-1:012345678901:certificate/test" cert = Certificate( context=cfngin_context, provider=MagicMock(), domain="example.com", hosted_zone_id="test", ) monkeypatch.setattr(cert, "domain_changed", lambda: False) monkeypatch.setattr(cert, "deploy_stack", lambda: STATUS.new) # type: ignore monkeypatch.setattr(cert, "get_certificate", lambda: cert_arn) monkeypatch.setattr( cert, "get_validation_record", lambda x: "get_validation_record" if x == cert_arn else ValueError, ) monkeypatch.setattr( cert, "put_record_set", MagicMock(side_effect=[ cert.r53_client.exceptions.InvalidChangeBatch({}, ""), cert.r53_client.exceptions.NoSuchHostedZone({}, ""), None, ]), ) monkeypatch.setattr( cert, "destroy", lambda records, skip_r53: check_bool_is_true(skip_r53)) monkeypatch.setattr(cert, "_wait_for_stack", MagicMock(side_effect=StackFailed("test"))) assert not cert.deploy( ) # cert.r53_client.exceptions.InvalidChangeBatch assert not cert.deploy() # cert.r53_client.exceptions.NoSuchHostedZone monkeypatch.setattr( cert, "destroy", lambda records, skip_r53: check_bool_is_false(skip_r53)) assert not cert.deploy() # StackFailed
def test_deploy_update(self, cfngin_context: MockCFNginContext, monkeypatch: MonkeyPatch) -> None: """Test deploy update stack.""" # setup context cfngin_context.add_stubber("acm", "us-east-1") cfngin_context.add_stubber("route53", "us-east-1") cfngin_context.config.namespace = "test" cert_arn = "arn:aws:acm:us-east-1:012345678901:certificate/test" expected = {"CertificateArn": cert_arn} cert = Certificate( context=cfngin_context, provider=MagicMock(), domain="example.com", hosted_zone_id="test", ) monkeypatch.setattr(cert, "domain_changed", lambda: False) monkeypatch.setattr(cert, "deploy_stack", lambda: STATUS.update) monkeypatch.setattr(cert, "get_certificate", lambda: cert_arn) monkeypatch.setattr( cert, "get_validation_record", lambda x, status: "get_validation_record" if x == cert_arn and status == "SUCCESS" else ValueError, ) monkeypatch.setattr( cert, "update_record_set", lambda x: None if x == "get_validation_record" else ValueError, ) monkeypatch.setattr(cert, "_wait_for_stack", lambda x, last_status: None) assert cert.deploy() == expected
def test_deploy_recreate(self, cfngin_context, monkeypatch): """Test deploy with stack recreation.""" # setup context cfngin_context.add_stubber('acm', 'us-east-1') cfngin_context.add_stubber('route53', 'us-east-1') cfngin_context.config.namespace = 'test' cert_arn = 'arn:aws:acm:us-east-1:012345678901:certificate/test' expected = {'CertificateArn': cert_arn} cert = Certificate(context=cfngin_context, provider=MagicMock(), domain='example.com', hosted_zone_id='test') monkeypatch.setattr(cert, 'domain_changed', lambda: False) monkeypatch.setattr(cert, 'deploy_stack', lambda: STATUS.recreate) monkeypatch.setattr(cert, 'get_certificate', MagicMock(side_effect=['old', cert_arn])) monkeypatch.setattr(cert, '_wait_for_stack', MagicMock(side_effect=[STATUS.new, None])) monkeypatch.setattr( cert, 'get_validation_record', lambda x: 'get_validation_record' if x == cert_arn else ValueError) monkeypatch.setattr( cert, 'put_record_set', lambda x: None if x == 'get_validation_record' else ValueError) assert cert.deploy() == expected
def test_deploy_update(self, cfngin_context, monkeypatch): """Test deploy update stack.""" # setup context cfngin_context.add_stubber('acm', 'us-east-1') cfngin_context.add_stubber('route53', 'us-east-1') cfngin_context.config.namespace = 'test' cert_arn = 'arn:aws:acm:us-east-1:012345678901:certificate/test' expected = {'CertificateArn': cert_arn} cert = Certificate(context=cfngin_context, provider=MagicMock(), domain='example.com', hosted_zone_id='test') monkeypatch.setattr(cert, 'domain_changed', lambda: False) monkeypatch.setattr(cert, 'deploy_stack', lambda: STATUS.update) monkeypatch.setattr(cert, 'get_certificate', lambda: cert_arn) monkeypatch.setattr( cert, 'get_validation_record', lambda x, status: 'get_validation_record' if x == cert_arn and status == 'SUCCESS' else ValueError) monkeypatch.setattr( cert, 'update_record_set', lambda x: None if x == 'get_validation_record' else ValueError) monkeypatch.setattr(cert, '_wait_for_stack', lambda x, last_status: None) assert cert.deploy() == expected
def test_deploy_error_destroy(self, cfngin_context, monkeypatch): """Test deploy with errors that result in destroy being called.""" # setup context cfngin_context.add_stubber('acm', 'us-east-1') cfngin_context.add_stubber('route53', 'us-east-1') cfngin_context.config.namespace = 'test' cert_arn = 'arn:aws:acm:us-east-1:012345678901:certificate/test' cert = Certificate(context=cfngin_context, provider=MagicMock(), domain='example.com', hosted_zone_id='test') monkeypatch.setattr(cert, 'domain_changed', lambda: False) monkeypatch.setattr(cert, 'deploy_stack', lambda: STATUS.new) monkeypatch.setattr(cert, 'get_certificate', lambda: cert_arn) monkeypatch.setattr( cert, 'get_validation_record', lambda x: 'get_validation_record' if x == cert_arn else ValueError) monkeypatch.setattr( cert, 'put_record_set', MagicMock(side_effect=[ cert.r53_client.exceptions.InvalidChangeBatch({}, ''), cert.r53_client.exceptions.NoSuchHostedZone({}, ''), None ])) monkeypatch.setattr( cert, 'destroy', lambda records, skip_r53: check_bool_is_true(skip_r53)) monkeypatch.setattr(cert, '_wait_for_stack', MagicMock(side_effect=StackFailed('test'))) assert not cert.deploy( ) # cert.r53_client.exceptions.InvalidChangeBatch assert not cert.deploy() # cert.r53_client.exceptions.NoSuchHostedZone monkeypatch.setattr( cert, 'destroy', lambda records, skip_r53: check_bool_is_false(skip_r53)) assert not cert.deploy() # StackFailed
def test_deploy_domain_changed(self, cfngin_context, monkeypatch): """Test deploy domain changed.""" # setup context cfngin_context.add_stubber('acm', 'us-east-1') cfngin_context.add_stubber('route53', 'us-east-1') cfngin_context.config.namespace = 'test' cert = Certificate(context=cfngin_context, provider=MagicMock(), domain='example.com', hosted_zone_id='test') monkeypatch.setattr(cert, 'domain_changed', lambda: True) assert not cert.deploy()
def test_deploy_domain_changed(self, cfngin_context, monkeypatch): """Test deploy domain changed.""" # setup context cfngin_context.add_stubber("acm", "us-east-1") cfngin_context.add_stubber("route53", "us-east-1") cfngin_context.config.namespace = "test" cert = Certificate( context=cfngin_context, provider=MagicMock(), domain="example.com", hosted_zone_id="test", ) monkeypatch.setattr(cert, "domain_changed", lambda: True) assert not cert.deploy()
def test_deploy_error_no_destroy(self, cfngin_context, monkeypatch): """Test deploy with errors that don't result in destroy being called.""" # setup context cfngin_context.add_stubber('acm', 'us-east-1') cfngin_context.add_stubber('route53', 'us-east-1') cfngin_context.config.namespace = 'test' cert = Certificate(context=cfngin_context, provider=MagicMock(), domain='example.com', hosted_zone_id='test') monkeypatch.setattr(cert, 'domain_changed', lambda: False) monkeypatch.setattr( cert, 'deploy_stack', MagicMock( side_effect=StackUpdateBadStatus('test', 'test', 'test'))) assert not cert.deploy()
def test_deploy_no_change(self, cfngin_context, monkeypatch): """Test deploy no change.""" # setup context cfngin_context.add_stubber('acm', 'us-east-1') cfngin_context.add_stubber('route53', 'us-east-1') cfngin_context.config.namespace = 'test' cert_arn = 'arn:aws:acm:us-east-1:012345678901:certificate/test' expected = {'CertificateArn': cert_arn} cert = Certificate(context=cfngin_context, provider=MagicMock(), domain='example.com', hosted_zone_id='test') monkeypatch.setattr(cert, 'domain_changed', lambda: False) monkeypatch.setattr(cert, 'deploy_stack', lambda: STATUS.no) monkeypatch.setattr(cert, 'get_certificate', lambda: cert_arn) assert cert.deploy() == expected
def test_deploy_error_no_destroy(self, cfngin_context, monkeypatch): """Test deploy with errors that don't result in destroy being called.""" # setup context cfngin_context.add_stubber("acm", "us-east-1") cfngin_context.add_stubber("route53", "us-east-1") cfngin_context.config.namespace = "test" cert = Certificate( context=cfngin_context, provider=MagicMock(), domain="example.com", hosted_zone_id="test", ) monkeypatch.setattr(cert, "domain_changed", lambda: False) monkeypatch.setattr( cert, "deploy_stack", MagicMock(side_effect=StackUpdateBadStatus("test", "test", "test")), ) assert not cert.deploy()
def test_deploy_no_change(self, cfngin_context, monkeypatch): """Test deploy no change.""" # setup context cfngin_context.add_stubber("acm", "us-east-1") cfngin_context.add_stubber("route53", "us-east-1") cfngin_context.config.namespace = "test" cert_arn = "arn:aws:acm:us-east-1:012345678901:certificate/test" expected = {"CertificateArn": cert_arn} cert = Certificate( context=cfngin_context, provider=MagicMock(), domain="example.com", hosted_zone_id="test", ) monkeypatch.setattr(cert, "domain_changed", lambda: False) monkeypatch.setattr(cert, "deploy_stack", lambda: STATUS.no) monkeypatch.setattr(cert, "get_certificate", lambda: cert_arn) assert cert.deploy() == expected
def test_deploy_recreate(self, cfngin_context: MockCFNginContext, monkeypatch: MonkeyPatch): """Test deploy with stack recreation.""" # setup context cfngin_context.add_stubber("acm", "us-east-1") cfngin_context.add_stubber("route53", "us-east-1") cfngin_context.config.namespace = "test" cert_arn = "arn:aws:acm:us-east-1:012345678901:certificate/test" expected = {"CertificateArn": cert_arn} cert = Certificate( context=cfngin_context, provider=MagicMock(), domain="example.com", hosted_zone_id="test", ) monkeypatch.setattr(cert, "domain_changed", lambda: False) monkeypatch.setattr(cert, "deploy_stack", lambda: STATUS.recreate) # type: ignore monkeypatch.setattr(cert, "get_certificate", MagicMock(side_effect=["old", cert_arn])) monkeypatch.setattr( cert, "_wait_for_stack", MagicMock(side_effect=[STATUS.new, None]) # type: ignore ) monkeypatch.setattr( cert, "get_validation_record", lambda x: "get_validation_record" if x == cert_arn else ValueError, ) monkeypatch.setattr( cert, "put_record_set", lambda x: None if x == "get_validation_record" else ValueError, ) assert cert.deploy() == expected