- Notifications
You must be signed in to change notification settings - Fork673
test: add unit tests for badges API#1180
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
nejch merged 1 commit intopython-gitlab:masterfromShkurupii:add-unittests-for-project-badgesSep 10, 2020
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
210 changes: 210 additions & 0 deletionsgitlab/tests/objects/test_badges.py
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 |
---|---|---|
@@ -0,0 +1,210 @@ | ||
""" | ||
GitLab API: https://docs.gitlab.com/ee/api/project_badges.html | ||
GitLab API: https://docs.gitlab.com/ee/api/group_badges.html | ||
""" | ||
import re | ||
import pytest | ||
import responses | ||
from gitlab.v4.objects import ProjectBadge, GroupBadge | ||
link_url = ( | ||
"http://example.com/ci_status.svg?project=example-org/example-project&ref=master" | ||
) | ||
image_url = "https://example.io/my/badge" | ||
rendered_link_url = ( | ||
"http://example.com/ci_status.svg?project=example-org/example-project&ref=master" | ||
) | ||
rendered_image_url = "https://example.io/my/badge" | ||
new_badge = { | ||
"link_url": link_url, | ||
"image_url": image_url, | ||
} | ||
badge_content = { | ||
"name": "Coverage", | ||
"id": 1, | ||
"link_url": link_url, | ||
"image_url": image_url, | ||
"rendered_link_url": rendered_image_url, | ||
"rendered_image_url": rendered_image_url, | ||
} | ||
preview_badge_content = { | ||
"link_url": link_url, | ||
"image_url": image_url, | ||
"rendered_link_url": rendered_link_url, | ||
"rendered_image_url": rendered_image_url, | ||
} | ||
@pytest.fixture() | ||
def resp_get_badge(): | ||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
method=responses.GET, | ||
url=re.compile(r"http://localhost/api/v4/(projects|groups)/1/badges/1"), | ||
json=badge_content, | ||
content_type="application/json", | ||
status=200, | ||
) | ||
yield rsps | ||
@pytest.fixture() | ||
def resp_list_badges(): | ||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
method=responses.GET, | ||
url=re.compile(r"http://localhost/api/v4/(projects|groups)/1/badges"), | ||
json=[badge_content], | ||
content_type="application/json", | ||
status=200, | ||
) | ||
yield rsps | ||
@pytest.fixture() | ||
def resp_create_badge(): | ||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
method=responses.POST, | ||
url=re.compile(r"http://localhost/api/v4/(projects|groups)/1/badges"), | ||
json=badge_content, | ||
content_type="application/json", | ||
status=200, | ||
) | ||
yield rsps | ||
@pytest.fixture() | ||
def resp_update_badge(): | ||
updated_content = dict(badge_content) | ||
updated_content["link_url"] = "http://link_url" | ||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
method=responses.PUT, | ||
url=re.compile(r"http://localhost/api/v4/(projects|groups)/1/badges/1"), | ||
json=updated_content, | ||
content_type="application/json", | ||
status=200, | ||
) | ||
yield rsps | ||
@pytest.fixture() | ||
def resp_delete_badge(no_content): | ||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
method=responses.DELETE, | ||
url=re.compile(r"http://localhost/api/v4/(projects|groups)/1/badges/1"), | ||
json=no_content, | ||
content_type="application/json", | ||
status=204, | ||
) | ||
yield rsps | ||
@pytest.fixture() | ||
def resp_preview_badge(): | ||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
method=responses.GET, | ||
url=re.compile( | ||
r"http://localhost/api/v4/(projects|groups)/1/badges/render" | ||
), | ||
json=preview_badge_content, | ||
content_type="application/json", | ||
status=200, | ||
) | ||
yield rsps | ||
def test_list_project_badges(project, resp_list_badges): | ||
badges = project.badges.list() | ||
assert isinstance(badges, list) | ||
assert isinstance(badges[0], ProjectBadge) | ||
def test_list_group_badges(group, resp_list_badges): | ||
badges = group.badges.list() | ||
assert isinstance(badges, list) | ||
assert isinstance(badges[0], GroupBadge) | ||
def test_get_project_badge(project, resp_get_badge): | ||
badge = project.badges.get(1) | ||
assert isinstance(badge, ProjectBadge) | ||
assert badge.name == "Coverage" | ||
assert badge.id == 1 | ||
def test_get_group_badge(group, resp_get_badge): | ||
badge = group.badges.get(1) | ||
assert isinstance(badge, GroupBadge) | ||
assert badge.name == "Coverage" | ||
assert badge.id == 1 | ||
def test_delete_project_badge(project, resp_delete_badge): | ||
badge = project.badges.get(1, lazy=True) | ||
badge.delete() | ||
def test_delete_group_badge(group, resp_delete_badge): | ||
badge = group.badges.get(1, lazy=True) | ||
badge.delete() | ||
def test_create_project_badge(project, resp_create_badge): | ||
badge = project.badges.create(new_badge) | ||
assert isinstance(badge, ProjectBadge) | ||
assert badge.image_url == image_url | ||
def test_create_group_badge(group, resp_create_badge): | ||
badge = group.badges.create(new_badge) | ||
assert isinstance(badge, GroupBadge) | ||
assert badge.image_url == image_url | ||
def test_preview_project_badge(project, resp_preview_badge): | ||
output = project.badges.render( | ||
link_url=link_url, | ||
image_url=image_url, | ||
) | ||
assert isinstance(output, dict) | ||
assert "rendered_link_url" in output | ||
assert "rendered_image_url" in output | ||
assert output["link_url"] == output["rendered_link_url"] | ||
assert output["image_url"] == output["rendered_image_url"] | ||
def test_preview_group_badge(group, resp_preview_badge): | ||
output = group.badges.render( | ||
link_url=link_url, | ||
image_url=image_url, | ||
) | ||
assert isinstance(output, dict) | ||
assert "rendered_link_url" in output | ||
assert "rendered_image_url" in output | ||
assert output["link_url"] == output["rendered_link_url"] | ||
assert output["image_url"] == output["rendered_image_url"] | ||
def test_update_project_badge(project, resp_update_badge): | ||
badge = project.badges.get(1, lazy=True) | ||
badge.link_url = "http://link_url" | ||
badge.save() | ||
assert badge.link_url == "http://link_url" | ||
def test_update_group_badge(group, resp_update_badge): | ||
badge = group.badges.get(1, lazy=True) | ||
badge.link_url = "http://link_url" | ||
badge.save() | ||
assert badge.link_url == "http://link_url" |
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.