Skip to content

Commit

Permalink
[gitlab] Increase test coverage
Browse files Browse the repository at this point in the history
This code increases the test coverage for the GitLab backend.
  • Loading branch information
valeriocos committed Dec 28, 2018
1 parent fec5a59 commit 0eae394
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
4 changes: 2 additions & 2 deletions perceval/backends/core/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class GitLab(Backend):
:param sleep_time: time to sleep in case
:param blacklist_ids: ids of items that must not be retrieved
"""
version = '0.7.0'
version = '0.7.1'

CATEGORIES = [CATEGORY_ISSUE, CATEGORY_MERGE_REQUEST]

Expand Down Expand Up @@ -350,7 +350,7 @@ def __get_note_award_emoji(self, item_type, item_id, note_id):
emojis.append(emoji)
except requests.exceptions.HTTPError as error:
if error.response.status_code == 404:
logger.warning("Emojis not available for %s ",
logger.warning("Emojis not available for %s",
urijoin(item_type, str(item_id), GitLabClient.NOTES,
str(note_id), GitLabClient.EMOJI))
return emojis
Expand Down
31 changes: 22 additions & 9 deletions tests/test_gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@
GITLAB_ENTERPRISE_MERGES_URL = GITLAB_ENTERPRISE_API_URL + "/projects/am%2Ftest/merge_requests"


def setup_http_server(url_project, issues_url, merges_url, user_url, rate_limit_headers=None):
def setup_http_server(url_project, issues_url, merges_url, user_url,
rate_limit_headers=None, no_id_user=False,
emojis_http_error=False):
project = read_file('data/gitlab/project')
page_issues_1 = read_file('data/gitlab/issue_page_1')
page_issues_2 = read_file('data/gitlab/issue_page_2')
Expand Down Expand Up @@ -121,7 +123,11 @@ def setup_http_server(url_project, issues_url, merges_url, user_url, rate_limit_
notes_1 = read_file('data/gitlab/notes_1')
notes_2 = read_file('data/gitlab/notes_2')
notes_3 = read_file('data/gitlab/notes_3')
notes_4 = read_file('data/gitlab/notes_4')

if no_id_user:
notes_4 = read_file('data/gitlab/notes_4_no_id_user')
else:
notes_4 = read_file('data/gitlab/notes_4')

# issue notes
httpretty.register_uri(httpretty.GET,
Expand Down Expand Up @@ -271,11 +277,18 @@ def setup_http_server(url_project, issues_url, merges_url, user_url, rate_limit_
status=200,
forcing_headers=rate_limit_headers)

httpretty.register_uri(httpretty.GET,
issues_url + "/1/notes/1/award_emoji",
body=emoji,
status=200,
forcing_headers=rate_limit_headers)
if emojis_http_error:
httpretty.register_uri(httpretty.GET,
issues_url + "/1/notes/1/award_emoji",
body=emoji,
status=404,
forcing_headers=rate_limit_headers)
else:
httpretty.register_uri(httpretty.GET,
issues_url + "/1/notes/1/award_emoji",
body=emoji,
status=200,
forcing_headers=rate_limit_headers)

httpretty.register_uri(httpretty.GET,
issues_url + "/1/notes/2/award_emoji",
Expand Down Expand Up @@ -514,7 +527,7 @@ def test_fetch_issues_http_error_emojis(self):
def test_fetch_issues_blacklisted(self):
"""Test whether blacklist issues are not fetched from GitLab"""

setup_http_server(GITLAB_URL_PROJECT, GITLAB_ISSUES_URL,
setup_http_server(GITLAB_URL_PROJECT, GITLAB_ISSUES_URL,
GITLAB_MERGES_URL, GITLAB_USERS_URL)

gitlab = GitLab("fdroid", "fdroiddata", "your-token", blacklist_ids=[1, 2, 3])
Expand Down Expand Up @@ -585,7 +598,7 @@ def test_fetch_merges(self):
def test_fetch_merges_blacklisted(self):
"""Test whether blacklist merge requests are not fetched from GitLab"""

setup_http_server(GITLAB_URL_PROJECT, GITLAB_ISSUES_URL,
setup_http_server(GITLAB_URL_PROJECT, GITLAB_ISSUES_URL,
GITLAB_MERGES_URL, GITLAB_USERS_URL)

gitlab = GitLab("fdroid", "fdroiddata", "your-token", blacklist_ids=[1, 2])
Expand Down

0 comments on commit 0eae394

Please sign in to comment.