-
Notifications
You must be signed in to change notification settings - Fork 671
feat: add support for deployment approval endpoint #2254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -6,7 +6,25 @@ | |
|
||
|
||
@pytest.fixture | ||
def resp_deployment(): | ||
def resp_deployment_get(): | ||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
method=responses.GET, | ||
url="http://localhost/api/v4/projects/1/deployments/42", | ||
json=response_get_content, | ||
content_type="application/json", | ||
status=200, | ||
) | ||
yield rsps | ||
|
||
|
||
@pytest.fixture | ||
def deployment(project): | ||
return project.deployments.get(42, lazy=True) | ||
|
||
|
||
@pytest.fixture | ||
def resp_deployment_create(): | ||
content = {"id": 42, "status": "success", "ref": "main"} | ||
|
||
with responses.RequestsMock() as rsps: | ||
|
@@ -31,7 +49,42 @@ def resp_deployment(): | |
yield rsps | ||
|
||
|
||
def test_deployment(project, resp_deployment): | ||
@pytest.fixture | ||
def resp_deployment_approval(): | ||
content = { | ||
"user": { | ||
"id": 100, | ||
"username": "security-user-1", | ||
"name": "security user-1", | ||
"state": "active", | ||
"avatar_url": "https://www.gravatar.com/avatar/e130fcd3a1681f41a3de69d10841afa9?s=80&d=identicon", | ||
"web_url": "http://localhost:3000/security-user-1", | ||
}, | ||
"status": "approved", | ||
"created_at": "2022-02-24T20:22:30.097Z", | ||
"comment": "Looks good to me", | ||
} | ||
|
||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
method=responses.POST, | ||
url="http://localhost/api/v4/projects/1/deployments/42/approval", | ||
json=content, | ||
content_type="application/json", | ||
status=200, | ||
) | ||
yield rsps | ||
|
||
|
||
def test_deployment_get(project, resp_deployment_get): | ||
deployment = project.deployments.get(42) | ||
assert deployment.id == 42 | ||
assert deployment.iid == 2 | ||
assert deployment.status == "success" | ||
assert deployment.ref == "main" | ||
|
||
|
||
def test_deployment_create(project, resp_deployment_create): | ||
deployment = project.deployments.create( | ||
{ | ||
"environment": "Test", | ||
|
@@ -48,3 +101,80 @@ def test_deployment(project, resp_deployment): | |
deployment.status = "failed" | ||
deployment.save() | ||
assert deployment.status == "failed" | ||
|
||
|
||
def test_deployment_approval(deployment, resp_deployment_approval) -> None: | ||
result = deployment.approval(status="approved") | ||
assert result["status"] == "approved" | ||
assert result["comment"] == "Looks good to me" | ||
|
||
|
||
response_get_content = { | ||
"id": 42, | ||
"iid": 2, | ||
"ref": "main", | ||
"sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a", | ||
"created_at": "2016-08-11T11:32:35.444Z", | ||
"updated_at": "2016-08-11T11:34:01.123Z", | ||
"status": "success", | ||
"user": { | ||
"name": "Administrator", | ||
"username": "root", | ||
"id": 1, | ||
"state": "active", | ||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", | ||
"web_url": "http://localhost:3000/root", | ||
}, | ||
"environment": { | ||
"id": 9, | ||
"name": "production", | ||
"external_url": "https://about.gitlab.com", | ||
}, | ||
"deployable": { | ||
"id": 664, | ||
"status": "success", | ||
"stage": "deploy", | ||
"name": "deploy", | ||
"ref": "main", | ||
"tag": False, | ||
"coverage": None, | ||
"created_at": "2016-08-11T11:32:24.456Z", | ||
"started_at": None, | ||
"finished_at": "2016-08-11T11:32:35.145Z", | ||
"user": { | ||
"id": 1, | ||
"name": "Administrator", | ||
"username": "root", | ||
"state": "active", | ||
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", | ||
"web_url": "http://gitlab.dev/root", | ||
"created_at": "2015-12-21T13:14:24.077Z", | ||
"bio": None, | ||
"location": None, | ||
"skype": "", | ||
"linkedin": "", | ||
"twitter": "", | ||
"website_url": "", | ||
"organization": "", | ||
}, | ||
"commit": { | ||
"id": "a91957a858320c0e17f3a0eca7cfacbff50ea29a", | ||
"short_id": "a91957a8", | ||
"title": "Merge branch 'rename-readme' into 'main'\r", | ||
"author_name": "Administrator", | ||
"author_email": "[email protected]", | ||
"created_at": "2016-08-11T13:28:26.000+02:00", | ||
"message": "Merge branch 'rename-readme' into 'main'\r\n\r\nRename README\r\n\r\n\r\n\r\nSee merge request !2", | ||
}, | ||
"pipeline": { | ||
"created_at": "2016-08-11T07:43:52.143Z", | ||
"id": 42, | ||
"ref": "main", | ||
"sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a", | ||
"status": "success", | ||
"updated_at": "2016-08-11T07:43:52.143Z", | ||
"web_url": "http://gitlab.dev/root/project/pipelines/5", | ||
}, | ||
"runner": None, | ||
}, | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.