Fix flake8 errors

Signed-off-by: Michal Konečný <mkonecny@redhat.com>
This commit is contained in:
Michal Konečný 2022-03-21 13:44:45 +01:00
parent 6e69a65ce0
commit a8dca5908f
9 changed files with 45 additions and 38 deletions

View file

@ -2,21 +2,22 @@
Unit tests for `toddlers.plugins.scm_request_processor` Unit tests for `toddlers.plugins.scm_request_processor`
""" """
import json import json
from unittest.mock import call, patch, MagicMock, Mock
import logging import logging
import re import re
from unittest.mock import call, MagicMock, Mock, patch
import arrow import arrow
from pagure_messages.issue_schema import IssueNewV1 from pagure_messages.issue_schema import IssueNewV1
import pytest import pytest
import toddlers.plugins.scm_request_processor as scm_request_processor
from toddlers.exceptions import ValidationError from toddlers.exceptions import ValidationError
import toddlers.plugins.scm_request_processor as scm_request_processor
class TestAcceptsTopic: class TestAcceptsTopic:
""" """
Test class for `toddlers.plugins.scm_request_processor.SCMRequestProcessor.accepts_topic` method. Test class for `toddlers.plugins.scm_request_processor.SCMRequestProcessor.accepts_topic`
method.
""" """
toddler_cls = scm_request_processor.SCMRequestProcessor toddler_cls = scm_request_processor.SCMRequestProcessor
@ -146,7 +147,8 @@ class TestProcess:
class TestProcessTicket: class TestProcessTicket:
""" """
Test class for `toddlers.plugins.scm_request_processor.SCMRequestProcessor.process_ticket` method. Test class for `toddlers.plugins.scm_request_processor.SCMRequestProcessor.process_ticket`
method.
""" """
def setup(self): def setup(self):
@ -488,7 +490,8 @@ class TestVerifySLAs:
class TestCreateNewRepo: class TestCreateNewRepo:
""" """
Test class for `toddlers.plugins.scm_request_processor.SCMRequestProcessor.create_new_repo` method. Test class for `toddlers.plugins.scm_request_processor.SCMRequestProcessor.create_new_repo`
method.
""" """
def setup(self): def setup(self):
@ -649,7 +652,8 @@ class TestCreateNewRepo:
def test_create_new_repo_requester_not_in_dist_git(self): def test_create_new_repo_requester_not_in_dist_git(self):
""" """
Assert that ticket will be commented on when requester doesn't have a valid dist git account. Assert that ticket will be commented on when requester doesn't
have a valid dist git account.
""" """
issue = {"id": 100, "user": {"name": "zlopez"}} issue = {"id": 100, "user": {"name": "zlopez"}}
@ -922,7 +926,8 @@ class TestCreateNewRepo:
@patch("toddlers.plugins.scm_request_processor.pdc") @patch("toddlers.plugins.scm_request_processor.pdc")
def test_create_new_repo_tests_namespace(self, mock_pdc): def test_create_new_repo_tests_namespace(self, mock_pdc):
""" """
Assert that ticket will be processed when everything is in order and namespace is set to tests. Assert that ticket will be processed when everything is in order and namespace
is set to tests.
""" """
issue = {"id": 100, "user": {"name": "zlopez"}} issue = {"id": 100, "user": {"name": "zlopez"}}
@ -979,7 +984,8 @@ class TestCreateNewRepo:
@patch("toddlers.plugins.scm_request_processor.pdc") @patch("toddlers.plugins.scm_request_processor.pdc")
def test_create_new_repo_non_default_branch(self, mock_pdc): def test_create_new_repo_non_default_branch(self, mock_pdc):
""" """
Assert that ticket will be processed when everything is in order and requested branch is not default. Assert that ticket will be processed when everything is in order and requested
branch is not default.
""" """
issue = {"id": 100, "user": {"name": "zlopez"}} issue = {"id": 100, "user": {"name": "zlopez"}}
@ -1128,7 +1134,8 @@ class TestCreateNewRepo:
class TestCreateNewBranch: class TestCreateNewBranch:
""" """
Test class for `toddlers.plugins.scm_request_processor.SCMRequestProcessor.create_new_branch` method. Test class for `toddlers.plugins.scm_request_processor.SCMRequestProcessor.create_new_branch`
method.
""" """
def setup(self): def setup(self):
@ -1660,7 +1667,8 @@ class TestCreateNewBranch:
class TestValidateReviewBug: class TestValidateReviewBug:
""" """
Test class for `toddlers.plugins.scm_request_processor.SCMRequestProcessor.validate_review_bug` method. Test class for `toddlers.plugins.scm_request_processor.SCMRequestProcessor.validate_review_bug`
method.
""" """
def setup(self): def setup(self):
@ -2398,7 +2406,8 @@ class TestValidateReviewBug:
class TestValidEpelPackage: class TestValidEpelPackage:
""" """
Test class for `toddlers.plugins.scm_request_processor.SCMRequestProcessor.valid_epel_package` method. Test class for `toddlers.plugins.scm_request_processor.SCMRequestProcessor.valid_epel_package`
method.
""" """
def setup(self): def setup(self):

View file

@ -1055,7 +1055,7 @@ class TestCommentOnBug:
mock_bz.return_value = server mock_bz.return_value = server
bug = toddlers.utils.bugzilla_system.comment_on_bug(bug_id, comment) toddlers.utils.bugzilla_system.comment_on_bug(bug_id, comment)
mock_bz.assert_called_with() mock_bz.assert_called_with()
server.comment.assert_called_with(id=bug_id, comment=comment) server.comment.assert_called_with(id=bug_id, comment=comment)

View file

@ -236,7 +236,7 @@ class TestFedoraAccountFASJSON:
assert output is False assert output is False
@patch("toddlers.utils.fedora_account.get_fasjson") @patch("toddlers.utils.fedora_account.get_fasjson")
def test_get_user_by_email(self, mock_fas): def test_get_user_by_username(self, mock_fas):
user = [{"username": "scoady", "emails": ["scoady@fp.o"]}] user = [{"username": "scoady", "emails": ["scoady@fp.o"]}]
result = Mock() result = Mock()
result.result = user result.result = user
@ -250,7 +250,7 @@ class TestFedoraAccountFASJSON:
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")
def test_get_user_by_email_empty(self, mock_fas): def test_get_user_by_username_empty(self, mock_fas):
user = [] user = []
result = Mock() result = Mock()
result.result = user result.result = user
@ -264,7 +264,7 @@ class TestFedoraAccountFASJSON:
assert output is None assert output is None
@patch("toddlers.utils.fedora_account.get_fasjson") @patch("toddlers.utils.fedora_account.get_fasjson")
def test_get_user_by_email_error(self, mock_fas): def test_get_user_by_username_error(self, mock_fas):
server = Mock() server = Mock()
server.search.side_effect = ClientError( server.search.side_effect = ClientError(
message="Error getting bz_email for group", message="Error getting bz_email for group",

View file

@ -1,9 +1,10 @@
""" """
Unit tests for `toddlers.utils.pagure`. Unit tests for `toddlers.utils.pagure`.
""" """
import pytest
from unittest.mock import call, Mock, patch from unittest.mock import call, Mock, patch
import pytest
from toddlers.exceptions import PagureError from toddlers.exceptions import PagureError
import toddlers.utils.pagure as pagure import toddlers.utils.pagure as pagure
@ -13,7 +14,7 @@ class TestPagureSetPagure:
Test class for `toddlers.pagure.set_pagure` function. Test class for `toddlers.pagure.set_pagure` function.
""" """
def test_set_pagure_no_pagure_url(self): def test_set_pagure(self):
""" """
Test initialization of pagure module. Test initialization of pagure module.
""" """
@ -109,7 +110,7 @@ class TestPagureCloseIssue:
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) 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",
@ -138,7 +139,7 @@ class TestPagureCloseIssue:
"toddlers.utils.pagure.Pagure.add_comment_to_issue" "toddlers.utils.pagure.Pagure.add_comment_to_issue"
) as comment_mock: ) as comment_mock:
comment_mock.return_value = True comment_mock.return_value = True
result = self.pagure.close_issue(issue_id, namespace, message, reason) 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",
@ -176,7 +177,7 @@ class TestPagureAddCommentToIssue:
namespace = "test" namespace = "test"
message = "message" message = "message"
result = self.pagure.add_comment_to_issue(issue_id, namespace, message) self.pagure.add_comment_to_issue(issue_id, namespace, message)
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",
@ -200,7 +201,7 @@ class TestPagureAddCommentToIssue:
expected_error = "Couldn't comment on issue 'https://pagure.io/test/issue/100'" expected_error = "Couldn't comment on issue 'https://pagure.io/test/issue/100'"
with pytest.raises(PagureError, match=expected_error): with pytest.raises(PagureError, match=expected_error):
result = self.pagure.add_comment_to_issue(issue_id, namespace, message) self.pagure.add_comment_to_issue(issue_id, namespace, message)
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",
@ -279,7 +280,7 @@ class TestPagureUserExists:
expected_error = "Couldn't get user '{0}'".format(username) expected_error = "Couldn't get user '{0}'".format(username)
with pytest.raises(PagureError, match=expected_error): with pytest.raises(PagureError, match=expected_error):
result = self.pagure.user_exists(username) self.pagure.user_exists(username)
self.pagure._requests_session.get.assert_called_with( self.pagure._requests_session.get.assert_called_with(
"https://pagure.io/api/0/users?pattern={0}".format(username), "https://pagure.io/api/0/users?pattern={0}".format(username),
@ -628,7 +629,7 @@ class TestPagureNewBranch:
with pytest.raises(RuntimeError, match=expected_error): 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): def test_new_branch_conflicting_params(self):
""" """
Assert that method fails if conflicting parameters are provided. Assert that method fails if conflicting parameters are provided.
""" """

View file

@ -1,7 +1,7 @@
""" """
Unit tests for `toddlers.utils.pdc`. Unit tests for `toddlers.utils.pdc`.
""" """
from unittest.mock import call, MagicMock, patch from unittest.mock import call, MagicMock
import toddlers.utils.pdc as pdc import toddlers.utils.pdc as pdc

View file

@ -1,2 +1,2 @@
from .pagure_error import PagureError from .pagure_error import PagureError # noqa: F401
from .validation_error import ValidationError from .validation_error import ValidationError # noqa: F401

View file

@ -17,8 +17,8 @@ import arrow
from pagure_messages.issue_schema import IssueNewV1 from pagure_messages.issue_schema import IssueNewV1
from toddlers.base import ToddlerBase from toddlers.base import ToddlerBase
from toddlers.utils import bugzilla_system, fedora_account, git, pagure, pdc, requests
from toddlers.exceptions import ValidationError from toddlers.exceptions import ValidationError
from toddlers.utils import bugzilla_system, fedora_account, git, pagure, pdc, requests
# Regex for branch name validation # Regex for branch name validation
STREAM_NAME_REGEX = r"^[a-zA-Z0-9.\-_+]+$" STREAM_NAME_REGEX = r"^[a-zA-Z0-9.\-_+]+$"
@ -413,7 +413,6 @@ class SCMRequestProcessor(ToddlerBase):
) )
return return
issue_id = issue["id"]
_log.info( _log.info(
"- Checking if user {0} has an account in dist-git.".format(requester) "- Checking if user {0} has an account in dist-git.".format(requester)
) )
@ -644,7 +643,6 @@ class SCMRequestProcessor(ToddlerBase):
) )
return return
issue_id = issue["id"]
issue_owner = issue["user"]["name"] issue_owner = issue["user"]["name"]
# Check if the branch requestor is one of the maintainers or part of the groups # Check if the branch requestor is one of the maintainers or part of the groups

View file

@ -18,8 +18,8 @@ Examples:
import logging import logging
from typing import Mapping from typing import Mapping
from toddlers.utils import requests
from toddlers.exceptions import PagureError from toddlers.exceptions import PagureError
from toddlers.utils import requests
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -260,7 +260,8 @@ class Pagure:
if response.status_code != 200: if response.status_code != 200:
log.error( log.error(
"Error when creating alias for project '{0}/{1}'. Got status_code '{2}'.".format( "Error when creating alias for project '{0}/{1}'. "
"Got status_code '{2}'.".format(
namespace, repo, response.status_code namespace, repo, response.status_code
) )
) )
@ -430,9 +431,8 @@ class Pagure:
if response.status_code != 200: if response.status_code != 200:
log.error( log.error(
"Error when retrieving contributors project '{0}/{1}'. Got status_code '{2}'.".format( "Error when retrieving contributors project '{0}/{1}'. "
namespace, repo, response.status_code "Got status_code '{2}'.".format(namespace, repo, response.status_code)
)
) )
raise PagureError( raise PagureError(
"Couldn't get contributors for project '{0}/{1}'".format( "Couldn't get contributors for project '{0}/{1}'".format(
@ -468,9 +468,8 @@ class Pagure:
if response.status_code != 200: if response.status_code != 200:
log.error( log.error(
"Error when getting default branch for project '{0}/{1}'. Got status_code '{2}'.".format( "Error when getting default branch for project '{0}/{1}'. "
namespace, repo, response.status_code "Got status_code '{2}'.".format(namespace, repo, response.status_code)
)
) )
raise PagureError( raise PagureError(
"Couldn't get default branch for project '{0}/{1}'".format( "Couldn't get default branch for project '{0}/{1}'".format(

View file

@ -1,4 +1,4 @@
from typing import Optional, Mapping from typing import Mapping, Optional
from pdc_client import PDCClient from pdc_client import PDCClient