Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rewrite unit tests for objects with responses
- Loading branch information
Showing
24 changed files
with
900 additions
and
940 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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"""Common mocks for resources in gitlab.v4.objects""" | ||
|
||
import re | ||
|
||
import pytest | ||
import responses | ||
|
||
|
||
@pytest.fixture | ||
def binary_content(): | ||
return b"binary content" | ||
|
||
|
||
@pytest.fixture | ||
def accepted_content(): | ||
return {"message": "202 Accepted"} | ||
|
||
|
||
@pytest.fixture | ||
def created_content(): | ||
return {"message": "201 Created"} | ||
|
||
|
||
@pytest.fixture | ||
def resp_export(accepted_content, binary_content): | ||
"""Common fixture for group and project exports.""" | ||
export_status_content = { | ||
"id": 1, | ||
"description": "Itaque perspiciatis minima aspernatur", | ||
"name": "Gitlab Test", | ||
"name_with_namespace": "Gitlab Org / Gitlab Test", | ||
"path": "gitlab-test", | ||
"path_with_namespace": "gitlab-org/gitlab-test", | ||
"created_at": "2017-08-29T04:36:44.383Z", | ||
"export_status": "finished", | ||
"_links": { | ||
"api_url": "https://gitlab.test/api/v4/projects/1/export/download", | ||
"web_url": "https://gitlab.test/gitlab-test/download_export", | ||
}, | ||
} | ||
|
||
with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps: | ||
rsps.add( | ||
method=responses.POST, | ||
url=re.compile(r".*/api/v4/(groups|projects)/1/export"), | ||
json=accepted_content, | ||
content_type="application/json", | ||
status=202, | ||
) | ||
rsps.add( | ||
method=responses.GET, | ||
url=re.compile(r".*/api/v4/(groups|projects)/1/export/download"), | ||
body=binary_content, | ||
content_type="application/octet-stream", | ||
status=200, | ||
) | ||
# Currently only project export supports status checks | ||
rsps.add( | ||
method=responses.GET, | ||
url="http://localhost/api/v4/projects/1/export", | ||
json=export_status_content, | ||
content_type="application/json", | ||
status=200, | ||
) | ||
yield rsps |
This file was deleted.
Oops, something went wrong.
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,66 @@ | ||
""" | ||
GitLab API: https://docs.gitlab.com/ce/api/appearance.html | ||
""" | ||
|
||
import pytest | ||
import responses | ||
|
||
|
||
title = "GitLab Test Instance" | ||
description = "gitlab-test.example.com" | ||
new_title = "new-title" | ||
new_description = "new-description" | ||
|
||
|
||
@pytest.fixture | ||
def resp_application_appearance(): | ||
content = { | ||
"title": title, | ||
"description": description, | ||
"logo": "/uploads/-/system/appearance/logo/1/logo.png", | ||
"header_logo": "/uploads/-/system/appearance/header_logo/1/header.png", | ||
"favicon": "/uploads/-/system/appearance/favicon/1/favicon.png", | ||
"new_project_guidelines": "Please read the FAQs for help.", | ||
"header_message": "", | ||
"footer_message": "", | ||
"message_background_color": "#e75e40", | ||
"message_font_color": "#ffffff", | ||
"email_header_and_footer_enabled": False, | ||
} | ||
|
||
with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps: | ||
rsps.add( | ||
method=responses.GET, | ||
url="http://localhost/api/v4/application/appearance", | ||
json=content, | ||
content_type="application/json", | ||
status=200, | ||
) | ||
|
||
updated_content = dict(content) | ||
updated_content["title"] = new_title | ||
updated_content["description"] = new_description | ||
|
||
rsps.add( | ||
method=responses.PUT, | ||
url="http://localhost/api/v4/application/appearance", | ||
json=updated_content, | ||
content_type="application/json", | ||
status=200, | ||
) | ||
yield rsps | ||
|
||
|
||
def test_get_update_appearance(gl, resp_application_appearance): | ||
appearance = gl.appearance.get() | ||
assert appearance.title == title | ||
assert appearance.description == description | ||
appearance.title = new_title | ||
appearance.description = new_description | ||
appearance.save() | ||
assert appearance.title == new_title | ||
assert appearance.description == new_description | ||
|
||
|
||
def test_update_appearance(gl, resp_application_appearance): | ||
resp = gl.appearance.update(title=new_title, description=new_description) |
This file was deleted.
Oops, something went wrong.
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,45 @@ | ||
""" | ||
GitLab API: https://docs.gitlab.com/ce/api/applications.html | ||
""" | ||
|
||
import pytest | ||
import responses | ||
|
||
|
||
title = "GitLab Test Instance" | ||
description = "gitlab-test.example.com" | ||
new_title = "new-title" | ||
new_description = "new-description" | ||
|
||
|
||
@pytest.fixture | ||
def resp_application_create(): | ||
content = { | ||
"name": "test_app", | ||
"redirect_uri": "http://localhost:8080", | ||
"scopes": ["api", "email"], | ||
} | ||
|
||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
method=responses.POST, | ||
url="http://localhost/api/v4/applications", | ||
json=content, | ||
content_type="application/json", | ||
status=200, | ||
) | ||
yield rsps | ||
|
||
|
||
def test_create_application(gl, resp_application_create): | ||
application = gl.applications.create( | ||
{ | ||
"name": "test_app", | ||
"redirect_uri": "http://localhost:8080", | ||
"scopes": ["api", "email"], | ||
"confidential": False, | ||
} | ||
) | ||
assert application.name == "test_app" | ||
assert application.redirect_uri == "http://localhost:8080" | ||
assert application.scopes == ["api", "email"] |
Oops, something went wrong.