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

View file

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

View file

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

View file

@ -19,7 +19,7 @@ class TestPagureSetPagure:
""" """
config = { config = {
"pagure_url": "https://pagure.io", "pagure_url": "https://pagure.io",
"pagure_api_key": "Very secret key" "pagure_api_key": "Very secret key",
} }
pagure_obj = pagure.set_pagure() pagure_obj = pagure.set_pagure()
@ -43,9 +43,7 @@ class TestPagureSetPagure:
with pytest.raises( with pytest.raises(
ValueError, match=r"No pagure_api_key found in the configuration file" ValueError, match=r"No pagure_api_key found in the configuration file"
): ):
config = { config = {"pagure_url": "https://pagure.io"}
"pagure_url": "https://pagure.io"
}
pagure.set_pagure(config) pagure.set_pagure(config)
@ -53,13 +51,14 @@ class TestPagureGetAuthHeader:
""" """
Test class for `toddlers.pagure.Pagure.get_auth_header` function. Test class for `toddlers.pagure.Pagure.get_auth_header` function.
""" """
def setup(self): def setup(self):
""" """
Setup method for the test class. Setup method for the test class.
""" """
config = { config = {
"pagure_url": "https://pagure.io", "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 = pagure.set_pagure(config)
@ -68,9 +67,9 @@ class TestPagureGetAuthHeader:
Assert that correct header is returned. Assert that correct header is returned.
""" """
exp_header = { exp_header = {
'Authorization': 'token Very secret key', "Authorization": "token Very secret key",
'Accept': 'application/json', "Accept": "application/json",
'Content-Type': 'application/json' "Content-Type": "application/json",
} }
header = self.pagure.get_auth_header() header = self.pagure.get_auth_header()
@ -82,13 +81,14 @@ class TestPagureCloseIssue:
""" """
Test class for `toddlers.pagure.Pagure.close_issue` function. Test class for `toddlers.pagure.Pagure.close_issue` function.
""" """
def setup(self): def setup(self):
""" """
Setup method for the test class. Setup method for the test class.
""" """
config = { config = {
"pagure_url": "https://pagure.io", "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 = pagure.set_pagure(config)
self.pagure._requests_session = Mock() self.pagure._requests_session = Mock()
@ -114,7 +114,7 @@ class TestPagureCloseIssue:
self.pagure._requests_session.post.assert_called_with( self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/test/issue/100/status", "https://pagure.io/test/issue/100/status",
data={"status": reason}, data={"status": reason},
headers=self.pagure.get_auth_header() headers=self.pagure.get_auth_header(),
) )
def test_close_issue_not_ok(self): 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'" expected_error = "Couldn't close issue 'https://pagure.io/test/issue/100'"
with pytest.raises(PagureError, match=expected_error): 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 comment_mock.return_value = True
result = self.pagure.close_issue(issue_id, namespace, message, reason) result = self.pagure.close_issue(issue_id, namespace, message, reason)
self.pagure._requests_session.post.assert_called_with( self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/test/issue/100/status", "https://pagure.io/test/issue/100/status",
data={"status": reason}, 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. Test class for `toddlers.pagure.Pagure.add_comment_to_issue` function.
""" """
def setup(self): def setup(self):
""" """
Setup method for the test class. Setup method for the test class.
""" """
config = { config = {
"pagure_url": "https://pagure.io", "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 = pagure.set_pagure(config)
self.pagure._requests_session = Mock() self.pagure._requests_session = Mock()
@ -178,7 +181,7 @@ class TestPagureAddCommentToIssue:
self.pagure._requests_session.post.assert_called_with( self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/test/issue/100/comment", "https://pagure.io/test/issue/100/comment",
data={"comment": message}, data={"comment": message},
headers=self.pagure.get_auth_header() headers=self.pagure.get_auth_header(),
) )
def test_add_comment_to_issue_not_ok(self): def test_add_comment_to_issue_not_ok(self):
@ -202,7 +205,7 @@ class TestPagureAddCommentToIssue:
self.pagure._requests_session.post.assert_called_with( self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/test/issue/100/comment", "https://pagure.io/test/issue/100/comment",
data={"comment": message}, 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. Test class for `toddlers.pagure.Pagure.user_exists` function.
""" """
def setup(self): def setup(self):
""" """
Setup method for the test class. Setup method for the test class.
""" """
config = { config = {
"pagure_url": "https://pagure.io", "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 = pagure.set_pagure(config)
self.pagure._requests_session = Mock() self.pagure._requests_session = Mock()
@ -286,13 +290,14 @@ class TestPagureNewProject:
""" """
Test class for `toddlers.pagure.Pagure.new_project` method. Test class for `toddlers.pagure.Pagure.new_project` method.
""" """
def setup(self): def setup(self):
""" """
Setup method for the test class. Setup method for the test class.
""" """
config = { config = {
"pagure_url": "https://pagure.io", "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 = pagure.set_pagure(config)
self.pagure._requests_session = Mock() self.pagure._requests_session = Mock()
@ -312,19 +317,21 @@ class TestPagureNewProject:
description = "description" description = "description"
upstream_url = "https://example.com" 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( self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/api/0/new", "https://pagure.io/api/0/new",
data={ data={
'namespace': namespace, "namespace": namespace,
'name': repo, "name": repo,
'default_branch': default_branch, "default_branch": default_branch,
'description': description, "description": description,
'url': upstream_url, "url": upstream_url,
'wait': True "wait": True,
}, },
headers=self.pagure.get_auth_header() headers=self.pagure.get_auth_header(),
) )
def test_new_project_initial_commit(self): def test_new_project_initial_commit(self):
@ -343,21 +350,26 @@ class TestPagureNewProject:
upstream_url = "https://example.com" upstream_url = "https://example.com"
self.pagure.new_project( 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( self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/api/0/new", "https://pagure.io/api/0/new",
data={ data={
'namespace': namespace, "namespace": namespace,
'name': repo, "name": repo,
'default_branch': default_branch, "default_branch": default_branch,
'description': description, "description": description,
'url': upstream_url, "url": upstream_url,
'wait': True, "wait": True,
'create_readme': True "create_readme": True,
}, },
headers=self.pagure.get_auth_header() headers=self.pagure.get_auth_header(),
) )
def test_new_project_alias(self): def test_new_project_alias(self):
@ -379,28 +391,32 @@ class TestPagureNewProject:
namespace, repo, description, upstream_url, default_branch, alias=True namespace, repo, description, upstream_url, default_branch, alias=True
) )
self.pagure._requests_session.post.assert_has_calls([ self.pagure._requests_session.post.assert_has_calls(
call( [
"https://pagure.io/api/0/new", call(
data={ "https://pagure.io/api/0/new",
'namespace': namespace, data={
'name': repo, "namespace": namespace,
'default_branch': default_branch, "name": repo,
'description': description, "default_branch": default_branch,
'url': upstream_url, "description": description,
'wait': True "url": upstream_url,
}, "wait": True,
headers=self.pagure.get_auth_header() },
), headers=self.pagure.get_auth_header(),
call( ),
"https://pagure.io/api/0/{0}/{1}/git/alias/new".format(namespace, repo), call(
data={ "https://pagure.io/api/0/{0}/{1}/git/alias/new".format(
'alias_from': 'main', namespace, repo
'alias_to': 'rawhide', ),
}, data={
headers=self.pagure.get_auth_header() "alias_from": "main",
), "alias_to": "rawhide",
]) },
headers=self.pagure.get_auth_header(),
),
]
)
def test_new_project_alias_wrong_namespace(self): def test_new_project_alias_wrong_namespace(self):
""" """
@ -425,14 +441,14 @@ class TestPagureNewProject:
self.pagure._requests_session.post.assert_called_with( self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/api/0/new", "https://pagure.io/api/0/new",
data={ data={
'namespace': namespace, "namespace": namespace,
'name': repo, "name": repo,
'default_branch': default_branch, "default_branch": default_branch,
'description': description, "description": description,
'url': upstream_url, "url": upstream_url,
'wait': True "wait": True,
}, },
headers=self.pagure.get_auth_header() headers=self.pagure.get_auth_header(),
) )
def test_new_project_failure(self): def test_new_project_failure(self):
@ -460,14 +476,14 @@ class TestPagureNewProject:
self.pagure._requests_session.post.assert_called_with( self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/api/0/new", "https://pagure.io/api/0/new",
data={ data={
'namespace': namespace, "namespace": namespace,
'name': repo, "name": repo,
'default_branch': default_branch, "default_branch": default_branch,
'description': description, "description": description,
'url': upstream_url, "url": upstream_url,
'wait': True "wait": True,
}, },
headers=self.pagure.get_auth_header() headers=self.pagure.get_auth_header(),
) )
def test_new_project_alias_failure(self): def test_new_project_alias_failure(self):
@ -480,7 +496,10 @@ class TestPagureNewProject:
response_mock_fail = Mock() response_mock_fail = Mock()
response_mock_fail.status_code = 500 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" namespace = "rpms"
repo = "repo" repo = "repo"
@ -488,48 +507,55 @@ class TestPagureNewProject:
description = "description" description = "description"
upstream_url = "https://example.com" 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): with pytest.raises(PagureError, match=expected_error):
self.pagure.new_project( self.pagure.new_project(
namespace, repo, description, upstream_url, default_branch, alias=True namespace, repo, description, upstream_url, default_branch, alias=True
) )
self.pagure._requests_session.post.assert_has_calls([ self.pagure._requests_session.post.assert_has_calls(
call( [
"https://pagure.io/api/0/new", call(
data={ "https://pagure.io/api/0/new",
'namespace': namespace, data={
'name': repo, "namespace": namespace,
'default_branch': default_branch, "name": repo,
'description': description, "default_branch": default_branch,
'url': upstream_url, "description": description,
'wait': True "url": upstream_url,
}, "wait": True,
headers=self.pagure.get_auth_header() },
), headers=self.pagure.get_auth_header(),
call( ),
"https://pagure.io/api/0/{0}/{1}/git/alias/new".format(namespace, repo), call(
data={ "https://pagure.io/api/0/{0}/{1}/git/alias/new".format(
'alias_from': 'main', namespace, repo
'alias_to': 'rawhide', ),
}, data={
headers=self.pagure.get_auth_header() "alias_from": "main",
), "alias_to": "rawhide",
]) },
headers=self.pagure.get_auth_header(),
),
]
)
class TestPagureNewBranch: class TestPagureNewBranch:
""" """
Test class for `toddlers.pagure.Pagure.new_branch` method. Test class for `toddlers.pagure.Pagure.new_branch` method.
""" """
def setup(self): def setup(self):
""" """
Setup method for the test class. Setup method for the test class.
""" """
config = { config = {
"pagure_url": "https://pagure.io", "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 = pagure.set_pagure(config)
self.pagure._requests_session = Mock() self.pagure._requests_session = Mock()
@ -553,10 +579,10 @@ class TestPagureNewBranch:
self.pagure._requests_session.post.assert_called_with( self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/api/0/{0}/{1}/git/branch".format(namespace, repo), "https://pagure.io/api/0/{0}/{1}/git/branch".format(namespace, repo),
data={ data={
'branch': branch, "branch": branch,
'from_commit': from_commit, "from_commit": from_commit,
}, },
headers=self.pagure.get_auth_header() headers=self.pagure.get_auth_header(),
) )
def test_new_branch_from_branch(self): def test_new_branch_from_branch(self):
@ -578,10 +604,10 @@ class TestPagureNewBranch:
self.pagure._requests_session.post.assert_called_with( self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/api/0/{0}/{1}/git/branch".format(namespace, repo), "https://pagure.io/api/0/{0}/{1}/git/branch".format(namespace, repo),
data={ data={
'branch': branch, "branch": branch,
'from_branch': from_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): def test_new_branch_missing_required_params(self):
@ -597,13 +623,10 @@ class TestPagureNewBranch:
repo = "repo" repo = "repo"
branch = "branch" branch = "branch"
expected_error = ("You must specify either `from_commit` or " expected_error = "You must specify either `from_commit` or " "`from_branch`"
"`from_branch`")
with pytest.raises(RuntimeError, match=expected_error): with pytest.raises(RuntimeError, match=expected_error):
self.pagure.new_branch( self.pagure.new_branch(namespace, repo, branch)
namespace, repo, branch
)
def test_new_branch_missing_required_params(self): def test_new_branch_missing_required_params(self):
""" """
@ -620,12 +643,17 @@ class TestPagureNewBranch:
from_branch = "existing_branch" from_branch = "existing_branch"
from_commit = "commit" from_commit = "commit"
expected_error = ("`from_commit` and `from_branch` were both " expected_error = (
"specified. Only use one.") "`from_commit` and `from_branch` were both " "specified. Only use one."
)
with pytest.raises(RuntimeError, match=expected_error): with pytest.raises(RuntimeError, match=expected_error):
self.pagure.new_branch( 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): def test_new_branch_failure(self):
@ -642,20 +670,20 @@ class TestPagureNewBranch:
branch = "branch" branch = "branch"
from_branch = "existing_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): with pytest.raises(PagureError, match=expected_error):
self.pagure.new_branch( self.pagure.new_branch(namespace, repo, branch, from_branch=from_branch)
namespace, repo, branch, from_branch=from_branch
)
self.pagure._requests_session.post.assert_called_with( self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/api/0/{0}/{1}/git/branch".format(namespace, repo), "https://pagure.io/api/0/{0}/{1}/git/branch".format(namespace, repo),
data={ data={
'branch': branch, "branch": branch,
'from_branch': from_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. Test class for `toddlers.pagure.Pagure.set_monitoring_status` method.
""" """
def setup(self): def setup(self):
""" """
Setup method for the test class. Setup method for the test class.
""" """
config = { config = {
"pagure_url": "https://pagure.io", "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 = pagure.set_pagure(config)
self.pagure._requests_session = Mock() self.pagure._requests_session = Mock()
@ -691,10 +720,8 @@ class TestPagureSetMonitoringStatus:
self.pagure._requests_session.post.assert_called_with( self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/_dg/anitya/{0}/{1}".format(namespace, repo), "https://pagure.io/_dg/anitya/{0}/{1}".format(namespace, repo),
data={ data={"anitya_status": monitoring_level},
'anitya_status': monitoring_level headers=self.pagure.get_auth_header(),
},
headers=self.pagure.get_auth_header()
) )
def test_set_monitoring_status_failure(self): def test_set_monitoring_status_failure(self):
@ -710,19 +737,17 @@ class TestPagureSetMonitoringStatus:
repo = "repo" repo = "repo"
monitoring_level = "no_monitoring" 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): with pytest.raises(PagureError, match=expected_error):
self.pagure.set_monitoring_status( self.pagure.set_monitoring_status(namespace, repo, monitoring_level)
namespace, repo, monitoring_level
)
self.pagure._requests_session.post.assert_called_with( self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/_dg/anitya/{0}/{1}".format(namespace, repo), "https://pagure.io/_dg/anitya/{0}/{1}".format(namespace, repo),
data={ data={"anitya_status": monitoring_level},
'anitya_status': monitoring_level headers=self.pagure.get_auth_header(),
},
headers=self.pagure.get_auth_header()
) )
@ -730,13 +755,14 @@ class TestPagureChangeProjectMainAdmin:
""" """
Test class for `toddlers.pagure.Pagure.change_project_main_admin` method. Test class for `toddlers.pagure.Pagure.change_project_main_admin` method.
""" """
def setup(self): def setup(self):
""" """
Setup method for the test class. Setup method for the test class.
""" """
config = { config = {
"pagure_url": "https://pagure.io", "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 = pagure.set_pagure(config)
self.pagure._requests_session = Mock() self.pagure._requests_session = Mock()
@ -758,10 +784,8 @@ class TestPagureChangeProjectMainAdmin:
self.pagure._requests_session.post.assert_called_with( self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/api/0/{0}/{1}".format(namespace, repo), "https://pagure.io/api/0/{0}/{1}".format(namespace, repo),
data={ data={"main_admin": main_admin},
'main_admin': main_admin headers=self.pagure.get_auth_header(),
},
headers=self.pagure.get_auth_header()
) )
def test_change_project_main_admin_failure(self): def test_change_project_main_admin_failure(self):
@ -777,19 +801,17 @@ class TestPagureChangeProjectMainAdmin:
repo = "repo" repo = "repo"
main_admin = "zlopez" 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): with pytest.raises(PagureError, match=expected_error):
self.pagure.change_project_main_admin( self.pagure.change_project_main_admin(namespace, repo, main_admin)
namespace, repo, main_admin
)
self.pagure._requests_session.post.assert_called_with( self.pagure._requests_session.post.assert_called_with(
"https://pagure.io/api/0/{0}/{1}".format(namespace, repo), "https://pagure.io/api/0/{0}/{1}".format(namespace, repo),
data={ data={"main_admin": main_admin},
'main_admin': main_admin headers=self.pagure.get_auth_header(),
},
headers=self.pagure.get_auth_header()
) )
@ -797,13 +819,14 @@ class TestPagureGetProjectContributors:
""" """
Test class for `toddlers.pagure.Pagure.get_project_contributors` method. Test class for `toddlers.pagure.Pagure.get_project_contributors` method.
""" """
def setup(self): def setup(self):
""" """
Setup method for the test class. Setup method for the test class.
""" """
config = { config = {
"pagure_url": "https://pagure.io", "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 = pagure.set_pagure(config)
self.pagure._requests_session = Mock() self.pagure._requests_session = Mock()
@ -829,7 +852,7 @@ class TestPagureGetProjectContributors:
self.pagure._requests_session.get.assert_called_with( self.pagure._requests_session.get.assert_called_with(
"https://pagure.io/api/0/{0}/{1}/contributors".format(namespace, repo), "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 assert result == data
@ -846,16 +869,16 @@ class TestPagureGetProjectContributors:
namespace = "namespace" namespace = "namespace"
repo = "repo" 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): with pytest.raises(PagureError, match=expected_error):
self.pagure.get_project_contributors( self.pagure.get_project_contributors(namespace, repo)
namespace, repo
)
self.pagure._requests_session.get.assert_called_with( self.pagure._requests_session.get.assert_called_with(
"https://pagure.io/api/0/{0}/{1}/contributors".format(namespace, repo), "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. Test class for `toddlers.pagure.Pagure.get_default_branch` method.
""" """
def setup(self): def setup(self):
""" """
Setup method for the test class. Setup method for the test class.
""" """
config = { config = {
"pagure_url": "https://pagure.io", "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 = pagure.set_pagure(config)
self.pagure._requests_session = Mock() self.pagure._requests_session = Mock()
@ -895,7 +919,7 @@ class TestPagureGetDefaultBranch:
self.pagure._requests_session.get.assert_called_with( self.pagure._requests_session.get.assert_called_with(
"https://pagure.io/api/0/{0}/{1}/git/branches".format(namespace, repo), "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 assert result == branch
@ -920,7 +944,7 @@ class TestPagureGetDefaultBranch:
self.pagure._requests_session.get.assert_called_with( self.pagure._requests_session.get.assert_called_with(
"https://pagure.io/api/0/{0}/{1}/git/branches".format(namespace, repo), "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 assert result is None
@ -937,14 +961,14 @@ class TestPagureGetDefaultBranch:
namespace = "namespace" namespace = "namespace"
repo = "repo" 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): with pytest.raises(PagureError, match=expected_error):
self.pagure.get_default_branch( self.pagure.get_default_branch(namespace, repo)
namespace, repo
)
self.pagure._requests_session.get.assert_called_with( self.pagure._requests_session.get.assert_called_with(
"https://pagure.io/api/0/{0}/{1}/git/branches".format(namespace, repo), "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": { "pdc_config": {
"server": "https://pdc.fedoraproject.org/rest_api/v1/", "server": "https://pdc.fedoraproject.org/rest_api/v1/",
"ssl_verify": False, "ssl_verify": False,
"token": "token" "token": "token",
} }
} }
pdc_client = pdc.set_pdc(config) pdc_client = pdc.set_pdc(config)
@ -41,13 +41,14 @@ class TestPdcPdcClientForConfig:
"pdc_config": { "pdc_config": {
"server": "https://pdc.fedoraproject.org/rest_api/v1/", "server": "https://pdc.fedoraproject.org/rest_api/v1/",
"ssl_verify": False, "ssl_verify": False,
"token": "token" "token": "token",
} }
} }
pdc_client = pdc.pdc_client_for_config(config) pdc_client = pdc.pdc_client_for_config(config)
assert pdc_client assert pdc_client
class TestPdcGetSla: class TestPdcGetSla:
""" """
Test class for `toddlers.utils.pdc.get_sla` function. Test class for `toddlers.utils.pdc.get_sla` function.
@ -63,7 +64,7 @@ class TestPdcGetSla:
""" """
Assert that correct response is handled. 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 pdc._PDC["component-sla-types"]._.return_value = response
@ -75,7 +76,7 @@ class TestPdcGetSla:
""" """
Assert that incorrect response is handled. Assert that incorrect response is handled.
""" """
response = {"count": 0, "results":[]} response = {"count": 0, "results": []}
pdc._PDC["component-sla-types"]._.return_value = response pdc._PDC["component-sla-types"]._.return_value = response
@ -110,18 +111,18 @@ class TestPdcNewSLAToBranch:
eol=eol, eol=eol,
global_component=global_component, global_component=global_component,
branch=branch_name, branch=branch_name,
branch_type=branch_type branch_type=branch_type,
) )
pdc._PDC["component-branch-slas"]._.assert_called_with( pdc._PDC["component-branch-slas"]._.assert_called_with(
{ {
'sla': sla, "sla": sla,
'eol': eol, "eol": eol,
'branch': { "branch": {
'global_component': global_component, "global_component": global_component,
'name': branch_name, "name": branch_name,
'type': branch_type "type": branch_type,
} },
} }
) )
@ -141,7 +142,7 @@ class TestPdcGetBranch:
""" """
Assert that correct response is handled. Assert that correct response is handled.
""" """
response = {"count": 1, "results":[{"id": 3}]} response = {"count": 1, "results": [{"id": 3}]}
global_component = "global_component" global_component = "global_component"
name = "branch" name = "branch"
@ -154,16 +155,14 @@ class TestPdcGetBranch:
assert result == {"id": 3} assert result == {"id": 3}
pdc._PDC["component-branches"]._.assert_called_with( pdc._PDC["component-branches"]._.assert_called_with(
global_component=global_component, global_component=global_component, name=name, type=branch_type
name=name,
type=branch_type
) )
def test_get_branch_not_found(self): def test_get_branch_not_found(self):
""" """
Assert that incorrect response is handled. Assert that incorrect response is handled.
""" """
response = {"count": 0, "results":[]} response = {"count": 0, "results": []}
global_component = "global_component" global_component = "global_component"
name = "branch" name = "branch"
@ -176,9 +175,7 @@ class TestPdcGetBranch:
assert not result assert not result
pdc._PDC["component-branches"]._.assert_called_with( pdc._PDC["component-branches"]._.assert_called_with(
global_component=global_component, global_component=global_component, name=name, type=branch_type
name=name,
type=branch_type
) )
@ -197,7 +194,7 @@ class TestPdcNewBranch:
""" """
Assert that component is not created when it doesn't exist. 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" global_component = "global_component"
branch = "branch" branch = "branch"
@ -208,16 +205,14 @@ class TestPdcNewBranch:
pdc.new_branch(global_component, branch, branch_type) pdc.new_branch(global_component, branch, branch_type)
pdc._PDC["component-branches"]._.assert_called_with( pdc._PDC["component-branches"]._.assert_called_with(
global_component=global_component, global_component=global_component, name=branch, type=branch_type
name=branch,
type=branch_type
) )
def test_new_branch_not_found(self): def test_new_branch_not_found(self):
""" """
Assert that component is created when not found. Assert that component is created when not found.
""" """
response = {"count": 0, "results":[]} response = {"count": 0, "results": []}
global_component = "global_component" global_component = "global_component"
branch = "branch" branch = "branch"
@ -229,18 +224,14 @@ class TestPdcNewBranch:
pdc._PDC["component-branches"]._.assert_has_calls( pdc._PDC["component-branches"]._.assert_has_calls(
[ [
call( call(global_component=global_component, name=branch, type=branch_type),
global_component=global_component,
name=branch,
type=branch_type
),
call( call(
{ {
"global_component": global_component, "global_component": global_component,
"name": branch, "name": branch,
"type": branch_type "type": branch_type,
} }
) ),
] ]
) )
@ -260,7 +251,7 @@ class TestPdcGetGlobalComponent:
""" """
Assert that correct response is handled. Assert that correct response is handled.
""" """
response = {"count": 1, "results":[{"id": 3}]} response = {"count": 1, "results": [{"id": 3}]}
global_component = "global_component" global_component = "global_component"
@ -278,7 +269,7 @@ class TestPdcGetGlobalComponent:
""" """
Assert that incorrect response is handled. Assert that incorrect response is handled.
""" """
response = {"count": 0, "results":[]} response = {"count": 0, "results": []}
global_component = "global_component" global_component = "global_component"
@ -308,7 +299,7 @@ class TestPdcNewGlobalComponent:
""" """
Assert that component is not created when it doesn't exist. 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" global_component = "global_component"
dist_git_url = "https://src.fedoraproject.org/example" dist_git_url = "https://src.fedoraproject.org/example"
@ -325,7 +316,7 @@ class TestPdcNewGlobalComponent:
""" """
Assert that component is created when not found. Assert that component is created when not found.
""" """
response = {"count": 0, "results":[]} response = {"count": 0, "results": []}
global_component = "global_component" global_component = "global_component"
dist_git_url = "https://src.fedoraproject.org/example" dist_git_url = "https://src.fedoraproject.org/example"
@ -337,11 +328,6 @@ class TestPdcNewGlobalComponent:
pdc._PDC["global-components"]._.assert_has_calls( pdc._PDC["global-components"]._.assert_has_calls(
[ [
call(name=global_component), call(name=global_component),
call( call({"name": global_component, "dist_git_web_url": dist_git_url}),
{
"name": global_component,
"dist_git_web_url": dist_git_url
}
)
] ]
) )

View file

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

View file

@ -1,5 +1,7 @@
""" """
Exception that is raised when validation fails. Exception that is raised when validation fails.
""" """
class ValidationError(Exception): class ValidationError(Exception):
pass 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() bz = get_bz()
try: 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: except xmlrpc.client.Fault as e:
# Output something useful in args # Output something useful in args
e.args = (bug_id, e.faultCode, e.faultString) 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() bz = get_bz()
_log.info("Adding comment `%s` to `%s`", comment, bug_id) _log.info("Adding comment `%s` to `%s`", comment, bug_id)
data = { data = {"id": bug_id, "comment": comment}
"id": bug_id,
"comment": comment
}
try: try:
execute_bugzilla_call(bz.comment, data) execute_bugzilla_call(bz.comment, data)

View file

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

View file

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

View file

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