diff --git a/tests/plugins/test_scm_request_processor.py b/tests/plugins/test_scm_request_processor.py index a50c0b1..bc1e79f 100644 --- a/tests/plugins/test_scm_request_processor.py +++ b/tests/plugins/test_scm_request_processor.py @@ -2,21 +2,22 @@ Unit tests for `toddlers.plugins.scm_request_processor` """ import json -from unittest.mock import call, patch, MagicMock, Mock import logging import re +from unittest.mock import call, MagicMock, Mock, patch import arrow from pagure_messages.issue_schema import IssueNewV1 import pytest -import toddlers.plugins.scm_request_processor as scm_request_processor from toddlers.exceptions import ValidationError +import toddlers.plugins.scm_request_processor as scm_request_processor 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 @@ -146,7 +147,8 @@ class TestProcess: 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): @@ -488,7 +490,8 @@ class TestVerifySLAs: 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): @@ -649,7 +652,8 @@ class TestCreateNewRepo: 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"}} @@ -922,7 +926,8 @@ class TestCreateNewRepo: @patch("toddlers.plugins.scm_request_processor.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"}} @@ -979,7 +984,8 @@ class TestCreateNewRepo: @patch("toddlers.plugins.scm_request_processor.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"}} @@ -1128,7 +1134,8 @@ class TestCreateNewRepo: 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): @@ -1660,7 +1667,8 @@ class TestCreateNewBranch: 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): @@ -2398,7 +2406,8 @@ class TestValidateReviewBug: 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): diff --git a/tests/utils/test_bugzilla_system.py b/tests/utils/test_bugzilla_system.py index 1022239..9d61f32 100644 --- a/tests/utils/test_bugzilla_system.py +++ b/tests/utils/test_bugzilla_system.py @@ -1055,7 +1055,7 @@ class TestCommentOnBug: 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() server.comment.assert_called_with(id=bug_id, comment=comment) diff --git a/tests/utils/test_fedora_account_fasjson.py b/tests/utils/test_fedora_account_fasjson.py index c15e37b..9f050f7 100644 --- a/tests/utils/test_fedora_account_fasjson.py +++ b/tests/utils/test_fedora_account_fasjson.py @@ -236,7 +236,7 @@ class TestFedoraAccountFASJSON: assert output is False @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"]}] result = Mock() result.result = user @@ -250,7 +250,7 @@ class TestFedoraAccountFASJSON: assert output == {"username": "scoady", "emails": ["scoady@fp.o"]} @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 = [] result = Mock() result.result = user @@ -264,7 +264,7 @@ class TestFedoraAccountFASJSON: assert output is None @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.search.side_effect = ClientError( message="Error getting bz_email for group", diff --git a/tests/utils/test_pagure.py b/tests/utils/test_pagure.py index d07ce26..81f89a6 100644 --- a/tests/utils/test_pagure.py +++ b/tests/utils/test_pagure.py @@ -1,9 +1,10 @@ """ Unit tests for `toddlers.utils.pagure`. """ -import pytest from unittest.mock import call, Mock, patch +import pytest + from toddlers.exceptions import PagureError import toddlers.utils.pagure as pagure @@ -13,7 +14,7 @@ class TestPagureSetPagure: 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. """ @@ -109,7 +110,7 @@ class TestPagureCloseIssue: 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.close_issue(issue_id, namespace, message, reason) self.pagure._requests_session.post.assert_called_with( "https://pagure.io/test/issue/100/status", @@ -138,7 +139,7 @@ class TestPagureCloseIssue: "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.close_issue(issue_id, namespace, message, reason) self.pagure._requests_session.post.assert_called_with( "https://pagure.io/test/issue/100/status", @@ -176,7 +177,7 @@ class TestPagureAddCommentToIssue: namespace = "test" 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( "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'" 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( "https://pagure.io/test/issue/100/comment", @@ -279,7 +280,7 @@ class TestPagureUserExists: expected_error = "Couldn't get user '{0}'".format(username) 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( "https://pagure.io/api/0/users?pattern={0}".format(username), @@ -628,7 +629,7 @@ class TestPagureNewBranch: with pytest.raises(RuntimeError, match=expected_error): 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. """ diff --git a/tests/utils/test_pdc.py b/tests/utils/test_pdc.py index e1911f5..ba03fe3 100644 --- a/tests/utils/test_pdc.py +++ b/tests/utils/test_pdc.py @@ -1,7 +1,7 @@ """ 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 diff --git a/toddlers/exceptions/__init__.py b/toddlers/exceptions/__init__.py index 846df53..2ed8d0c 100644 --- a/toddlers/exceptions/__init__.py +++ b/toddlers/exceptions/__init__.py @@ -1,2 +1,2 @@ -from .pagure_error import PagureError -from .validation_error import ValidationError +from .pagure_error import PagureError # noqa: F401 +from .validation_error import ValidationError # noqa: F401 diff --git a/toddlers/plugins/scm_request_processor.py b/toddlers/plugins/scm_request_processor.py index 340366d..255fa8a 100644 --- a/toddlers/plugins/scm_request_processor.py +++ b/toddlers/plugins/scm_request_processor.py @@ -17,8 +17,8 @@ import arrow from pagure_messages.issue_schema import IssueNewV1 from toddlers.base import ToddlerBase -from toddlers.utils import bugzilla_system, fedora_account, git, pagure, pdc, requests from toddlers.exceptions import ValidationError +from toddlers.utils import bugzilla_system, fedora_account, git, pagure, pdc, requests # Regex for branch name validation STREAM_NAME_REGEX = r"^[a-zA-Z0-9.\-_+]+$" @@ -413,7 +413,6 @@ class SCMRequestProcessor(ToddlerBase): ) return - issue_id = issue["id"] _log.info( "- Checking if user {0} has an account in dist-git.".format(requester) ) @@ -644,7 +643,6 @@ class SCMRequestProcessor(ToddlerBase): ) return - issue_id = issue["id"] issue_owner = issue["user"]["name"] # Check if the branch requestor is one of the maintainers or part of the groups diff --git a/toddlers/utils/pagure.py b/toddlers/utils/pagure.py index 0f25b91..68c30c9 100644 --- a/toddlers/utils/pagure.py +++ b/toddlers/utils/pagure.py @@ -18,8 +18,8 @@ Examples: import logging from typing import Mapping -from toddlers.utils import requests from toddlers.exceptions import PagureError +from toddlers.utils import requests log = logging.getLogger(__name__) @@ -260,7 +260,8 @@ class Pagure: if response.status_code != 200: 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 ) ) @@ -430,9 +431,8 @@ class Pagure: if response.status_code != 200: log.error( - "Error when retrieving contributors project '{0}/{1}'. Got status_code '{2}'.".format( - namespace, repo, response.status_code - ) + "Error when retrieving contributors project '{0}/{1}'. " + "Got status_code '{2}'.".format(namespace, repo, response.status_code) ) raise PagureError( "Couldn't get contributors for project '{0}/{1}'".format( @@ -468,9 +468,8 @@ class Pagure: if response.status_code != 200: log.error( - "Error when getting default branch for project '{0}/{1}'. Got status_code '{2}'.".format( - namespace, repo, response.status_code - ) + "Error when getting default branch for project '{0}/{1}'. " + "Got status_code '{2}'.".format(namespace, repo, response.status_code) ) raise PagureError( "Couldn't get default branch for project '{0}/{1}'".format( diff --git a/toddlers/utils/pdc.py b/toddlers/utils/pdc.py index ea6961f..9e931ee 100644 --- a/toddlers/utils/pdc.py +++ b/toddlers/utils/pdc.py @@ -1,4 +1,4 @@ -from typing import Optional, Mapping +from typing import Mapping, Optional from pdc_client import PDCClient