Fix formatting

Signed-off-by: Michal Konečný <mkonecny@redhat.com>
This commit is contained in:
Michal Konečný 2022-03-21 13:25:42 +01:00
parent d5f38f16d6
commit 6e69a65ce0
14 changed files with 1266 additions and 1370 deletions

File diff suppressed because it is too large Load diff

View file

@ -1078,7 +1078,9 @@ class TestCommentOnBug:
assert exc.value.args == ({"id": bug_id, "comment": comment}, 50, "Fault")
mock_bz.assert_called_with()
mock_bz_call.assert_called_with(server.comment, {"id": bug_id, "comment": comment})
mock_bz_call.assert_called_with(
server.comment, {"id": bug_id, "comment": comment}
)
@patch("toddlers.utils.bugzilla_system.execute_bugzilla_call")
@patch("toddlers.utils.bugzilla_system.get_bz")
@ -1100,7 +1102,9 @@ class TestCommentOnBug:
assert exc.value.args == ("ProtocolError", 10, "Error message")
mock_bz.assert_called_with()
mock_bz_call.assert_called_with(server.comment, {"id": bug_id, "comment": comment})
mock_bz_call.assert_called_with(
server.comment, {"id": bug_id, "comment": comment}
)
class TestExecuteBugzillaCall:

View file

@ -204,15 +204,12 @@ class TestFedoraAccountFASJSON:
mock_fas.return_value = server
group = "group"
user = {
"username": "user"
}
user = {"username": "user"}
output = toddlers.utils.fedora_account.user_member_of(user, group)
server.check_membership.assert_called_with(
groupname=group,
username=user["username"]
groupname=group, username=user["username"]
)
assert output is True
@ -229,15 +226,12 @@ class TestFedoraAccountFASJSON:
mock_fas.return_value = server
group = "group"
user = {
"username": "user"
}
user = {"username": "user"}
output = toddlers.utils.fedora_account.user_member_of(user, group)
server.check_membership.assert_called_with(
groupname=group,
username=user["username"]
groupname=group, username=user["username"]
)
assert output is False
@ -252,9 +246,7 @@ class TestFedoraAccountFASJSON:
output = toddlers.utils.fedora_account.get_user_by_username("scoady")
server.search.assert_called_with(
username="scoady"
)
server.search.assert_called_with(username="scoady")
assert output == {"username": "scoady", "emails": ["scoady@fp.o"]}
@patch("toddlers.utils.fedora_account.get_fasjson")
@ -268,9 +260,7 @@ class TestFedoraAccountFASJSON:
output = toddlers.utils.fedora_account.get_user_by_username("scoady")
server.search.assert_called_with(
username="scoady"
)
server.search.assert_called_with(username="scoady")
assert output is None
@patch("toddlers.utils.fedora_account.get_fasjson")
@ -284,7 +274,5 @@ class TestFedoraAccountFASJSON:
output = toddlers.utils.fedora_account.get_user_by_username("scoady")
server.search.assert_called_with(
username="scoady"
)
server.search.assert_called_with(username="scoady")
assert output is None

View file

@ -5,6 +5,7 @@ from unittest.mock import Mock, patch
from toddlers.utils.git import clone_repo, GitRepo
class TestCloneRepo:
"""
Test class for `toddlers.utils.git.clone_repo` function.
@ -70,9 +71,7 @@ class TestGitRepoFirstCommit:
commit = self.repo.first_commit(branch)
self.repo.repo.git.rev_list.assert_called_with(
"--max-parents=0", branch
)
self.repo.repo.git.rev_list.assert_called_with("--max-parents=0", branch)
assert commit == "hash"
@ -88,9 +87,7 @@ class TestGitRepoFirstCommit:
commit = self.repo.first_commit(branch)
self.repo.repo.git.rev_list.assert_called_with(
"--max-parents=0", branch
)
self.repo.repo.git.rev_list.assert_called_with("--max-parents=0", branch)
assert commit == "last_hash"
@ -106,8 +103,6 @@ class TestGitRepoFirstCommit:
commit = self.repo.first_commit(branch)
self.repo.repo.git.rev_list.assert_called_with(
"--max-parents=0", branch
)
self.repo.repo.git.rev_list.assert_called_with("--max-parents=0", branch)
assert commit is None

View file

@ -19,7 +19,7 @@ class TestPagureSetPagure:
"""
config = {
"pagure_url": "https://pagure.io",
"pagure_api_key": "Very secret key"
"pagure_api_key": "Very secret key",
}
pagure_obj = pagure.set_pagure()
@ -43,9 +43,7 @@ class TestPagureSetPagure:
with pytest.raises(
ValueError, match=r"No pagure_api_key found in the configuration file"
):
config = {
"pagure_url": "https://pagure.io"
}
config = {"pagure_url": "https://pagure.io"}
pagure.set_pagure(config)
@ -53,13 +51,14 @@ class TestPagureGetAuthHeader:
"""
Test class for `toddlers.pagure.Pagure.get_auth_header` function.
"""
def setup(self):
"""
Setup method for the test class.
"""
config = {
"pagure_url": "https://pagure.io",
"pagure_api_key": "Very secret key"
"pagure_api_key": "Very secret key",
}
self.pagure = pagure.set_pagure(config)
@ -68,9 +67,9 @@ class TestPagureGetAuthHeader:
Assert that correct header is returned.
"""
exp_header = {
'Authorization': 'token Very secret key',
'Accept': 'application/json',
'Content-Type': 'application/json'
"Authorization": "token Very secret key",
"Accept": "application/json",
"Content-Type": "application/json",
}
header = self.pagure.get_auth_header()
@ -82,13 +81,14 @@ class TestPagureCloseIssue:
"""
Test class for `toddlers.pagure.Pagure.close_issue` function.
"""
def setup(self):
"""
Setup method for the test class.
"""
config = {
"pagure_url": "https://pagure.io",
"pagure_api_key": "Very secret key"
"pagure_api_key": "Very secret key",
}
self.pagure = pagure.set_pagure(config)
self.pagure._requests_session = Mock()
@ -114,7 +114,7 @@ class TestPagureCloseIssue:
self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/test/issue/100/status",
data={"status": reason},
headers=self.pagure.get_auth_header()
headers=self.pagure.get_auth_header(),
)
def test_close_issue_not_ok(self):
@ -134,14 +134,16 @@ class TestPagureCloseIssue:
expected_error = "Couldn't close issue 'https://pagure.io/test/issue/100'"
with pytest.raises(PagureError, match=expected_error):
with patch("toddlers.utils.pagure.Pagure.add_comment_to_issue") as comment_mock:
with patch(
"toddlers.utils.pagure.Pagure.add_comment_to_issue"
) as comment_mock:
comment_mock.return_value = True
result = self.pagure.close_issue(issue_id, namespace, message, reason)
self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/test/issue/100/status",
data={"status": reason},
headers=self.pagure.get_auth_header()
headers=self.pagure.get_auth_header(),
)
@ -149,13 +151,14 @@ class TestPagureAddCommentToIssue:
"""
Test class for `toddlers.pagure.Pagure.add_comment_to_issue` function.
"""
def setup(self):
"""
Setup method for the test class.
"""
config = {
"pagure_url": "https://pagure.io",
"pagure_api_key": "Very secret key"
"pagure_api_key": "Very secret key",
}
self.pagure = pagure.set_pagure(config)
self.pagure._requests_session = Mock()
@ -178,7 +181,7 @@ class TestPagureAddCommentToIssue:
self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/test/issue/100/comment",
data={"comment": message},
headers=self.pagure.get_auth_header()
headers=self.pagure.get_auth_header(),
)
def test_add_comment_to_issue_not_ok(self):
@ -202,7 +205,7 @@ class TestPagureAddCommentToIssue:
self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/test/issue/100/comment",
data={"comment": message},
headers=self.pagure.get_auth_header()
headers=self.pagure.get_auth_header(),
)
@ -210,13 +213,14 @@ class TestPagureUserExists:
"""
Test class for `toddlers.pagure.Pagure.user_exists` function.
"""
def setup(self):
"""
Setup method for the test class.
"""
config = {
"pagure_url": "https://pagure.io",
"pagure_api_key": "Very secret key"
"pagure_api_key": "Very secret key",
}
self.pagure = pagure.set_pagure(config)
self.pagure._requests_session = Mock()
@ -286,13 +290,14 @@ class TestPagureNewProject:
"""
Test class for `toddlers.pagure.Pagure.new_project` method.
"""
def setup(self):
"""
Setup method for the test class.
"""
config = {
"pagure_url": "https://pagure.io",
"pagure_api_key": "Very secret key"
"pagure_api_key": "Very secret key",
}
self.pagure = pagure.set_pagure(config)
self.pagure._requests_session = Mock()
@ -312,19 +317,21 @@ class TestPagureNewProject:
description = "description"
upstream_url = "https://example.com"
self.pagure.new_project(namespace, repo, description, upstream_url, default_branch)
self.pagure.new_project(
namespace, repo, description, upstream_url, default_branch
)
self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/api/0/new",
data={
'namespace': namespace,
'name': repo,
'default_branch': default_branch,
'description': description,
'url': upstream_url,
'wait': True
"namespace": namespace,
"name": repo,
"default_branch": default_branch,
"description": description,
"url": upstream_url,
"wait": True,
},
headers=self.pagure.get_auth_header()
headers=self.pagure.get_auth_header(),
)
def test_new_project_initial_commit(self):
@ -343,21 +350,26 @@ class TestPagureNewProject:
upstream_url = "https://example.com"
self.pagure.new_project(
namespace, repo, description, upstream_url, default_branch, initial_commit=True
namespace,
repo,
description,
upstream_url,
default_branch,
initial_commit=True,
)
self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/api/0/new",
data={
'namespace': namespace,
'name': repo,
'default_branch': default_branch,
'description': description,
'url': upstream_url,
'wait': True,
'create_readme': True
"namespace": namespace,
"name": repo,
"default_branch": default_branch,
"description": description,
"url": upstream_url,
"wait": True,
"create_readme": True,
},
headers=self.pagure.get_auth_header()
headers=self.pagure.get_auth_header(),
)
def test_new_project_alias(self):
@ -379,28 +391,32 @@ class TestPagureNewProject:
namespace, repo, description, upstream_url, default_branch, alias=True
)
self.pagure._requests_session.post.assert_has_calls([
call(
"https://pagure.io/api/0/new",
data={
'namespace': namespace,
'name': repo,
'default_branch': default_branch,
'description': description,
'url': upstream_url,
'wait': True
},
headers=self.pagure.get_auth_header()
),
call(
"https://pagure.io/api/0/{0}/{1}/git/alias/new".format(namespace, repo),
data={
'alias_from': 'main',
'alias_to': 'rawhide',
},
headers=self.pagure.get_auth_header()
),
])
self.pagure._requests_session.post.assert_has_calls(
[
call(
"https://pagure.io/api/0/new",
data={
"namespace": namespace,
"name": repo,
"default_branch": default_branch,
"description": description,
"url": upstream_url,
"wait": True,
},
headers=self.pagure.get_auth_header(),
),
call(
"https://pagure.io/api/0/{0}/{1}/git/alias/new".format(
namespace, repo
),
data={
"alias_from": "main",
"alias_to": "rawhide",
},
headers=self.pagure.get_auth_header(),
),
]
)
def test_new_project_alias_wrong_namespace(self):
"""
@ -425,14 +441,14 @@ class TestPagureNewProject:
self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/api/0/new",
data={
'namespace': namespace,
'name': repo,
'default_branch': default_branch,
'description': description,
'url': upstream_url,
'wait': True
"namespace": namespace,
"name": repo,
"default_branch": default_branch,
"description": description,
"url": upstream_url,
"wait": True,
},
headers=self.pagure.get_auth_header()
headers=self.pagure.get_auth_header(),
)
def test_new_project_failure(self):
@ -460,14 +476,14 @@ class TestPagureNewProject:
self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/api/0/new",
data={
'namespace': namespace,
'name': repo,
'default_branch': default_branch,
'description': description,
'url': upstream_url,
'wait': True
"namespace": namespace,
"name": repo,
"default_branch": default_branch,
"description": description,
"url": upstream_url,
"wait": True,
},
headers=self.pagure.get_auth_header()
headers=self.pagure.get_auth_header(),
)
def test_new_project_alias_failure(self):
@ -480,7 +496,10 @@ class TestPagureNewProject:
response_mock_fail = Mock()
response_mock_fail.status_code = 500
self.pagure._requests_session.post.side_effect = [response_mock_ok, response_mock_fail]
self.pagure._requests_session.post.side_effect = [
response_mock_ok,
response_mock_fail,
]
namespace = "rpms"
repo = "repo"
@ -488,48 +507,55 @@ class TestPagureNewProject:
description = "description"
upstream_url = "https://example.com"
expected_error = "Couldn't create alias for project '{0}/{1}'".format(namespace, repo)
expected_error = "Couldn't create alias for project '{0}/{1}'".format(
namespace, repo
)
with pytest.raises(PagureError, match=expected_error):
self.pagure.new_project(
namespace, repo, description, upstream_url, default_branch, alias=True
)
self.pagure._requests_session.post.assert_has_calls([
call(
"https://pagure.io/api/0/new",
data={
'namespace': namespace,
'name': repo,
'default_branch': default_branch,
'description': description,
'url': upstream_url,
'wait': True
},
headers=self.pagure.get_auth_header()
),
call(
"https://pagure.io/api/0/{0}/{1}/git/alias/new".format(namespace, repo),
data={
'alias_from': 'main',
'alias_to': 'rawhide',
},
headers=self.pagure.get_auth_header()
),
])
self.pagure._requests_session.post.assert_has_calls(
[
call(
"https://pagure.io/api/0/new",
data={
"namespace": namespace,
"name": repo,
"default_branch": default_branch,
"description": description,
"url": upstream_url,
"wait": True,
},
headers=self.pagure.get_auth_header(),
),
call(
"https://pagure.io/api/0/{0}/{1}/git/alias/new".format(
namespace, repo
),
data={
"alias_from": "main",
"alias_to": "rawhide",
},
headers=self.pagure.get_auth_header(),
),
]
)
class TestPagureNewBranch:
"""
Test class for `toddlers.pagure.Pagure.new_branch` method.
"""
def setup(self):
"""
Setup method for the test class.
"""
config = {
"pagure_url": "https://pagure.io",
"pagure_api_key": "Very secret key"
"pagure_api_key": "Very secret key",
}
self.pagure = pagure.set_pagure(config)
self.pagure._requests_session = Mock()
@ -553,10 +579,10 @@ class TestPagureNewBranch:
self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/api/0/{0}/{1}/git/branch".format(namespace, repo),
data={
'branch': branch,
'from_commit': from_commit,
"branch": branch,
"from_commit": from_commit,
},
headers=self.pagure.get_auth_header()
headers=self.pagure.get_auth_header(),
)
def test_new_branch_from_branch(self):
@ -578,10 +604,10 @@ class TestPagureNewBranch:
self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/api/0/{0}/{1}/git/branch".format(namespace, repo),
data={
'branch': branch,
'from_branch': from_branch,
"branch": branch,
"from_branch": from_branch,
},
headers=self.pagure.get_auth_header()
headers=self.pagure.get_auth_header(),
)
def test_new_branch_missing_required_params(self):
@ -597,13 +623,10 @@ class TestPagureNewBranch:
repo = "repo"
branch = "branch"
expected_error = ("You must specify either `from_commit` or "
"`from_branch`")
expected_error = "You must specify either `from_commit` or " "`from_branch`"
with pytest.raises(RuntimeError, match=expected_error):
self.pagure.new_branch(
namespace, repo, branch
)
self.pagure.new_branch(namespace, repo, branch)
def test_new_branch_missing_required_params(self):
"""
@ -620,12 +643,17 @@ class TestPagureNewBranch:
from_branch = "existing_branch"
from_commit = "commit"
expected_error = ("`from_commit` and `from_branch` were both "
"specified. Only use one.")
expected_error = (
"`from_commit` and `from_branch` were both " "specified. Only use one."
)
with pytest.raises(RuntimeError, match=expected_error):
self.pagure.new_branch(
namespace, repo, branch, from_branch=from_branch, from_commit=from_commit
namespace,
repo,
branch,
from_branch=from_branch,
from_commit=from_commit,
)
def test_new_branch_failure(self):
@ -642,20 +670,20 @@ class TestPagureNewBranch:
branch = "branch"
from_branch = "existing_branch"
expected_error = "Couldn't create branch in project '{0}/{1}'".format(namespace, repo)
expected_error = "Couldn't create branch in project '{0}/{1}'".format(
namespace, repo
)
with pytest.raises(PagureError, match=expected_error):
self.pagure.new_branch(
namespace, repo, branch, from_branch=from_branch
)
self.pagure.new_branch(namespace, repo, branch, from_branch=from_branch)
self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/api/0/{0}/{1}/git/branch".format(namespace, repo),
data={
'branch': branch,
'from_branch': from_branch,
"branch": branch,
"from_branch": from_branch,
},
headers=self.pagure.get_auth_header()
headers=self.pagure.get_auth_header(),
)
@ -663,13 +691,14 @@ class TestPagureSetMonitoringStatus:
"""
Test class for `toddlers.pagure.Pagure.set_monitoring_status` method.
"""
def setup(self):
"""
Setup method for the test class.
"""
config = {
"pagure_url": "https://pagure.io",
"pagure_api_key": "Very secret key"
"pagure_api_key": "Very secret key",
}
self.pagure = pagure.set_pagure(config)
self.pagure._requests_session = Mock()
@ -691,10 +720,8 @@ class TestPagureSetMonitoringStatus:
self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/_dg/anitya/{0}/{1}".format(namespace, repo),
data={
'anitya_status': monitoring_level
},
headers=self.pagure.get_auth_header()
data={"anitya_status": monitoring_level},
headers=self.pagure.get_auth_header(),
)
def test_set_monitoring_status_failure(self):
@ -710,19 +737,17 @@ class TestPagureSetMonitoringStatus:
repo = "repo"
monitoring_level = "no_monitoring"
expected_error = "Couldn't set monitoring on project '{0}/{1}'".format(namespace, repo)
expected_error = "Couldn't set monitoring on project '{0}/{1}'".format(
namespace, repo
)
with pytest.raises(PagureError, match=expected_error):
self.pagure.set_monitoring_status(
namespace, repo, monitoring_level
)
self.pagure.set_monitoring_status(namespace, repo, monitoring_level)
self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/_dg/anitya/{0}/{1}".format(namespace, repo),
data={
'anitya_status': monitoring_level
},
headers=self.pagure.get_auth_header()
data={"anitya_status": monitoring_level},
headers=self.pagure.get_auth_header(),
)
@ -730,13 +755,14 @@ class TestPagureChangeProjectMainAdmin:
"""
Test class for `toddlers.pagure.Pagure.change_project_main_admin` method.
"""
def setup(self):
"""
Setup method for the test class.
"""
config = {
"pagure_url": "https://pagure.io",
"pagure_api_key": "Very secret key"
"pagure_api_key": "Very secret key",
}
self.pagure = pagure.set_pagure(config)
self.pagure._requests_session = Mock()
@ -758,10 +784,8 @@ class TestPagureChangeProjectMainAdmin:
self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/api/0/{0}/{1}".format(namespace, repo),
data={
'main_admin': main_admin
},
headers=self.pagure.get_auth_header()
data={"main_admin": main_admin},
headers=self.pagure.get_auth_header(),
)
def test_change_project_main_admin_failure(self):
@ -777,19 +801,17 @@ class TestPagureChangeProjectMainAdmin:
repo = "repo"
main_admin = "zlopez"
expected_error = "Couldn't set new admin on project '{0}/{1}'".format(namespace, repo)
expected_error = "Couldn't set new admin on project '{0}/{1}'".format(
namespace, repo
)
with pytest.raises(PagureError, match=expected_error):
self.pagure.change_project_main_admin(
namespace, repo, main_admin
)
self.pagure.change_project_main_admin(namespace, repo, main_admin)
self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/api/0/{0}/{1}".format(namespace, repo),
data={
'main_admin': main_admin
},
headers=self.pagure.get_auth_header()
data={"main_admin": main_admin},
headers=self.pagure.get_auth_header(),
)
@ -797,13 +819,14 @@ class TestPagureGetProjectContributors:
"""
Test class for `toddlers.pagure.Pagure.get_project_contributors` method.
"""
def setup(self):
"""
Setup method for the test class.
"""
config = {
"pagure_url": "https://pagure.io",
"pagure_api_key": "Very secret key"
"pagure_api_key": "Very secret key",
}
self.pagure = pagure.set_pagure(config)
self.pagure._requests_session = Mock()
@ -829,7 +852,7 @@ class TestPagureGetProjectContributors:
self.pagure._requests_session.get.assert_called_with(
"https://pagure.io/api/0/{0}/{1}/contributors".format(namespace, repo),
headers=self.pagure.get_auth_header()
headers=self.pagure.get_auth_header(),
)
assert result == data
@ -846,16 +869,16 @@ class TestPagureGetProjectContributors:
namespace = "namespace"
repo = "repo"
expected_error = "Couldn't get contributors for project '{0}/{1}'".format(namespace, repo)
expected_error = "Couldn't get contributors for project '{0}/{1}'".format(
namespace, repo
)
with pytest.raises(PagureError, match=expected_error):
self.pagure.get_project_contributors(
namespace, repo
)
self.pagure.get_project_contributors(namespace, repo)
self.pagure._requests_session.get.assert_called_with(
"https://pagure.io/api/0/{0}/{1}/contributors".format(namespace, repo),
headers=self.pagure.get_auth_header()
headers=self.pagure.get_auth_header(),
)
@ -863,13 +886,14 @@ class TestPagureGetDefaultBranch:
"""
Test class for `toddlers.pagure.Pagure.get_default_branch` method.
"""
def setup(self):
"""
Setup method for the test class.
"""
config = {
"pagure_url": "https://pagure.io",
"pagure_api_key": "Very secret key"
"pagure_api_key": "Very secret key",
}
self.pagure = pagure.set_pagure(config)
self.pagure._requests_session = Mock()
@ -895,7 +919,7 @@ class TestPagureGetDefaultBranch:
self.pagure._requests_session.get.assert_called_with(
"https://pagure.io/api/0/{0}/{1}/git/branches".format(namespace, repo),
headers=self.pagure.get_auth_header()
headers=self.pagure.get_auth_header(),
)
assert result == branch
@ -920,7 +944,7 @@ class TestPagureGetDefaultBranch:
self.pagure._requests_session.get.assert_called_with(
"https://pagure.io/api/0/{0}/{1}/git/branches".format(namespace, repo),
headers=self.pagure.get_auth_header()
headers=self.pagure.get_auth_header(),
)
assert result is None
@ -937,14 +961,14 @@ class TestPagureGetDefaultBranch:
namespace = "namespace"
repo = "repo"
expected_error = "Couldn't get default branch for project '{0}/{1}'".format(namespace, repo)
expected_error = "Couldn't get default branch for project '{0}/{1}'".format(
namespace, repo
)
with pytest.raises(PagureError, match=expected_error):
self.pagure.get_default_branch(
namespace, repo
)
self.pagure.get_default_branch(namespace, repo)
self.pagure._requests_session.get.assert_called_with(
"https://pagure.io/api/0/{0}/{1}/git/branches".format(namespace, repo),
headers=self.pagure.get_auth_header()
headers=self.pagure.get_auth_header(),
)

View file

@ -19,7 +19,7 @@ class TestPdcSetPdc:
"pdc_config": {
"server": "https://pdc.fedoraproject.org/rest_api/v1/",
"ssl_verify": False,
"token": "token"
"token": "token",
}
}
pdc_client = pdc.set_pdc(config)
@ -41,13 +41,14 @@ class TestPdcPdcClientForConfig:
"pdc_config": {
"server": "https://pdc.fedoraproject.org/rest_api/v1/",
"ssl_verify": False,
"token": "token"
"token": "token",
}
}
pdc_client = pdc.pdc_client_for_config(config)
assert pdc_client
class TestPdcGetSla:
"""
Test class for `toddlers.utils.pdc.get_sla` function.
@ -63,7 +64,7 @@ class TestPdcGetSla:
"""
Assert that correct response is handled.
"""
response = {"count": 1, "results":[{"id": 3}]}
response = {"count": 1, "results": [{"id": 3}]}
pdc._PDC["component-sla-types"]._.return_value = response
@ -75,7 +76,7 @@ class TestPdcGetSla:
"""
Assert that incorrect response is handled.
"""
response = {"count": 0, "results":[]}
response = {"count": 0, "results": []}
pdc._PDC["component-sla-types"]._.return_value = response
@ -110,18 +111,18 @@ class TestPdcNewSLAToBranch:
eol=eol,
global_component=global_component,
branch=branch_name,
branch_type=branch_type
branch_type=branch_type,
)
pdc._PDC["component-branch-slas"]._.assert_called_with(
{
'sla': sla,
'eol': eol,
'branch': {
'global_component': global_component,
'name': branch_name,
'type': branch_type
}
"sla": sla,
"eol": eol,
"branch": {
"global_component": global_component,
"name": branch_name,
"type": branch_type,
},
}
)
@ -141,7 +142,7 @@ class TestPdcGetBranch:
"""
Assert that correct response is handled.
"""
response = {"count": 1, "results":[{"id": 3}]}
response = {"count": 1, "results": [{"id": 3}]}
global_component = "global_component"
name = "branch"
@ -154,16 +155,14 @@ class TestPdcGetBranch:
assert result == {"id": 3}
pdc._PDC["component-branches"]._.assert_called_with(
global_component=global_component,
name=name,
type=branch_type
global_component=global_component, name=name, type=branch_type
)
def test_get_branch_not_found(self):
"""
Assert that incorrect response is handled.
"""
response = {"count": 0, "results":[]}
response = {"count": 0, "results": []}
global_component = "global_component"
name = "branch"
@ -176,9 +175,7 @@ class TestPdcGetBranch:
assert not result
pdc._PDC["component-branches"]._.assert_called_with(
global_component=global_component,
name=name,
type=branch_type
global_component=global_component, name=name, type=branch_type
)
@ -197,7 +194,7 @@ class TestPdcNewBranch:
"""
Assert that component is not created when it doesn't exist.
"""
response = {"count": 1, "results":[{"id": 3}]}
response = {"count": 1, "results": [{"id": 3}]}
global_component = "global_component"
branch = "branch"
@ -208,16 +205,14 @@ class TestPdcNewBranch:
pdc.new_branch(global_component, branch, branch_type)
pdc._PDC["component-branches"]._.assert_called_with(
global_component=global_component,
name=branch,
type=branch_type
global_component=global_component, name=branch, type=branch_type
)
def test_new_branch_not_found(self):
"""
Assert that component is created when not found.
"""
response = {"count": 0, "results":[]}
response = {"count": 0, "results": []}
global_component = "global_component"
branch = "branch"
@ -229,18 +224,14 @@ class TestPdcNewBranch:
pdc._PDC["component-branches"]._.assert_has_calls(
[
call(
global_component=global_component,
name=branch,
type=branch_type
),
call(global_component=global_component, name=branch, type=branch_type),
call(
{
"global_component": global_component,
"name": branch,
"type": branch_type
"type": branch_type,
}
)
),
]
)
@ -260,7 +251,7 @@ class TestPdcGetGlobalComponent:
"""
Assert that correct response is handled.
"""
response = {"count": 1, "results":[{"id": 3}]}
response = {"count": 1, "results": [{"id": 3}]}
global_component = "global_component"
@ -278,7 +269,7 @@ class TestPdcGetGlobalComponent:
"""
Assert that incorrect response is handled.
"""
response = {"count": 0, "results":[]}
response = {"count": 0, "results": []}
global_component = "global_component"
@ -308,7 +299,7 @@ class TestPdcNewGlobalComponent:
"""
Assert that component is not created when it doesn't exist.
"""
response = {"count": 1, "results":[{"id": 3}]}
response = {"count": 1, "results": [{"id": 3}]}
global_component = "global_component"
dist_git_url = "https://src.fedoraproject.org/example"
@ -325,7 +316,7 @@ class TestPdcNewGlobalComponent:
"""
Assert that component is created when not found.
"""
response = {"count": 0, "results":[]}
response = {"count": 0, "results": []}
global_component = "global_component"
dist_git_url = "https://src.fedoraproject.org/example"
@ -337,11 +328,6 @@ class TestPdcNewGlobalComponent:
pdc._PDC["global-components"]._.assert_has_calls(
[
call(name=global_component),
call(
{
"name": global_component,
"dist_git_web_url": dist_git_url
}
)
call({"name": global_component, "dist_git_web_url": dist_git_url}),
]
)

View file

@ -1,5 +1,7 @@
"""
Exception that is raised by pagure module.
"""
class PagureError(Exception):
pass

View file

@ -1,5 +1,7 @@
"""
Exception that is raised when validation fails.
"""
class ValidationError(Exception):
pass

File diff suppressed because it is too large Load diff

View file

@ -576,7 +576,7 @@ def get_bug(bug_id: str) -> Optional[Bug]:
bz = get_bz()
try:
bug = execute_bugzilla_call(bz.getbug, {"id": bug_id})
bug = execute_bugzilla_call(bz.getbug, {"id": bug_id})
except xmlrpc.client.Fault as e:
# Output something useful in args
e.args = (bug_id, e.faultCode, e.faultString)
@ -603,10 +603,7 @@ def comment_on_bug(bug_id: str, comment: str) -> None:
bz = get_bz()
_log.info("Adding comment `%s` to `%s`", comment, bug_id)
data = {
"id": bug_id,
"comment": comment
}
data = {"id": bug_id, "comment": comment}
try:
execute_bugzilla_call(bz.comment, data)

View file

@ -122,8 +122,7 @@ def user_member_of(user: dict, group: str) -> bool:
is_member = False
try:
is_member = fasjson.check_membership(
groupname=group,
username=user["username"]
groupname=group, username=user["username"]
).result
except ClientError:
pass

View file

@ -6,7 +6,7 @@ Author: mkonecny@redhat.com
import git
def clone_repo(remote: str, destination: str) -> 'GitRepo':
def clone_repo(remote: str, destination: str) -> "GitRepo":
"""
Clone the remote repository.
@ -58,4 +58,3 @@ class GitRepo:
return commits[-1]
else:
return None

View file

@ -38,6 +38,7 @@ class Pagure:
"""
Object that is a wrapper above pagure API.
"""
# URL to pagure
_pagure_url: str = None
# API key for pagure instance
@ -73,12 +74,14 @@ class Pagure:
A dictionary of the HTTP header
"""
return {
'Authorization': 'token {0}'.format(self._pagure_api_key),
'Accept': 'application/json',
'Content-Type': 'application/json'
"Authorization": "token {0}".format(self._pagure_api_key),
"Accept": "application/json",
"Content-Type": "application/json",
}
def close_issue(self, issue_id: int, namespace: str, message: str, reason: str = 'Closed'):
def close_issue(
self, issue_id: int, namespace: str, message: str, reason: str = "Closed"
):
"""
Close the issue defined by the id with provided message and reason.
@ -93,22 +96,21 @@ class Pagure:
toddlers.utils.exceptions.PagureError when the issue couldn't be closed.
"""
issue_url = "{0}/{1}/issue/{2}".format(self._pagure_url, namespace, issue_id)
api_url = '{0}/status'.format(issue_url)
status_payload = {'status': reason}
api_url = "{0}/status".format(issue_url)
status_payload = {"status": reason}
headers = self.get_auth_header()
if message:
self.add_comment_to_issue(
issue_id,
namespace=namespace,
comment=message
)
self.add_comment_to_issue(issue_id, namespace=namespace, comment=message)
log.debug(
"Closing issue '{0}' with reason '{1}' adding message '{2}'".format(
issue_url, reason, message)
issue_url, reason, message
)
)
response = self._requests_session.post(
api_url, data=status_payload, headers=headers
)
response = self._requests_session.post(api_url, data=status_payload, headers=headers)
if response.status_code == 200:
return
@ -121,7 +123,6 @@ class Pagure:
raise PagureError("Couldn't close issue '{0}'".format(issue_url))
def add_comment_to_issue(self, issue_id: str, namespace: str, comment: str) -> bool:
"""
Comment on issue defined by the id.
@ -135,15 +136,16 @@ class Pagure:
toddlers.utils.exceptions.PagureError: When the issue couldn't be commented on.
"""
issue_url = "{0}/{1}/issue/{2}".format(self._pagure_url, namespace, issue_id)
api_url = '{0}/comment'.format(issue_url)
comment_payload = {'comment': comment}
api_url = "{0}/comment".format(issue_url)
comment_payload = {"comment": comment}
headers = self.get_auth_header()
log.debug(
"Commenting on issue '{0}' with message '{1}'".format(
issue_url, comment)
"Commenting on issue '{0}' with message '{1}'".format(issue_url, comment)
)
response = self._requests_session.post(
api_url, data=comment_payload, headers=headers
)
response = self._requests_session.post(api_url, data=comment_payload, headers=headers)
if response.status_code == 200:
return
@ -156,7 +158,6 @@ class Pagure:
raise PagureError("Couldn't comment on issue '{0}'".format(issue_url))
def user_exists(self, username: str) -> bool:
"""
Check if the user exists in Pagure.
@ -173,9 +174,9 @@ class Pagure:
if response.status_code == 200:
data = response.json()
if not data['users']:
if not data["users"]:
return False
return username in data['users']
return username in data["users"]
log.error(
"Error when checking for user '{0}'. Got status_code '{1}'.".format(
@ -186,14 +187,14 @@ class Pagure:
raise PagureError("Couldn't get user '{0}'".format(username))
def new_project(
self,
namespace: str,
repo: str,
description: str,
upstream_url: str,
default_branch: str,
initial_commit: bool = False,
alias: bool = False
self,
namespace: str,
repo: str,
description: str,
upstream_url: str,
default_branch: str,
initial_commit: bool = False,
alias: bool = False,
) -> None:
"""
Create mew project in Pagure.
@ -214,16 +215,16 @@ class Pagure:
pagure_new_project_url = "{0}/api/0/new".format(self._pagure_url)
headers = self.get_auth_header()
payload = {
'namespace': namespace,
'name': repo,
'default_branch': default_branch,
'description': description or 'The {0} package\n'.format(repo),
'url': upstream_url or '',
'wait': True
"namespace": namespace,
"name": repo,
"default_branch": default_branch,
"description": description or "The {0} package\n".format(repo),
"url": upstream_url or "",
"wait": True,
}
if initial_commit:
payload['create_readme'] = True
payload["create_readme"] = True
log.debug("Creating project '{0}/{1}'".format(namespace, repo))
response = self._requests_session.post(
@ -236,18 +237,23 @@ class Pagure:
namespace, repo, response.status_code
)
)
raise PagureError("Couldn't create project '{0}/{1}'".format(namespace, repo))
raise PagureError(
"Couldn't create project '{0}/{1}'".format(namespace, repo)
)
if alias:
# Only create alias for rpms and container namespace
if namespace in ['rpms', 'container']:
pagure_new_git_alias_url = \
'{0}/api/0/{1}/{2}/git/alias/new'.format(self._pagure_url, namespace, repo)
if namespace in ["rpms", "container"]:
pagure_new_git_alias_url = "{0}/api/0/{1}/{2}/git/alias/new".format(
self._pagure_url, namespace, repo
)
payload = {
'alias_from': 'main',
'alias_to': 'rawhide',
"alias_from": "main",
"alias_to": "rawhide",
}
log.debug("Creating alias for project '{0}/{1}'".format(namespace, repo))
log.debug(
"Creating alias for project '{0}/{1}'".format(namespace, repo)
)
response = self._requests_session.post(
pagure_new_git_alias_url, data=payload, headers=headers
)
@ -258,15 +264,19 @@ class Pagure:
namespace, repo, response.status_code
)
)
raise PagureError("Couldn't create alias for project '{0}/{1}'".format(namespace, repo))
raise PagureError(
"Couldn't create alias for project '{0}/{1}'".format(
namespace, repo
)
)
def new_branch(
self,
namespace: str,
repo: str,
branch: str,
from_commit: str = "",
from_branch: str = ""
self,
namespace: str,
repo: str,
branch: str,
from_commit: str = "",
from_branch: str = "",
) -> None:
"""
Create a new branch in pagure repository.
@ -284,20 +294,23 @@ class Pagure:
`toddlers.utils.exceptions.PagureError``: When the branch creation fails.
"""
if from_commit and from_branch:
raise RuntimeError('`from_commit` and `from_branch` were both '
'specified. Only use one.')
raise RuntimeError(
"`from_commit` and `from_branch` were both " "specified. Only use one."
)
elif not from_commit and not from_branch:
raise RuntimeError('You must specify either `from_commit` or '
'`from_branch`')
raise RuntimeError(
"You must specify either `from_commit` or " "`from_branch`"
)
branch_api_url = '{0}/api/0/{1}/{2}/git/branch'.format(
self._pagure_url, namespace, repo)
branch_api_url = "{0}/api/0/{1}/{2}/git/branch".format(
self._pagure_url, namespace, repo
)
headers = self.get_auth_header()
payload = {'branch': branch}
payload = {"branch": branch}
if from_commit:
payload['from_commit'] = from_commit
payload["from_commit"] = from_commit
else:
payload['from_branch'] = from_branch
payload["from_branch"] = from_branch
log.debug("Creating branch for project '{0}/{1}'".format(namespace, repo))
response = self._requests_session.post(
@ -310,13 +323,15 @@ class Pagure:
namespace, repo, response.status_code
)
)
raise PagureError("Couldn't create branch in project '{0}/{1}'".format(namespace, repo))
raise PagureError(
"Couldn't create branch in project '{0}/{1}'".format(namespace, repo)
)
def set_monitoring_status(
self,
namespace: str,
repo: str,
monitoring_level: str,
self,
namespace: str,
repo: str,
monitoring_level: str,
) -> None:
"""
Set a monitoring status for pagure repository. This will work only on dist git.
@ -329,12 +344,17 @@ class Pagure:
Raises:
`toddlers.utils.exceptions.PagureError``: When setting the monitoring level fails.
"""
monitoring_api_url = '{0}/_dg/anitya/{1}/{2}'.format(self._pagure_url, namespace, repo)
monitoring_api_url = "{0}/_dg/anitya/{1}/{2}".format(
self._pagure_url, namespace, repo
)
headers = self.get_auth_header()
payload = {'anitya_status': monitoring_level}
payload = {"anitya_status": monitoring_level}
log.debug("Setting monitoring to '{0}' for project '{1}/{2}'".format(
monitoring_level, namespace, repo))
log.debug(
"Setting monitoring to '{0}' for project '{1}/{2}'".format(
monitoring_level, namespace, repo
)
)
response = self._requests_session.post(
monitoring_api_url, data=payload, headers=headers
)
@ -345,9 +365,13 @@ class Pagure:
namespace, repo, response.status_code
)
)
raise PagureError("Couldn't set monitoring on project '{0}/{1}'".format(namespace, repo))
raise PagureError(
"Couldn't set monitoring on project '{0}/{1}'".format(namespace, repo)
)
def change_project_main_admin(self, namespace: str, repo: str, new_main_admin: str) -> None:
def change_project_main_admin(
self, namespace: str, repo: str, new_main_admin: str
) -> None:
"""
Change the main admin of a project in pagure.
@ -359,12 +383,15 @@ class Pagure:
Raises:
`toddlers.utils.exceptions.PagureError``: When setting new admin fails.
"""
admin_api_url = '{0}/api/0/{1}/{2}'.format(self._pagure_url, namespace, repo)
admin_api_url = "{0}/api/0/{1}/{2}".format(self._pagure_url, namespace, repo)
headers = self.get_auth_header()
payload = {'main_admin': new_main_admin}
payload = {"main_admin": new_main_admin}
log.debug("Setting new admin to '{0}' for project '{1}/{2}'".format(
new_main_admin, namespace, repo))
log.debug(
"Setting new admin to '{0}' for project '{1}/{2}'".format(
new_main_admin, namespace, repo
)
)
response = self._requests_session.post(
admin_api_url, data=payload, headers=headers
)
@ -375,7 +402,9 @@ class Pagure:
namespace, repo, response.status_code
)
)
raise PagureError("Couldn't set new admin on project '{0}/{1}'".format(namespace, repo))
raise PagureError(
"Couldn't set new admin on project '{0}/{1}'".format(namespace, repo)
)
def get_project_contributors(self, namespace: str, repo: str) -> dict:
"""
@ -391,14 +420,13 @@ class Pagure:
Raises:
`toddlers.utils.exceptions.PagureError``: When getting contributors fails.
"""
contributors_api_url = '{0}/api/0/{1}/{2}/contributors'.format(self._pagure_url, namespace, repo)
contributors_api_url = "{0}/api/0/{1}/{2}/contributors".format(
self._pagure_url, namespace, repo
)
headers = self.get_auth_header()
log.debug("Getting contributors for project '{0}/{1}'".format(
namespace, repo))
response = self._requests_session.get(
contributors_api_url, headers=headers
)
log.debug("Getting contributors for project '{0}/{1}'".format(namespace, repo))
response = self._requests_session.get(contributors_api_url, headers=headers)
if response.status_code != 200:
log.error(
@ -406,7 +434,11 @@ class Pagure:
namespace, repo, response.status_code
)
)
raise PagureError("Couldn't get contributors for project '{0}/{1}'".format(namespace, repo))
raise PagureError(
"Couldn't get contributors for project '{0}/{1}'".format(
namespace, repo
)
)
return response.json()
@ -424,14 +456,15 @@ class Pagure:
Raises:
`toddlers.utils.exceptions.PagureError``: When getting default branch fails.
"""
branches_api_url = '{0}/api/0/{1}/{2}/git/branches'.format(self._pagure_url, namespace, repo)
branches_api_url = "{0}/api/0/{1}/{2}/git/branches".format(
self._pagure_url, namespace, repo
)
headers = self.get_auth_header()
log.debug("Getting default branch for project '{0}/{1}'".format(
namespace, repo))
response = self._requests_session.get(
branches_api_url, headers=headers
log.debug(
"Getting default branch for project '{0}/{1}'".format(namespace, repo)
)
response = self._requests_session.get(branches_api_url, headers=headers)
if response.status_code != 200:
log.error(
@ -439,6 +472,10 @@ class Pagure:
namespace, repo, response.status_code
)
)
raise PagureError("Couldn't get default branch for project '{0}/{1}'".format(namespace, repo))
raise PagureError(
"Couldn't get default branch for project '{0}/{1}'".format(
namespace, repo
)
)
return response.json().get("default", None)

View file

@ -43,11 +43,7 @@ def get_sla(sla_name: str) -> Optional[dict]:
def new_sla_to_branch(
sla_name: str,
eol: str,
global_component: str,
branch: str,
branch_type: str
sla_name: str, eol: str, global_component: str, branch: str, branch_type: str
) -> None:
"""
Create a new SLA to branch mapping in PDC.
@ -60,13 +56,13 @@ def new_sla_to_branch(
branch_type: Type of the branch (e.g. rpm, module, etc.)
"""
payload = {
'sla': sla_name,
'eol': eol,
'branch': {
'global_component': global_component,
'name': branch,
'type': branch_type
}
"sla": sla_name,
"eol": eol,
"branch": {
"global_component": global_component,
"name": branch,
"type": branch_type,
},
}
_PDC["component-branch-slas"]._(payload)
@ -86,16 +82,16 @@ def get_branch(global_component: str, branch: str, branch_type: str) -> Optional
A dictionary of the branch in PDC
"""
query_args = {
'global_component': global_component,
'name': branch,
'type': branch_type
"global_component": global_component,
"name": branch,
"type": branch_type,
}
branch_query = _PDC["component-branches"]._(**query_args)
if branch_query['count'] == 0:
if branch_query["count"] == 0:
return None
else:
return branch_query['results'][0]
return branch_query["results"][0]
def new_branch(global_component: str, branch: str, branch_type: str) -> None:
@ -115,9 +111,9 @@ def new_branch(global_component: str, branch: str, branch_type: str) -> None:
return
payload = {
'global_component': global_component,
'name': branch,
'type': branch_type
"global_component": global_component,
"name": branch,
"type": branch_type,
}
_PDC["component-branches"]._(payload)
@ -154,10 +150,7 @@ def new_global_component(global_component: str, dist_git_url: str) -> None:
if existing_global_component:
return
payload = {
"name": global_component,
"dist_git_web_url": dist_git_url
}
payload = {"name": global_component, "dist_git_web_url": dist_git_url}
# If it doesn't exist create one
_PDC["global-components"]._(payload)