From e001ff8a5a2a0a7ab5468590493a149394166e71 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 19 2019 12:39:47 +0000 Subject: [PATCH 1/3] Make the pagure_distgit code black and flake8 compliant We ran black on all the code and made it flake8 compliant with the import order plugin. Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure_distgit/forms.py b/pagure_distgit/forms.py index d75e7f0..6d59a56 100644 --- a/pagure_distgit/forms.py +++ b/pagure_distgit/forms.py @@ -9,12 +9,12 @@ """ -from __future__ import unicode_literals, print_function - -import wtforms +from __future__ import print_function, unicode_literals import pagure.forms +import wtforms + class AnityaForm(pagure.forms.PagureForm): """ Form to configure taiga for a project. """ @@ -29,16 +29,14 @@ class AnityaForm(pagure.forms.PagureForm): ], ) - + class BZOverrideForm(pagure.forms.PagureForm): """ Form to configure the Fedora/EPEL maintainer for a project. """ fedora_assignee = wtforms.StringField( - "Maintainer name", - [ wtforms.validators.optional(strip_whitespace=True) ], + "Maintainer name", [wtforms.validators.optional(strip_whitespace=True)] ) epel_assignee = wtforms.StringField( "EPEL Maintainer name", - [ wtforms.validators.optional(strip_whitespace=True) ], + [wtforms.validators.optional(strip_whitespace=True)], ) - diff --git a/pagure_distgit/model.py b/pagure_distgit/model.py index 61537e1..4655be6 100644 --- a/pagure_distgit/model.py +++ b/pagure_distgit/model.py @@ -8,17 +8,15 @@ """ -from __future__ import unicode_literals, print_function +from __future__ import print_function, unicode_literals import logging -import sqlalchemy as sa - -from sqlalchemy.orm import backref -from sqlalchemy.orm import relation -from pagure.lib.model_base import BASE from pagure.lib.model import Project +from pagure.lib.model_base import BASE +import sqlalchemy as sa +from sqlalchemy.orm import backref, relation _log = logging.getLogger(__name__) @@ -76,12 +74,8 @@ class PagureBZOverride(BASE): index=True, ) - epel_assignee = sa.Column( - sa.String(255), unique=False - ) - fedora_assignee = sa.Column( - sa.String(255), unique=False - ) + epel_assignee = sa.Column(sa.String(255), unique=False) + fedora_assignee = sa.Column(sa.String(255), unique=False) project = relation( "Project", diff --git a/pagure_distgit/plugin.py b/pagure_distgit/plugin.py index 9d08d58..79f1d22 100644 --- a/pagure_distgit/plugin.py +++ b/pagure_distgit/plugin.py @@ -9,22 +9,24 @@ """ -from __future__ import unicode_literals, print_function +from __future__ import print_function, unicode_literals + import collections -import datetime import logging import flask -import requests -from sqlalchemy.exc import SQLAlchemyError import pagure.utils -from pagure.api import api_method, APIERROR, api_login_required -from pagure.api.utils import _get_repo, _check_token +from pagure.api import APIERROR, api_login_required, api_method +from pagure.api.utils import _check_token, _get_repo import pagure_distgit.forms from pagure_distgit import model +import requests + +from sqlalchemy.exc import SQLAlchemyError + _log = logging.getLogger(__name__) @@ -122,8 +124,8 @@ def _is_active_in_pdc(name, namespace): raise pagure.exceptions.APIError( 500, error_code=APIERROR.ENOCODE, - error="This pagure instance has no PDC_URL configured, please inform" - " your pagure administrators", + error="This pagure instance has no PDC_URL configured, please " + "inform your pagure administrators", ) else: pdc_url = "%s/component-branches/" % pdc_url.rstrip("/") @@ -141,7 +143,7 @@ def _is_active_in_pdc(name, namespace): try: pdc_namespace = to_pdc_namespace[namespace] - except: + except Exception: raise pagure.exceptions.APIError( 500, error_code=APIERROR.ENOCODE, @@ -167,7 +169,7 @@ def _is_active_in_pdc(name, namespace): try: data = req.json() - except: + except Exception: raise pagure.exceptions.APIError( 500, error_code=APIERROR.ENOCODE, @@ -177,7 +179,7 @@ def _is_active_in_pdc(name, namespace): _log.info( "%s/%s is active: %s", namespace, name, data["results"][0]["active"] ) - return data["results"][0]["active"] == True + return data["results"][0]["active"] is True @DISTGIT_NS.route("/take_orphan//", methods=["POST"]) @@ -323,11 +325,16 @@ def bodhi_updates_endpoint(namespace, repo): updates[update["release"]["name"]][update["status"]] = name if html: - html_output = """ - -""" + html_output = ( + '
ReleaseStable versionVersion in testing
\n' + '\n' + ) for release in sorted(releases, reverse=True): - row = "" + row = ( + "" + "" + ) stable = "" if updates.get(release, {}).get("stable"): stable = ( @@ -337,8 +344,9 @@ def bodhi_updates_endpoint(namespace, repo): ) ) else: - # This makes things a little slower and is only needed up until all releases will have gone - # through bodhi all the time (ie: up until about F31 is eol). + # This makes things a little slower and is only needed up until + # all releases will have gone through bodhi all the time + # (ie: up until about F31 is eol). mdapi_url = "https://mdapi.fedoraproject.org/%s/srcpkg/%s" % ( release.lower(), repo.name, @@ -384,8 +392,10 @@ def bzoverride_get_endpoint(repo, namespace): Defaults to the repo user if unset. """ repo = _get_repo(repo, namespace=namespace) - output = {"fedora_assignee": repo.user.username, - "epel_assignee": repo.user.username } + output = { + "fedora_assignee": repo.user.username, + "epel_assignee": repo.user.username, + } if repo.bzoverride: if repo.bzoverride.fedora_assignee: output["fedora_assignee"] = repo.bzoverride.fedora_assignee @@ -406,10 +416,7 @@ def bzoverride_patch_endpoint(repo, namespace): is_site_admin = pagure.utils.is_admin() # Only allow the main admin and Pagure site admins to modify projects' # monitoring, even if the user has the right ACLs on their token - if ( - flask.g.fas_user.username != repo.user.username - and not is_site_admin - ): + if flask.g.fas_user.username != repo.user.username and not is_site_admin: raise pagure.exceptions.APIError( 401, error_code=APIERROR.EMODIFYPROJECTNOTALLOWED ) @@ -431,8 +438,9 @@ def bzoverride_patch_endpoint(repo, namespace): flask.g.session.add(repo) else: mapping = model.PagureBZOverride( - project_id=repo.id, epel_assignee=epel_assignee, - fedora_assignee=fedora_assignee + project_id=repo.id, + epel_assignee=epel_assignee, + fedora_assignee=fedora_assignee, ) flask.g.session.add(mapping) flask.g.session.commit() diff --git a/pagure_distgit_tests/bugzilla_overrides_tests.py b/pagure_distgit_tests/bugzilla_overrides_tests.py index 6f27149..6b86a9c 100644 --- a/pagure_distgit_tests/bugzilla_overrides_tests.py +++ b/pagure_distgit_tests/bugzilla_overrides_tests.py @@ -193,7 +193,6 @@ class PagureFlaskApiProjectBZOverrideTests(tests.Modeltests): user = tests.FakeUser(username="pingou") with tests.user_set(self.app.application, user): # change one assignee - expected_result = {"epel_assignee": "foo"} datainput = {"epel_assignee": "foo"} output = self.app.post( "/_dg/bzoverrides/somenamespace/test3", data=datainput diff --git a/pagure_distgit_tests/dist_git_auth_tests.py b/pagure_distgit_tests/dist_git_auth_tests.py index 36a2ce4..0b6825e 100644 --- a/pagure_distgit_tests/dist_git_auth_tests.py +++ b/pagure_distgit_tests/dist_git_auth_tests.py @@ -1,13 +1,11 @@ from __future__ import print_function -import tempfile -import os - from mock import Mock, patch import pagure.config import pagure.exceptions import pagure.lib.model + try: from pagure.lib import _get_project as get_project except ImportError: @@ -19,7 +17,6 @@ import tests import dist_git_auth - def patch_pdc(values): """ Decorator to patch the PDC calls to return values for this test. @@ -31,6 +28,7 @@ def patch_pdc(values): for rpms and modules. e.g.: {'rpm/test': {'f28': True, 'f27': False}} """ + def pdc_get_paged(_, global_component, type, name, fields): """ Function that emulates the pdc.get_paged call @@ -43,7 +41,7 @@ def patch_pdc(values): name (string): The branch name fields (list): Always ["active"] """ - fullname = '%s/%s' % (type, global_component) + fullname = "%s/%s" % (type, global_component) if fullname not in values: return [] val = values[fullname] @@ -57,11 +55,16 @@ def patch_pdc(values): def decorator(func): def test_wrapper(*args, **kwargs): - with patch.object(dist_git_auth.PDCClient, '__getitem__'): - with patch.object(dist_git_auth.PDCClient, 'get_paged', - side_effect=pdc_get_paged): + with patch.object(dist_git_auth.PDCClient, "__getitem__"): + with patch.object( + dist_git_auth.PDCClient, + "get_paged", + side_effect=pdc_get_paged, + ): return func(*args, **kwargs) + return test_wrapper + return decorator @@ -74,8 +77,8 @@ class DistGitAuthTests(tests.Modeltests): """ Set up the environment in which to run the tests. """ super(DistGitAuthTests, self).setUp() - pagure.config.config['ACL_DEBUG'] = True - pagure.config.config['EXTERNAL_COMMITTER'] = {"relenggroup": {}} + pagure.config.config["ACL_DEBUG"] = True + pagure.config.config["EXTERNAL_COMMITTER"] = {"relenggroup": {}} pagure.config.config.update(self.dga_config) self.dga = dist_git_auth.DistGitAuth() @@ -85,17 +88,17 @@ class DistGitAuthTests(tests.Modeltests): # Create an RCM user/group rcmuser = pagure.lib.model.User( - user='releng', - fullname='Release Engineering', - token='aaabbbcd', - default_email='rcm@local.local', + user="releng", + fullname="Release Engineering", + token="aaabbbcd", + default_email="rcm@local.local", ) self.session.add(rcmuser) self.session.flush() rcmgroup = pagure.lib.model.PagureGroup( - group_name='relenggroup', - group_type='user', - display_name='Releng group', + group_name="relenggroup", + group_type="user", + display_name="Releng group", user_id=rcmuser.id, ) self.session.add(rcmgroup) @@ -108,23 +111,28 @@ class DistGitAuthTests(tests.Modeltests): self.dga = None super(DistGitAuthTests, self).tearDown() - def create_namespaced_project(self, namespace, name, is_fork=False, settings={}): + def create_namespaced_project( + self, namespace, name, is_fork=False, settings={} + ): item = pagure.lib.model.Project( user_id=1, # pingou name=name, is_fork=is_fork, parent_id=3 if is_fork else None, - description='namespaced test project', - hook_token='aaabbbeee', + description="namespaced test project", + hook_token="aaabbbeee", namespace=namespace, - settings=settings + settings=settings, ) item.close_status = [ - 'Invalid', 'Insufficient data', 'Fixed', 'Duplicate'] + "Invalid", + "Insufficient data", + "Fixed", + "Duplicate", + ] self.session.add(item) self.session.commit() - return get_project( - self.session, name=name, namespace=namespace) + return get_project(self.session, name=name, namespace=namespace) def expect_info_msg(self, expect_msg): found = False @@ -135,7 +143,8 @@ class DistGitAuthTests(tests.Modeltests): found = True if not found: raise AssertionError( - "Info message '%s' expected but not found" % expect_msg) + "Info message '%s' expected but not found" % expect_msg + ) class DistGitAuthTestsGeneric(DistGitAuthTests): @@ -150,7 +159,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): refname=None, pull_request=None, repodir=None, - repotype='tickets', + repotype="tickets", revfrom=None, revto=None, is_internal=False, @@ -162,7 +171,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): def test_branch_deletion(self): dist_git_auth.is_forced_push.return_value = True - project = self.create_namespaced_project('rpms', 'test') + project = self.create_namespaced_project("rpms", "test") self.assertFalse( self.dga.check_acl( @@ -172,9 +181,9 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): refname=None, pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, - revto='0000000000000000000000000000000000000000', + revto="0000000000000000000000000000000000000000", is_internal=False, ) ) @@ -184,7 +193,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): def test_forced_push(self): dist_git_auth.is_forced_push.return_value = True - project = self.create_namespaced_project('rpms', 'test') + project = self.create_namespaced_project("rpms", "test") self.assertFalse( self.dga.check_acl( @@ -194,7 +203,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): refname=None, pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -204,7 +213,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): self.expect_info_msg("Forced pushes are not allowed") def test_internal(self): - project = self.create_namespaced_project('rpms', 'test') + project = self.create_namespaced_project("rpms", "test") self.assertTrue( self.dga.check_acl( @@ -214,7 +223,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): refname=None, pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=True, @@ -224,7 +233,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): self.expect_info_msg("Internal push allowed") def test_deploykey(self): - project = self.create_namespaced_project('rpms', 'test') + project = self.create_namespaced_project("rpms", "test") self.assertFalse( self.dga.check_acl( @@ -234,7 +243,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): refname=None, pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -244,7 +253,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): self.expect_info_msg("Deploy keys are disabled") def test_invalid_user(self): - project = self.create_namespaced_project('rpms', 'test') + project = self.create_namespaced_project("rpms", "test") self.assertRaises( pagure.exceptions.PagureException, @@ -255,14 +264,14 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): refname=None, pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, ) def test_unprotected_committer(self): - project = self.create_namespaced_project('unprotected', 'test') + project = self.create_namespaced_project("unprotected", "test") self.assertTrue( self.dga.check_acl( @@ -272,7 +281,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): refname="refs/heads/mywip", pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -282,7 +291,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): self.expect_info_msg("Committer push") def test_unprotected_non_committer(self): - project = self.create_namespaced_project('unprotected', 'test') + project = self.create_namespaced_project("unprotected", "test") self.assertFalse( self.dga.check_acl( @@ -292,7 +301,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): refname="refs/heads/mywip", pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -302,7 +311,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): self.expect_info_msg("Fall-through deny") def test_unprotected_pr_required_pr(self): - project = self.create_namespaced_project('unprotected', 'test') + project = self.create_namespaced_project("unprotected", "test") self.dga.global_pr_only = True self.assertTrue( @@ -313,7 +322,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): refname="refs/heads/mywip", pull_request=True, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -323,7 +332,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): self.expect_info_msg("Committer push") def test_unprotected_pr_required_no_pr(self): - project = self.create_namespaced_project('unprotected', 'test') + project = self.create_namespaced_project("unprotected", "test") self.dga.global_pr_only = True self.assertFalse( @@ -334,7 +343,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): refname="refs/heads/mywip", pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -344,7 +353,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): self.expect_info_msg("A pull request is required for this branch") def test_unprotected_pr_required_no_pr_cvsadmin(self): - project = self.create_namespaced_project('unprotected', 'test') + project = self.create_namespaced_project("unprotected", "test") self.dga.global_pr_only = True self.assertTrue( @@ -355,7 +364,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): refname="refs/heads/mywip", pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -365,7 +374,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): self.expect_info_msg("Committer push") def test_unprotected_pr_required_requests(self): - project = self.create_namespaced_project('unprotected', 'test') + project = self.create_namespaced_project("unprotected", "test") self.dga.global_pr_only = True self.assertTrue( @@ -376,7 +385,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): refname="refs/heads/mywip", pull_request=None, repodir=None, - repotype='requests', + repotype="requests", revfrom=None, revto=None, is_internal=False, @@ -387,7 +396,9 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): def test_unprotected_pr_required_repo_pr_only_no_pr(self): settings = {"pull_request_access_only": True} - project = self.create_namespaced_project('unprotected', 'test', settings=settings) + project = self.create_namespaced_project( + "unprotected", "test", settings=settings + ) self.assertFalse( self.dga.check_acl( @@ -397,7 +408,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): refname="refs/heads/mywip", pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -409,9 +420,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): def test_unprotected_pr_required_repo_pr_only(self): settings = {"pull_request_access_only": True} project = self.create_namespaced_project( - 'unprotected', - 'test', - settings=settings + "unprotected", "test", settings=settings ) self.assertTrue( self.dga.check_acl( @@ -421,7 +430,7 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): refname="refs/heads/mywip", pull_request="pull_request", repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -433,20 +442,18 @@ class DistGitAuthTestsGeneric(DistGitAuthTests): class DistGitAuthTestsFedora(DistGitAuthTests): dga_config = { - 'PR_ONLY': False, - 'ACL_BLOCK_UNSPECIFIED': False, - 'BLACKLIST_RES': ['refs/heads/c[0-9]+.*'], - 'UNSPECIFIED_BLACKLIST_RES': [ - 'refs/heads/f[0-9]+', - ], - 'RCM_GROUP': 'relenggroup', - 'RCM_BRANCHES': ['refs/heads/f[0-9]+'], - 'ACL_PROTECTED_NAMESPACES': ['rpms', 'modules', 'container'], - 'PDC_URL': 'invalid://', + "PR_ONLY": False, + "ACL_BLOCK_UNSPECIFIED": False, + "BLACKLIST_RES": ["refs/heads/c[0-9]+.*"], + "UNSPECIFIED_BLACKLIST_RES": ["refs/heads/f[0-9]+"], + "RCM_GROUP": "relenggroup", + "RCM_BRANCHES": ["refs/heads/f[0-9]+"], + "ACL_PROTECTED_NAMESPACES": ["rpms", "modules", "container"], + "PDC_URL": "invalid://", } def test_protected_blacklisted_ref(self): - project = self.create_namespaced_project('rpms', 'test') + project = self.create_namespaced_project("rpms", "test") self.assertFalse( self.dga.check_acl( @@ -456,7 +463,7 @@ class DistGitAuthTestsFedora(DistGitAuthTests): refname="refs/heads/c7", pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -466,7 +473,7 @@ class DistGitAuthTestsFedora(DistGitAuthTests): self.expect_info_msg("Ref refs/heads/c7 is blocked") def test_protected_rcm(self): - project = self.create_namespaced_project('rpms', 'test') + project = self.create_namespaced_project("rpms", "test") self.assertTrue( self.dga.check_acl( @@ -476,7 +483,7 @@ class DistGitAuthTestsFedora(DistGitAuthTests): refname="refs/heads/f27", pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -487,7 +494,7 @@ class DistGitAuthTestsFedora(DistGitAuthTests): @patch_pdc({"rpm/test": {"f26": False, "f27": True}}) def test_protected_unsupported_branch(self): - project = self.create_namespaced_project('rpms', 'test') + project = self.create_namespaced_project("rpms", "test") self.assertFalse( self.dga.check_acl( @@ -497,7 +504,7 @@ class DistGitAuthTestsFedora(DistGitAuthTests): refname="refs/heads/f26", pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -508,7 +515,7 @@ class DistGitAuthTestsFedora(DistGitAuthTests): @patch_pdc({"rpm/test": {"f26": False, "f27": True}}) def test_protected_supported_branch_committer(self): - project = self.create_namespaced_project('rpms', 'test') + project = self.create_namespaced_project("rpms", "test") self.assertTrue( self.dga.check_acl( @@ -518,7 +525,7 @@ class DistGitAuthTestsFedora(DistGitAuthTests): refname="refs/heads/f27", pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -529,7 +536,7 @@ class DistGitAuthTestsFedora(DistGitAuthTests): @patch_pdc({"rpm/test": {"f26": False, "f27": True}}) def test_protected_supported_branch_non_committer(self): - project = self.create_namespaced_project('rpms', 'test') + project = self.create_namespaced_project("rpms", "test") self.assertFalse( self.dga.check_acl( @@ -539,7 +546,7 @@ class DistGitAuthTestsFedora(DistGitAuthTests): refname="refs/heads/f27", pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -550,7 +557,7 @@ class DistGitAuthTestsFedora(DistGitAuthTests): @patch_pdc({"rpm/test": {"f26": False, "f27": True}}) def test_protected_unspecified_branch_blacklisted(self): - project = self.create_namespaced_project('rpms', 'test') + project = self.create_namespaced_project("rpms", "test") self.assertFalse( self.dga.check_acl( @@ -560,7 +567,7 @@ class DistGitAuthTestsFedora(DistGitAuthTests): refname="refs/heads/f28", pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -571,7 +578,7 @@ class DistGitAuthTestsFedora(DistGitAuthTests): @patch_pdc({"rpm/test": {"f26": False, "f27": True}}) def test_protected_unspecified_branch_normal_committer(self): - project = self.create_namespaced_project('rpms', 'test') + project = self.create_namespaced_project("rpms", "test") self.assertTrue( self.dga.check_acl( @@ -581,7 +588,7 @@ class DistGitAuthTestsFedora(DistGitAuthTests): refname="refs/heads/mywip", pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -592,7 +599,7 @@ class DistGitAuthTestsFedora(DistGitAuthTests): @patch_pdc({"rpm/test": {"f26": False, "f27": True}}) def test_protected_unspecified_branch_normal_non_committer(self): - project = self.create_namespaced_project('rpms', 'test') + project = self.create_namespaced_project("rpms", "test") self.assertFalse( self.dga.check_acl( @@ -602,7 +609,7 @@ class DistGitAuthTestsFedora(DistGitAuthTests): refname="refs/heads/mywip", pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -614,14 +621,14 @@ class DistGitAuthTestsFedora(DistGitAuthTests): class DistGitAuthTestsCentOS(DistGitAuthTests): dga_config = { - 'PR_ONLY': False, - 'ACL_BLOCK_UNSPECIFIED': True, - 'BLACKLIST_RES': ['refs/heads/f[0-9]+.*'], - 'RCM_GROUP': 'relenggroup', - 'RCM_BRANCHES': ['refs/heads/c[0-9]+'], - 'SUPPORTED_SIGS': ['sig-core'], - 'SIG_PREFIXES': ['refs/heads/c7'], - 'ACL_PROTECTED_NAMESPACES': ['rpms'], + "PR_ONLY": False, + "ACL_BLOCK_UNSPECIFIED": True, + "BLACKLIST_RES": ["refs/heads/f[0-9]+.*"], + "RCM_GROUP": "relenggroup", + "RCM_BRANCHES": ["refs/heads/c[0-9]+"], + "SUPPORTED_SIGS": ["sig-core"], + "SIG_PREFIXES": ["refs/heads/c7"], + "ACL_PROTECTED_NAMESPACES": ["rpms"], } def setUp(self): @@ -629,17 +636,17 @@ class DistGitAuthTestsCentOS(DistGitAuthTests): # Create an RCM user/group arrfab = pagure.lib.model.User( - user='arrfab', - fullname='Fabian Arriton', - token='aaabbbcd', - default_email='arrfab@local.local', + user="arrfab", + fullname="Fabian Arriton", + token="aaabbbcd", + default_email="arrfab@local.local", ) self.session.add(arrfab) self.session.flush() sigcore = pagure.lib.model.PagureGroup( - group_name='sig-core', - group_type='user', - display_name='Core SIG group', + group_name="sig-core", + group_type="user", + display_name="Core SIG group", user_id=arrfab.id, ) self.session.add(sigcore) @@ -648,7 +655,7 @@ class DistGitAuthTestsCentOS(DistGitAuthTests): self.session.commit() def test_protected_blacklisted_ref(self): - project = self.create_namespaced_project('rpms', 'test') + project = self.create_namespaced_project("rpms", "test") self.assertFalse( self.dga.check_acl( @@ -658,7 +665,7 @@ class DistGitAuthTestsCentOS(DistGitAuthTests): refname="refs/heads/f27", pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -668,7 +675,7 @@ class DistGitAuthTestsCentOS(DistGitAuthTests): self.expect_info_msg("Ref refs/heads/f27 is blocked") def test_protected_rcm(self): - project = self.create_namespaced_project('rpms', 'test') + project = self.create_namespaced_project("rpms", "test") self.assertTrue( self.dga.check_acl( @@ -678,7 +685,7 @@ class DistGitAuthTestsCentOS(DistGitAuthTests): refname="refs/heads/c7", pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -688,7 +695,7 @@ class DistGitAuthTestsCentOS(DistGitAuthTests): self.expect_info_msg("RCM push") def test_protected_sig_sig_member(self): - project = self.create_namespaced_project('rpms', 'test') + project = self.create_namespaced_project("rpms", "test") self.assertTrue( self.dga.check_acl( @@ -698,7 +705,7 @@ class DistGitAuthTestsCentOS(DistGitAuthTests): refname="refs/heads/c7-sig-core-test", pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -708,7 +715,7 @@ class DistGitAuthTestsCentOS(DistGitAuthTests): self.expect_info_msg("SIG push") def test_protected_sig_sig_member_precise(self): - project = self.create_namespaced_project('rpms', 'test') + project = self.create_namespaced_project("rpms", "test") self.assertTrue( self.dga.check_acl( @@ -718,7 +725,7 @@ class DistGitAuthTestsCentOS(DistGitAuthTests): refname="refs/heads/c7-sig-core", pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -728,7 +735,7 @@ class DistGitAuthTestsCentOS(DistGitAuthTests): self.expect_info_msg("SIG push") def test_protected_sig_no_sig_member(self): - project = self.create_namespaced_project('rpms', 'test') + project = self.create_namespaced_project("rpms", "test") self.assertFalse( self.dga.check_acl( @@ -738,7 +745,7 @@ class DistGitAuthTestsCentOS(DistGitAuthTests): refname="refs/heads/c7-sig-core-test", pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, @@ -748,7 +755,7 @@ class DistGitAuthTestsCentOS(DistGitAuthTests): self.expect_info_msg("Access to namespace rpms is restricted") def test_protected_sig_sig_member_no_sig_branch(self): - project = self.create_namespaced_project('rpms', 'test') + project = self.create_namespaced_project("rpms", "test") self.assertFalse( self.dga.check_acl( @@ -758,7 +765,7 @@ class DistGitAuthTestsCentOS(DistGitAuthTests): refname="refs/heads/c7", pull_request=None, repodir=None, - repotype='main', + repotype="main", revfrom=None, revto=None, is_internal=False, From 60f7538a85d072327da20724f2634c387c2d4b89 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 19 2019 12:39:47 +0000 Subject: [PATCH 2/3] Adjust the requirements for testing Signed-off-by: Pierre-Yves Chibon --- diff --git a/requirements-testing.txt b/requirements-testing.txt index 1284c92..80bae14 100644 --- a/requirements-testing.txt +++ b/requirements-testing.txt @@ -1 +1,4 @@ -pdc_client \ No newline at end of file +flake8 +flake8-import-order +nose +pdc_client From e97fdd5ba8cf25da84d4730e71afbcaa2884e144 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 19 2019 12:39:47 +0000 Subject: [PATCH 3/3] Add a test for the coding style we want to follow on pagure-dist-git Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure_distgit_tests/tests_style.py b/pagure_distgit_tests/tests_style.py new file mode 100644 index 0000000..c2f4b9a --- /dev/null +++ b/pagure_distgit_tests/tests_style.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" + (c) 2019 - Copyright Red Hat Inc + + Authors: + Pierre-Yves Chibon + +Tests for flake8 and black compliance of the code + +""" + +from __future__ import unicode_literals, absolute_import + +import os +import subprocess +import sys +import unittest + +import six + +REPO_PATH = os.path.abspath( + os.path.join(os.path.dirname(__file__), "..", "pagure_distgit") +) +TESTS_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__))) + + +class TestStyle(unittest.TestCase): + """This test class contains tests pertaining to code style.""" + + def test_code_with_flake8(self): + """Enforce PEP-8 compliance on the codebase. + + This test runs flake8 on the code, and will fail if it returns a + non-zero exit code. + """ + # We ignore E712, which disallows non-identity comparisons with True and False + # We ignore W503, which disallows line break before binary operator + flake8_command = [ + sys.executable, + "-m", + "flake8", + "--ignore=E712,W503,E203", + REPO_PATH, + ] + + # check if we have an old flake8 or not + import flake8 + + flake8_v = flake8.__version__.split(".") + for idx, val in enumerate(flake8_v): + try: + val = int(val) + except ValueError: + pass + flake8_v[idx] = val + old_flake = tuple(flake8_v) < (3, 0) + + if old_flake: + raise unittest.SkipTest("Flake8 version too old to be useful") + + proc = subprocess.Popen( + flake8_command, stdout=subprocess.PIPE, cwd=REPO_PATH + ) + print(proc.communicate()) + + self.assertEqual(proc.returncode, 0) + + @unittest.skipIf( + not (six.PY3 and sys.version_info.minor >= 6), + "Black is only available in python 3.6+", + ) + def test_code_with_black(self): + """Enforce black compliance on the codebase. + + This test runs black on the code, and will fail if it returns a + non-zero exit code. + """ + black_command = [ + sys.executable, + "-m", + "black", + "-l", + "79", + "--check", + "--exclude", + '"/(\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|' + '_build|buck-out|build|dist)/"', # noqa + REPO_PATH, + TESTS_PATH, + ] + proc = subprocess.Popen( + black_command, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + cwd=REPO_PATH, + ) + stdout, stderr = proc.communicate() + print("stdout: ") + print(stdout.decode("utf-8")) + print("stderr: ") + print(stderr.decode("utf-8")) + + self.assertEqual(proc.returncode, 0) + + +if __name__ == "__main__": + unittest.main(verbosity=2)
ReleaseStable version' + 'Version in testing
{release}{stable}{testing}
{release}{stable}{testing}