Пример #1
0
def test_get_releases_skips_objects_with_invalid_data():
    s3 = boto3.resource("s3")
    client = boto3.client("s3")

    s3.create_bucket(Bucket="test")
    bucket = s3.BucketVersioning("test")
    bucket.enable()

    # missing fields
    client.put_object(
        Bucket="test",
        Key="test-app",
        Body=json.dumps({
            "changelog": "some changes",
            "image":
            "sha256:eb1494dee949e52c20084672700c9961d7fc99d1be1c07b5492bc61c3b22a460",
            "author": "*****@*****.**",
        }),
    )

    # invalid JSON
    client.put_object(Bucket="test",
                      Key="test-app",
                      Body='{ "this": "is" invalid')

    with freeze_time("2018-02-02T00:00:00"):
        new = client.put_object(
            Bucket="test",
            Key="test-app",
            Body=json.dumps({
                "version": 2,
                "commit": "abcdef0123456789",
                "changelog": "some other changes to fix version 1",
                "image":
                "sha256:000dd6d0c34dd4bb2ec51316ec41f723dd546ef79b30e551ec8390d032707351",
                "author": "*****@*****.**",
            }),
        )

    rs = release.get_releases(client, "test-app", bucket="test")

    expected = [
        release.Release(
            version=2,
            commit="abcdef0123456789",
            changelog="some other changes to fix version 1",
            version_id=new["VersionId"],
            image=
            "sha256:000dd6d0c34dd4bb2ec51316ec41f723dd546ef79b30e551ec8390d032707351",
            timestamp=datetime(2018, 2, 2, 0, 0, 0, tzinfo=pytz.utc),
            author="*****@*****.**",
        )
    ]

    compare(expected, list(rs))
Пример #2
0
def test_get_latest_release():
    """
    Gets the latest release when the object's Version ID is not specified.
    """
    s3 = boto3.resource("s3")
    client = boto3.client("s3")

    s3.create_bucket(Bucket="test")
    bucket = s3.BucketVersioning("test")
    bucket.enable()

    with freeze_time("2018-01-01T12:00:00"):
        client.put_object(
            Bucket="test",
            Key="test-app",
            Body=json.dumps(
                {
                    "version": 1,
                    "commit": "0123456789abcdef",
                    "changelog": "some changes",
                    "image": "sha256:eb1494dee949e52c20084672700c9961d7fc99d1be1c07b5492bc61c3b22a460",
                    "author": "*****@*****.**",
                }
            ),
        )

    with freeze_time("2018-02-02T00:00:00"):
        new = client.put_object(
            Bucket="test",
            Key="test-app",
            Body=json.dumps(
                {
                    "version": 2,
                    "commit": "abcdef0123456789",
                    "changelog": "some other changes to fix version 1",
                    "image": "sha256:000dd6d0c34dd4bb2ec51316ec41f723dd546ef79b30e551ec8390d032707351",
                    "author": "*****@*****.**",
                }
            ),
        )

    expected = release.Release(
        version=2,
        commit="abcdef0123456789",
        changelog="some other changes to fix version 1",
        version_id=new["VersionId"],
        image="sha256:000dd6d0c34dd4bb2ec51316ec41f723dd546ef79b30e551ec8390d032707351",
        timestamp=datetime(2018, 2, 2, 0, 0, 0, tzinfo=pytz.utc),
        author="*****@*****.**",
    )

    r = release._get_release(client, "test", "test-app", None)

    compare(expected, r)
Пример #3
0
def test_create_new_release():
    s3 = boto3.resource("s3")
    client = boto3.client("s3")

    s3.create_bucket(Bucket="test")
    bucket = s3.BucketVersioning("test")
    bucket.enable()

    new = release.Release(
        version=1,
        commit="abcdef0123456789",
        changelog="some changes",
        version_id=None,
        image="sha256:000dd6d0c34dd4bb2ec51316ec41f723dd546ef79b30e551ec8390d032707351",
        timestamp=None,
        author="*****@*****.**",
    )

    pushed = release.put_release(client, "test", "test-app", new)
    fetched = release.get_release(client, "test-app", 1, bucket="test")

    compare(pushed, fetched)
Пример #4
0
def test_get_release_from_bucket():
    """
    Gets the release from an object stored in a S3 bucket.
    """
    s3 = boto3.resource("s3")
    client = boto3.client("s3")

    s3.create_bucket(Bucket="test")
    bucket = s3.BucketVersioning("test")
    bucket.enable()

    resp = client.put_object(
        Bucket="test",
        Key="test-app",
        Body=json.dumps({
            "version": 2,
            "commit": "0123456789abcdef",
            "changelog": "some changes",
            "image":
            "sha256:eb1494dee949e52c20084672700c9961d7fc99d1be1c07b5492bc61c3b22a460",
            "author": "*****@*****.**",
        }),
    )

    expected = release.Release(
        version=2,
        commit="0123456789abcdef",
        changelog="some changes",
        version_id=resp["VersionId"],
        image=
        "sha256:eb1494dee949e52c20084672700c9961d7fc99d1be1c07b5492bc61c3b22a460",
        timestamp=datetime(2018, 1, 1, 12, 0, 0, tzinfo=pytz.utc),
        author="*****@*****.**",
    )

    r = release.fetch_release(client, "test", "test-app", None)

    compare(expected, r)
Пример #5
0
def test_get_releases_since():
    s3 = boto3.resource("s3")
    client = boto3.client("s3")

    s3.create_bucket(Bucket="test")
    bucket = s3.BucketVersioning("test")
    bucket.enable()

    with freeze_time("2018-01-01T12:00:00"):
        client.put_object(
            Bucket="test",
            Key="test-app",
            Body=json.dumps({
                "version": 1,
                "commit": "0123456789abcdef",
                "changelog": "some changes",
                "image":
                "sha256:eb1494dee949e52c20084672700c9961d7fc99d1be1c07b5492bc61c3b22a460",
                "author": "*****@*****.**",
            }),
        )

    with freeze_time("2018-02-02T00:00:00"):
        second = client.put_object(
            Bucket="test",
            Key="test-app",
            Body=json.dumps({
                "version": 2,
                "commit": "abcdef0123456789",
                "changelog": "some other changes to fix version 1",
                "image":
                "sha256:000dd6d0c34dd4bb2ec51316ec41f723dd546ef79b30e551ec8390d032707351",
                "author": "*****@*****.**",
            }),
        )

    with freeze_time("2018-03-03T00:00:00"):
        third = client.put_object(
            Bucket="test",
            Key="test-app",
            Body=json.dumps({
                "version": 3,
                "commit": "zxcvbnm12345",
                "changelog": "new awesome feature",
                "image":
                "sha256:b0190de683bc5d190c4c09473e0d2a5696850f22244cd8e9fc925117580b6361",
                "author": "*****@*****.**",
            }),
        )

    rs = release.get_releases(client, "test-app", since=2, bucket="test")

    expected = [
        release.Release(
            version=3,
            commit="zxcvbnm12345",
            changelog="new awesome feature",
            version_id=third["VersionId"],
            image=
            "sha256:b0190de683bc5d190c4c09473e0d2a5696850f22244cd8e9fc925117580b6361",
            timestamp=datetime(2018, 3, 3, 0, 0, 0, tzinfo=pytz.utc),
            author="*****@*****.**",
        ),
        release.Release(
            version=2,
            commit="abcdef0123456789",
            changelog="some other changes to fix version 1",
            version_id=second["VersionId"],
            image=
            "sha256:000dd6d0c34dd4bb2ec51316ec41f723dd546ef79b30e551ec8390d032707351",
            timestamp=datetime(2018, 2, 2, 0, 0, 0, tzinfo=pytz.utc),
            author="*****@*****.**",
        ),
    ]

    compare(expected, list(rs))