-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API for creating publish objects - initial commit
/{env}/publish end point. https://projects.engineering.redhat.com/browse/RHELDST-2159
- Loading branch information
Showing
7 changed files
with
144 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ commands= | |
deps= | ||
pytest-cov | ||
coveralls | ||
mock | ||
usedevelop=true | ||
commands_pre= | ||
commands= | ||
|