예제 #1
0
    def test_create_us_west_2(self, runway_context):
        """Test create with region=us-west-2."""
        stubber = runway_context.add_stubber("s3", region="us-west-2")
        bucket = Bucket(runway_context, "test-bucket", region="us-west-2")

        stubber.add_client_error(
            "head_bucket",
            "NoSuchBucket",
            "The specified bucket does not exist.",
            404,
            expected_params={"Bucket": "test-bucket"},
        )
        stubber.add_response(
            "create_bucket",
            {"Location": "us-east-1"},
            {
                "Bucket": "test-bucket",
                "CreateBucketConfiguration": {
                    "LocationConstraint": "us-west-2"
                },
            },
        )

        with stubber:
            assert bucket.create()
        stubber.assert_no_pending_responses()
예제 #2
0
    def test_create_exists(
        self, caplog: LogCaptureFixture, runway_context: MockRunwayContext
    ) -> None:
        """Test create with exists=True."""
        caplog.set_level(logging.DEBUG, logger="runway.core.providers.aws.s3.bucket")
        stubber = runway_context.add_stubber("s3", region="us-west-2")
        bucket = Bucket(runway_context, "test-bucket", region="us-west-2")

        stubber.add_response(
            "head_bucket",
            {"ResponseMetadata": {"HostId": "test", "HTTPStatusCode": 200}},
            {"Bucket": "test-bucket"},
        )

        with stubber:
            assert not bucket.create()
        stubber.assert_no_pending_responses()
        assert "bucket already exists" in "\n".join(caplog.messages)
예제 #3
0
    def test_create_forbidden(self, caplog, runway_context):
        """Test create with forbidden=True."""
        caplog.set_level(logging.DEBUG,
                         logger="runway.core.providers.aws.s3.bucket")
        stubber = runway_context.add_stubber("s3", region="us-west-2")
        bucket = Bucket(runway_context, "test-bucket", region="us-west-2")

        stubber.add_client_error(
            "head_bucket",
            "AccessDenied",
            "Forbidden",
            403,
            expected_params={"Bucket": "test-bucket"},
        )

        with stubber:
            assert not bucket.create()
        stubber.assert_no_pending_responses()
        assert "access denied" in "\n".join(caplog.messages)
예제 #4
0
    def test_create(self, runway_context: MockRunwayContext) -> None:
        """Test create."""
        stubber = runway_context.add_stubber("s3")
        bucket = Bucket(runway_context, "test-bucket")

        stubber.add_client_error(
            "head_bucket",
            "NoSuchBucket",
            "Not Found",
            404,
            expected_params={"Bucket": "test-bucket"},
        )
        stubber.add_response(
            "create_bucket",
            {"Location": "us-east-1"},
            {"ACL": "private", "Bucket": "test-bucket"},
        )

        with stubber:
            assert bucket.create(ACL="private")
        stubber.assert_no_pending_responses()