Skip to content

Commit

Permalink
API for creating publish objects - initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lmilbaum committed Aug 27, 2020
1 parent a88aae2 commit c20df10
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,6 @@ disable=print-statement,
protected-access,
# we use black code style and don't need additional checks
bad-continuation,
line-too-long,
line-too-long,

extension-pkg-whitelist=pydantic
16 changes: 16 additions & 0 deletions exodus_gw/gateway.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
from pydantic import BaseModel

from .app import app
from .publish import publish_artifacts


@app.get("/healthcheck")
def healthcheck():
"""Returns a successful response if the service is running."""
return {"detail": "exodus-gw is running"}


class PublishObject(BaseModel):
artifacts: list


@app.put("/{env}/publish")
def publish(env: str, publishobject: PublishObject):
"""Publish artifacts"""
if env not in ["dev", "qa", "stage", "prod"]:
return {"error": "environment {0} not found".format(env)}
publish_artifacts(env, publishobject.artifacts)
return {"detail": "Publishing"}
19 changes: 19 additions & 0 deletions exodus_gw/publish.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def publish_artifacts(env, artifacts):
"""Publish all artifacts"""
for artifact in artifacts:
publish_artifacts(env, artifact)
return {
"detail": "Publishing artifacts {0} in environment {1}".format(
artifacts, env
)
}


def publish_artifact(env, artifact):
"""Publish single artifact"""
print("{0} {1}".format(env, artifact))
return {
"detail": "Publishing artifact {0} in environment {1}".format(
artifact, env
)
}
24 changes: 16 additions & 8 deletions tests/s3/test_manage_mpu.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import mock
import pytest
import textwrap

from fastapi import HTTPException
import pytest

from exodus_gw.s3.api import multipart_upload, abort_multipart_upload, upload
import mock
from exodus_gw.s3.api import abort_multipart_upload, multipart_upload, upload
from exodus_gw.s3.util import xml_response
from fastapi import HTTPException

TEST_KEY = "b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c"

Expand All @@ -30,12 +30,16 @@ async def test_create_mpu(mock_s3_client):
}

response = await multipart_upload(
None, bucket="my-bucket", key=TEST_KEY, uploads="",
None,
bucket="my-bucket",
key=TEST_KEY,
uploads="",
)

# It should delegate request to real S3
mock_s3_client.create_multipart_upload.assert_called_once_with(
Bucket="my-bucket", Key=TEST_KEY,
Bucket="my-bucket",
Key=TEST_KEY,
)

# It should succeed
Expand Down Expand Up @@ -142,12 +146,16 @@ async def test_abort_mpu(mock_s3_client):
"""Aborting a multipart upload is correctly delegated to S3."""

response = await abort_multipart_upload(
bucket="my-bucket", key=TEST_KEY, uploadId="my-lame-upload",
bucket="my-bucket",
key=TEST_KEY,
uploadId="my-lame-upload",
)

# It should delegate the request to real S3
mock_s3_client.abort_multipart_upload.assert_called_once_with(
Bucket="my-bucket", Key=TEST_KEY, UploadId="my-lame-upload",
Bucket="my-bucket",
Key=TEST_KEY,
UploadId="my-lame-upload",
)

# It should be a successful, empty response
Expand Down
28 changes: 28 additions & 0 deletions tests/test_gateway.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
import pytest

from exodus_gw import gateway


def test_healthcheck():
assert gateway.healthcheck() == {"detail": "exodus-gw is running"}


@pytest.mark.parametrize(
"env,publishobject,expected",
[
("dev", gateway.PublishObject(artifacts=[]), {"detail": "Publishing"}),
("qa", gateway.PublishObject(artifacts=[]), {"detail": "Publishing"}),
(
"stage",
gateway.PublishObject(artifacts=[]),
{"detail": "Publishing"},
),
(
"prod",
gateway.PublishObject(artifacts=[]),
{"detail": "Publishing"},
),
(
"env_doesnt_exist",
gateway.PublishObject(artifacts=[]),
{"error": "environment env_doesnt_exist not found"},
),
],
)
def test_publish(env, publishobject, expected):
assert gateway.publish(env, publishobject) == expected
61 changes: 61 additions & 0 deletions tests/test_publish.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import pytest

from exodus_gw import publish


@pytest.mark.parametrize(
"env,artifacts,expected",
[
(
"dev",
[],
{"detail": "Publishing artifacts [] in environment dev"},
),
(
"qa",
[],
{"detail": "Publishing artifacts [] in environment qa"},
),
(
"stage",
[],
{"detail": "Publishing artifacts [] in environment stage"},
),
(
"prod",
[],
{"detail": "Publishing artifacts [] in environment prod"},
),
],
)
def test_publish_artifacts(env, artifacts, expected):
assert publish.publish_artifacts(env, artifacts) == expected


@pytest.mark.parametrize(
"env,artifact,expected",
[
(
"dev",
{},
{"detail": "Publishing artifact {} in environment dev"},
),
(
"qa",
{},
{"detail": "Publishing artifact {} in environment qa"},
),
(
"stage",
{},
{"detail": "Publishing artifact {} in environment stage"},
),
(
"prod",
{},
{"detail": "Publishing artifact {} in environment prod"},
),
],
)
def test_publish_artifact(env, artifact, expected):
assert publish.publish_artifact(env, artifact) == expected
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ commands=
deps=
pytest-cov
coveralls
mock
usedevelop=true
commands_pre=
commands=
Expand Down

0 comments on commit c20df10

Please sign in to comment.