Browse Source

Project wide black fixes, including tests, docs and all

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
Pierre-Yves Chibon 5 years ago
parent
commit
73d1200552
100 changed files with 16116 additions and 13816 deletions
  1. 24 16
      createdb.py
  2. 231 234
      dev-data.py
  3. 2 1
      dev/containers/f29-rpms-py3
  4. 20 9
      dev/run-tests-container.py
  5. 90 90
      doc/conf.py
  6. 3 8
      fedmsg.d/pagure.py
  7. 1 3
      fedmsg.d/pagure_ci.py
  8. 1 1
      files/aclchecker.py
  9. 38 26
      files/api_key_expire_mail.py
  10. 6 6
      files/emoji_clean_json.py
  11. 28 18
      files/mirror_project_in.py
  12. 67 55
      pagure-ev/pagure_stream_server.py
  13. 95 91
      pagure-milters/comment_email_milter.py
  14. 32 18
      rundocserver.py
  15. 40 26
      runserver.py
  16. 95 47
      runtests.py
  17. 21 15
      runworker.py
  18. 32 30
      setup.py
  19. 248 223
      tests/__init__.py
  20. 9 8
      tests/test_alembic.py
  21. 3 2
      tests/test_dev_data.py
  22. 17 17
      tests/test_fnmatch.py
  23. 341 313
      tests/test_pagure_admin.py
  24. 43 47
      tests/test_pagure_exclude_group_index.py
  25. 104 101
      tests/test_pagure_flask.py
  26. 128 123
      tests/test_pagure_flask_api.py
  27. 51 43
      tests/test_pagure_flask_api_auth.py
  28. 355 366
      tests/test_pagure_flask_api_fork.py
  29. 80 89
      tests/test_pagure_flask_api_fork_assign.py
  30. 445 394
      tests/test_pagure_flask_api_fork_update.py
  31. 154 209
      tests/test_pagure_flask_api_group.py
  32. 847 916
      tests/test_pagure_flask_api_issue.py
  33. 109 126
      tests/test_pagure_flask_api_issue_change_status.py
  34. 127 141
      tests/test_pagure_flask_api_issue_comment.py
  35. 131 150
      tests/test_pagure_flask_api_issue_create.py
  36. 93 61
      tests/test_pagure_flask_api_issue_custom_fields.py
  37. 344 318
      tests/test_pagure_flask_api_pr_flag.py
  38. 292 346
      tests/test_pagure_flask_api_project.py
  39. 16 17
      tests/test_pagure_flask_api_project_blockuser.py
  40. 90 107
      tests/test_pagure_flask_api_project_update_watch.py
  41. 257 242
      tests/test_pagure_flask_api_ui_private_repo.py
  42. 776 620
      tests/test_pagure_flask_api_user.py
  43. 91 74
      tests/test_pagure_flask_docs.py
  44. 61 59
      tests/test_pagure_flask_dump_load_ticket.py
  45. 45 41
      tests/test_pagure_flask_form.py
  46. 296 336
      tests/test_pagure_flask_internal.py
  47. 171 148
      tests/test_pagure_flask_rebase.py
  48. 579 397
      tests/test_pagure_flask_ui_app.py
  49. 166 179
      tests/test_pagure_flask_ui_app_browse.py
  50. 152 146
      tests/test_pagure_flask_ui_app_give_project.py
  51. 21 16
      tests/test_pagure_flask_ui_app_index.py
  52. 113 93
      tests/test_pagure_flask_ui_app_userdash.py
  53. 170 122
      tests/test_pagure_flask_ui_archives.py
  54. 93 63
      tests/test_pagure_flask_ui_clone.py
  55. 393 295
      tests/test_pagure_flask_ui_fork.py
  56. 343 219
      tests/test_pagure_flask_ui_groups.py
  57. 50 47
      tests/test_pagure_flask_ui_issue_pr_link.py
  58. 454 415
      tests/test_pagure_flask_ui_issues.py
  59. 273 268
      tests/test_pagure_flask_ui_issues_acl_checks.py
  60. 360 334
      tests/test_pagure_flask_ui_issues_open_access.py
  61. 118 104
      tests/test_pagure_flask_ui_issues_private.py
  62. 149 126
      tests/test_pagure_flask_ui_issues_read_only.py
  63. 104 104
      tests/test_pagure_flask_ui_issues_templates.py
  64. 557 366
      tests/test_pagure_flask_ui_login.py
  65. 99 85
      tests/test_pagure_flask_ui_no_master_branch.py
  66. 96 60
      tests/test_pagure_flask_ui_old_commit.py
  67. 51 55
      tests/test_pagure_flask_ui_plugins.py
  68. 6 7
      tests/test_pagure_flask_ui_plugins_default_hook.py
  69. 177 92
      tests/test_pagure_flask_ui_plugins_fedmsg.py
  70. 105 54
      tests/test_pagure_flask_ui_plugins_irc.py
  71. 79 57
      tests/test_pagure_flask_ui_plugins_mail.py
  72. 150 92
      tests/test_pagure_flask_ui_plugins_mirror.py
  73. 165 75
      tests/test_pagure_flask_ui_plugins_noff.py
  74. 253 159
      tests/test_pagure_flask_ui_plugins_pagure_ci.py
  75. 241 146
      tests/test_pagure_flask_ui_plugins_pagure_hook.py
  76. 118 66
      tests/test_pagure_flask_ui_plugins_pagure_no_new_branch.py
  77. 102 62
      tests/test_pagure_flask_ui_plugins_pagure_request_hook.py
  78. 109 72
      tests/test_pagure_flask_ui_plugins_pagure_ticket_hook.py
  79. 96 63
      tests/test_pagure_flask_ui_plugins_rtd_hook.py
  80. 93 54
      tests/test_pagure_flask_ui_plugins_unsigned.py
  81. 90 93
      tests/test_pagure_flask_ui_pr_no_sources.py
  82. 684 452
      tests/test_pagure_flask_ui_priorities.py
  83. 83 82
      tests/test_pagure_flask_ui_quick_reply.py
  84. 275 235
      tests/test_pagure_flask_ui_remote_pr.py
  85. 491 402
      tests/test_pagure_flask_ui_repo.py
  86. 141 90
      tests/test_pagure_flask_ui_repo_delete_project.py
  87. 168 151
      tests/test_pagure_flask_ui_repo_flag_commit.py
  88. 69 58
      tests/test_pagure_flask_ui_repo_milestones.py
  89. 85 74
      tests/test_pagure_flask_ui_repo_slash_name.py
  90. 141 101
      tests/test_pagure_flask_ui_repo_view_file.py
  91. 312 238
      tests/test_pagure_flask_ui_roadmap.py
  92. 97 88
      tests/test_pagure_flask_ui_slash_branch_name.py
  93. 72 89
      tests/test_pagure_flask_ui_star_project.py
  94. 23 23
      tests/test_pagure_flask_util.py
  95. 76 48
      tests/test_pagure_hooks_pagure_hook.py
  96. 262 272
      tests/test_pagure_lib.py
  97. 115 129
      tests/test_pagure_lib_add_user_to_project.py
  98. 43 58
      tests/test_pagure_lib_drop_issue.py
  99. 51 34
      tests/test_pagure_lib_encoding_utils.py
  100. 253 275
      tests/test_pagure_lib_git.py

+ 24 - 16
createdb.py

@@ -8,33 +8,40 @@ import os
 
 
 
 
 parser = argparse.ArgumentParser(
 parser = argparse.ArgumentParser(
-    description='Create/Update the Pagure database')
+    description="Create/Update the Pagure database"
+)
 parser.add_argument(
 parser.add_argument(
-    '--config', '-c', dest='config',
-    help='Configuration file to use for pagure.')
+    "--config",
+    "-c",
+    dest="config",
+    help="Configuration file to use for pagure.",
+)
 parser.add_argument(
 parser.add_argument(
-    '--initial', '-i', dest='alembic_cfg',
-    help='With this option, the database will be automatically stamped to '
-         'the latest version according to alembic. Point to the alembic.ini '
-         'file to use.')
+    "--initial",
+    "-i",
+    dest="alembic_cfg",
+    help="With this option, the database will be automatically stamped to "
+    "the latest version according to alembic. Point to the alembic.ini "
+    "file to use.",
+)
 
 
 
 
 args = parser.parse_args()
 args = parser.parse_args()
 
 
 if args.config:
 if args.config:
     config = args.config
     config = args.config
-    if not config.startswith('/'):
+    if not config.startswith("/"):
         here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
         here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
         config = os.path.join(here, config)
         config = os.path.join(here, config)
-    os.environ['PAGURE_CONFIG'] = config
+    os.environ["PAGURE_CONFIG"] = config
 
 
 
 
 if args.alembic_cfg:
 if args.alembic_cfg:
-    if not args.alembic_cfg.endswith('alembic.ini'):
-        print('--initial should point to the alembic.ini file to use.')
+    if not args.alembic_cfg.endswith("alembic.ini"):
+        print("--initial should point to the alembic.ini file to use.")
         sys.exit(1)
         sys.exit(1)
     if not os.path.exists(args.alembic_cfg):
     if not os.path.exists(args.alembic_cfg):
-        print('The file `{0}` could not be found'.format(args.alembic_cfg))
+        print("The file `{0}` could not be found".format(args.alembic_cfg))
         sys.exit(2)
         sys.exit(2)
 
 
 
 
@@ -44,7 +51,8 @@ from pagure.lib import model
 _config = pagure.config.reload_config()
 _config = pagure.config.reload_config()
 
 
 model.create_tables(
 model.create_tables(
-    _config['DB_URL'],
-    _config.get('PATH_ALEMBIC_INI', args.alembic_cfg),
-    acls=_config.get('ACLS', {}),
-    debug=True)
+    _config["DB_URL"],
+    _config.get("PATH_ALEMBIC_INI", args.alembic_cfg),
+    acls=_config.get("ACLS", {}),
+    debug=True,
+)

+ 231 - 234
dev-data.py

@@ -23,24 +23,24 @@ from pagure.lib.model import create_default_status
 from pagure.lib.repo import PagureRepo
 from pagure.lib.repo import PagureRepo
 
 
 
 
-'''
+"""
 Usage:
 Usage:
 python dev-data.py --init
 python dev-data.py --init
 python dev-data.py --clean
 python dev-data.py --clean
 python dev-data.py --populate
 python dev-data.py --populate
 python dev-data.py --all
 python dev-data.py --all
-'''
+"""
 
 
 _config = pagure.config.reload_config()
 _config = pagure.config.reload_config()
 
 
 
 
 def empty_dev_db(session):
 def empty_dev_db(session):
-    print('')
-    print('WARNING: Deleting all data from', _config['DB_URL'])
+    print("")
+    print("WARNING: Deleting all data from", _config["DB_URL"])
     response = os.environ.get("FORCE_DELETE")
     response = os.environ.get("FORCE_DELETE")
     if not response:
     if not response:
-        response = six.moves.input('Do you want to continue? (yes/no)    ')
-    if response.lower().startswith('y'):
+        response = six.moves.input("Do you want to continue? (yes/no)    ")
+    if response.lower().startswith("y"):
         tables = reversed(pagure.lib.model_base.BASE.metadata.sorted_tables)
         tables = reversed(pagure.lib.model_base.BASE.metadata.sorted_tables)
         for tbl in tables:
         for tbl in tables:
             session.execute(tbl.delete())
             session.execute(tbl.delete())
@@ -49,14 +49,12 @@ def empty_dev_db(session):
 
 
 
 
 def insert_data(session, username, user_email):
 def insert_data(session, username, user_email):
-    _config['EMAIL_SEND'] = False
-    _config['TESTING'] = True
+    _config["EMAIL_SEND"] = False
+    _config["TESTING"] = True
 
 
     ######################################
     ######################################
     # tags
     # tags
-    item = pagure.lib.model.Tag(
-        tag='tag1',
-    )
+    item = pagure.lib.model.Tag(tag="tag1")
     session.add(item)
     session.add(item)
     session.commit()
     session.commit()
 
 
@@ -64,46 +62,58 @@ def insert_data(session, username, user_email):
     # Users
     # Users
     # Create a couple of users
     # Create a couple of users
     pingou = item = pagure.lib.model.User(
     pingou = item = pagure.lib.model.User(
-        user='pingou',
-        fullname='PY C',
-        password=generate_hashed_value(u'testing123'),
+        user="pingou",
+        fullname="PY C",
+        password=generate_hashed_value("testing123"),
         token=None,
         token=None,
-        default_email='bar@pingou.com',
+        default_email="bar@pingou.com",
     )
     )
     session.add(item)
     session.add(item)
     session.commit()
     session.commit()
-    print("User created: {} <{}>, {}".format(item.user, item.default_email, 'testing123'))
+    print(
+        "User created: {} <{}>, {}".format(
+            item.user, item.default_email, "testing123"
+        )
+    )
 
 
     foo = item = pagure.lib.model.User(
     foo = item = pagure.lib.model.User(
-        user='foo',
-        fullname='foo bar',
-        password=generate_hashed_value(u'testing123'),
+        user="foo",
+        fullname="foo bar",
+        password=generate_hashed_value("testing123"),
         token=None,
         token=None,
-        default_email='foo@bar.com',
+        default_email="foo@bar.com",
     )
     )
     session.add(item)
     session.add(item)
     session.commit()
     session.commit()
-    print("User created: {} <{}>, {}".format(item.user, item.default_email, 'testing123'))
+    print(
+        "User created: {} <{}>, {}".format(
+            item.user, item.default_email, "testing123"
+        )
+    )
 
 
     you = item = pagure.lib.model.User(
     you = item = pagure.lib.model.User(
         user=username,
         user=username,
         fullname=username,
         fullname=username,
-        password=generate_hashed_value(u'testing123'),
+        password=generate_hashed_value("testing123"),
         token=None,
         token=None,
         default_email=user_email,
         default_email=user_email,
     )
     )
     session.add(item)
     session.add(item)
     session.commit()
     session.commit()
-    print("User created: {} <{}>, {}".format(item.user, item.default_email, 'testing123'))
+    print(
+        "User created: {} <{}>, {}".format(
+            item.user, item.default_email, "testing123"
+        )
+    )
 
 
     ######################################
     ######################################
     # pagure_group
     # pagure_group
     item = pagure.lib.model.PagureGroup(
     item = pagure.lib.model.PagureGroup(
-        group_name='admin',
-        group_type='admin',
+        group_name="admin",
+        group_type="admin",
         user_id=pingou.id,
         user_id=pingou.id,
-        display_name='admin',
-        description='Admin Group',
+        display_name="admin",
+        description="Admin Group",
     )
     )
     session.add(item)
     session.add(item)
     session.commit()
     session.commit()
@@ -111,22 +121,22 @@ def insert_data(session, username, user_email):
 
 
     # Add a couple of groups so that we can list them
     # Add a couple of groups so that we can list them
     item = pagure.lib.model.PagureGroup(
     item = pagure.lib.model.PagureGroup(
-        group_name='group',
-        group_type='user',
+        group_name="group",
+        group_type="user",
         user_id=pingou.id,
         user_id=pingou.id,
-        display_name='group group',
-        description='this is a group group',
+        display_name="group group",
+        description="this is a group group",
     )
     )
     session.add(item)
     session.add(item)
     session.commit()
     session.commit()
     print('Created "group" group. Pingou is a member.')
     print('Created "group" group. Pingou is a member.')
 
 
     item = pagure.lib.model.PagureGroup(
     item = pagure.lib.model.PagureGroup(
-        group_name='rel-eng',
-        group_type='user',
+        group_name="rel-eng",
+        group_type="user",
         user_id=pingou.id,
         user_id=pingou.id,
-        display_name='Release Engineering',
-        description='The group of release engineers',
+        display_name="Release Engineering",
+        description="The group of release engineers",
     )
     )
     session.add(item)
     session.add(item)
     session.commit()
     session.commit()
@@ -135,86 +145,82 @@ def insert_data(session, username, user_email):
     # projects
     # projects
 
 
     import shutil
     import shutil
+
     # delete folder from local instance to start from a clean slate
     # delete folder from local instance to start from a clean slate
-    if os.path.exists(_config['GIT_FOLDER']):
-        shutil.rmtree(_config['GIT_FOLDER'])
+    if os.path.exists(_config["GIT_FOLDER"]):
+        shutil.rmtree(_config["GIT_FOLDER"])
 
 
     # Create projects
     # Create projects
     item = project1 = pagure.lib.model.Project(
     item = project1 = pagure.lib.model.Project(
         user_id=pingou.id,
         user_id=pingou.id,
-        name='test',
+        name="test",
         is_fork=False,
         is_fork=False,
         parent_id=None,
         parent_id=None,
-        description='test project #1',
-        hook_token='aaabbbccc',
+        description="test project #1",
+        hook_token="aaabbbccc",
     )
     )
-    item.close_status = ['Invalid', 'Insufficient data', 'Fixed', 'Duplicate']
+    item.close_status = ["Invalid", "Insufficient data", "Fixed", "Duplicate"]
     session.add(item)
     session.add(item)
     session.flush()
     session.flush()
     tests.create_locks(session, item)
     tests.create_locks(session, item)
 
 
     item = project2 = pagure.lib.model.Project(
     item = project2 = pagure.lib.model.Project(
         user_id=pingou.id,
         user_id=pingou.id,
-        name='test2',
+        name="test2",
         is_fork=False,
         is_fork=False,
         parent_id=None,
         parent_id=None,
-        description='test project #2',
-        hook_token='aaabbbddd',
+        description="test project #2",
+        hook_token="aaabbbddd",
     )
     )
-    item.close_status = ['Invalid', 'Insufficient data', 'Fixed', 'Duplicate']
+    item.close_status = ["Invalid", "Insufficient data", "Fixed", "Duplicate"]
     session.add(item)
     session.add(item)
 
 
     item = project3 = pagure.lib.model.Project(
     item = project3 = pagure.lib.model.Project(
         user_id=pingou.id,
         user_id=pingou.id,
-        name='test3',
+        name="test3",
         is_fork=False,
         is_fork=False,
         parent_id=None,
         parent_id=None,
-        description='namespaced test project',
-        hook_token='aaabbbeee',
-        namespace='somenamespace',
+        description="namespaced test project",
+        hook_token="aaabbbeee",
+        namespace="somenamespace",
     )
     )
-    item.close_status = ['Invalid', 'Insufficient data', 'Fixed', 'Duplicate']
+    item.close_status = ["Invalid", "Insufficient data", "Fixed", "Duplicate"]
     session.add(item)
     session.add(item)
 
 
     session.commit()
     session.commit()
 
 
-    tests.create_projects_git(_config['GIT_FOLDER'], bare=True)
-    add_content_git_repo(
-        os.path.join(_config['GIT_FOLDER'], 'test.git'))
-    tests.add_readme_git_repo(
-        os.path.join(_config['GIT_FOLDER'], 'test.git'))
+    tests.create_projects_git(_config["GIT_FOLDER"], bare=True)
+    add_content_git_repo(os.path.join(_config["GIT_FOLDER"], "test.git"))
+    tests.add_readme_git_repo(os.path.join(_config["GIT_FOLDER"], "test.git"))
 
 
     # Add some content to the git repo
     # Add some content to the git repo
     add_content_git_repo(
     add_content_git_repo(
-        os.path.join(_config['GIT_FOLDER'], 'forks', 'pingou',
-                     'test.git'))
+        os.path.join(_config["GIT_FOLDER"], "forks", "pingou", "test.git")
+    )
     tests.add_readme_git_repo(
     tests.add_readme_git_repo(
-        os.path.join(_config['GIT_FOLDER'], 'forks', 'pingou',
-                     'test.git'))
+        os.path.join(_config["GIT_FOLDER"], "forks", "pingou", "test.git")
+    )
     tests.add_commit_git_repo(
     tests.add_commit_git_repo(
-        os.path.join(_config['GIT_FOLDER'], 'forks', 'pingou',
-                     'test.git'), ncommits=10)
+        os.path.join(_config["GIT_FOLDER"], "forks", "pingou", "test.git"),
+        ncommits=10,
+    )
 
 
     ######################################
     ######################################
     # user_emails
     # user_emails
     item = pagure.lib.model.UserEmail(
     item = pagure.lib.model.UserEmail(
-        user_id=pingou.id,
-        email='bar@pingou.com')
+        user_id=pingou.id, email="bar@pingou.com"
+    )
     session.add(item)
     session.add(item)
 
 
     item = pagure.lib.model.UserEmail(
     item = pagure.lib.model.UserEmail(
-        user_id=pingou.id,
-        email='foo@pingou.com')
+        user_id=pingou.id, email="foo@pingou.com"
+    )
     session.add(item)
     session.add(item)
 
 
-    item = pagure.lib.model.UserEmail(
-        user_id=foo.id,
-        email='foo@bar.com')
+    item = pagure.lib.model.UserEmail(user_id=foo.id, email="foo@bar.com")
     session.add(item)
     session.add(item)
 
 
-    item = pagure.lib.model.UserEmail(
-        user_id=you.id,
-        email=user_email)
+    item = pagure.lib.model.UserEmail(user_id=you.id, email=user_email)
     session.add(item)
     session.add(item)
 
 
     session.commit()
     session.commit()
@@ -222,9 +228,7 @@ def insert_data(session, username, user_email):
     ######################################
     ######################################
     # user_emails_pending
     # user_emails_pending
     email_pend = pagure.lib.model.UserEmailPending(
     email_pend = pagure.lib.model.UserEmailPending(
-        user_id=pingou.id,
-        email='foo@fp.o',
-        token='abcdef',
+        user_id=pingou.id, email="foo@fp.o", token="abcdef"
     )
     )
     session.add(email_pend)
     session.add(email_pend)
     session.commit()
     session.commit()
@@ -234,10 +238,10 @@ def insert_data(session, username, user_email):
     # Add an issue and tag it so that we can list them
     # Add an issue and tag it so that we can list them
     item = pagure.lib.model.Issue(
     item = pagure.lib.model.Issue(
         id=1001,
         id=1001,
-        uid='foobar',
+        uid="foobar",
         project_id=project1.id,
         project_id=project1.id,
-        title='Problem with jenkins build',
-        content='For some reason the tests fail at line:24',
+        title="Problem with jenkins build",
+        content="For some reason the tests fail at line:24",
         user_id=pingou.id,
         user_id=pingou.id,
     )
     )
     session.add(item)
     session.add(item)
@@ -245,11 +249,11 @@ def insert_data(session, username, user_email):
 
 
     item = pagure.lib.model.Issue(
     item = pagure.lib.model.Issue(
         id=1002,
         id=1002,
-        uid='foobar2',
+        uid="foobar2",
         project_id=project1.id,
         project_id=project1.id,
-        title='Unit tests failing',
-        content='Need to fix code for the unit tests to '
-                'pass so jenkins build can complete.',
+        title="Unit tests failing",
+        content="Need to fix code for the unit tests to "
+        "pass so jenkins build can complete.",
         user_id=pingou.id,
         user_id=pingou.id,
     )
     )
     session.add(item)
     session.add(item)
@@ -257,10 +261,10 @@ def insert_data(session, username, user_email):
 
 
     item = pagure.lib.model.Issue(
     item = pagure.lib.model.Issue(
         id=1003,
         id=1003,
-        uid='foobar3',
+        uid="foobar3",
         project_id=project1.id,
         project_id=project1.id,
-        title='Segfault during execution',
-        content='Index out of bounds for variable i?',
+        title="Segfault during execution",
+        content="Index out of bounds for variable i?",
         user_id=you.id,
         user_id=you.id,
     )
     )
     session.add(item)
     session.add(item)
@@ -268,166 +272,155 @@ def insert_data(session, username, user_email):
 
 
     ######################################
     ######################################
     # pagure_user_group
     # pagure_user_group
-    group = pagure.lib.query.search_groups(session, pattern=None,
-                                     group_name="rel-eng", group_type=None)
+    group = pagure.lib.query.search_groups(
+        session, pattern=None, group_name="rel-eng", group_type=None
+    )
     item = pagure.lib.model.PagureUserGroup(
     item = pagure.lib.model.PagureUserGroup(
-        user_id=pingou.id,
-        group_id=group.id
+        user_id=pingou.id, group_id=group.id
     )
     )
     session.add(item)
     session.add(item)
     session.commit()
     session.commit()
 
 
-    group = pagure.lib.query.search_groups(session, pattern=None,
-                                     group_name="admin", group_type=None)
-
-    item = pagure.lib.model.PagureUserGroup(
-        user_id=you.id,
-        group_id=group.id
+    group = pagure.lib.query.search_groups(
+        session, pattern=None, group_name="admin", group_type=None
     )
     )
+
+    item = pagure.lib.model.PagureUserGroup(user_id=you.id, group_id=group.id)
     session.add(item)
     session.add(item)
     session.commit()
     session.commit()
 
 
-    group = pagure.lib.query.search_groups(session, pattern=None,
-                                     group_name="group", group_type=None)
-
-    item = pagure.lib.model.PagureUserGroup(
-        user_id=foo.id,
-        group_id=group.id
+    group = pagure.lib.query.search_groups(
+        session, pattern=None, group_name="group", group_type=None
     )
     )
+
+    item = pagure.lib.model.PagureUserGroup(user_id=foo.id, group_id=group.id)
     session.add(item)
     session.add(item)
     session.commit()
     session.commit()
 
 
     ######################################
     ######################################
     # projects_groups
     # projects_groups
-    group = pagure.lib.query.search_groups(session, pattern=None,
-                                     group_name="rel-eng", group_type=None)
-    repo = pagure.lib.query.get_authorized_project(session, 'test')
+    group = pagure.lib.query.search_groups(
+        session, pattern=None, group_name="rel-eng", group_type=None
+    )
+    repo = pagure.lib.query.get_authorized_project(session, "test")
     item = pagure.lib.model.ProjectGroup(
     item = pagure.lib.model.ProjectGroup(
-        project_id=repo.id,
-        group_id=group.id,
-        access="commit"
+        project_id=repo.id, group_id=group.id, access="commit"
     )
     )
     session.add(item)
     session.add(item)
     session.commit()
     session.commit()
 
 
-    group = pagure.lib.query.search_groups(session, pattern=None,
-                                     group_name="admin", group_type=None)
-    repo = pagure.lib.query.get_authorized_project(session, 'test2')
+    group = pagure.lib.query.search_groups(
+        session, pattern=None, group_name="admin", group_type=None
+    )
+    repo = pagure.lib.query.get_authorized_project(session, "test2")
     item = pagure.lib.model.ProjectGroup(
     item = pagure.lib.model.ProjectGroup(
-        project_id=repo.id,
-        group_id=group.id,
-        access="admin"
+        project_id=repo.id, group_id=group.id, access="admin"
     )
     )
     session.add(item)
     session.add(item)
     session.commit()
     session.commit()
 
 
     ######################################
     ######################################
     # pull_requests
     # pull_requests
-    repo = pagure.lib.query.get_authorized_project(session, 'test')
-    forked_repo = pagure.lib.query.get_authorized_project(session, 'test')
+    repo = pagure.lib.query.get_authorized_project(session, "test")
+    forked_repo = pagure.lib.query.get_authorized_project(session, "test")
     req = pagure.lib.query.new_pull_request(
     req = pagure.lib.query.new_pull_request(
         session=session,
         session=session,
         repo_from=forked_repo,
         repo_from=forked_repo,
-        branch_from='master',
+        branch_from="master",
         repo_to=repo,
         repo_to=repo,
-        branch_to='master',
-        title='Fixing code for unittest',
+        branch_to="master",
+        title="Fixing code for unittest",
         user=username,
         user=username,
-        status="Open"
+        status="Open",
     )
     )
     session.commit()
     session.commit()
 
 
-    repo = pagure.lib.query.get_authorized_project(session, 'test')
-    forked_repo = pagure.lib.query.get_authorized_project(session, 'test')
+    repo = pagure.lib.query.get_authorized_project(session, "test")
+    forked_repo = pagure.lib.query.get_authorized_project(session, "test")
     req = pagure.lib.query.new_pull_request(
     req = pagure.lib.query.new_pull_request(
         session=session,
         session=session,
         repo_from=forked_repo,
         repo_from=forked_repo,
-        branch_from='master',
+        branch_from="master",
         repo_to=repo,
         repo_to=repo,
-        branch_to='master',
-        title='add very nice README',
+        branch_to="master",
+        title="add very nice README",
         user=username,
         user=username,
-        status="Open"
+        status="Open",
     )
     )
     session.commit()
     session.commit()
 
 
-    repo = pagure.lib.query.get_authorized_project(session, 'test')
-    forked_repo = pagure.lib.query.get_authorized_project(session, 'test')
+    repo = pagure.lib.query.get_authorized_project(session, "test")
+    forked_repo = pagure.lib.query.get_authorized_project(session, "test")
     req = pagure.lib.query.new_pull_request(
     req = pagure.lib.query.new_pull_request(
         session=session,
         session=session,
         repo_from=forked_repo,
         repo_from=forked_repo,
-        branch_from='master',
+        branch_from="master",
         repo_to=repo,
         repo_to=repo,
-        branch_to='master',
-        title='Add README',
+        branch_to="master",
+        title="Add README",
         user=username,
         user=username,
-        status="Closed"
+        status="Closed",
     )
     )
     session.commit()
     session.commit()
 
 
-    repo = pagure.lib.query.get_authorized_project(session, 'test')
-    forked_repo = pagure.lib.query.get_authorized_project(session, 'test')
+    repo = pagure.lib.query.get_authorized_project(session, "test")
+    forked_repo = pagure.lib.query.get_authorized_project(session, "test")
     req = pagure.lib.query.new_pull_request(
     req = pagure.lib.query.new_pull_request(
         session=session,
         session=session,
         repo_from=forked_repo,
         repo_from=forked_repo,
-        branch_from='master',
+        branch_from="master",
         repo_to=repo,
         repo_to=repo,
-        branch_to='master',
-        title='Fix some containers',
+        branch_to="master",
+        title="Fix some containers",
         user=username,
         user=username,
-        status="Merged"
+        status="Merged",
     )
     )
     session.commit()
     session.commit()
 
 
-    repo = pagure.lib.query.get_authorized_project(session, 'test')
-    forked_repo = pagure.lib.query.get_authorized_project(session, 'test')
+    repo = pagure.lib.query.get_authorized_project(session, "test")
+    forked_repo = pagure.lib.query.get_authorized_project(session, "test")
     req = pagure.lib.query.new_pull_request(
     req = pagure.lib.query.new_pull_request(
         session=session,
         session=session,
         repo_from=forked_repo,
         repo_from=forked_repo,
-        branch_from='master',
+        branch_from="master",
         repo_to=repo,
         repo_to=repo,
-        branch_to='master',
-        title='Fix pull request statuses',
+        branch_to="master",
+        title="Fix pull request statuses",
         user=username,
         user=username,
-        status="Closed"
+        status="Closed",
     )
     )
     session.commit()
     session.commit()
 
 
-    repo = pagure.lib.query.get_authorized_project(session, 'test')
-    forked_repo = pagure.lib.query.get_authorized_project(session, 'test')
+    repo = pagure.lib.query.get_authorized_project(session, "test")
+    forked_repo = pagure.lib.query.get_authorized_project(session, "test")
     req = pagure.lib.query.new_pull_request(
     req = pagure.lib.query.new_pull_request(
         session=session,
         session=session,
         repo_from=forked_repo,
         repo_from=forked_repo,
-        branch_from='master',
+        branch_from="master",
         repo_to=repo,
         repo_to=repo,
-        branch_to='master',
-        title='Fixing UI of issue',
+        branch_to="master",
+        title="Fixing UI of issue",
         user=username,
         user=username,
-        status="Merged"
+        status="Merged",
     )
     )
     session.commit()
     session.commit()
 
 
-
     #####################################
     #####################################
     # tokens
     # tokens
     tests.create_tokens(session, user_id=pingou.id, project_id=project1.id)
     tests.create_tokens(session, user_id=pingou.id, project_id=project1.id)
 
 
     ######################################
     ######################################
     # user_projects
     # user_projects
-    repo = pagure.lib.query.get_authorized_project(session, 'test')
+    repo = pagure.lib.query.get_authorized_project(session, "test")
     item = pagure.lib.model.ProjectUser(
     item = pagure.lib.model.ProjectUser(
-        project_id=repo.id,
-        user_id=foo.id,
-        access="commit"
+        project_id=repo.id, user_id=foo.id, access="commit"
     )
     )
     session.add(item)
     session.add(item)
     session.commit()
     session.commit()
 
 
-    repo = pagure.lib.query.get_authorized_project(session, 'test2')
+    repo = pagure.lib.query.get_authorized_project(session, "test2")
     item = pagure.lib.model.ProjectUser(
     item = pagure.lib.model.ProjectUser(
-        project_id=repo.id,
-        user_id=you.id,
-        access="commit"
+        project_id=repo.id, user_id=you.id, access="commit"
     )
     )
     session.add(item)
     session.add(item)
     session.commit()
     session.commit()
@@ -436,29 +429,30 @@ def insert_data(session, username, user_email):
     # issue_comments
     # issue_comments
     item = pagure.lib.model.IssueComment(
     item = pagure.lib.model.IssueComment(
         user_id=pingou.id,
         user_id=pingou.id,
-        issue_uid='foobar',
-        comment='We may need to adjust the unittests instead of the code.',
+        issue_uid="foobar",
+        comment="We may need to adjust the unittests instead of the code.",
     )
     )
     session.add(item)
     session.add(item)
     session.commit()
     session.commit()
 
 
     ######################################
     ######################################
     # issue_to_issue
     # issue_to_issue
-    repo = pagure.lib.query.get_authorized_project(session, 'test')
+    repo = pagure.lib.query.get_authorized_project(session, "test")
     all_issues = pagure.lib.query.search_issues(session, repo)
     all_issues = pagure.lib.query.search_issues(session, repo)
-    pagure.lib.query.add_issue_dependency(session, all_issues[0],
-                                    all_issues[1], 'pingou')
+    pagure.lib.query.add_issue_dependency(
+        session, all_issues[0], all_issues[1], "pingou"
+    )
 
 
     ######################################
     ######################################
     # pull_request_comments
     # pull_request_comments
-    user = pagure.lib.query.search_user(session, username='pingou')
+    user = pagure.lib.query.search_user(session, username="pingou")
     # only 1 pull request available atm
     # only 1 pull request available atm
     pr = pagure.lib.query.get_pull_request_of_user(session, "pingou")[0]
     pr = pagure.lib.query.get_pull_request_of_user(session, "pingou")[0]
     item = pagure.lib.model.PullRequestComment(
     item = pagure.lib.model.PullRequestComment(
         pull_request_uid=pr.uid,
         pull_request_uid=pr.uid,
         user_id=user.id,
         user_id=user.id,
         comment="+1 for me. Btw, could you rebase before you merge?",
         comment="+1 for me. Btw, could you rebase before you merge?",
-        notification=0
+        notification=0,
     )
     )
     session.add(item)
     session.add(item)
     session.commit()
     session.commit()
@@ -475,7 +469,7 @@ def insert_data(session, username, user_email):
         percent=80,
         percent=80,
         comment="Jenkins build passes",
         comment="Jenkins build passes",
         url=str(pr.id),
         url=str(pr.id),
-        status="success"
+        status="success",
     )
     )
     session.add(item)
     session.add(item)
     session.commit()
     session.commit()
@@ -489,33 +483,30 @@ def insert_data(session, username, user_email):
         percent=80,
         percent=80,
         comment="Jenkins does not pass",
         comment="Jenkins does not pass",
         url=str(pr.id),
         url=str(pr.id),
-        status="failure"
+        status="failure",
     )
     )
     session.add(item)
     session.add(item)
     session.commit()
     session.commit()
 
 
     ######################################
     ######################################
     # pull_request_assignee
     # pull_request_assignee
-    pr = pagure.lib.query.search_pull_requests(session, requestid='1006')
+    pr = pagure.lib.query.search_pull_requests(session, requestid="1006")
     pr.assignee_id = pingou.id
     pr.assignee_id = pingou.id
     session.commit()
     session.commit()
 
 
-    pr = pagure.lib.query.search_pull_requests(session, requestid='1007')
+    pr = pagure.lib.query.search_pull_requests(session, requestid="1007")
     pr.assignee_id = you.id
     pr.assignee_id = you.id
     session.commit()
     session.commit()
 
 
-    pr = pagure.lib.query.search_pull_requests(session, requestid='1004')
+    pr = pagure.lib.query.search_pull_requests(session, requestid="1004")
     pr.assignee_id = foo.id
     pr.assignee_id = foo.id
     session.commit()
     session.commit()
 
 
     ######################################
     ######################################
     # tags_issues
     # tags_issues
-    repo = pagure.lib.query.get_authorized_project(session, 'test')
+    repo = pagure.lib.query.get_authorized_project(session, "test")
     issues = pagure.lib.query.search_issues(session, repo)
     issues = pagure.lib.query.search_issues(session, repo)
-    item = pagure.lib.model.TagIssue(
-        issue_uid=issues[0].uid,
-        tag='tag1',
-    )
+    item = pagure.lib.model.TagIssue(issue_uid=issues[0].uid, tag="tag1")
     session.add(item)
     session.add(item)
     session.commit()
     session.commit()
 
 
@@ -528,55 +519,54 @@ def insert_data(session, username, user_email):
     # delete fork data
     # delete fork data
     fork_proj_location = "forks/foo/test.git"
     fork_proj_location = "forks/foo/test.git"
     try:
     try:
-        shutil.rmtree(os.path.join(_config['GIT_FOLDER'],
-                                   fork_proj_location))
+        shutil.rmtree(os.path.join(_config["GIT_FOLDER"], fork_proj_location))
     except:
     except:
-        print('git folder already deleted')
+        print("git folder already deleted")
 
 
     try:
     try:
-        shutil.rmtree(os.path.join(_config['DOCS_FOLDER'],
-                                   fork_proj_location))
+        shutil.rmtree(os.path.join(_config["DOCS_FOLDER"], fork_proj_location))
     except:
     except:
-        print('docs folder already deleted')
+        print("docs folder already deleted")
 
 
     try:
     try:
-        shutil.rmtree(os.path.join(_config['TICKETS_FOLDER'],
-                                   fork_proj_location))
+        shutil.rmtree(
+            os.path.join(_config["TICKETS_FOLDER"], fork_proj_location)
+        )
     except:
     except:
-        print('tickets folder already deleted')
+        print("tickets folder already deleted")
 
 
     try:
     try:
-        shutil.rmtree(os.path.join(_config['REQUESTS_FOLDER'],
-                                   fork_proj_location))
+        shutil.rmtree(
+            os.path.join(_config["REQUESTS_FOLDER"], fork_proj_location)
+        )
     except:
     except:
-        print('requests folder already deleted')
+        print("requests folder already deleted")
 
 
-    repo = pagure.lib.query.get_authorized_project(session, 'test')
-    result = pagure.lib.query.fork_project(session, 'foo', repo)
+    repo = pagure.lib.query.get_authorized_project(session, "test")
+    result = pagure.lib.query.fork_project(session, "foo", repo)
     if result == 'Repo "test" cloned to "foo/test"':
     if result == 'Repo "test" cloned to "foo/test"':
         session.commit()
         session.commit()
 
 
 
 
-def add_content_git_repo(folder, branch='master'):
+def add_content_git_repo(folder, branch="master"):
     """ Create some content for the specified git repo. """
     """ Create some content for the specified git repo. """
     if not os.path.exists(folder):
     if not os.path.exists(folder):
         os.makedirs(folder)
         os.makedirs(folder)
     brepo = pygit2.init_repository(folder, bare=True)
     brepo = pygit2.init_repository(folder, bare=True)
 
 
-    newfolder = tempfile.mkdtemp(prefix='pagure-tests')
+    newfolder = tempfile.mkdtemp(prefix="pagure-tests")
     repo = pygit2.clone_repository(folder, newfolder)
     repo = pygit2.clone_repository(folder, newfolder)
 
 
     # Create a file in that git repo
     # Create a file in that git repo
-    with open(os.path.join(newfolder, 'sources'), 'w') as stream:
-        stream.write('foo\n bar')
-    repo.index.add('sources')
+    with open(os.path.join(newfolder, "sources"), "w") as stream:
+        stream.write("foo\n bar")
+    repo.index.add("sources")
     repo.index.write()
     repo.index.write()
 
 
     parents = []
     parents = []
     commit = None
     commit = None
     try:
     try:
-        commit = repo.revparse_single(
-            'HEAD' if branch == 'master' else branch)
+        commit = repo.revparse_single("HEAD" if branch == "master" else branch)
     except KeyError:
     except KeyError:
         pass
         pass
     if commit:
     if commit:
@@ -584,15 +574,13 @@ def add_content_git_repo(folder, branch='master'):
 
 
     # Commits the files added
     # Commits the files added
     tree = repo.index.write_tree()
     tree = repo.index.write_tree()
-    author = pygit2.Signature(
-        'Alice Author', 'alice@authors.tld')
-    committer = pygit2.Signature(
-        'Cecil Committer', 'cecil@committers.tld')
+    author = pygit2.Signature("Alice Author", "alice@authors.tld")
+    committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
     repo.create_commit(
     repo.create_commit(
-        'refs/heads/%s' % branch,  # the name of the reference to update
+        "refs/heads/%s" % branch,  # the name of the reference to update
         author,
         author,
         committer,
         committer,
-        'Add sources file for testing',
+        "Add sources file for testing",
         # binary string representing the tree object ID
         # binary string representing the tree object ID
         tree,
         tree,
         # list of binary strings representing parents of the new commit
         # list of binary strings representing parents of the new commit
@@ -602,44 +590,42 @@ def add_content_git_repo(folder, branch='master'):
     parents = []
     parents = []
     commit = None
     commit = None
     try:
     try:
-        commit = repo.revparse_single(
-            'HEAD' if branch == 'master' else branch)
+        commit = repo.revparse_single("HEAD" if branch == "master" else branch)
     except KeyError:
     except KeyError:
         pass
         pass
     if commit:
     if commit:
         parents = [commit.oid.hex]
         parents = [commit.oid.hex]
 
 
-    subfolder = os.path.join('folder1', 'folder2')
+    subfolder = os.path.join("folder1", "folder2")
     if not os.path.exists(os.path.join(newfolder, subfolder)):
     if not os.path.exists(os.path.join(newfolder, subfolder)):
         os.makedirs(os.path.join(newfolder, subfolder))
         os.makedirs(os.path.join(newfolder, subfolder))
     # Create a file in that git repo
     # Create a file in that git repo
-    with open(os.path.join(newfolder, subfolder, 'file'), 'w') as stream:
-        stream.write('foo\n bar\nbaz')
-    repo.index.add(os.path.join(subfolder, 'file'))
+    with open(os.path.join(newfolder, subfolder, "file"), "w") as stream:
+        stream.write("foo\n bar\nbaz")
+    repo.index.add(os.path.join(subfolder, "file"))
     repo.index.write()
     repo.index.write()
 
 
     # Commits the files added
     # Commits the files added
     tree = repo.index.write_tree()
     tree = repo.index.write_tree()
-    author = pygit2.Signature(
-        'Alice Author', 'alice@authors.tld')
-    committer = pygit2.Signature(
-        'Cecil Committer', 'cecil@committers.tld')
+    author = pygit2.Signature("Alice Author", "alice@authors.tld")
+    committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
     repo.create_commit(
     repo.create_commit(
-        'refs/heads/%s' % branch,  # the name of the reference to update
+        "refs/heads/%s" % branch,  # the name of the reference to update
         author,
         author,
         committer,
         committer,
-        'Add some directory and a file for more testing',
+        "Add some directory and a file for more testing",
         # binary string representing the tree object ID
         # binary string representing the tree object ID
         tree,
         tree,
         # list of binary strings representing parents of the new commit
         # list of binary strings representing parents of the new commit
-        parents
+        parents,
     )
     )
 
 
     # Push to origin
     # Push to origin
     ori_remote = repo.remotes[0]
     ori_remote = repo.remotes[0]
     master_ref = repo.lookup_reference(
     master_ref = repo.lookup_reference(
-        'HEAD' if branch == 'master' else 'refs/heads/%s' % branch).resolve()
-    refname = '%s:%s' % (master_ref.name, master_ref.name)
+        "HEAD" if branch == "master" else "refs/heads/%s" % branch
+    ).resolve()
+    refname = "%s:%s" % (master_ref.name, master_ref.name)
 
 
     PagureRepo.push(ori_remote, refname)
     PagureRepo.push(ori_remote, refname)
 
 
@@ -647,18 +633,19 @@ def add_content_git_repo(folder, branch='master'):
 
 
 
 
 def _get_username():
 def _get_username():
-    invalid_option = ['pingou', 'foo']
+    invalid_option = ["pingou", "foo"]
     user_name = os.environ.get("USER_NAME")
     user_name = os.environ.get("USER_NAME")
     if not user_name:
     if not user_name:
         print("")
         print("")
         user_name = six.moves.input(
         user_name = six.moves.input(
-            "Enter your username so we can add you into the test data:  ")
+            "Enter your username so we can add you into the test data:  "
+        )
     cnt = 0
     cnt = 0
     while not user_name.strip() or user_name in invalid_option:
     while not user_name.strip() or user_name in invalid_option:
         print("Reserved names: " + str(invalid_option))
         print("Reserved names: " + str(invalid_option))
         user_name = six.moves.input(
         user_name = six.moves.input(
-            "Enter your username so we can add you into the "
-            "test data:  ")
+            "Enter your username so we can add you into the " "test data:  "
+        )
         cnt += 1
         cnt += 1
         if cnt == 4:
         if cnt == 4:
             print("We asked too many times, bailing")
             print("We asked too many times, bailing")
@@ -668,7 +655,7 @@ def _get_username():
 
 
 
 
 def _get_user_email():
 def _get_user_email():
-    invalid_option = ['bar@pingou.com', 'foo@bar.com']
+    invalid_option = ["bar@pingou.com", "foo@bar.com"]
     user_email = os.environ.get("USER_EMAIL")
     user_email = os.environ.get("USER_EMAIL")
     if not user_email:
     if not user_email:
         print("")
         print("")
@@ -687,23 +674,32 @@ def _get_user_email():
 
 
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":
-    desc = "Run the dev database initialization/insertion/deletion " \
-           "script for db located  " + str(_config['DB_URL'])
+    desc = (
+        "Run the dev database initialization/insertion/deletion "
+        "script for db located  " + str(_config["DB_URL"])
+    )
     parser = argparse.ArgumentParser(prog="dev-data", description=desc)
     parser = argparse.ArgumentParser(prog="dev-data", description=desc)
-    parser.add_argument('-i', '--init', action="store_true",
-                        help="Create the dev db")
-    parser.add_argument('-p', '--populate', action="store_true",
-                        help="Add test data to the db")
-    parser.add_argument('-d', '--delete', action="store_true",
-                        help="Wipe the dev db")
-    parser.add_argument('-a', '--all', action="store_true",
-                        help="Create, Populate then Wipe the dev db")
+    parser.add_argument(
+        "-i", "--init", action="store_true", help="Create the dev db"
+    )
+    parser.add_argument(
+        "-p", "--populate", action="store_true", help="Add test data to the db"
+    )
+    parser.add_argument(
+        "-d", "--delete", action="store_true", help="Wipe the dev db"
+    )
+    parser.add_argument(
+        "-a",
+        "--all",
+        action="store_true",
+        help="Create, Populate then Wipe the dev db",
+    )
 
 
     args = parser.parse_args()
     args = parser.parse_args()
 
 
     # forcing the user to choose
     # forcing the user to choose
     if not any(vars(args).values()):
     if not any(vars(args).values()):
-        parser.error('No arguments provided.')
+        parser.error("No arguments provided.")
 
 
     session = None
     session = None
 
 
@@ -712,12 +708,13 @@ if __name__ == "__main__":
             db_url=_config["DB_URL"],
             db_url=_config["DB_URL"],
             alembic_ini=None,
             alembic_ini=None,
             acls=_config["ACLS"],
             acls=_config["ACLS"],
-            debug=False)
+            debug=False,
+        )
         print("Database created")
         print("Database created")
 
 
     if args.populate or args.all:
     if args.populate or args.all:
         if not session:
         if not session:
-            session = pagure.lib.query.create_session(_config['DB_URL'])
+            session = pagure.lib.query.create_session(_config["DB_URL"])
 
 
         user_name = _get_username()
         user_name = _get_username()
         user_email = _get_user_email()
         user_email = _get_user_email()

+ 2 - 1
dev/containers/f29-rpms-py3

@@ -20,7 +20,8 @@ RUN dnf -y install \
 
 
 RUN cd / \
 RUN cd / \
     && git clone -b $BRANCH $REPO \
     && git clone -b $BRANCH $REPO \
-    && chmod +x /pagure/dev/containers/runtests_py3.sh
+    && chmod +x /pagure/dev/containers/runtests_py3.sh \
+    && sed -i -e "s|\['alembic',|\['alembic-3',|" /pagure/tests/test_alembic.py
 
 
 # Install all the requirements from the spec file and replace the macro
 # Install all the requirements from the spec file and replace the macro
 # %{python_pkgversion} by '3' which thus installs all the py3 version of
 # %{python_pkgversion} by '3' which thus installs all the py3 version of

+ 20 - 9
dev/run-tests-container.py

@@ -58,12 +58,14 @@ if __name__ == "__main__":
         container_files = ["fedora-pip-py3"]
         container_files = ["fedora-pip-py3"]
     else:
     else:
         container_names = [
         container_names = [
-            "pagure-f29-rpms-py3", "pagure-c7-rpms-py2",
-            "pagure-fedora-pip-py3"
+            "pagure-f29-rpms-py3",
+            "pagure-c7-rpms-py2",
+            "pagure-fedora-pip-py3",
         ]
         ]
         container_files = [
         container_files = [
-            "f29-rpms-py3", "centos7-rpms-py2",
-            "fedora-pip-py3"
+            "f29-rpms-py3",
+            "centos7-rpms-py2",
+            "fedora-pip-py3",
         ]
         ]
 
 
     failed = []
     failed = []
@@ -77,7 +79,10 @@ if __name__ == "__main__":
                     "--build-arg",
                     "--build-arg",
                     "branch={}".format(os.environ.get("BRANCH") or "master"),
                     "branch={}".format(os.environ.get("BRANCH") or "master"),
                     "--build-arg",
                     "--build-arg",
-                    "repo={}".format(os.environ.get("REPO") or "https://pagure.io/pagure.git"),
+                    "repo={}".format(
+                        os.environ.get("REPO")
+                        or "https://pagure.io/pagure.git"
+                    ),
                     "--rm",
                     "--rm",
                     "-t",
                     "-t",
                     container_name,
                     container_name,
@@ -105,11 +110,14 @@ if __name__ == "__main__":
                 container_name,
                 container_name,
                 "-v",
                 "-v",
                 "{}/results_{}:/pagure/results:z".format(
                 "{}/results_{}:/pagure/results:z".format(
-                    os.getcwd(), container_files[idx]),
+                    os.getcwd(), container_files[idx]
+                ),
                 "-e",
                 "-e",
                 "BRANCH={}".format(os.environ.get("BRANCH") or "master"),
                 "BRANCH={}".format(os.environ.get("BRANCH") or "master"),
                 "-e",
                 "-e",
-                "REPO={}".format(os.environ.get("REPO") or "https://pagure.io/pagure.git"),
+                "REPO={}".format(
+                    os.environ.get("REPO") or "https://pagure.io/pagure.git"
+                ),
                 "--entrypoint=/bin/bash",
                 "--entrypoint=/bin/bash",
                 container_name,
                 container_name,
             ]
             ]
@@ -125,11 +133,14 @@ if __name__ == "__main__":
                 container_name,
                 container_name,
                 "-v",
                 "-v",
                 "{}/results_{}:/pagure/results:z".format(
                 "{}/results_{}:/pagure/results:z".format(
-                    os.getcwd(), container_files[idx]),
+                    os.getcwd(), container_files[idx]
+                ),
                 "-e",
                 "-e",
                 "BRANCH={}".format(os.environ.get("BRANCH") or "master"),
                 "BRANCH={}".format(os.environ.get("BRANCH") or "master"),
                 "-e",
                 "-e",
-                "REPO={}".format(os.environ.get("REPO") or "https://pagure.io/pagure.git"),
+                "REPO={}".format(
+                    os.environ.get("REPO") or "https://pagure.io/pagure.git"
+                ),
                 "-e",
                 "-e",
                 "TESTCASE={}".format(args.test_case or ""),
                 "TESTCASE={}".format(args.test_case or ""),
                 container_name,
                 container_name,

+ 90 - 90
doc/conf.py

@@ -16,234 +16,227 @@ import os
 import re
 import re
 
 
 pagurefile = os.path.join(
 pagurefile = os.path.join(
-    os.path.dirname(__file__), '..', 'pagure', '__init__.py')
+    os.path.dirname(__file__), "..", "pagure", "__init__.py"
+)
 
 
 # Thanks to SQLAlchemy:
 # Thanks to SQLAlchemy:
 # https://github.com/zzzeek/sqlalchemy/blob/master/setup.py#L104
 # https://github.com/zzzeek/sqlalchemy/blob/master/setup.py#L104
 with open(pagurefile) as stream:
 with open(pagurefile) as stream:
-    VERSION = re.compile(
-        r".*__version__ = \"(.*?)\"", re.S
-    ).match(stream.read()).group(1)
+    VERSION = (
+        re.compile(r".*__version__ = \"(.*?)\"", re.S)
+        .match(stream.read())
+        .group(1)
+    )
 
 
 # If extensions (or modules to document with autodoc) are in another
 # If extensions (or modules to document with autodoc) are in another
 # directory, add these directories to sys.path here. If the directory is
 # directory, add these directories to sys.path here. If the directory is
 # relative to the documentation root, use os.path.abspath to make it
 # relative to the documentation root, use os.path.abspath to make it
 # absolute, like shown here.
 # absolute, like shown here.
-#sys.path.insert(0, os.path.abspath('.'))
+# sys.path.insert(0, os.path.abspath('.'))
 
 
 # -- General configuration ------------------------------------------------
 # -- General configuration ------------------------------------------------
 
 
 # If your documentation needs a minimal Sphinx version, state it here.
 # If your documentation needs a minimal Sphinx version, state it here.
-#needs_sphinx = '1.0'
+# needs_sphinx = '1.0'
 
 
 # Add any Sphinx extension module names here, as strings. They can be
 # Add any Sphinx extension module names here, as strings. They can be
 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
 extensions = [
 extensions = [
-    'sphinx.ext.autodoc', 'sphinx.ext.coverage', 'sphinx.ext.viewcode'
+    "sphinx.ext.autodoc",
+    "sphinx.ext.coverage",
+    "sphinx.ext.viewcode",
 ]
 ]
 
 
 # Add any paths that contain templates here, relative to this directory.
 # Add any paths that contain templates here, relative to this directory.
-templates_path = ['_templates']
+templates_path = ["_templates"]
 
 
 # The suffix of source filenames.
 # The suffix of source filenames.
-source_suffix = '.rst'
+source_suffix = ".rst"
 
 
 # The encoding of source files.
 # The encoding of source files.
-#source_encoding = 'utf-8-sig'
+# source_encoding = 'utf-8-sig'
 
 
 # The master toctree document.
 # The master toctree document.
-master_doc = 'index'
+master_doc = "index"
 
 
 # General information about the project.
 # General information about the project.
-project = u'pagure'
-copyright = u'2015, Red Hat Inc, Pierre-Yves Chibon <pingou@pingoured.fr>'
+project = u"pagure"
+copyright = u"2015, Red Hat Inc, Pierre-Yves Chibon <pingou@pingoured.fr>"
 
 
 # The version info for the project you're documenting, acts as replacement
 # The version info for the project you're documenting, acts as replacement
 # for |version| and |release|, also used in various other places throughout
 # for |version| and |release|, also used in various other places throughout
 # the built documents.
 # the built documents.
 #
 #
 # The short X.Y version.
 # The short X.Y version.
-#version = __version__
+# version = __version__
 version = VERSION
 version = VERSION
 # The full version, including alpha/beta/rc tags.
 # The full version, including alpha/beta/rc tags.
-#release = '1'
+# release = '1'
 
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
 # for a list of supported languages.
-#language = None
+# language = None
 
 
 # There are two options for replacing |today|: either, you set today to some
 # There are two options for replacing |today|: either, you set today to some
 # non-false value, then it is used:
 # non-false value, then it is used:
-#today = ''
+# today = ''
 # Else, today_fmt is used as the format for a strftime call.
 # Else, today_fmt is used as the format for a strftime call.
-#today_fmt = '%B %d, %Y'
+# today_fmt = '%B %d, %Y'
 
 
 # List of patterns, relative to source directory, that match files and
 # List of patterns, relative to source directory, that match files and
 # directories to ignore when looking for source files.
 # directories to ignore when looking for source files.
-exclude_patterns = ['_build']
+exclude_patterns = ["_build"]
 
 
 # The reST default role (used for this markup: `text`) to use for all
 # The reST default role (used for this markup: `text`) to use for all
 # documents.
 # documents.
-#default_role = None
+# default_role = None
 
 
 # If true, '()' will be appended to :func: etc. cross-reference text.
 # If true, '()' will be appended to :func: etc. cross-reference text.
-#add_function_parentheses = True
+# add_function_parentheses = True
 
 
 # If true, the current module name will be prepended to all description
 # If true, the current module name will be prepended to all description
 # unit titles (such as .. function::).
 # unit titles (such as .. function::).
-#add_module_names = True
+# add_module_names = True
 
 
 # If true, sectionauthor and moduleauthor directives will be shown in the
 # If true, sectionauthor and moduleauthor directives will be shown in the
 # output. They are ignored by default.
 # output. They are ignored by default.
-#show_authors = False
+# show_authors = False
 
 
 # The name of the Pygments (syntax highlighting) style to use.
 # The name of the Pygments (syntax highlighting) style to use.
-pygments_style = 'sphinx'
+pygments_style = "sphinx"
 
 
 # A list of ignored prefixes for module index sorting.
 # A list of ignored prefixes for module index sorting.
-#modindex_common_prefix = []
+# modindex_common_prefix = []
 
 
 
 
 # -- Options for HTML output ----------------------------------------------
 # -- Options for HTML output ----------------------------------------------
 
 
 import cloud_sptheme as csp
 import cloud_sptheme as csp
 
 
-html_style = 'site.css'
+html_style = "site.css"
 
 
 # The theme to use for HTML and HTML Help pages. See the documentation for
 # The theme to use for HTML and HTML Help pages. See the documentation for
 # a list of builtin themes.
 # a list of builtin themes.
-#html_theme = 'default'
+# html_theme = 'default'
 html_theme = "cloud"
 html_theme = "cloud"
 
 
 # Theme options are theme-specific and customize the look and feel of a theme
 # Theme options are theme-specific and customize the look and feel of a theme
 # further. For a list of options available for each theme, see the
 # further. For a list of options available for each theme, see the
 # documentation.
 # documentation.
-#html_theme_options = {}
+# html_theme_options = {}
 
 
 html_theme_options = {
 html_theme_options = {
     "sidebarwidth": "200px",
     "sidebarwidth": "200px",
     "max_width": "900px",
     "max_width": "900px",
     "compact_width": "800px",
     "compact_width": "800px",
     "minimal_width": "700px",
     "minimal_width": "700px",
-
     # Style it like Fedora..
     # Style it like Fedora..
     "bodyfont": "Cantarell",
     "bodyfont": "Cantarell",
-
     "highlightcolor": "#79db32",  # First Green
     "highlightcolor": "#79db32",  # First Green
-
     "sidebarbgcolor": "#FEFEFE",
     "sidebarbgcolor": "#FEFEFE",
     "sidebartrimcolor": "#FEFEFE",
     "sidebartrimcolor": "#FEFEFE",
-
     "sectionbgcolor": "#FEFEFE",
     "sectionbgcolor": "#FEFEFE",
     "sectiontrimcolor": "#FEFEFE",
     "sectiontrimcolor": "#FEFEFE",
     "sectiontextcolor": "#444444",
     "sectiontextcolor": "#444444",
-
     "relbarbgcolor": "#FEFEFE",
     "relbarbgcolor": "#FEFEFE",
     "relbartextcolor": "#444444",
     "relbartextcolor": "#444444",
     "relbarlinkcolor": "#444444",
     "relbarlinkcolor": "#444444",
-
     "bgcolor": "#FEFEFE",
     "bgcolor": "#FEFEFE",
     "textcolor": "#444444",
     "textcolor": "#444444",
-    #"linkcolor": "#79db32",  # First Green
+    # "linkcolor": "#79db32",  # First Green
     "linkcolor": "#00009d",
     "linkcolor": "#00009d",
-
     "headtextcolor": "#444444",
     "headtextcolor": "#444444",
     "headlinkcolor": "#444444",
     "headlinkcolor": "#444444",
-
-    #"codebgcolor"
-    #"codetextcolor"
+    # "codebgcolor"
+    # "codetextcolor"
     "codetrimcolor": "#79db32",  # First Green
     "codetrimcolor": "#79db32",  # First Green
-
     "footerbgcolor": "#FEFEFE",
     "footerbgcolor": "#FEFEFE",
-
-    "fontcssurl": "_static/site.css"
+    "fontcssurl": "_static/site.css",
 }
 }
 # Add any paths that contain custom themes here, relative to this directory.
 # Add any paths that contain custom themes here, relative to this directory.
-#html_theme_path = []
+# html_theme_path = []
 html_theme_path = [csp.get_theme_dir()]
 html_theme_path = [csp.get_theme_dir()]
 
 
 # The name for this set of Sphinx documents. If None, it defaults to
 # The name for this set of Sphinx documents. If None, it defaults to
 # "<project> v<release> documentation".
 # "<project> v<release> documentation".
-#html_title = None
+# html_title = None
 
 
 # A shorter title for the navigation bar. Default is the same as html_title.
 # A shorter title for the navigation bar. Default is the same as html_title.
-#html_short_title = None
+# html_short_title = None
 
 
 # The name of an image file (relative to this directory) to place at the top
 # The name of an image file (relative to this directory) to place at the top
 # of the sidebar.
 # of the sidebar.
-#html_logo = None
+# html_logo = None
 
 
 # The name of an image file (within the static path) to use as favicon of the
 # The name of an image file (within the static path) to use as favicon of the
 # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
 # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
 # pixels large.
 # pixels large.
-#html_favicon = None
+# html_favicon = None
 
 
 # Add any paths that contain custom static files (such as style sheets) here,
 # Add any paths that contain custom static files (such as style sheets) here,
 # relative to this directory. They are copied after the builtin static files,
 # relative to this directory. They are copied after the builtin static files,
 # so a file named "default.css" will overwrite the builtin "default.css".
 # so a file named "default.css" will overwrite the builtin "default.css".
-html_static_path = ['_static']
+html_static_path = ["_static"]
 
 
 # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
 # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
 # using the given strftime format.
 # using the given strftime format.
-#html_last_updated_fmt = '%b %d, %Y'
+# html_last_updated_fmt = '%b %d, %Y'
 
 
 # If true, SmartyPants will be used to convert quotes and dashes to
 # If true, SmartyPants will be used to convert quotes and dashes to
 # typographically correct entities.
 # typographically correct entities.
-#html_use_smartypants = True
+# html_use_smartypants = True
 
 
 # Custom sidebar templates, maps document names to template names.
 # Custom sidebar templates, maps document names to template names.
 html_sidebars = {
 html_sidebars = {
-    '**': [
-        'pagure-logo.html',
-        'localtoc.html',
-        'relations.html',
-        'sourcelink.html',
-        'searchbox.html',
+    "**": [
+        "pagure-logo.html",
+        "localtoc.html",
+        "relations.html",
+        "sourcelink.html",
+        "searchbox.html",
     ]
     ]
 }
 }
 
 
 # Additional templates that should be rendered to pages, maps page names to
 # Additional templates that should be rendered to pages, maps page names to
 # template names.
 # template names.
-#html_additional_pages = {}
+# html_additional_pages = {}
 
 
 # If false, no module index is generated.
 # If false, no module index is generated.
-#html_domain_indices = True
+# html_domain_indices = True
 
 
 # If false, no index is generated.
 # If false, no index is generated.
-#html_use_index = True
+# html_use_index = True
 
 
 # If true, the index is split into individual pages for each letter.
 # If true, the index is split into individual pages for each letter.
-#html_split_index = False
+# html_split_index = False
 
 
 # If true, links to the reST sources are added to the pages.
 # If true, links to the reST sources are added to the pages.
-#html_show_sourcelink = True
+# html_show_sourcelink = True
 
 
 # If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
 # If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
-#html_show_sphinx = True
+# html_show_sphinx = True
 
 
 # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
 # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
-#html_show_copyright = True
+# html_show_copyright = True
 
 
 # If true, an OpenSearch description file will be output, and all pages will
 # If true, an OpenSearch description file will be output, and all pages will
 # contain a <link> tag referring to it. The value of this option must be the
 # contain a <link> tag referring to it. The value of this option must be the
 # base URL from which the finished HTML is served.
 # base URL from which the finished HTML is served.
-#html_use_opensearch = ''
+# html_use_opensearch = ''
 
 
 # This is the file name suffix for HTML files (e.g. ".xhtml").
 # This is the file name suffix for HTML files (e.g. ".xhtml").
-#html_file_suffix = None
+# html_file_suffix = None
 
 
 # Output file base name for HTML help builder.
 # Output file base name for HTML help builder.
-htmlhelp_basename = 'pagure'
+htmlhelp_basename = "pagure"
 
 
 # -- Options for LaTeX output ---------------------------------------------
 # -- Options for LaTeX output ---------------------------------------------
 
 
 latex_elements = {
 latex_elements = {
     # The paper size ('letterpaper' or 'a4paper').
     # The paper size ('letterpaper' or 'a4paper').
     #'papersize': 'letterpaper',
     #'papersize': 'letterpaper',
-
     # The font size ('10pt', '11pt' or '12pt').
     # The font size ('10pt', '11pt' or '12pt').
     #'pointsize': '10pt',
     #'pointsize': '10pt',
-
     # Additional stuff for the LaTeX preamble.
     # Additional stuff for the LaTeX preamble.
     #'preamble': '',
     #'preamble': '',
 }
 }
@@ -253,31 +246,33 @@ latex_elements = {
 # [howto/manual]).
 # [howto/manual]).
 latex_documents = [
 latex_documents = [
     (
     (
-        'index', 'pagure.tex', u'Pagure Documentation',
-        u'Pierre-Yves Chibon \\textless{}pingou@pingoured.fr\\textgreater{}',
-        'manual'
-    ),
+        "index",
+        "pagure.tex",
+        u"Pagure Documentation",
+        u"Pierre-Yves Chibon \\textless{}pingou@pingoured.fr\\textgreater{}",
+        "manual",
+    )
 ]
 ]
 
 
 # The name of an image file (relative to this directory) to place at the top of
 # The name of an image file (relative to this directory) to place at the top of
 # the title page.
 # the title page.
-#latex_logo = None
+# latex_logo = None
 
 
 # For "manual" documents, if this is true, then toplevel headings are parts,
 # For "manual" documents, if this is true, then toplevel headings are parts,
 # not chapters.
 # not chapters.
-#latex_use_parts = False
+# latex_use_parts = False
 
 
 # If true, show page references after internal links.
 # If true, show page references after internal links.
-#latex_show_pagerefs = False
+# latex_show_pagerefs = False
 
 
 # If true, show URL addresses after external links.
 # If true, show URL addresses after external links.
-#latex_show_urls = False
+# latex_show_urls = False
 
 
 # Documents to append as an appendix to all manuals.
 # Documents to append as an appendix to all manuals.
-#latex_appendices = []
+# latex_appendices = []
 
 
 # If false, no module index is generated.
 # If false, no module index is generated.
-#latex_domain_indices = True
+# latex_domain_indices = True
 
 
 # -- Options for manual page output ---------------------------------------
 # -- Options for manual page output ---------------------------------------
 
 
@@ -285,14 +280,16 @@ latex_documents = [
 # (source start file, name, description, authors, manual section).
 # (source start file, name, description, authors, manual section).
 man_pages = [
 man_pages = [
     (
     (
-        'index', 'pagure', u'Pagure Documentation',
-        [u'Pierre-Yves Chibon <pingou@pingoured.fr>'],
-        1
+        "index",
+        "pagure",
+        u"Pagure Documentation",
+        [u"Pierre-Yves Chibon <pingou@pingoured.fr>"],
+        1,
     )
     )
 ]
 ]
 
 
 # If true, show URL addresses after external links.
 # If true, show URL addresses after external links.
-#man_show_urls = False
+# man_show_urls = False
 
 
 
 
 # -- Options for Texinfo output -------------------------------------------
 # -- Options for Texinfo output -------------------------------------------
@@ -302,18 +299,21 @@ man_pages = [
 # dir menu entry, description, category)
 # dir menu entry, description, category)
 texinfo_documents = [
 texinfo_documents = [
     (
     (
-        'index', 'pagure', u'Pagure Documentation',
-        u'Pierre-Yves Chibon <pingou@pingoured.fr>', 'pagure',
-        'Small git-centric forge',
-        'Miscellaneous'
-    ),
+        "index",
+        "pagure",
+        u"Pagure Documentation",
+        u"Pierre-Yves Chibon <pingou@pingoured.fr>",
+        "pagure",
+        "Small git-centric forge",
+        "Miscellaneous",
+    )
 ]
 ]
 
 
 # Documents to append as an appendix to all manuals.
 # Documents to append as an appendix to all manuals.
-#texinfo_appendices = []
+# texinfo_appendices = []
 
 
 # If false, no module index is generated.
 # If false, no module index is generated.
-#texinfo_domain_indices = True
+# texinfo_domain_indices = True
 
 
 # How to display URL addresses: 'footnote', 'no', or 'inline'.
 # How to display URL addresses: 'footnote', 'no', or 'inline'.
-#texinfo_show_urls = 'footnote'
+# texinfo_show_urls = 'footnote'

+ 3 - 8
fedmsg.d/pagure.py

@@ -9,12 +9,7 @@ pagure producer (wsgi process).
 """
 """
 
 
 import socket
 import socket
-hostname = socket.gethostname().split('.')[0]
 
 
-config = dict(
-    endpoints={
-        "pagure.%s" % hostname: [
-            "tcp://127.0.0.1:3005",
-        ],
-    },
-)
+hostname = socket.gethostname().split(".")[0]
+
+config = dict(endpoints={"pagure.%s" % hostname: ["tcp://127.0.0.1:3005"]})

+ 1 - 3
fedmsg.d/pagure_ci.py

@@ -1,3 +1 @@
-config = {
-    'integrator.enabled': True,
-}
+config = {"integrator.enabled": True}

+ 1 - 1
files/aclchecker.py

@@ -99,7 +99,7 @@ result.update({"username": remoteuser, "cmd": cmd})
 
 
 for key in result:
 for key in result:
     if result[key] is None:
     if result[key] is None:
-        result[key] = ''
+        result[key] = ""
 
 
 runargs = [arg % result for arg in runner]
 runargs = [arg % result for arg in runner]
 if env:
 if env:

+ 38 - 26
files/api_key_expire_mail.py

@@ -13,29 +13,29 @@ import pagure.lib.model_base
 import pagure.lib.notify
 import pagure.lib.notify
 import pagure.lib.query
 import pagure.lib.query
 
 
-if 'PAGURE_CONFIG' not in os.environ \
-        and os.path.exists('/etc/pagure/pagure.cfg'):
-    print('Using configuration file `/etc/pagure/pagure.cfg`')
-    os.environ['PAGURE_CONFIG'] = '/etc/pagure/pagure.cfg'
+if "PAGURE_CONFIG" not in os.environ and os.path.exists(
+    "/etc/pagure/pagure.cfg"
+):
+    print("Using configuration file `/etc/pagure/pagure.cfg`")
+    os.environ["PAGURE_CONFIG"] = "/etc/pagure/pagure.cfg"
 
 
 _config = pagure.config.reload_config()
 _config = pagure.config.reload_config()
 
 
 
 
 def main(check=False, debug=False):
 def main(check=False, debug=False):
-    ''' The function that actually sends the email
-    in case the expiration date is near'''
+    """ The function that actually sends the email
+    in case the expiration date is near"""
 
 
     current_time = datetime.utcnow()
     current_time = datetime.utcnow()
     day_diff_for_mail = [10, 5, 1]
     day_diff_for_mail = [10, 5, 1]
     email_dates = [
     email_dates = [
         email_day.date()
         email_day.date()
         for email_day in [
         for email_day in [
-            current_time + timedelta(days=i)
-                   for i in day_diff_for_mail
+            current_time + timedelta(days=i) for i in day_diff_for_mail
         ]
         ]
     ]
     ]
 
 
-    session = pagure.lib.model_base.create_session(_config['DB_URL'])
+    session = pagure.lib.model_base.create_session(_config["DB_URL"])
     tokens = session.query(model.Token).all()
     tokens = session.query(model.Token).all()
 
 
     for token in tokens:
     for token in tokens:
@@ -46,51 +46,63 @@ def main(check=False, debug=False):
             username = user.fullname or user.username
             username = user.fullname or user.username
             user_email = user.default_email
             user_email = user.default_email
             days_left = (token.expiration - datetime.utcnow()).days
             days_left = (token.expiration - datetime.utcnow()).days
-            subject = 'Pagure API key expiration date is near!'
+            subject = "Pagure API key expiration date is near!"
             if token.project:
             if token.project:
-                text = '''Hi %s,
+                text = """Hi %s,
 Your Pagure API key %s linked to the project %s
 Your Pagure API key %s linked to the project %s
 will expire in %s day(s).
 will expire in %s day(s).
 Please get a new key for non-interrupted service.
 Please get a new key for non-interrupted service.
 
 
 Thanks,
 Thanks,
-Your Pagure Admin. ''' % (
+Your Pagure Admin. """ % (
                     username,
                     username,
                     token.description,
                     token.description,
                     token.project.fullname,
                     token.project.fullname,
-                    days_left
+                    days_left,
                 )
                 )
             else:
             else:
-                text = '''Hi %s,
+                text = """Hi %s,
 Your Pagure API key %s will expire in %s day(s).
 Your Pagure API key %s will expire in %s day(s).
 Please get a new key for non-interrupted service.
 Please get a new key for non-interrupted service.
 
 
 Thanks,
 Thanks,
-Your Pagure Admin. ''' % (
+Your Pagure Admin. """ % (
                     username,
                     username,
                     token.description,
                     token.description,
-                    days_left)
+                    days_left,
+                )
             if not check:
             if not check:
                 msg = pagure.lib.notify.send_email(text, subject, user_email)
                 msg = pagure.lib.notify.send_email(text, subject, user_email)
             else:
             else:
-                print('Sending email to %s (%s) about key: %s' % (
-                    username, user_email, token.id))
+                print(
+                    "Sending email to %s (%s) about key: %s"
+                    % (username, user_email, token.id)
+                )
             if debug:
             if debug:
-                print('Sent mail to %s' % username)
+                print("Sent mail to %s" % username)
 
 
     session.remove()
     session.remove()
     if debug:
     if debug:
-        print('Done')
+        print("Done")
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     parser = argparse.ArgumentParser(
     parser = argparse.ArgumentParser(
-            description='Script to send email before the api token expires')
+        description="Script to send email before the api token expires"
+    )
     parser.add_argument(
     parser.add_argument(
-        '--check', dest='check', action='store_true', default=False,
-        help='Print the some output but does not send any email')
+        "--check",
+        dest="check",
+        action="store_true",
+        default=False,
+        help="Print the some output but does not send any email",
+    )
     parser.add_argument(
     parser.add_argument(
-        '--debug', dest='debug', action='store_true', default=False,
-        help='Print the debugging output')
+        "--debug",
+        dest="debug",
+        action="store_true",
+        default=False,
+        help="Print the debugging output",
+    )
     args = parser.parse_args()
     args = parser.parse_args()
     main(debug=args.debug)
     main(debug=args.debug)

+ 6 - 6
files/emoji_clean_json.py

@@ -6,27 +6,27 @@ import os
 import sys
 import sys
 
 
 data = None
 data = None
-with open('emoji_strategy.json') as stream:
+with open("emoji_strategy.json") as stream:
     data = json.load(stream)
     data = json.load(stream)
 
 
 if not data:
 if not data:
-    print('Could not load the data from the JSON file')
+    print("Could not load the data from the JSON file")
     sys.exit(1)
     sys.exit(1)
 
 
 # Retrieve the items we keep in the JSON
 # Retrieve the items we keep in the JSON
 tokeep = {}
 tokeep = {}
 for key in data:
 for key in data:
-    if '-' in data[key]['unicode'] and data[key]['unicode'].startswith('1F'):
+    if "-" in data[key]["unicode"] and data[key]["unicode"].startswith("1F"):
         continue
         continue
     tokeep[key] = data[key]
     tokeep[key] = data[key]
 
 
 # Check if we have the keys of all images we kept
 # Check if we have the keys of all images we kept
 
 
-unicodes = [tokeep[key]['unicode'] for key in tokeep]
-images = [item.replace('.png', '') for item in os.listdir('png')]
+unicodes = [tokeep[key]["unicode"] for key in tokeep]
+images = [item.replace(".png", "") for item in os.listdir("png")]
 
 
 print(set(unicodes).symmetric_difference(set(images)))
 print(set(unicodes).symmetric_difference(set(images)))
 
 
 
 
-with open('emoji_strategy2.json', 'w') as stream:
+with open("emoji_strategy2.json", "w") as stream:
     json.dump(tokeep, stream)
     json.dump(tokeep, stream)

+ 28 - 18
files/mirror_project_in.py

@@ -13,23 +13,24 @@ import pagure.lib.model_base
 import pagure.lib.notify
 import pagure.lib.notify
 import pagure.lib.query
 import pagure.lib.query
 
 
-if 'PAGURE_CONFIG' not in os.environ \
-        and os.path.exists('/etc/pagure/pagure.cfg'):
-    print('Using configuration file `/etc/pagure/pagure.cfg`')
-    os.environ['PAGURE_CONFIG'] = '/etc/pagure/pagure.cfg'
+if "PAGURE_CONFIG" not in os.environ and os.path.exists(
+    "/etc/pagure/pagure.cfg"
+):
+    print("Using configuration file `/etc/pagure/pagure.cfg`")
+    os.environ["PAGURE_CONFIG"] = "/etc/pagure/pagure.cfg"
 
 
 _config = pagure.config.reload_config()
 _config = pagure.config.reload_config()
 
 
 
 
 def main(check=False, debug=False):
 def main(check=False, debug=False):
-    ''' The function pulls in all the changes from upstream'''
+    """ The function pulls in all the changes from upstream"""
 
 
-    session = pagure.lib.model_base.create_session(_config['DB_URL'])
-    projects = session.query(
-        model.Project
-    ).filter(
-        model.Project.mirrored_from != None
-    ).all()
+    session = pagure.lib.model_base.create_session(_config["DB_URL"])
+    projects = (
+        session.query(model.Project)
+        .filter(model.Project.mirrored_from != None)
+        .all()
+    )
 
 
     for project in projects:
     for project in projects:
         if debug:
         if debug:
@@ -41,17 +42,26 @@ def main(check=False, debug=False):
 
 
     session.remove()
     session.remove()
     if debug:
     if debug:
-        print('Done')
+        print("Done")
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     parser = argparse.ArgumentParser(
     parser = argparse.ArgumentParser(
-            description='Script to send email before the api token expires')
+        description="Script to send email before the api token expires"
+    )
     parser.add_argument(
     parser.add_argument(
-        '--check', dest='check', action='store_true', default=False,
-        help='Print the some output but does not send any email')
+        "--check",
+        dest="check",
+        action="store_true",
+        default=False,
+        help="Print the some output but does not send any email",
+    )
     parser.add_argument(
     parser.add_argument(
-        '--debug', dest='debug', action='store_true', default=False,
-        help='Print the debugging output')
+        "--debug",
+        dest="debug",
+        action="store_true",
+        default=False,
+        help="Print the debugging output",
+    )
     args = parser.parse_args()
     args = parser.parse_args()
     main(debug=args.debug)
     main(debug=args.debug)

+ 67 - 55
pagure-ev/pagure_stream_server.py

@@ -33,10 +33,11 @@ from six.moves.urllib.parse import urlparse
 log = logging.getLogger(__name__)
 log = logging.getLogger(__name__)
 
 
 
 
-if 'PAGURE_CONFIG' not in os.environ \
-        and os.path.exists('/etc/pagure/pagure.cfg'):
-    print('Using configuration file `/etc/pagure/pagure.cfg`')
-    os.environ['PAGURE_CONFIG'] = '/etc/pagure/pagure.cfg'
+if "PAGURE_CONFIG" not in os.environ and os.path.exists(
+    "/etc/pagure/pagure.cfg"
+):
+    print("Using configuration file `/etc/pagure/pagure.cfg`")
+    os.environ["PAGURE_CONFIG"] = "/etc/pagure/pagure.cfg"
 
 
 
 
 import pagure  # noqa: E402
 import pagure  # noqa: E402
@@ -47,17 +48,19 @@ from pagure.exceptions import PagureException, PagureEvException  # noqa: E402
 SERVER = None
 SERVER = None
 SESSION = None
 SESSION = None
 POOL = redis.ConnectionPool(
 POOL = redis.ConnectionPool(
-    host=pagure.config.config['REDIS_HOST'],
-    port=pagure.config.config['REDIS_PORT'],
-    db=pagure.config.config['REDIS_DB'])
+    host=pagure.config.config["REDIS_HOST"],
+    port=pagure.config.config["REDIS_PORT"],
+    db=pagure.config.config["REDIS_DB"],
+)
 
 
 
 
 def _get_session():
 def _get_session():
     global SESSION
     global SESSION
     if SESSION is None:
     if SESSION is None:
-        print(pagure.config.config['DB_URL'])
+        print(pagure.config.config["DB_URL"])
         SESSION = pagure.lib.model_base.create_session(
         SESSION = pagure.lib.model_base.create_session(
-            pagure.config.config['DB_URL'])
+            pagure.config.config["DB_URL"]
+        )
 
 
     return SESSION
     return SESSION
 
 
@@ -67,7 +70,7 @@ def _get_issue(repo, objid):
     objid (issue number).
     objid (issue number).
     """
     """
     issue = None
     issue = None
-    if not repo.settings.get('issue_tracker', True):
+    if not repo.settings.get("issue_tracker", True):
         raise PagureEvException("No issue tracker found for this project")
         raise PagureEvException("No issue tracker found for this project")
 
 
     session = _get_session()
     session = _get_session()
@@ -79,7 +82,8 @@ def _get_issue(repo, objid):
     if issue.private:
     if issue.private:
         # TODO: find a way to do auth
         # TODO: find a way to do auth
         raise PagureEvException(
         raise PagureEvException(
-            "This issue is private and you are not allowed to view it")
+            "This issue is private and you are not allowed to view it"
+        )
 
 
     return issue
     return issue
 
 
@@ -88,13 +92,15 @@ def _get_pull_request(repo, objid):
     """Get a PullRequest instance for a given repo (Project) and objid
     """Get a PullRequest instance for a given repo (Project) and objid
     (request number).
     (request number).
     """
     """
-    if not repo.settings.get('pull_requests', True):
+    if not repo.settings.get("pull_requests", True):
         raise PagureEvException(
         raise PagureEvException(
-            "No pull-request tracker found for this project")
+            "No pull-request tracker found for this project"
+        )
 
 
     session = _get_session()
     session = _get_session()
     request = pagure.lib.query.search_pull_requests(
     request = pagure.lib.query.search_pull_requests(
-        session, project_id=repo.id, requestid=objid)
+        session, project_id=repo.id, requestid=objid
+    )
 
 
     if request is None or request.project != repo:
     if request is None or request.project != repo:
         raise PagureEvException("Pull-Request '%s' not found" % objid)
         raise PagureEvException("Pull-Request '%s' not found" % objid)
@@ -105,20 +111,19 @@ def _get_pull_request(repo, objid):
 # Dict representing known object types that we handle requests for,
 # Dict representing known object types that we handle requests for,
 # and the bound functions for getting an object instance from the
 # and the bound functions for getting an object instance from the
 # parsed path data. Has to come after the functions it binds
 # parsed path data. Has to come after the functions it binds
-OBJECTS = {
-    'issue': _get_issue,
-    'pull-request': _get_pull_request
-}
+OBJECTS = {"issue": _get_issue, "pull-request": _get_pull_request}
 
 
 
 
 def get_obj_from_path(path):
 def get_obj_from_path(path):
     """ Return the Ticket or Request object based on the path provided.
     """ Return the Ticket or Request object based on the path provided.
     """
     """
     (username, namespace, reponame, objtype, objid) = pagure.utils.parse_path(
     (username, namespace, reponame, objtype, objid) = pagure.utils.parse_path(
-        path)
+        path
+    )
     session = _get_session()
     session = _get_session()
     repo = pagure.lib.query.get_authorized_project(
     repo = pagure.lib.query.get_authorized_project(
-            session, reponame, user=username, namespace=namespace)
+        session, reponame, user=username, namespace=namespace
+    )
 
 
     if repo is None:
     if repo is None:
         raise PagureEvException("Project '%s' not found" % reponame)
         raise PagureEvException("Project '%s' not found" % reponame)
@@ -137,9 +142,9 @@ def handle_client(client_reader, client_writer):
     data = None
     data = None
     while True:
     while True:
         # give client a chance to respond, timeout after 10 seconds
         # give client a chance to respond, timeout after 10 seconds
-        line = yield trololio.From(trololio.asyncio.wait_for(
-            client_reader.readline(),
-            timeout=10.0))
+        line = yield trololio.From(
+            trololio.asyncio.wait_for(client_reader.readline(), timeout=10.0)
+        )
         if not line.decode().strip():
         if not line.decode().strip():
             break
             break
         line = line.decode().rstrip()
         line = line.decode().rstrip()
@@ -156,7 +161,7 @@ def handle_client(client_reader, client_writer):
         log.warning("No URL provided: %s" % data)
         log.warning("No URL provided: %s" % data)
         return
         return
 
 
-    if '/' not in data[1]:
+    if "/" not in data[1]:
         log.warning("Invalid URL provided: %s" % data[1])
         log.warning("Invalid URL provided: %s" % data[1])
         return
         return
 
 
@@ -168,24 +173,25 @@ def handle_client(client_reader, client_writer):
         log.warning(err.message)
         log.warning(err.message)
         return
         return
 
 
-    origin = pagure.config.config.get('APP_URL')
-    if origin.endswith('/'):
+    origin = pagure.config.config.get("APP_URL")
+    if origin.endswith("/"):
         origin = origin[:-1]
         origin = origin[:-1]
 
 
-    client_writer.write((
-        "HTTP/1.0 200 OK\n"
-        "Content-Type: text/event-stream\n"
-        "Cache: nocache\n"
-        "Connection: keep-alive\n"
-        "Access-Control-Allow-Origin: %s\n\n" % origin
-    ).encode())
-
+    client_writer.write(
+        (
+            "HTTP/1.0 200 OK\n"
+            "Content-Type: text/event-stream\n"
+            "Cache: nocache\n"
+            "Connection: keep-alive\n"
+            "Access-Control-Allow-Origin: %s\n\n" % origin
+        ).encode()
+    )
 
 
     conn = redis.Redis(connection_pool=POOL)
     conn = redis.Redis(connection_pool=POOL)
     subscriber = conn.pubsub(ignore_subscribe_messages=True)
     subscriber = conn.pubsub(ignore_subscribe_messages=True)
 
 
     try:
     try:
-        subscriber.subscribe('pagure.%s' % obj.uid)
+        subscriber.subscribe("pagure.%s" % obj.uid)
 
 
         # Inside a while loop, wait for incoming events.
         # Inside a while loop, wait for incoming events.
         oncall = 0
         oncall = 0
@@ -195,14 +201,14 @@ def handle_client(client_reader, client_writer):
                 # Send a ping to see if the client is still alive
                 # Send a ping to see if the client is still alive
                 if oncall >= 5:
                 if oncall >= 5:
                     # Only send a ping once every 5 seconds
                     # Only send a ping once every 5 seconds
-                    client_writer.write(('event: ping\n\n').encode())
+                    client_writer.write(("event: ping\n\n").encode())
                     oncall = 0
                     oncall = 0
                 oncall += 1
                 oncall += 1
                 yield trololio.From(client_writer.drain())
                 yield trololio.From(client_writer.drain())
                 yield trololio.From(trololio.asyncio.sleep(1))
                 yield trololio.From(trololio.asyncio.sleep(1))
             else:
             else:
-                log.info("Sending %s", msg['data'])
-                client_writer.write(('data: %s\n\n' % msg['data']).encode())
+                log.info("Sending %s", msg["data"])
+                client_writer.write(("data: %s\n\n" % msg["data"]).encode())
                 yield trololio.From(client_writer.drain())
                 yield trololio.From(client_writer.drain())
 
 
     except OSError:
     except OSError:
@@ -223,12 +229,11 @@ def handle_client(client_reader, client_writer):
 def stats(client_reader, client_writer):
 def stats(client_reader, client_writer):
 
 
     try:
     try:
-        log.info('Clients: %s', SERVER.active_count)
-        client_writer.write((
-            "HTTP/1.0 200 OK\n"
-            "Cache: nocache\n\n"
-        ).encode())
-        client_writer.write(('data: %s\n\n' % SERVER.active_count).encode())
+        log.info("Clients: %s", SERVER.active_count)
+        client_writer.write(
+            ("HTTP/1.0 200 OK\n" "Cache: nocache\n\n").encode()
+        )
+        client_writer.write(("data: %s\n\n" % SERVER.active_count).encode())
         yield trololio.From(client_writer.drain())
         yield trololio.From(client_writer.drain())
 
 
     except trololio.ConnectionResetError as err:
     except trololio.ConnectionResetError as err:
@@ -247,20 +252,26 @@ def main():
         coro = trololio.asyncio.start_server(
         coro = trololio.asyncio.start_server(
             handle_client,
             handle_client,
             host=None,
             host=None,
-            port=pagure.config.config['EVENTSOURCE_PORT'],
-            loop=loop)
+            port=pagure.config.config["EVENTSOURCE_PORT"],
+            loop=loop,
+        )
         SERVER = loop.run_until_complete(coro)
         SERVER = loop.run_until_complete(coro)
         log.info(
         log.info(
-            'Serving server at {}'.format(SERVER.sockets[0].getsockname()))
-        if pagure.config.config.get('EV_STATS_PORT'):
+            "Serving server at {}".format(SERVER.sockets[0].getsockname())
+        )
+        if pagure.config.config.get("EV_STATS_PORT"):
             stats_coro = trololio.asyncio.start_server(
             stats_coro = trololio.asyncio.start_server(
                 stats,
                 stats,
                 host=None,
                 host=None,
-                port=pagure.config.config.get('EV_STATS_PORT'),
-                loop=loop)
+                port=pagure.config.config.get("EV_STATS_PORT"),
+                loop=loop,
+            )
             stats_server = loop.run_until_complete(stats_coro)
             stats_server = loop.run_until_complete(stats_coro)
-            log.info('Serving stats  at {}'.format(
-                stats_server.sockets[0].getsockname()))
+            log.info(
+                "Serving stats  at {}".format(
+                    stats_server.sockets[0].getsockname()
+                )
+            )
         loop.run_forever()
         loop.run_forever()
     except KeyboardInterrupt:
     except KeyboardInterrupt:
         pass
         pass
@@ -271,7 +282,7 @@ def main():
     finally:
     finally:
         # Close the server
         # Close the server
         SERVER.close()
         SERVER.close()
-        if pagure.config.config.get('EV_STATS_PORT'):
+        if pagure.config.config.get("EV_STATS_PORT"):
             stats_server.close()
             stats_server.close()
         log.info("End Connection")
         log.info("End Connection")
         loop.run_until_complete(SERVER.wait_closed())
         loop.run_until_complete(SERVER.wait_closed())
@@ -279,10 +290,11 @@ def main():
         log.info("End")
         log.info("End")
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     log = logging.getLogger("")
     log = logging.getLogger("")
     formatter = logging.Formatter(
     formatter = logging.Formatter(
-        "%(asctime)s %(levelname)s [%(module)s:%(lineno)d] %(message)s")
+        "%(asctime)s %(levelname)s [%(module)s:%(lineno)d] %(message)s"
+    )
 
 
     # setup console logging
     # setup console logging
     log.setLevel(logging.DEBUG)
     log.setLevel(logging.DEBUG)

+ 95 - 91
pagure-milters/comment_email_milter.py

@@ -26,9 +26,10 @@ import pagure.lib.model_base
 import pagure.lib.query
 import pagure.lib.query
 
 
 
 
-if 'PAGURE_CONFIG' not in os.environ \
-        and os.path.exists('/etc/pagure/pagure.cfg'):
-    os.environ['PAGURE_CONFIG'] = '/etc/pagure/pagure.cfg'
+if "PAGURE_CONFIG" not in os.environ and os.path.exists(
+    "/etc/pagure/pagure.cfg"
+):
+    os.environ["PAGURE_CONFIG"] = "/etc/pagure/pagure.cfg"
 
 
 
 
 logq = Queue(maxsize=4)
 logq = Queue(maxsize=4)
@@ -36,8 +37,9 @@ _config = pagure.config.reload_config()
 
 
 
 
 def get_email_body(emailobj):
 def get_email_body(emailobj):
-    ''' Return the body of the email, preferably in text.
-    '''
+    """ Return the body of the email, preferably in text.
+    """
+
     def _get_body(emailobj):
     def _get_body(emailobj):
         """ Return the first text/plain body found if the email is multipart
         """ Return the first text/plain body found if the email is multipart
         or just the regular payload otherwise.
         or just the regular payload otherwise.
@@ -51,34 +53,33 @@ def get_email_body(emailobj):
                     return _get_body(payload)
                     return _get_body(payload)
 
 
                 body = payload.get_payload()
                 body = payload.get_payload()
-                if payload.get_content_type() == 'text/plain':
+                if payload.get_content_type() == "text/plain":
                     return body
                     return body
         else:
         else:
             return emailobj.get_payload()
             return emailobj.get_payload()
 
 
     body = _get_body(emailobj)
     body = _get_body(emailobj)
 
 
-    enc = emailobj['Content-Transfer-Encoding']
-    if enc == 'base64':
+    enc = emailobj["Content-Transfer-Encoding"]
+    if enc == "base64":
         body = base64.decodestring(body)
         body = base64.decodestring(body)
 
 
     return body
     return body
 
 
 
 
 def clean_item(item):
 def clean_item(item):
-    ''' For an item provided as <item> return the content, if there are no
+    """ For an item provided as <item> return the content, if there are no
     <> then return the string.
     <> then return the string.
-    '''
-    if '<' in item:
-        item = item.split('<')[1]
-    if '>' in item:
-        item = item.split('>')[0]
+    """
+    if "<" in item:
+        item = item.split("<")[1]
+    if ">" in item:
+        item = item.split(">")[0]
 
 
     return item
     return item
 
 
 
 
 class PagureMilter(Milter.Base):
 class PagureMilter(Milter.Base):
-
     def __init__(self):  # A new instance with each new connection.
     def __init__(self):  # A new instance with each new connection.
         self.id = Milter.uniqueID()  # Integer incremented with each call.
         self.id = Milter.uniqueID()  # Integer incremented with each call.
         self.fp = None
         self.fp = None
@@ -94,28 +95,28 @@ class PagureMilter(Milter.Base):
         # must use addheader, chgheader, replacebody to change the message
         # must use addheader, chgheader, replacebody to change the message
         # on the MTA.
         # on the MTA.
         self.fp = BytesIO()
         self.fp = BytesIO()
-        self.canon_from = '@'.join(parse_addr(mailfrom))
-        from_txt = 'From %s %s\n' % (self.canon_from, time.ctime())
-        self.fp.write(from_txt.encode('utf-8'))
+        self.canon_from = "@".join(parse_addr(mailfrom))
+        from_txt = "From %s %s\n" % (self.canon_from, time.ctime())
+        self.fp.write(from_txt.encode("utf-8"))
         return Milter.CONTINUE
         return Milter.CONTINUE
 
 
     @Milter.noreply
     @Milter.noreply
     def header(self, name, hval):
     def header(self, name, hval):
-        ''' Headers '''
+        """ Headers """
         # add header to buffer
         # add header to buffer
         header_txt = "%s: %s\n" % (name, hval)
         header_txt = "%s: %s\n" % (name, hval)
-        self.fp.write(header_txt.encode('utf-8'))
+        self.fp.write(header_txt.encode("utf-8"))
         return Milter.CONTINUE
         return Milter.CONTINUE
 
 
     @Milter.noreply
     @Milter.noreply
     def eoh(self):
     def eoh(self):
-        ''' End of Headers '''
+        """ End of Headers """
         self.fp.write(b"\n")
         self.fp.write(b"\n")
         return Milter.CONTINUE
         return Milter.CONTINUE
 
 
     @Milter.noreply
     @Milter.noreply
     def body(self, chunk):
     def body(self, chunk):
-        ''' Body '''
+        """ Body """
         self.fp.write(chunk)
         self.fp.write(chunk)
         return Milter.CONTINUE
         return Milter.CONTINUE
 
 
@@ -127,138 +128,139 @@ class PagureMilter(Milter.Base):
         return Milter.CONTINUE
         return Milter.CONTINUE
 
 
     def eom(self):
     def eom(self):
-        ''' End of Message '''
+        """ End of Message """
         self.fp.seek(0)
         self.fp.seek(0)
         msg = email.message_from_file(self.fp)
         msg = email.message_from_file(self.fp)
 
 
-        msg_id = msg.get('In-Reply-To', None)
+        msg_id = msg.get("In-Reply-To", None)
         if msg_id is None:
         if msg_id is None:
-            self.log('No In-Reply-To, keep going')
+            self.log("No In-Reply-To, keep going")
             return Milter.CONTINUE
             return Milter.CONTINUE
 
 
         # Ensure we don't get extra lines in the message-id
         # Ensure we don't get extra lines in the message-id
-        msg_id = msg_id.split('\n')[0].strip()
+        msg_id = msg_id.split("\n")[0].strip()
 
 
-        self.log('msg-ig %s' % msg_id)
-        self.log('To %s' % msg['to'])
-        self.log('Cc %s' % msg.get('cc'))
-        self.log('From %s' % msg['From'])
+        self.log("msg-ig %s" % msg_id)
+        self.log("To %s" % msg["to"])
+        self.log("Cc %s" % msg.get("cc"))
+        self.log("From %s" % msg["From"])
 
 
         # Check the email was sent to the right address
         # Check the email was sent to the right address
-        email_address = msg['to']
-        if 'reply+' in msg.get('cc', ''):
-            email_address = msg['cc']
-        if 'reply+' not in email_address:
+        email_address = msg["to"]
+        if "reply+" in msg.get("cc", ""):
+            email_address = msg["cc"]
+        if "reply+" not in email_address:
             self.log(
             self.log(
-                'No valid recipient email found in To/Cc: %s'
-                % email_address)
+                "No valid recipient email found in To/Cc: %s" % email_address
+            )
             return Milter.CONTINUE
             return Milter.CONTINUE
 
 
         # Ensure the user replied to his/her own notification, not that
         # Ensure the user replied to his/her own notification, not that
         # they are trying to forge their ID into someone else's
         # they are trying to forge their ID into someone else's
-        salt = _config.get('SALT_EMAIL')
-        from_email = clean_item(msg['From'])
-        session = pagure.lib.model_base.create_session(_config['DB_URL'])
+        salt = _config.get("SALT_EMAIL")
+        from_email = clean_item(msg["From"])
+        session = pagure.lib.model_base.create_session(_config["DB_URL"])
         try:
         try:
             user = pagure.lib.query.get_user(session, from_email)
             user = pagure.lib.query.get_user(session, from_email)
         except:
         except:
             self.log(
             self.log(
-                "Could not find an user in the DB associated with %s" %
-                from_email)
+                "Could not find an user in the DB associated with %s"
+                % from_email
+            )
             session.remove()
             session.remove()
             return Milter.CONTINUE
             return Milter.CONTINUE
 
 
         hashes = []
         hashes = []
         for email_obj in user.emails:
         for email_obj in user.emails:
-            m = hashlib.sha512('%s%s%s' % (msg_id, salt, email_obj.email))
+            m = hashlib.sha512("%s%s%s" % (msg_id, salt, email_obj.email))
             hashes.append(m.hexdigest())
             hashes.append(m.hexdigest())
 
 
-        tohash = email_address.split('@')[0].split('+')[-1]
+        tohash = email_address.split("@")[0].split("+")[-1]
         if tohash not in hashes:
         if tohash not in hashes:
-            self.log('hash list: %s' % hashes)
-            self.log('tohash:    %s' % tohash)
-            self.log('Hash does not correspond to the destination')
+            self.log("hash list: %s" % hashes)
+            self.log("tohash:    %s" % tohash)
+            self.log("Hash does not correspond to the destination")
             session.remove()
             session.remove()
             return Milter.CONTINUE
             return Milter.CONTINUE
 
 
-        if msg['From'] and msg['From'] == _config.get('FROM_EMAIL'):
+        if msg["From"] and msg["From"] == _config.get("FROM_EMAIL"):
             self.log("Let's not process the email we send")
             self.log("Let's not process the email we send")
             session.remove()
             session.remove()
             return Milter.CONTINUE
             return Milter.CONTINUE
 
 
         msg_id = clean_item(msg_id)
         msg_id = clean_item(msg_id)
 
 
-        if msg_id and '-ticket-' in msg_id:
-            self.log('Processing issue')
+        if msg_id and "-ticket-" in msg_id:
+            self.log("Processing issue")
             session.remove()
             session.remove()
             return self.handle_ticket_email(msg, msg_id)
             return self.handle_ticket_email(msg, msg_id)
-        elif msg_id and '-pull-request-' in msg_id:
-            self.log('Processing pull-request')
+        elif msg_id and "-pull-request-" in msg_id:
+            self.log("Processing pull-request")
             session.remove()
             session.remove()
             return self.handle_request_email(msg, msg_id)
             return self.handle_request_email(msg, msg_id)
         else:
         else:
-            self.log('Not a pagure ticket or pull-request email, let it go')
+            self.log("Not a pagure ticket or pull-request email, let it go")
             session.remove()
             session.remove()
             return Milter.CONTINUE
             return Milter.CONTINUE
 
 
     def handle_ticket_email(self, emailobj, msg_id):
     def handle_ticket_email(self, emailobj, msg_id):
-        ''' Add the email as a comment on a ticket. '''
-        uid = msg_id.split('-ticket-')[-1].split('@')[0]
+        """ Add the email as a comment on a ticket. """
+        uid = msg_id.split("-ticket-")[-1].split("@")[0]
         parent_id = None
         parent_id = None
-        if '-' in uid:
-            uid, parent_id = uid.rsplit('-', 1)
-        if '/' in uid:
-            uid = uid.split('/')[0]
-        self.log('uid %s' % uid)
-        self.log('parent_id %s' % parent_id)
+        if "-" in uid:
+            uid, parent_id = uid.rsplit("-", 1)
+        if "/" in uid:
+            uid = uid.split("/")[0]
+        self.log("uid %s" % uid)
+        self.log("parent_id %s" % parent_id)
 
 
         data = {
         data = {
-            'objid': uid,
-            'comment': get_email_body(emailobj),
-            'useremail': clean_item(emailobj['From']),
+            "objid": uid,
+            "comment": get_email_body(emailobj),
+            "useremail": clean_item(emailobj["From"]),
         }
         }
-        url = _config.get('APP_URL')
+        url = _config.get("APP_URL")
 
 
-        if url.endswith('/'):
+        if url.endswith("/"):
             url = url[:-1]
             url = url[:-1]
-        url = '%s/pv/ticket/comment/' % url
-        self.log('Calling URL: %s' % url)
+        url = "%s/pv/ticket/comment/" % url
+        self.log("Calling URL: %s" % url)
         req = requests.put(url, data=data)
         req = requests.put(url, data=data)
         if req.status_code == 200:
         if req.status_code == 200:
-            self.log('Comment added')
+            self.log("Comment added")
             return Milter.ACCEPT
             return Milter.ACCEPT
-        self.log('Could not add the comment to ticket to pagure')
+        self.log("Could not add the comment to ticket to pagure")
         self.log(req.text)
         self.log(req.text)
 
 
         return Milter.CONTINUE
         return Milter.CONTINUE
 
 
     def handle_request_email(self, emailobj, msg_id):
     def handle_request_email(self, emailobj, msg_id):
-        ''' Add the email as a comment on a request. '''
-        uid = msg_id.split('-pull-request-')[-1].split('@')[0]
+        """ Add the email as a comment on a request. """
+        uid = msg_id.split("-pull-request-")[-1].split("@")[0]
         parent_id = None
         parent_id = None
-        if '-' in uid:
-            uid, parent_id = uid.rsplit('-', 1)
-        if '/' in uid:
-            uid = uid.split('/')[0]
-        self.log('uid %s' % uid)
-        self.log('parent_id %s' % parent_id)
+        if "-" in uid:
+            uid, parent_id = uid.rsplit("-", 1)
+        if "/" in uid:
+            uid = uid.split("/")[0]
+        self.log("uid %s" % uid)
+        self.log("parent_id %s" % parent_id)
 
 
         data = {
         data = {
-            'objid': uid,
-            'comment': get_email_body(emailobj),
-            'useremail': clean_item(emailobj['From']),
+            "objid": uid,
+            "comment": get_email_body(emailobj),
+            "useremail": clean_item(emailobj["From"]),
         }
         }
-        url = _config.get('APP_URL')
+        url = _config.get("APP_URL")
 
 
-        if url.endswith('/'):
+        if url.endswith("/"):
             url = url[:-1]
             url = url[:-1]
-        url = '%s/pv/pull-request/comment/' % url
-        self.log('Calling URL: %s' % url)
+        url = "%s/pv/pull-request/comment/" % url
+        self.log("Calling URL: %s" % url)
         req = requests.put(url, data=data)
         req = requests.put(url, data=data)
         if req.status_code == 200:
         if req.status_code == 200:
-            self.log('Comment added on PR')
+            self.log("Comment added on PR")
             return Milter.ACCEPT
             return Milter.ACCEPT
-        self.log('Could not add the comment to PR to pagure')
+        self.log("Could not add the comment to PR to pagure")
         self.log(req.text)
         self.log(req.text)
 
 
         return Milter.CONTINUE
         return Milter.CONTINUE
@@ -270,11 +272,13 @@ def background():
         if not t:
         if not t:
             break
             break
         msg, id, ts = t
         msg, id, ts = t
-        print("%s [%d]" % (time.strftime(
-            '%Y%b%d %H:%M:%S', time.localtime(ts)), id))
+        print(
+            "%s [%d]"
+            % (time.strftime("%Y%b%d %H:%M:%S", time.localtime(ts)), id)
+        )
         # 2005Oct13 02:34:11 [1] msg1 msg2 msg3 ...
         # 2005Oct13 02:34:11 [1] msg1 msg2 msg3 ...
         for i in msg:
         for i in msg:
-            print(i,)
+            print(i)
         print
         print
 
 
 
 
@@ -285,12 +289,12 @@ def main():
     timeout = 600
     timeout = 600
     # Register to have the Milter factory create instances of your class:
     # Register to have the Milter factory create instances of your class:
     Milter.factory = PagureMilter
     Milter.factory = PagureMilter
-    print("%s pagure milter startup" % time.strftime('%Y%b%d %H:%M:%S'))
+    print("%s pagure milter startup" % time.strftime("%Y%b%d %H:%M:%S"))
     sys.stdout.flush()
     sys.stdout.flush()
     Milter.runmilter("paguremilter", socketname, timeout)
     Milter.runmilter("paguremilter", socketname, timeout)
     logq.put(None)
     logq.put(None)
     bt.join()
     bt.join()
-    print("%s pagure milter shutdown" % time.strftime('%Y%b%d %H:%M:%S'))
+    print("%s pagure milter shutdown" % time.strftime("%Y%b%d %H:%M:%S"))
 
 
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":

+ 32 - 18
rundocserver.py

@@ -3,7 +3,7 @@
 from __future__ import unicode_literals, absolute_import
 from __future__ import unicode_literals, absolute_import
 
 
 # These two lines are needed to run on EL6
 # These two lines are needed to run on EL6
-__requires__ = ['jinja2 >= 2.4']
+__requires__ = ["jinja2 >= 2.4"]
 import pkg_resources
 import pkg_resources
 
 
 import argparse
 import argparse
@@ -11,42 +11,56 @@ import sys
 import os
 import os
 
 
 
 
-parser = argparse.ArgumentParser(
-    description='Run the Pagure doc server')
+parser = argparse.ArgumentParser(description="Run the Pagure doc server")
 parser.add_argument(
 parser.add_argument(
-    '--config', '-c', dest='config',
-    help='Configuration file to use for the pagure doc server.')
+    "--config",
+    "-c",
+    dest="config",
+    help="Configuration file to use for the pagure doc server.",
+)
 parser.add_argument(
 parser.add_argument(
-    '--debug', dest='debug', action='store_true',
+    "--debug",
+    dest="debug",
+    action="store_true",
     default=False,
     default=False,
-    help='Expand the level of data returned.')
+    help="Expand the level of data returned.",
+)
 parser.add_argument(
 parser.add_argument(
-    '--profile', dest='profile', action='store_true',
+    "--profile",
+    dest="profile",
+    action="store_true",
     default=False,
     default=False,
-    help='Profile the doc server.')
+    help="Profile the doc server.",
+)
 parser.add_argument(
 parser.add_argument(
-    '--port', '-p', default=5001,
-    help='Port for the Pagure doc server to run on.')
+    "--port",
+    "-p",
+    default=5001,
+    help="Port for the Pagure doc server to run on.",
+)
 parser.add_argument(
 parser.add_argument(
-    '--host', default="127.0.0.1",
-    help='Hostname to listen on. When set to 0.0.0.0 the server is '
-    'available externally. Defaults to 127.0.0.1 making the it only '
-    'visible on localhost')
+    "--host",
+    default="127.0.0.1",
+    help="Hostname to listen on. When set to 0.0.0.0 the server is "
+    "available externally. Defaults to 127.0.0.1 making the it only "
+    "visible on localhost",
+)
 
 
 args = parser.parse_args()
 args = parser.parse_args()
 
 
 if args.config:
 if args.config:
     config = args.config
     config = args.config
-    if not config.startswith('/'):
+    if not config.startswith("/"):
         here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
         here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
         config = os.path.join(here, config)
         config = os.path.join(here, config)
-    os.environ['PAGURE_CONFIG'] = config
+    os.environ["PAGURE_CONFIG"] = config
 
 
 from pagure.docs_server import APP
 from pagure.docs_server import APP
 
 
 if args.profile:
 if args.profile:
     from werkzeug.contrib.profiler import ProfilerMiddleware
     from werkzeug.contrib.profiler import ProfilerMiddleware
-    APP.config['PROFILE'] = True
+
+    APP.config["PROFILE"] = True
     APP.wsgi_app = ProfilerMiddleware(APP.wsgi_app, restrictions=[30])
     APP.wsgi_app = ProfilerMiddleware(APP.wsgi_app, restrictions=[30])
 
 
 APP.debug = True
 APP.debug = True

+ 40 - 26
runserver.py

@@ -7,56 +7,69 @@ import sys
 import os
 import os
 
 
 
 
-parser = argparse.ArgumentParser(
-    description='Run the Pagure app')
+parser = argparse.ArgumentParser(description="Run the Pagure app")
 parser.add_argument(
 parser.add_argument(
-    '--config', '-c', dest='config',
-    help='Configuration file to use for pagure.')
+    "--config",
+    "-c",
+    dest="config",
+    help="Configuration file to use for pagure.",
+)
 parser.add_argument(
 parser.add_argument(
-    '--plugins',  dest='plugins',
-    help='Configuration file for pagure plugin.')
+    "--plugins", dest="plugins", help="Configuration file for pagure plugin."
+)
 parser.add_argument(
 parser.add_argument(
-    '--debug', dest='debug', action='store_true',
+    "--debug",
+    dest="debug",
+    action="store_true",
     default=False,
     default=False,
-    help='Expand the level of data returned.')
+    help="Expand the level of data returned.",
+)
 parser.add_argument(
 parser.add_argument(
-    '--profile', dest='profile', action='store_true',
+    "--profile",
+    dest="profile",
+    action="store_true",
     default=False,
     default=False,
-    help='Profile Pagure.')
+    help="Profile Pagure.",
+)
 parser.add_argument(
 parser.add_argument(
-    '--perf-verbose', dest='perfverbose', action='store_true',
+    "--perf-verbose",
+    dest="perfverbose",
+    action="store_true",
     default=False,
     default=False,
-    help='Enable per-request printing of performance statistics.')
+    help="Enable per-request printing of performance statistics.",
+)
 parser.add_argument(
 parser.add_argument(
-    '--port', '-p', default=5000,
-    help='Port for the Pagure to run on.')
+    "--port", "-p", default=5000, help="Port for the Pagure to run on."
+)
 parser.add_argument(
 parser.add_argument(
-    '--no-debug', action='store_true',
-    help='Disable debugging')
+    "--no-debug", action="store_true", help="Disable debugging"
+)
 parser.add_argument(
 parser.add_argument(
-    '--host', default="127.0.0.1",
-    help='Hostname to listen on. When set to 0.0.0.0 the server is available '
-    'externally. Defaults to 127.0.0.1 making the it only visible on localhost')
+    "--host",
+    default="127.0.0.1",
+    help="Hostname to listen on. When set to 0.0.0.0 the server is available "
+    "externally. Defaults to 127.0.0.1 making the it only visible on localhost",
+)
 
 
 args = parser.parse_args()
 args = parser.parse_args()
 
 
 if args.config:
 if args.config:
     config = args.config
     config = args.config
-    if not config.startswith('/'):
+    if not config.startswith("/"):
         here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
         here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
         config = os.path.join(here, config)
         config = os.path.join(here, config)
-    os.environ['PAGURE_CONFIG'] = config
+    os.environ["PAGURE_CONFIG"] = config
 
 
 if args.plugins:
 if args.plugins:
     config = args.plugins
     config = args.plugins
-    if not config.startswith('/'):
+    if not config.startswith("/"):
         here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
         here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
         config = os.path.join(here, config)
         config = os.path.join(here, config)
-    os.environ['PAGURE_PLUGIN'] = config
+    os.environ["PAGURE_PLUGIN"] = config
 
 
 if args.perfverbose:
 if args.perfverbose:
-    os.environ['PAGURE_PERFREPO'] = 'true'
-    os.environ['PAGURE_PERFREPO_VERBOSE'] = 'true'
+    os.environ["PAGURE_PERFREPO"] = "true"
+    os.environ["PAGURE_PERFREPO_VERBOSE"] = "true"
 
 
 from pagure.flask_app import create_app
 from pagure.flask_app import create_app
 
 
@@ -64,7 +77,8 @@ APP = create_app()
 
 
 if args.profile:
 if args.profile:
     from werkzeug.contrib.profiler import ProfilerMiddleware
     from werkzeug.contrib.profiler import ProfilerMiddleware
-    APP.config['PROFILE'] = True
+
+    APP.config["PROFILE"] = True
     APP.wsgi_app = ProfilerMiddleware(APP.wsgi_app, restrictions=[30])
     APP.wsgi_app = ProfilerMiddleware(APP.wsgi_app, restrictions=[30])
 
 
 APP.debug = not args.no_debug
 APP.debug = not args.no_debug

+ 95 - 47
runtests.py

@@ -28,12 +28,13 @@ PRINTLOCK = None
 RUNNING = []
 RUNNING = []
 FAILED = []
 FAILED = []
 NUMPROCS = multiprocessing.cpu_count() - 1
 NUMPROCS = multiprocessing.cpu_count() - 1
-if os.environ.get('BUILD_ID'):
+if os.environ.get("BUILD_ID"):
     NUMPROCS = multiprocessing.cpu_count()
     NUMPROCS = multiprocessing.cpu_count()
 
 
 HERE = os.path.join(os.path.dirname(os.path.abspath(__file__)))
 HERE = os.path.join(os.path.dirname(os.path.abspath(__file__)))
 LOG = logging.getLogger(__name__)
 LOG = logging.getLogger(__name__)
 
 
+
 def setup_parser():
 def setup_parser():
     """ Set up the command line arguments supported and return the arguments
     """ Set up the command line arguments supported and return the arguments
     """
     """
@@ -144,7 +145,10 @@ def setup_parser():
         help="Show the error files using `less`",
         help="Show the error files using `less`",
     )
     )
     parser_run.add_argument(
     parser_run.add_argument(
-        "-n", default=None, nargs="?", type=int,
+        "-n",
+        default=None,
+        nargs="?",
+        type=int,
         help="Number of failed test to show",
         help="Number of failed test to show",
     )
     )
     parser_run.set_defaults(func=do_list)
     parser_run.set_defaults(func=do_list)
@@ -152,7 +156,8 @@ def setup_parser():
     # SHOW-COVERAGE
     # SHOW-COVERAGE
     parser_run = subparsers.add_parser(
     parser_run = subparsers.add_parser(
         "show-coverage",
         "show-coverage",
-        help="Shows the coverage report from the data in the results folder")
+        help="Shows the coverage report from the data in the results folder",
+    )
     parser_run.add_argument(
     parser_run.add_argument(
         "--debug",
         "--debug",
         dest="debug",
         dest="debug",
@@ -221,9 +226,9 @@ def remove_running(suite, failed):
     with PRINTLOCK:
     with PRINTLOCK:
         RUNNING.remove(suite)
         RUNNING.remove(suite)
         clean_line()
         clean_line()
-        status = 'passed'
+        status = "passed"
         if failed:
         if failed:
-            status = 'FAILED'
+            status = "FAILED"
         print("Test suite %s: %s" % (status, suite))
         print("Test suite %s: %s" % (status, suite))
         print_running()
         print_running()
 
 
@@ -255,15 +260,21 @@ class WorkerThread(threading.Thread):
                     cmd.append("--with-cover")
                     cmd.append("--with-cover")
 
 
                 env = os.environ.copy()
                 env = os.environ.copy()
-                env.update({
-                    "PAGURE_CONFIG": "../tests/test_config",
-                    "COVERAGE_FILE": os.path.join(
-                        self.results, "%s.coverage" % self.name
-                    ),
-                    "LANG": "en_US.UTF-8",
-                })
+                env.update(
+                    {
+                        "PAGURE_CONFIG": "../tests/test_config",
+                        "COVERAGE_FILE": os.path.join(
+                            self.results, "%s.coverage" % self.name
+                        ),
+                        "LANG": "en_US.UTF-8",
+                    }
+                )
                 proc = subprocess.Popen(
                 proc = subprocess.Popen(
-                    cmd, cwd=".", stdout=resfile, stderr=subprocess.STDOUT, env=env
+                    cmd,
+                    cwd=".",
+                    stdout=resfile,
+                    stderr=subprocess.STDOUT,
+                    env=env,
                 )
                 )
                 res = proc.wait()
                 res = proc.wait()
                 if res == 0:
                 if res == 0:
@@ -299,9 +310,10 @@ def do_run(args):
             except:
             except:
                 print(
                 print(
                     "Could not delete the %s directory, it will be "
                     "Could not delete the %s directory, it will be "
-                    "wiped clean" % args.results)
+                    "wiped clean" % args.results
+                )
                 for content in os.listdir(args.results):
                 for content in os.listdir(args.results):
-                   os.remove(content)
+                    os.remove(content)
     else:
     else:
         os.mkdir(args.results)
         os.mkdir(args.results)
 
 
@@ -313,7 +325,9 @@ def do_run(args):
         here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
         here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
         failed_tests_fullpath = os.path.join(here, args.failed_tests)
         failed_tests_fullpath = os.path.join(here, args.failed_tests)
         if not os.path.exists(failed_tests_fullpath):
         if not os.path.exists(failed_tests_fullpath):
-            print("Could not find the specified file:%s" % failed_tests_fullpath)
+            print(
+                "Could not find the specified file:%s" % failed_tests_fullpath
+            )
             return 1
             return 1
         print("Loading failed tests")
         print("Loading failed tests")
         try:
         try:
@@ -346,12 +360,15 @@ def do_rerun(args):
         return 1
         return 1
 
 
     if not os.path.exists(args.results):
     if not os.path.exists(args.results):
-        print("Could not find an existing results folder at: %s" % args.results)
+        print(
+            "Could not find an existing results folder at: %s" % args.results
+        )
         return 1
         return 1
 
 
     if not os.path.exists(os.path.join(args.results, "newfailed")):
     if not os.path.exists(os.path.join(args.results, "newfailed")):
         print(
         print(
-            "Could not find an failed tests in the results folder at: %s" % args.results
+            "Could not find an failed tests in the results folder at: %s"
+            % args.results
         )
         )
         return 1
         return 1
 
 
@@ -378,9 +395,9 @@ def do_rerun(args):
 def _get_pyvers(args):
 def _get_pyvers(args):
     pyvers = [2, 3]
     pyvers = [2, 3]
     if args.py2:
     if args.py2:
-        pyvers = [2,]
+        pyvers = [2]
     elif args.py3:
     elif args.py3:
-        pyvers = [3,]
+        pyvers = [3]
 
 
     un_versioned = False
     un_versioned = False
     try:
     try:
@@ -433,23 +450,45 @@ def _run_test_suites(args, suites):
 
 
     if len(pyvers) == 1:
     if len(pyvers) == 1:
         if pyvers[0] == 2:
         if pyvers[0] == 2:
-            subprocess.check_call([
-                "sed", "-i", "-e", "s|python|python2|",
-                "pagure/hooks/files/hookrunner"
-            ])
-            subprocess.check_call([
-                "sed", "-i", "-e", "s|\['alembic',|\['alembic-2',|",
-                "tests/test_alembic.py"
-            ])
+            subprocess.check_call(
+                [
+                    "sed",
+                    "-i",
+                    "-e",
+                    "s|python|python2|",
+                    "pagure/hooks/files/hookrunner",
+                ]
+            )
+            subprocess.check_call(
+                [
+                    "sed",
+                    "-i",
+                    "-e",
+                    "s|\['alembic',|\['alembic-2',|",
+                    "tests/test_alembic.py",
+                ]
+            )
         elif pyvers[0] == 3:
         elif pyvers[0] == 3:
-            subprocess.check_call([
-                "sed", "-i", "-e", "s|python|python3|",
-                "pagure/hooks/files/hookrunner"
-            ], cwd=HERE)
-            subprocess.check_call([
-                "sed", "-i", "-e", "s|\['alembic',|\['alembic-3',|",
-                "tests/test_alembic.py"
-            ], cwd=HERE)
+            subprocess.check_call(
+                [
+                    "sed",
+                    "-i",
+                    "-e",
+                    "s|python|python3|",
+                    "pagure/hooks/files/hookrunner",
+                ],
+                cwd=HERE,
+            )
+            subprocess.check_call(
+                [
+                    "sed",
+                    "-i",
+                    "-e",
+                    "s|\['alembic',|\['alembic-3',|",
+                    "tests/test_alembic.py",
+                ],
+                cwd=HERE,
+            )
 
 
     for suite in suites:
     for suite in suites:
         for pyver in pyvers:
         for pyver in pyvers:
@@ -472,12 +511,14 @@ def _run_test_suites(args, suites):
     print()
     print()
     print("All work done")
     print("All work done")
 
 
-    subprocess.check_call([
-        "git",
-        "checkout",
-        "pagure/hooks/files/hookrunner",
-        "tests/test_alembic.py"
-    ])
+    subprocess.check_call(
+        [
+            "git",
+            "checkout",
+            "pagure/hooks/files/hookrunner",
+            "tests/test_alembic.py",
+        ]
+    )
 
 
     # Gather results
     # Gather results
     print()
     print()
@@ -527,12 +568,15 @@ def do_list(args):
         return 1
         return 1
 
 
     if not os.path.exists(args.results):
     if not os.path.exists(args.results):
-        print("Could not find an existing results folder at: %s" % args.results)
+        print(
+            "Could not find an existing results folder at: %s" % args.results
+        )
         return 1
         return 1
 
 
     if not os.path.exists(os.path.join(args.results, "newfailed")):
     if not os.path.exists(os.path.join(args.results, "newfailed")):
         print(
         print(
-            "Could not find an failed tests in the results folder at: %s" % args.results
+            "Could not find an failed tests in the results folder at: %s"
+            % args.results
         )
         )
         return 1
         return 1
 
 
@@ -553,7 +597,7 @@ def do_list(args):
     failed_tests = len(suites)
     failed_tests = len(suites)
 
 
     if args.n:
     if args.n:
-        suites = suites[:args.n]
+        suites = suites[: args.n]
     print("- " + "\n- ".join(suites))
     print("- " + "\n- ".join(suites))
     print("Total: %s test failed" % failed_tests)
     print("Total: %s test failed" % failed_tests)
 
 
@@ -572,7 +616,9 @@ def do_show_coverage(args):
     for pyver in pyvers:
     for pyver in pyvers:
         coverfiles = []
         coverfiles = []
         for fname in os.listdir(args.results):
         for fname in os.listdir(args.results):
-            if fname.endswith(".coverage") and fname.startswith("py%s-" % pyver):
+            if fname.endswith(".coverage") and fname.startswith(
+                "py%s-" % pyver
+            ):
                 coverfiles.append(os.path.join(args.results, fname))
                 coverfiles.append(os.path.join(args.results, fname))
 
 
         cover = None
         cover = None
@@ -583,7 +629,9 @@ def do_show_coverage(args):
         else:
         else:
             cover = COVER_PY
             cover = COVER_PY
 
 
-        env = {"COVERAGE_FILE": os.path.join(args.results, "combined.coverage")}
+        env = {
+            "COVERAGE_FILE": os.path.join(args.results, "combined.coverage")
+        }
         cmd = [cover, "combine"] + coverfiles
         cmd = [cover, "combine"] + coverfiles
         subprocess.check_call(cmd, env=env)
         subprocess.check_call(cmd, env=env)
         print()
         print()

+ 21 - 15
runworker.py

@@ -8,40 +8,46 @@ import os
 import subprocess
 import subprocess
 
 
 
 
-parser = argparse.ArgumentParser(
-    description='Run the Pagure worker')
+parser = argparse.ArgumentParser(description="Run the Pagure worker")
 parser.add_argument(
 parser.add_argument(
-    '--config', '-c', dest='config',
-    help='Configuration file to use for pagure.')
+    "--config",
+    "-c",
+    dest="config",
+    help="Configuration file to use for pagure.",
+)
 parser.add_argument(
 parser.add_argument(
-    '--debug', dest='debug', action='store_true',
+    "--debug",
+    dest="debug",
+    action="store_true",
     default=False,
     default=False,
-    help='Expand the level of data returned.')
+    help="Expand the level of data returned.",
+)
 parser.add_argument(
 parser.add_argument(
-    '--noinfo', dest='noinfo', action='store_true',
+    "--noinfo",
+    dest="noinfo",
+    action="store_true",
     default=False,
     default=False,
-    help='Reduce the log level.')
+    help="Reduce the log level.",
+)
 
 
 args = parser.parse_args()
 args = parser.parse_args()
 
 
 env = {}
 env = {}
 if args.config:
 if args.config:
     config = args.config
     config = args.config
-    if not config.startswith('/'):
+    if not config.startswith("/"):
         here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
         here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
         config = os.path.join(here, config)
         config = os.path.join(here, config)
-    env['PAGURE_CONFIG'] = config
+    env["PAGURE_CONFIG"] = config
 
 
-cmd = [
-    sys.executable, '-m', 'celery', 'worker', '-A', 'pagure.lib.tasks'
-]
+cmd = [sys.executable, "-m", "celery", "worker", "-A", "pagure.lib.tasks"]
 
 
 if args.debug:
 if args.debug:
-    cmd.append('--loglevel=debug')
+    cmd.append("--loglevel=debug")
 elif args.noinfo:
 elif args.noinfo:
     pass
     pass
 else:
 else:
-    cmd.append('--loglevel=info')
+    cmd.append("--loglevel=info")
 
 
 subp = subprocess.Popen(cmd, env=env or None)
 subp = subprocess.Popen(cmd, env=env or None)
 subp.wait()
 subp.wait()

+ 32 - 30
setup.py

@@ -10,17 +10,19 @@ import re
 from setuptools import setup
 from setuptools import setup
 
 
 
 
-pagurefile = os.path.join(os.path.dirname(__file__), 'pagure', '__init__.py')
+pagurefile = os.path.join(os.path.dirname(__file__), "pagure", "__init__.py")
 
 
 # Thanks to SQLAlchemy:
 # Thanks to SQLAlchemy:
 # https://github.com/zzzeek/sqlalchemy/blob/master/setup.py#L104
 # https://github.com/zzzeek/sqlalchemy/blob/master/setup.py#L104
 with open(pagurefile) as stream:
 with open(pagurefile) as stream:
-    __version__ = re.compile(
-        r".*__version__ = \"(.*?)\"", re.S
-    ).match(stream.read()).group(1)
+    __version__ = (
+        re.compile(r".*__version__ = \"(.*?)\"", re.S)
+        .match(stream.read())
+        .group(1)
+    )
 
 
 
 
-def get_requirements(requirements_file='requirements.txt'):
+def get_requirements(requirements_file="requirements.txt"):
     """Get the contents of a file listing the requirements.
     """Get the contents of a file listing the requirements.
 
 
     :arg requirements_file: path to a requirements file
     :arg requirements_file: path to a requirements file
@@ -32,24 +34,24 @@ def get_requirements(requirements_file='requirements.txt'):
 
 
     with open(requirements_file) as f:
     with open(requirements_file) as f:
         return [
         return [
-            line.rstrip().split('#')[0]
+            line.rstrip().split("#")[0]
             for line in f.readlines()
             for line in f.readlines()
-            if not line.startswith('#')
+            if not line.startswith("#")
         ]
         ]
 
 
 
 
 setup(
 setup(
-    name='pagure',
-    description='A light-weight git-centered forge based on pygit2.',
+    name="pagure",
+    description="A light-weight git-centered forge based on pygit2.",
     version=__version__,
     version=__version__,
-    author='Pierre-Yves Chibon',
-    author_email='pingou@pingoured.fr',
-    maintainer='Pierre-Yves Chibon',
-    maintainer_email='pingou@pingoured.fr',
-    license='GPLv2+',
-    download_url='https://pagure.io/releases/pagure/',
-    url='https://pagure.io/pagure/',
-    packages=['pagure'],
+    author="Pierre-Yves Chibon",
+    author_email="pingou@pingoured.fr",
+    maintainer="Pierre-Yves Chibon",
+    maintainer_email="pingou@pingoured.fr",
+    license="GPLv2+",
+    download_url="https://pagure.io/releases/pagure/",
+    url="https://pagure.io/pagure/",
+    packages=["pagure"],
     include_package_data=True,
     include_package_data=True,
     install_requires=get_requirements(),
     install_requires=get_requirements(),
     entry_points="""
     entry_points="""
@@ -63,17 +65,17 @@ setup(
     pagure = pagure.lib.git_auth:PagureGitAuth
     pagure = pagure.lib.git_auth:PagureGitAuth
     """,
     """,
     classifiers=[
     classifiers=[
-        'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)',
-        'Operating System :: POSIX :: Linux',
-        'Programming Language :: Python :: 2',
-        'Programming Language :: Python :: 2.7',
-        'Programming Language :: Python :: 3',
-        'Programming Language :: Python :: 3.4',
-        'Programming Language :: Python :: 3.5',
-        'Programming Language :: Python :: 3.6',
-        'Programming Language :: Python :: 3.7',
-        'Topic :: Internet :: WWW/HTTP :: WSGI :: Application',
-        'Topic :: Software Development :: Bug Tracking',
-        'Topic :: Software Development :: Version Control',
-    ]
+        "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
+        "Operating System :: POSIX :: Linux",
+        "Programming Language :: Python :: 2",
+        "Programming Language :: Python :: 2.7",
+        "Programming Language :: Python :: 3",
+        "Programming Language :: Python :: 3.4",
+        "Programming Language :: Python :: 3.5",
+        "Programming Language :: Python :: 3.6",
+        "Programming Language :: Python :: 3.7",
+        "Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
+        "Topic :: Software Development :: Bug Tracking",
+        "Topic :: Software Development :: Version Control",
+    ],
 )
 )

File diff suppressed because it is too large
+ 248 - 223
tests/__init__.py


+ 9 - 8
tests/test_alembic.py

@@ -14,9 +14,10 @@ import os
 import subprocess
 import subprocess
 import unittest
 import unittest
 
 
+import six
 
 
-REPO_PATH = os.path.abspath(
-    os.path.join(os.path.dirname(__file__), '..'))
+
+REPO_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
 
 
 
 
 class TestAlembic(unittest.TestCase):
 class TestAlembic(unittest.TestCase):
@@ -30,16 +31,16 @@ class TestAlembic(unittest.TestCase):
         """
         """
 
 
         proc1 = subprocess.Popen(
         proc1 = subprocess.Popen(
-            ['alembic', 'history'],
-            cwd=REPO_PATH, stdout=subprocess.PIPE)
+            ["alembic", "history"], cwd=REPO_PATH, stdout=subprocess.PIPE
+        )
         proc2 = subprocess.Popen(
         proc2 = subprocess.Popen(
-            ['grep', ' (head), '],
-            stdin=proc1.stdout, stdout=subprocess.PIPE)
+            ["grep", " (head), "], stdin=proc1.stdout, stdout=subprocess.PIPE
+        )
         stdout = proc2.communicate()[0]
         stdout = proc2.communicate()[0]
-        stdout = stdout.strip().decode('utf-8').split('\n')
+        stdout = stdout.strip().decode("utf-8").split("\n")
 
 
         self.assertEqual(len(stdout), 1)
         self.assertEqual(len(stdout), 1)
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 3 - 2
tests/test_dev_data.py

@@ -39,8 +39,9 @@ class TestDevData(tests.Modeltests):
             f.write("DB_URL = 'sqlite:///%s/db_dev_data.sqlite'\n" % self.path)
             f.write("DB_URL = 'sqlite:///%s/db_dev_data.sqlite'\n" % self.path)
             f.write("GIT_FOLDER = '%s/repos'\n" % self.path)
             f.write("GIT_FOLDER = '%s/repos'\n" % self.path)
             f.write(
             f.write(
-                "BROKER_URL = 'redis+socket://%(global_path)s/broker'\n" % \
-                    self.config_values)
+                "BROKER_URL = 'redis+socket://%(global_path)s/broker'\n"
+                % self.config_values
+            )
             f.write("CELERY_CONFIG = {'task_always_eager': True}\n")
             f.write("CELERY_CONFIG = {'task_always_eager': True}\n")
 
 
         env = {
         env = {

+ 17 - 17
tests/test_fnmatch.py

@@ -27,26 +27,26 @@ class FnmatchTests(unittest.TestCase):
     def test_fnmatch(self):
     def test_fnmatch(self):
         """ Test the matching done by fnmatch. """
         """ Test the matching done by fnmatch. """
         matrix = [
         matrix = [
-            ['pagure', '*', True],
-            ['ns/pagure', '*', True],
-            ['forks/user/ns/pagure', '*', True],
-            ['forks/user/pagure', '*', True],
-            ['pagure', 'rpms/*', False],
-            ['rpms/pagure', 'rpms/*', True],
-            ['forks/user/pagure', 'rpms/*', False],
-            ['forks/user/pagure', 'rpms/*', False],
-            ['pagure', 'pagure', True],
-            ['rpms/pagure', 'pagure', False],
-            ['forks/user/pagure', 'pagure', False],
-            ['forks/user/pagure', 'pagure', False],
-            ['pagure', 'pag*', True],
-            ['rpms/pagure', 'pag*', False],
-            ['forks/user/pagure', 'pag*', False],
-            ['forks/user/pagure', 'pag*', False],
+            ["pagure", "*", True],
+            ["ns/pagure", "*", True],
+            ["forks/user/ns/pagure", "*", True],
+            ["forks/user/pagure", "*", True],
+            ["pagure", "rpms/*", False],
+            ["rpms/pagure", "rpms/*", True],
+            ["forks/user/pagure", "rpms/*", False],
+            ["forks/user/pagure", "rpms/*", False],
+            ["pagure", "pagure", True],
+            ["rpms/pagure", "pagure", False],
+            ["forks/user/pagure", "pagure", False],
+            ["forks/user/pagure", "pagure", False],
+            ["pagure", "pag*", True],
+            ["rpms/pagure", "pag*", False],
+            ["forks/user/pagure", "pag*", False],
+            ["forks/user/pagure", "pag*", False],
         ]
         ]
         for row in matrix:
         for row in matrix:
             self.assertEqual(fnmatch.fnmatch(row[0], row[1]), row[2])
             self.assertEqual(fnmatch.fnmatch(row[0], row[1]), row[2])
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

File diff suppressed because it is too large
+ 341 - 313
tests/test_pagure_admin.py


+ 43 - 47
tests/test_pagure_exclude_group_index.py

@@ -17,13 +17,15 @@ import os
 
 
 import mock
 import mock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import pagure.lib.model
 import pagure.lib.model
 import tests
 import tests
 
 
+
 class PagureExcludeGroupIndex(tests.Modeltests):
 class PagureExcludeGroupIndex(tests.Modeltests):
     """ Tests the EXCLUDE_GROUP_INDEX configuration key in pagure """
     """ Tests the EXCLUDE_GROUP_INDEX configuration key in pagure """
 
 
@@ -32,71 +34,66 @@ class PagureExcludeGroupIndex(tests.Modeltests):
         super(PagureExcludeGroupIndex, self).setUp()
         super(PagureExcludeGroupIndex, self).setUp()
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         # Create a ``provenpackger`` group:
         # Create a ``provenpackger`` group:
         msg = pagure.lib.query.add_group(
         msg = pagure.lib.query.add_group(
             self.session,
             self.session,
-            group_name='provenpackager',
-            display_name='Proven Packagers',
-            description='Packagers having access to all the repo',
-            group_type='user',
-            user='pingou',
+            group_name="provenpackager",
+            display_name="Proven Packagers",
+            description="Packagers having access to all the repo",
+            group_type="user",
+            user="pingou",
             is_admin=False,
             is_admin=False,
             blacklist=[],
             blacklist=[],
         )
         )
         self.session.commit()
         self.session.commit()
         self.assertEqual(
         self.assertEqual(
-            msg, 'User `pingou` added to the group `provenpackager`.')
+            msg, "User `pingou` added to the group `provenpackager`."
+        )
 
 
         # Add the `provenpackager` group to the test2 project
         # Add the `provenpackager` group to the test2 project
-        project = pagure.lib.query._get_project(self.session, 'test2')
+        project = pagure.lib.query._get_project(self.session, "test2")
         msg = pagure.lib.query.add_group_to_project(
         msg = pagure.lib.query.add_group_to_project(
             session=self.session,
             session=self.session,
             project=project,
             project=project,
-            new_group='provenpackager',
-            user='pingou',
+            new_group="provenpackager",
+            user="pingou",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'Group added')
+        self.assertEqual(msg, "Group added")
 
 
     def test_defaults_pingou(self):
     def test_defaults_pingou(self):
         """ Test which repo pingou has by default. """
         """ Test which repo pingou has by default. """
 
 
         repos = pagure.lib.query.search_projects(
         repos = pagure.lib.query.search_projects(
-            self.session,
-            username='pingou',
-            fork=False,
+            self.session, username="pingou", fork=False
         )
         )
 
 
         self.assertEqual(len(repos), 3)
         self.assertEqual(len(repos), 3)
-        for idx, name in enumerate(['test', 'test2', 'test3']):
+        for idx, name in enumerate(["test", "test2", "test3"]):
             self.assertEqual(repos[idx].name, name)
             self.assertEqual(repos[idx].name, name)
 
 
     def test_defaults_foo(self):
     def test_defaults_foo(self):
         """ Test which repo foo has by default. """
         """ Test which repo foo has by default. """
 
 
         repos = pagure.lib.query.search_projects(
         repos = pagure.lib.query.search_projects(
-            self.session,
-            username='foo',
-            fork=False,
+            self.session, username="foo", fork=False
         )
         )
 
 
         self.assertEqual(len(repos), 0)
         self.assertEqual(len(repos), 0)
 
 
-
     def test_add_foo_test(self):
     def test_add_foo_test(self):
         """ Test adding foo to the test project. """
         """ Test adding foo to the test project. """
 
 
         group = pagure.lib.query.search_groups(
         group = pagure.lib.query.search_groups(
-            self.session, group_name='provenpackager')
-        self.assertEqual(group.group_name, 'provenpackager')
+            self.session, group_name="provenpackager"
+        )
+        self.assertEqual(group.group_name, "provenpackager")
 
 
         # List all foo's project before (ie: there should be none)
         # List all foo's project before (ie: there should be none)
         repos = pagure.lib.query.search_projects(
         repos = pagure.lib.query.search_projects(
-            self.session,
-            username='foo',
-            fork=False,
+            self.session, username="foo", fork=False
         )
         )
 
 
         self.assertEqual(len(repos), 0)
         self.assertEqual(len(repos), 0)
@@ -104,47 +101,48 @@ class PagureExcludeGroupIndex(tests.Modeltests):
         # Adding `foo` to the `provenpackager` group
         # Adding `foo` to the `provenpackager` group
         msg = pagure.lib.query.add_user_to_group(
         msg = pagure.lib.query.add_user_to_group(
             self.session,
             self.session,
-            username='foo',
+            username="foo",
             group=group,
             group=group,
-            user='pingou',
+            user="pingou",
             is_admin=False,
             is_admin=False,
         )
         )
         self.assertEqual(
         self.assertEqual(
-            msg, 'User `foo` added to the group `provenpackager`.')
+            msg, "User `foo` added to the group `provenpackager`."
+        )
 
 
         # Test that foo has now one project, via the provenpackager group
         # Test that foo has now one project, via the provenpackager group
         repos = pagure.lib.query.search_projects(
         repos = pagure.lib.query.search_projects(
-            self.session,
-            username='foo',
-            fork=False,
+            self.session, username="foo", fork=False
         )
         )
 
 
         self.assertEqual(len(repos), 1)
         self.assertEqual(len(repos), 1)
-        self.assertEqual(repos[0].name, 'test2')
+        self.assertEqual(repos[0].name, "test2")
 
 
     def test_excluding_provenpackager(self):
     def test_excluding_provenpackager(self):
         """ Test retrieving user's repo with a group excluded. """
         """ Test retrieving user's repo with a group excluded. """
 
 
         # Add `foo` to `provenpackager`
         # Add `foo` to `provenpackager`
         group = pagure.lib.query.search_groups(
         group = pagure.lib.query.search_groups(
-            self.session, group_name='provenpackager')
-        self.assertEqual(group.group_name, 'provenpackager')
+            self.session, group_name="provenpackager"
+        )
+        self.assertEqual(group.group_name, "provenpackager")
 
 
         msg = pagure.lib.query.add_user_to_group(
         msg = pagure.lib.query.add_user_to_group(
             self.session,
             self.session,
-            username='foo',
+            username="foo",
             group=group,
             group=group,
-            user='pingou',
+            user="pingou",
             is_admin=False,
             is_admin=False,
         )
         )
         self.assertEqual(
         self.assertEqual(
-            msg, 'User `foo` added to the group `provenpackager`.')
+            msg, "User `foo` added to the group `provenpackager`."
+        )
 
 
         # Get foo's project outside of proven packager
         # Get foo's project outside of proven packager
         repos = pagure.lib.query.search_projects(
         repos = pagure.lib.query.search_projects(
             self.session,
             self.session,
-            username='foo',
-            exclude_groups=['provenpackager'],
+            username="foo",
+            exclude_groups=["provenpackager"],
             fork=False,
             fork=False,
         )
         )
 
 
@@ -153,21 +151,19 @@ class PagureExcludeGroupIndex(tests.Modeltests):
         # Get pingou's project outside of proven packager (nothing changes)
         # Get pingou's project outside of proven packager (nothing changes)
         repos = pagure.lib.query.search_projects(
         repos = pagure.lib.query.search_projects(
             self.session,
             self.session,
-            username='pingou',
-            exclude_groups=['provenpackager'],
+            username="pingou",
+            exclude_groups=["provenpackager"],
             fork=False,
             fork=False,
         )
         )
         repos2 = pagure.lib.query.search_projects(
         repos2 = pagure.lib.query.search_projects(
-            self.session,
-            username='pingou',
-            fork=False,
+            self.session, username="pingou", fork=False
         )
         )
 
 
         self.assertEqual(repos, repos2)
         self.assertEqual(repos, repos2)
         self.assertEqual(len(repos), 3)
         self.assertEqual(len(repos), 3)
-        for idx, name in enumerate(['test', 'test2', 'test3']):
+        for idx, name in enumerate(["test", "test2", "test3"]):
             self.assertEqual(repos[idx].name, name)
             self.assertEqual(repos[idx].name, name)
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 104 - 101
tests/test_pagure_flask.py

@@ -20,8 +20,9 @@ import munch
 import pygit2
 import pygit2
 import werkzeug
 import werkzeug
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import pagure.lib.model
 import pagure.lib.model
@@ -37,24 +38,29 @@ class PagureGetRemoteRepoPath(tests.SimplePagureTest):
         super(PagureGetRemoteRepoPath, self).setUp()
         super(PagureGetRemoteRepoPath, self).setUp()
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
-        tests.add_content_git_repo(os.path.join(self.path, 'repos', 'test2.git'))
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
+        tests.add_content_git_repo(
+            os.path.join(self.path, "repos", "test2.git")
+        )
 
 
     @mock.patch(
     @mock.patch(
-        'pagure.lib.repo.PagureRepo.pull',
-        mock.MagicMock(side_effect=pygit2.GitError))
+        "pagure.lib.repo.PagureRepo.pull",
+        mock.MagicMock(side_effect=pygit2.GitError),
+    )
     def test_passing(self):
     def test_passing(self):
         """ Test get_remote_repo_path in pagure. """
         """ Test get_remote_repo_path in pagure. """
         output = pagure.utils.get_remote_repo_path(
         output = pagure.utils.get_remote_repo_path(
-            os.path.join(self.path, 'repos', 'test2.git'), 'master',
-            ignore_non_exist=True)
+            os.path.join(self.path, "repos", "test2.git"),
+            "master",
+            ignore_non_exist=True,
+        )
 
 
-        self.assertTrue(output.endswith('repos_test2.git_master'))
+        self.assertTrue(output.endswith("repos_test2.git_master"))
 
 
     def test_is_repo_committer_logged_out(self):
     def test_is_repo_committer_logged_out(self):
         """ Test is_repo_committer in pagure when there is no logged in user.
         """ Test is_repo_committer in pagure when there is no logged in user.
         """
         """
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
         with self.app.application.app_context():
         with self.app.application.app_context():
             output = pagure.utils.is_repo_committer(repo)
             output = pagure.utils.is_repo_committer(repo)
         self.assertFalse(output)
         self.assertFalse(output)
@@ -62,13 +68,13 @@ class PagureGetRemoteRepoPath(tests.SimplePagureTest):
     def test_is_repo_committer_logged_in(self):
     def test_is_repo_committer_logged_in(self):
         """ Test is_repo_committer in pagure with the appropriate user logged
         """ Test is_repo_committer in pagure with the appropriate user logged
         in. """
         in. """
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
 
 
         g = munch.Munch()
         g = munch.Munch()
-        g.fas_user = tests.FakeUser(username='pingou')
+        g.fas_user = tests.FakeUser(username="pingou")
         g.authenticated = True
         g.authenticated = True
         g.session = self.session
         g.session = self.session
-        with mock.patch('flask.g', g):
+        with mock.patch("flask.g", g):
             output = pagure.utils.is_repo_committer(repo)
             output = pagure.utils.is_repo_committer(repo)
             self.assertTrue(output)
             self.assertTrue(output)
 
 
@@ -78,45 +84,46 @@ class PagureGetRemoteRepoPath(tests.SimplePagureTest):
         # Create group
         # Create group
         msg = pagure.lib.query.add_group(
         msg = pagure.lib.query.add_group(
             self.session,
             self.session,
-            group_name='packager',
-            display_name='packager',
-            description='The Fedora packager groups',
-            group_type='user',
-            user='pingou',
+            group_name="packager",
+            display_name="packager",
+            description="The Fedora packager groups",
+            group_type="user",
+            user="pingou",
             is_admin=False,
             is_admin=False,
-            blacklist=[])
+            blacklist=[],
+        )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'User `pingou` added to the group `packager`.')
+        self.assertEqual(msg, "User `pingou` added to the group `packager`.")
 
 
         # Add user to group
         # Add user to group
-        group = pagure.lib.query.search_groups(self.session, group_name='packager')
+        group = pagure.lib.query.search_groups(
+            self.session, group_name="packager"
+        )
         msg = pagure.lib.query.add_user_to_group(
         msg = pagure.lib.query.add_user_to_group(
             self.session,
             self.session,
-            username='foo',
+            username="foo",
             group=group,
             group=group,
-            user='pingou',
-            is_admin=True)
+            user="pingou",
+            is_admin=True,
+        )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'User `foo` added to the group `packager`.')
+        self.assertEqual(msg, "User `foo` added to the group `packager`.")
 
 
         # Add group packager to project test
         # Add group packager to project test
-        project = pagure.lib.query._get_project(self.session, 'test')
+        project = pagure.lib.query._get_project(self.session, "test")
         msg = pagure.lib.query.add_group_to_project(
         msg = pagure.lib.query.add_group_to_project(
-            self.session,
-            project=project,
-            new_group='packager',
-            user='pingou',
+            self.session, project=project, new_group="packager", user="pingou"
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'Group added')
+        self.assertEqual(msg, "Group added")
 
 
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
 
 
         g = munch.Munch()
         g = munch.Munch()
-        g.fas_user = tests.FakeUser(username='foo')
+        g.fas_user = tests.FakeUser(username="foo")
         g.authenticated = True
         g.authenticated = True
         g.session = self.session
         g.session = self.session
-        with mock.patch('flask.g', g):
+        with mock.patch("flask.g", g):
             output = pagure.utils.is_repo_committer(repo)
             output = pagure.utils.is_repo_committer(repo)
             self.assertTrue(output)
             self.assertTrue(output)
 
 
@@ -126,195 +133,191 @@ class PagureGetRemoteRepoPath(tests.SimplePagureTest):
         # Create group
         # Create group
         msg = pagure.lib.query.add_group(
         msg = pagure.lib.query.add_group(
             self.session,
             self.session,
-            group_name='packager',
-            display_name='packager',
-            description='The Fedora packager groups',
-            group_type='user',
-            user='pingou',
+            group_name="packager",
+            display_name="packager",
+            description="The Fedora packager groups",
+            group_type="user",
+            user="pingou",
             is_admin=False,
             is_admin=False,
-            blacklist=[])
+            blacklist=[],
+        )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'User `pingou` added to the group `packager`.')
+        self.assertEqual(msg, "User `pingou` added to the group `packager`.")
 
 
         # Add user to group
         # Add user to group
-        group = pagure.lib.query.search_groups(self.session, group_name='packager')
+        group = pagure.lib.query.search_groups(
+            self.session, group_name="packager"
+        )
         msg = pagure.lib.query.add_user_to_group(
         msg = pagure.lib.query.add_user_to_group(
             self.session,
             self.session,
-            username='foo',
+            username="foo",
             group=group,
             group=group,
-            user='pingou',
-            is_admin=True)
+            user="pingou",
+            is_admin=True,
+        )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'User `foo` added to the group `packager`.')
+        self.assertEqual(msg, "User `foo` added to the group `packager`.")
 
 
         # Add group packager to project test
         # Add group packager to project test
-        project = pagure.lib.query._get_project(self.session, 'test')
+        project = pagure.lib.query._get_project(self.session, "test")
         msg = pagure.lib.query.add_group_to_project(
         msg = pagure.lib.query.add_group_to_project(
             self.session,
             self.session,
             project=project,
             project=project,
-            new_group='packager',
-            user='pingou',
-            access='ticket',
+            new_group="packager",
+            user="pingou",
+            access="ticket",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'Group added')
+        self.assertEqual(msg, "Group added")
 
 
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
 
 
         g = munch.Munch()
         g = munch.Munch()
-        g.fas_user = tests.FakeUser(username='foo')
+        g.fas_user = tests.FakeUser(username="foo")
         g.authenticated = True
         g.authenticated = True
         g.session = self.session
         g.session = self.session
-        with mock.patch('flask.g', g):
+        with mock.patch("flask.g", g):
             output = pagure.utils.is_repo_committer(repo)
             output = pagure.utils.is_repo_committer(repo)
             self.assertFalse(output)
             self.assertFalse(output)
 
 
     def test_is_repo_committer_logged_in_wrong_user(self):
     def test_is_repo_committer_logged_in_wrong_user(self):
         """ Test is_repo_committer in pagure with the wrong user logged in.
         """ Test is_repo_committer in pagure with the wrong user logged in.
         """
         """
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
 
 
         g = munch.Munch()
         g = munch.Munch()
         g.fas_user = tests.FakeUser()
         g.fas_user = tests.FakeUser()
         g.authenticated = True
         g.authenticated = True
         g.session = self.session
         g.session = self.session
-        with mock.patch('flask.g', g):
+        with mock.patch("flask.g", g):
             output = pagure.utils.is_repo_committer(repo)
             output = pagure.utils.is_repo_committer(repo)
             self.assertFalse(output)
             self.assertFalse(output)
 
 
     # Mocked config
     # Mocked config
-    config = {
-        'provenpackager': {}
-    }
+    config = {"provenpackager": {}}
 
 
-    @mock.patch.dict('pagure.config.config', {'EXTERNAL_COMMITTER': config})
+    @mock.patch.dict("pagure.config.config", {"EXTERNAL_COMMITTER": config})
     def test_is_repo_committer_external_committer_generic_no_member(self):
     def test_is_repo_committer_external_committer_generic_no_member(self):
         """ Test is_repo_committer in pagure with EXTERNAL_COMMITTER
         """ Test is_repo_committer in pagure with EXTERNAL_COMMITTER
         configured to give access to all the provenpackager, but the user
         configured to give access to all the provenpackager, but the user
         is not one.
         is not one.
         """
         """
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
         g = munch.Munch()
         g = munch.Munch()
         g.fas_user = user
         g.fas_user = user
         g.authenticated = True
         g.authenticated = True
         g.session = self.session
         g.session = self.session
-        with mock.patch('flask.g', g):
+        with mock.patch("flask.g", g):
             output = pagure.utils.is_repo_committer(repo)
             output = pagure.utils.is_repo_committer(repo)
             self.assertFalse(output)
             self.assertFalse(output)
 
 
-    @mock.patch.dict('pagure.config.config', {'EXTERNAL_COMMITTER': config})
+    @mock.patch.dict("pagure.config.config", {"EXTERNAL_COMMITTER": config})
     def test_is_repo_committer_external_committer_generic_member(self):
     def test_is_repo_committer_external_committer_generic_member(self):
         """ Test is_repo_committer in pagure with EXTERNAL_COMMITTER
         """ Test is_repo_committer in pagure with EXTERNAL_COMMITTER
         configured to give access to all the provenpackager, and the user
         configured to give access to all the provenpackager, and the user
         is one
         is one
         """
         """
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
 
 
         g = munch.Munch()
         g = munch.Munch()
-        g.fas_user = tests.FakeUser(username='foo')
-        g.fas_user.groups.append('provenpackager')
+        g.fas_user = tests.FakeUser(username="foo")
+        g.fas_user.groups.append("provenpackager")
         g.authenticated = True
         g.authenticated = True
         g.session = self.session
         g.session = self.session
-        with mock.patch('flask.g', g):
+        with mock.patch("flask.g", g):
             output = pagure.utils.is_repo_committer(repo)
             output = pagure.utils.is_repo_committer(repo)
             self.assertTrue(output)
             self.assertTrue(output)
 
 
-    config = {
-        'provenpackager': {
-            'exclude': ['test']
-        }
-    }
+    config = {"provenpackager": {"exclude": ["test"]}}
 
 
-    @mock.patch.dict('pagure.config.config', {'EXTERNAL_COMMITTER': config})
+    @mock.patch.dict("pagure.config.config", {"EXTERNAL_COMMITTER": config})
     def test_is_repo_committer_external_committer_excluding_one(self):
     def test_is_repo_committer_external_committer_excluding_one(self):
         """ Test is_repo_committer in pagure with EXTERNAL_COMMITTER
         """ Test is_repo_committer in pagure with EXTERNAL_COMMITTER
         configured to give access to all the provenpackager but for this
         configured to give access to all the provenpackager but for this
         one repo
         one repo
         """
         """
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
 
 
         g = munch.Munch()
         g = munch.Munch()
         g.fas_user = tests.FakeUser()
         g.fas_user = tests.FakeUser()
-        g.fas_user.groups.append('provenpackager')
+        g.fas_user.groups.append("provenpackager")
         g.authenticated = True
         g.authenticated = True
         g.session = self.session
         g.session = self.session
-        with mock.patch('flask.g', g):
+        with mock.patch("flask.g", g):
             output = pagure.utils.is_repo_committer(repo)
             output = pagure.utils.is_repo_committer(repo)
             self.assertFalse(output)
             self.assertFalse(output)
 
 
-    @mock.patch.dict('pagure.config.config', {'EXTERNAL_COMMITTER': config})
+    @mock.patch.dict("pagure.config.config", {"EXTERNAL_COMMITTER": config})
     def test_is_repo_committer_owner_external_committer_excluding_one(self):
     def test_is_repo_committer_owner_external_committer_excluding_one(self):
         """ Test is_repo_committer in pagure with EXTERNAL_COMMITTER
         """ Test is_repo_committer in pagure with EXTERNAL_COMMITTER
         configured to give access to all the provenpackager but for this
         configured to give access to all the provenpackager but for this
         one repo, but the user is still a direct committer
         one repo, but the user is still a direct committer
         """
         """
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
 
 
         g = munch.Munch()
         g = munch.Munch()
-        g.fas_user = tests.FakeUser(username='pingou')
-        g.fas_user.groups.append('provenpackager')
+        g.fas_user = tests.FakeUser(username="pingou")
+        g.fas_user.groups.append("provenpackager")
         g.authenticated = True
         g.authenticated = True
         g.session = self.session
         g.session = self.session
-        with mock.patch('flask.g', g):
+        with mock.patch("flask.g", g):
             output = pagure.utils.is_repo_committer(repo)
             output = pagure.utils.is_repo_committer(repo)
             self.assertTrue(output)
             self.assertTrue(output)
 
 
-    config = {
-        'provenpackager': {
-            'restrict': ['test']
-        }
-    }
+    config = {"provenpackager": {"restrict": ["test"]}}
 
 
-    @mock.patch.dict('pagure.config.config', {'EXTERNAL_COMMITTER': config})
+    @mock.patch.dict("pagure.config.config", {"EXTERNAL_COMMITTER": config})
     def test_is_repo_committer_external_committer_restricted_not_member(self):
     def test_is_repo_committer_external_committer_restricted_not_member(self):
         """ Test is_repo_committer in pagure with EXTERNAL_COMMITTER
         """ Test is_repo_committer in pagure with EXTERNAL_COMMITTER
         configured to give access the provenpackager just for one repo
         configured to give access the provenpackager just for one repo
         """
         """
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
 
 
         g = munch.Munch()
         g = munch.Munch()
         g.fas_user = tests.FakeUser()
         g.fas_user = tests.FakeUser()
         g.authenticated = True
         g.authenticated = True
         g.session = self.session
         g.session = self.session
-        with mock.patch('flask.g', g):
+        with mock.patch("flask.g", g):
             output = pagure.utils.is_repo_committer(repo)
             output = pagure.utils.is_repo_committer(repo)
             self.assertFalse(output)
             self.assertFalse(output)
 
 
-    @mock.patch.dict('pagure.config.config', {'EXTERNAL_COMMITTER': config})
+    @mock.patch.dict("pagure.config.config", {"EXTERNAL_COMMITTER": config})
     def test_is_repo_committer_external_committer_restricting_to_one(self):
     def test_is_repo_committer_external_committer_restricting_to_one(self):
         """ Test is_repo_committer in pagure with EXTERNAL_COMMITTER
         """ Test is_repo_committer in pagure with EXTERNAL_COMMITTER
         configured to give access the provenpackager just for one repo
         configured to give access the provenpackager just for one repo
         """
         """
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
 
 
         g = munch.Munch()
         g = munch.Munch()
-        g.fas_user = tests.FakeUser(username='foo')
+        g.fas_user = tests.FakeUser(username="foo")
         g.authenticated = True
         g.authenticated = True
-        g.fas_user.groups.append('provenpackager')
+        g.fas_user.groups.append("provenpackager")
         g.session = self.session
         g.session = self.session
-        with mock.patch('flask.g', g):
+        with mock.patch("flask.g", g):
             output = pagure.utils.is_repo_committer(repo)
             output = pagure.utils.is_repo_committer(repo)
             self.assertTrue(output)
             self.assertTrue(output)
 
 
-    @mock.patch.dict('pagure.config.config', {'EXTERNAL_COMMITTER': config})
-    def test_is_repo_committer_external_committer_restricting_another_one(self):
+    @mock.patch.dict("pagure.config.config", {"EXTERNAL_COMMITTER": config})
+    def test_is_repo_committer_external_committer_restricting_another_one(
+        self
+    ):
         """ Test is_repo_committer in pagure with EXTERNAL_COMMITTER
         """ Test is_repo_committer in pagure with EXTERNAL_COMMITTER
         configured to give access the provenpackager just for one repo not
         configured to give access the provenpackager just for one repo not
         this one
         this one
         """
         """
-        repo = pagure.lib.query._get_project(self.session, 'test2')
+        repo = pagure.lib.query._get_project(self.session, "test2")
 
 
         g = munch.Munch()
         g = munch.Munch()
-        g.fas_user = tests.FakeUser(username='foo')
+        g.fas_user = tests.FakeUser(username="foo")
         g.authenticated = True
         g.authenticated = True
-        g.fas_user.groups.append('provenpackager')
+        g.fas_user.groups.append("provenpackager")
         g.session = self.session
         g.session = self.session
-        with mock.patch('flask.g', g):
+        with mock.patch("flask.g", g):
             output = pagure.utils.is_repo_committer(repo)
             output = pagure.utils.is_repo_committer(repo)
             self.assertFalse(output)
             self.assertFalse(output)
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 128 - 123
tests/test_pagure_flask_api.py

@@ -18,8 +18,9 @@ import os
 import json
 import json
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.api
 import pagure.api
 import pagure.flask_app
 import pagure.flask_app
@@ -35,168 +36,171 @@ class PagureFlaskApitests(tests.SimplePagureTest):
     def test_api_doc(self):
     def test_api_doc(self):
         """ Test the API documentation page. """
         """ Test the API documentation page. """
         print(dir(self.app))
         print(dir(self.app))
-        output = self.app.get('/api/0/')
+        output = self.app.get("/api/0/")
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
+        self.assertIn("<title> API | pagure  - Pagure</title>\n", output_text)
         self.assertIn(
         self.assertIn(
-            '<title> API | pagure  - Pagure</title>\n', output_text)
-        self.assertIn(
-            '&nbsp; Pagure API Reference\n        </h2>\n', output_text)
+            "&nbsp; Pagure API Reference\n        </h2>\n", output_text
+        )
 
 
     def test_api_doc_authenticated(self):
     def test_api_doc_authenticated(self):
         """ Test the API documentation page. """
         """ Test the API documentation page. """
-        user = tests.FakeUser(username='foo')
+        user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/api/0/')
+            output = self.app.get("/api/0/")
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title> API | pagure  - Pagure</title>\n', output_text)
+                "<title> API | pagure  - Pagure</title>\n", output_text
+            )
             self.assertIn(
             self.assertIn(
-                '&nbsp; Pagure API Reference\n        </h2>\n', output_text)
+                "&nbsp; Pagure API Reference\n        </h2>\n", output_text
+            )
 
 
     def test_api_get_request_data(self):
     def test_api_get_request_data(self):
-        data = {'foo': 'bar'}
+        data = {"foo": "bar"}
         # test_request_context doesn't set flask.g, but some teardown
         # test_request_context doesn't set flask.g, but some teardown
         # functions try to use that, so let's exclude them
         # functions try to use that, so let's exclude them
         self._app.teardown_request_funcs = {}
         self._app.teardown_request_funcs = {}
         with self._app.test_request_context(
         with self._app.test_request_context(
-                '/api/0/version', method="POST", data=data):
-            self.assertEqual(pagure.api.get_request_data()['foo'], 'bar')
+            "/api/0/version", method="POST", data=data
+        ):
+            self.assertEqual(pagure.api.get_request_data()["foo"], "bar")
         data = json.dumps(data)
         data = json.dumps(data)
-        with self._app.test_request_context('/api/0/version', data=data,
-                                            content_type='application/json'):
-            self.assertEqual(pagure.api.get_request_data()['foo'], 'bar')
+        with self._app.test_request_context(
+            "/api/0/version", data=data, content_type="application/json"
+        ):
+            self.assertEqual(pagure.api.get_request_data()["foo"], "bar")
 
 
     def test_api_version_old_url(self):
     def test_api_version_old_url(self):
         """ Test the api_version function.  """
         """ Test the api_version function.  """
-        output = self.app.get('/api/0/version')
+        output = self.app.get("/api/0/version")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(data['version'], pagure.__api_version__)
-        self.assertEqual(sorted(data.keys()), ['version'])
+        self.assertEqual(data["version"], pagure.__api_version__)
+        self.assertEqual(sorted(data.keys()), ["version"])
 
 
     def test_api_version_new_url(self):
     def test_api_version_new_url(self):
         """ Test the api_version function at its new url.  """
         """ Test the api_version function at its new url.  """
-        output = self.app.get('/api/0/-/version')
+        output = self.app.get("/api/0/-/version")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(data['version'], pagure.__api_version__)
-        self.assertEqual(sorted(data.keys()), ['version'])
+        self.assertEqual(data["version"], pagure.__api_version__)
+        self.assertEqual(sorted(data.keys()), ["version"])
 
 
     def test_api_project_tags(self):
     def test_api_project_tags(self):
         """ Test the api_project_tags function.  """
         """ Test the api_project_tags function.  """
         tests.create_projects(self.session)
         tests.create_projects(self.session)
 
 
-        output = self.app.get('/api/0/foo/tags/')
+        output = self.app.get("/api/0/foo/tags/")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(set(data.keys()), set(['output', 'error']))
-        self.assertEqual(data['output'], 'notok')
-        self.assertEqual(data['error'], 'Project not found')
+        self.assertEqual(set(data.keys()), set(["output", "error"]))
+        self.assertEqual(data["output"], "notok")
+        self.assertEqual(data["error"], "Project not found")
 
 
-        output = self.app.get('/api/0/test/tags/')
+        output = self.app.get("/api/0/test/tags/")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(sorted(data.keys()), ['tags', 'total_tags'])
-        self.assertEqual(data['tags'], [])
-        self.assertEqual(data['total_tags'], 0)
+        self.assertEqual(sorted(data.keys()), ["tags", "total_tags"])
+        self.assertEqual(data["tags"], [])
+        self.assertEqual(data["total_tags"], 0)
 
 
         # Add an issue and tag it so that we can list them
         # Add an issue and tag it so that we can list them
         item = pagure.lib.model.Issue(
         item = pagure.lib.model.Issue(
             id=1,
             id=1,
-            uid='foobar',
+            uid="foobar",
             project_id=1,
             project_id=1,
-            title='issue',
-            content='a bug report',
+            title="issue",
+            content="a bug report",
             user_id=1,  # pingou
             user_id=1,  # pingou
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
         item = pagure.lib.model.TagColored(
         item = pagure.lib.model.TagColored(
-            tag='tag1', tag_color='DeepBlueSky', project_id=1,
+            tag="tag1", tag_color="DeepBlueSky", project_id=1
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
         item = pagure.lib.model.TagIssueColored(
         item = pagure.lib.model.TagIssueColored(
-            issue_uid='foobar',
-            tag_id=item.id
+            issue_uid="foobar", tag_id=item.id
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
 
 
-        output = self.app.get('/api/0/test/tags/')
+        output = self.app.get("/api/0/test/tags/")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(sorted(data.keys()), ['tags', 'total_tags'])
-        self.assertEqual(data['tags'], ['tag1'])
-        self.assertEqual(data['total_tags'], 1)
+        self.assertEqual(sorted(data.keys()), ["tags", "total_tags"])
+        self.assertEqual(data["tags"], ["tag1"])
+        self.assertEqual(data["total_tags"], 1)
 
 
-        output = self.app.get('/api/0/test/tags/?pattern=t')
+        output = self.app.get("/api/0/test/tags/?pattern=t")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(sorted(data.keys()), ['tags', 'total_tags'])
-        self.assertEqual(data['tags'], ['tag1'])
-        self.assertEqual(data['total_tags'], 1)
+        self.assertEqual(sorted(data.keys()), ["tags", "total_tags"])
+        self.assertEqual(data["tags"], ["tag1"])
+        self.assertEqual(data["total_tags"], 1)
 
 
-        output = self.app.get('/api/0/test/tags/?pattern=p')
+        output = self.app.get("/api/0/test/tags/?pattern=p")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(sorted(data.keys()), ['tags', 'total_tags'])
-        self.assertEqual(data['tags'], [])
-        self.assertEqual(data['total_tags'], 0)
+        self.assertEqual(sorted(data.keys()), ["tags", "total_tags"])
+        self.assertEqual(data["tags"], [])
+        self.assertEqual(data["total_tags"], 0)
 
 
     def test_api_groups(self):
     def test_api_groups(self):
         """ Test the api_groups function.  """
         """ Test the api_groups function.  """
 
 
         # Add a couple of groups so that we can list them
         # Add a couple of groups so that we can list them
         item = pagure.lib.model.PagureGroup(
         item = pagure.lib.model.PagureGroup(
-            group_name='group1',
-            group_type='user',
-            display_name='User group',
+            group_name="group1",
+            group_type="user",
+            display_name="User group",
             user_id=1,  # pingou
             user_id=1,  # pingou
         )
         )
         self.session.add(item)
         self.session.add(item)
 
 
         item = pagure.lib.model.PagureGroup(
         item = pagure.lib.model.PagureGroup(
-            group_name='rel-eng',
-            group_type='user',
-            display_name='Release engineering group',
+            group_name="rel-eng",
+            group_type="user",
+            display_name="Release engineering group",
             user_id=1,  # pingou
             user_id=1,  # pingou
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
 
 
-        output = self.app.get('/api/0/groups')
+        output = self.app.get("/api/0/groups")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(data['groups'], ['group1', 'rel-eng'])
+        self.assertEqual(data["groups"], ["group1", "rel-eng"])
         self.assertEqual(
         self.assertEqual(
-            sorted(data.keys()),
-            ['groups', 'pagination', 'total_groups'])
-        self.assertEqual(data['total_groups'], 2)
+            sorted(data.keys()), ["groups", "pagination", "total_groups"]
+        )
+        self.assertEqual(data["total_groups"], 2)
 
 
-        output = self.app.get('/api/0/groups?pattern=re')
+        output = self.app.get("/api/0/groups?pattern=re")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(data['groups'], ['rel-eng'])
+        self.assertEqual(data["groups"], ["rel-eng"])
         self.assertEqual(
         self.assertEqual(
-            sorted(data.keys()),
-            ['groups', 'pagination', 'total_groups'])
-        self.assertEqual(data['total_groups'], 1)
+            sorted(data.keys()), ["groups", "pagination", "total_groups"]
+        )
+        self.assertEqual(data["total_groups"], 1)
 
 
     def test_api_whoami_unauth(self):
     def test_api_whoami_unauth(self):
         """ Test the api_whoami function. """
         """ Test the api_whoami function. """
 
 
-        output = self.app.post('/api/0/-/whoami')
+        output = self.app.post("/api/0/-/whoami")
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertEqual(
         self.assertEqual(
             data,
             data,
             {
             {
-                u'error': u'Invalid or expired token. Please visit '
-                'http://localhost.localdomain/settings#api-keys to get or '
-                'renew your API token.',
-                u'error_code': u'EINVALIDTOK'
-            }
+                "error": "Invalid or expired token. Please visit "
+                "http://localhost.localdomain/settings#api-keys to get or "
+                "renew your API token.",
+                "error_code": "EINVALIDTOK",
+            },
         )
         )
 
 
     def test_api_whoami_invalid_auth(self):
     def test_api_whoami_invalid_auth(self):
@@ -204,20 +208,20 @@ class PagureFlaskApitests(tests.SimplePagureTest):
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
 
 
-        headers = {'Authorization': 'token invalid'}
+        headers = {"Authorization": "token invalid"}
 
 
-        output = self.app.post('/api/0/-/whoami', headers=headers)
+        output = self.app.post("/api/0/-/whoami", headers=headers)
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertEqual(
         self.assertEqual(
             data,
             data,
             {
             {
-                u'error': u'Invalid or expired token. Please visit '
-                'http://localhost.localdomain/settings#api-keys to get or '
-                'renew your API token.',
-                u'error_code': u'EINVALIDTOK',
-                u'errors': 'Invalid token',
-            }
+                "error": "Invalid or expired token. Please visit "
+                "http://localhost.localdomain/settings#api-keys to get or "
+                "renew your API token.",
+                "error_code": "EINVALIDTOK",
+                "errors": "Invalid token",
+            },
         )
         )
 
 
     def test_api_whoami_auth(self):
     def test_api_whoami_auth(self):
@@ -225,59 +229,61 @@ class PagureFlaskApitests(tests.SimplePagureTest):
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
-        output = self.app.post('/api/0/-/whoami', headers=headers)
+        output = self.app.post("/api/0/-/whoami", headers=headers)
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(data, {u'username': u'pingou'})
+        self.assertEqual(data, {"username": "pingou"})
 
 
     def test_api_error_codes(self):
     def test_api_error_codes(self):
         """ Test the api_error_codes endpoint. """
         """ Test the api_error_codes endpoint. """
-        output = self.app.get('/api/0/-/error_codes')
+        output = self.app.get("/api/0/-/error_codes")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertEqual(len(data), 36)
         self.assertEqual(len(data), 36)
         self.assertEqual(
         self.assertEqual(
             sorted(data.keys()),
             sorted(data.keys()),
-            sorted([
-                'EDATETIME',
-                'EDBERROR',
-                'EGITERROR',
-                'EINVALIDISSUEFIELD',
-                'EINVALIDISSUEFIELD_LINK',
-                'EINVALIDPERPAGEVALUE',
-                'EINVALIDPRIORITY',
-                'EINVALIDREQ',
-                'EINVALIDTOK',
-                'EISSUENOTALLOWED',
-                'EMODIFYPROJECTNOTALLOWED',
-                'ENEWPROJECTDISABLED',
-                'ENOCODE',
-                'ENOCOMMENT',
-                'ENOCOMMIT',
-                'ENOGROUP',
-                'ENOISSUE',
-                'ENOPRCLOSE',
-                'ENOPROJECT',
-                'ENOPROJECTS',
-                'ENOPRSTATS',
-                'ENOREQ',
-                'ENOSIGNEDOFF',
-                'ENOTASSIGNED',
-                'ENOTASSIGNEE',
-                'ENOTHIGHENOUGH',
-                'ENOTMAINADMIN',
-                'ENOUSER',
-                'EPRCONFLICTS',
-                'EPRNOTALLOWED',
-                'EPRSCORE',
-                'EPULLREQUESTSDISABLED',
-                'ETIMESTAMP',
-                'ETRACKERDISABLED',
-                'ETRACKERREADONLY',
-                'EUBLOCKED',
-            ])
+            sorted(
+                [
+                    "EDATETIME",
+                    "EDBERROR",
+                    "EGITERROR",
+                    "EINVALIDISSUEFIELD",
+                    "EINVALIDISSUEFIELD_LINK",
+                    "EINVALIDPERPAGEVALUE",
+                    "EINVALIDPRIORITY",
+                    "EINVALIDREQ",
+                    "EINVALIDTOK",
+                    "EISSUENOTALLOWED",
+                    "EMODIFYPROJECTNOTALLOWED",
+                    "ENEWPROJECTDISABLED",
+                    "ENOCODE",
+                    "ENOCOMMENT",
+                    "ENOCOMMIT",
+                    "ENOGROUP",
+                    "ENOISSUE",
+                    "ENOPRCLOSE",
+                    "ENOPROJECT",
+                    "ENOPROJECTS",
+                    "ENOPRSTATS",
+                    "ENOREQ",
+                    "ENOSIGNEDOFF",
+                    "ENOTASSIGNED",
+                    "ENOTASSIGNEE",
+                    "ENOTHIGHENOUGH",
+                    "ENOTMAINADMIN",
+                    "ENOUSER",
+                    "EPRCONFLICTS",
+                    "EPRNOTALLOWED",
+                    "EPRSCORE",
+                    "EPULLREQUESTSDISABLED",
+                    "ETIMESTAMP",
+                    "ETRACKERDISABLED",
+                    "ETRACKERREADONLY",
+                    "EUBLOCKED",
+                ]
+            ),
         )
         )
 
 
     @patch("pagure.lib.tasks.get_result")
     @patch("pagure.lib.tasks.get_result")
@@ -300,10 +306,9 @@ class PagureFlaskApitests(tests.SimplePagureTest):
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertEqual(
         self.assertEqual(
-            data,
-            {"ready": True, "status": "finished", "successful": True}
+            data, {"ready": True, "status": "finished", "successful": True}
         )
         )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 51 - 43
tests/test_pagure_flask_api_auth.py

@@ -18,8 +18,9 @@ import os
 import json
 import json
 from mock import patch
 from mock import patch
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.api
 import pagure.api
 import pagure.lib
 import pagure.lib
@@ -33,21 +34,23 @@ class PagureFlaskApiAuthtests(tests.SimplePagureTest):
         """ Test the authentication when there is nothing in the database.
         """ Test the authentication when there is nothing in the database.
         """
         """
 
 
-        output = self.app.post('/api/0/foo/new_issue')
+        output = self.app.post("/api/0/foo/new_issue")
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
-                         data['error_code'])
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
+        self.assertEqual(
+            pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
+        )
+        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
 
 
-        headers = {'Authorization': 'token aabbbccc'}
+        headers = {"Authorization": "token aabbbccc"}
 
 
-        output = self.app.post('/api/0/foo/new_issue', headers=headers)
+        output = self.app.post("/api/0/foo/new_issue", headers=headers)
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
-                         data['error_code'])
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
+        self.assertEqual(
+            pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
+        )
+        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
 
 
     def test_auth_noacl(self):
     def test_auth_noacl(self):
         """ Test the authentication when the token does not have any ACL.
         """ Test the authentication when the token does not have any ACL.
@@ -55,21 +58,23 @@ class PagureFlaskApiAuthtests(tests.SimplePagureTest):
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
 
 
-        output = self.app.post('/api/0/test/new_issue')
+        output = self.app.post("/api/0/test/new_issue")
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
-                         data['error_code'])
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
+        self.assertEqual(
+            pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
+        )
+        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
-        output = self.app.post('/api/0/test/new_issue', headers=headers)
+        output = self.app.post("/api/0/test/new_issue", headers=headers)
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
-                         data['error_code'])
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
+        self.assertEqual(
+            pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
+        )
+        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
 
 
     def test_auth_expired(self):
     def test_auth_expired(self):
         """ Test the authentication when the token has expired.
         """ Test the authentication when the token has expired.
@@ -77,21 +82,23 @@ class PagureFlaskApiAuthtests(tests.SimplePagureTest):
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
 
 
-        output = self.app.post('/api/0/test/new_issue')
+        output = self.app.post("/api/0/test/new_issue")
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
-                         data['error_code'])
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
+        self.assertEqual(
+            pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
+        )
+        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
 
 
-        headers = {'Authorization': 'token expired_token'}
+        headers = {"Authorization": "token expired_token"}
 
 
-        output = self.app.post('/api/0/test/new_issue', headers=headers)
+        output = self.app.post("/api/0/test/new_issue", headers=headers)
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
-                         data['error_code'])
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
+        self.assertEqual(
+            pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
+        )
+        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
 
 
     def test_auth(self):
     def test_auth(self):
         """ Test the token based authentication.
         """ Test the token based authentication.
@@ -100,30 +107,31 @@ class PagureFlaskApiAuthtests(tests.SimplePagureTest):
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
         tests.create_tokens_acl(self.session)
         tests.create_tokens_acl(self.session)
 
 
-        output = self.app.post('/api/0/test/new_issue')
+        output = self.app.post("/api/0/test/new_issue")
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
-                         data['error_code'])
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
+        self.assertEqual(
+            pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
+        )
+        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
-        output = self.app.post('/api/0/test/new_issue', headers=headers)
+        output = self.app.post("/api/0/test/new_issue", headers=headers)
         self.assertEqual(output.status_code, 400)
         self.assertEqual(output.status_code, 400)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
             {
             {
-              "error": "Invalid or incomplete input submitted",
-              "error_code": "EINVALIDREQ",
-              "errors": {
-                "issue_content": ["This field is required."],
-                "title": ["This field is required."]
-              }
-            }
+                "error": "Invalid or incomplete input submitted",
+                "error_code": "EINVALIDREQ",
+                "errors": {
+                    "issue_content": ["This field is required."],
+                    "title": ["This field is required."],
+                },
+            },
         )
         )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

File diff suppressed because it is too large
+ 355 - 366
tests/test_pagure_flask_api_fork.py


+ 80 - 89
tests/test_pagure_flask_api_fork_assign.py

@@ -25,8 +25,9 @@ import munch
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 from sqlalchemy.exc import SQLAlchemyError
 from sqlalchemy.exc import SQLAlchemyError
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import tests
 import tests
@@ -37,40 +38,39 @@ class PagureFlaskApiForkAssigntests(tests.SimplePagureTest):
 
 
     maxDiff = None
     maxDiff = None
 
 
-    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.git.update_git", MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def setUp(self):
     def setUp(self):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(PagureFlaskApiForkAssigntests, self).setUp()
         super(PagureFlaskApiForkAssigntests, self).setUp()
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         tests.add_content_git_repo(
         tests.add_content_git_repo(
-            os.path.join(self.path, "repos", "test.git"))
+            os.path.join(self.path, "repos", "test.git")
+        )
 
 
         # Fork
         # Fork
-        project = pagure.lib.query.get_authorized_project(
-            self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         task = pagure.lib.query.fork_project(
         task = pagure.lib.query.fork_project(
-            session=self.session,
-            user='pingou',
-            repo=project,
+            session=self.session, user="pingou", repo=project
         )
         )
         self.session.commit()
         self.session.commit()
         self.assertEqual(
         self.assertEqual(
             task.get(),
             task.get(),
-            {'endpoint': 'ui_ns.view_repo',
-             'repo': 'test',
-             'namespace': None,
-             'username': 'pingou'})
+            {
+                "endpoint": "ui_ns.view_repo",
+                "repo": "test",
+                "namespace": None,
+                "username": "pingou",
+            },
+        )
 
 
         tests.add_readme_git_repo(
         tests.add_readme_git_repo(
-            os.path.join(self.path, "repos", "forks", "pingou", "test.git"))
-        project = pagure.lib.query.get_authorized_project(
-            self.session, 'test')
+            os.path.join(self.path, "repos", "forks", "pingou", "test.git")
+        )
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         fork = pagure.lib.query.get_authorized_project(
         fork = pagure.lib.query.get_authorized_project(
-            self.session,
-            'test',
-            user='pingou',
+            self.session, "test", user="pingou"
         )
         )
 
 
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
@@ -79,64 +79,63 @@ class PagureFlaskApiForkAssigntests(tests.SimplePagureTest):
         req = pagure.lib.query.new_pull_request(
         req = pagure.lib.query.new_pull_request(
             session=self.session,
             session=self.session,
             repo_from=fork,
             repo_from=fork,
-            branch_from='master',
+            branch_from="master",
             repo_to=project,
             repo_to=project,
-            branch_to='master',
-            title='test pull-request',
-            user='pingou',
+            branch_to="master",
+            title="test pull-request",
+            user="pingou",
         )
         )
         self.session.commit()
         self.session.commit()
         self.assertEqual(req.id, 1)
         self.assertEqual(req.id, 1)
-        self.assertEqual(req.title, 'test pull-request')
+        self.assertEqual(req.title, "test pull-request")
 
 
         # Assert the PR is open
         # Assert the PR is open
         self.session = pagure.lib.query.create_session(self.dbpath)
         self.session = pagure.lib.query.create_session(self.dbpath)
-        project = pagure.lib.query.get_authorized_project(
-            self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(project.requests), 1)
         self.assertEqual(len(project.requests), 1)
         self.assertEqual(project.requests[0].status, "Open")
         self.assertEqual(project.requests[0].status, "Open")
         # Check how the PR renders in the API and the UI
         # Check how the PR renders in the API and the UI
-        output = self.app.get('/api/0/test/pull-request/1')
+        output = self.app.get("/api/0/test/pull-request/1")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
-        output = self.app.get('/test/pull-request/1')
+        output = self.app.get("/test/pull-request/1")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
 
 
     def test_api_assign_pr_invalid_project_namespace(self):
     def test_api_assign_pr_invalid_project_namespace(self):
         """ Test api_pull_request_assign method when the project doesn't exist.
         """ Test api_pull_request_assign method when the project doesn't exist.
         """
         """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # Valid token, wrong project
         # Valid token, wrong project
         output = self.app.post(
         output = self.app.post(
-            '/api/0/somenamespace/test3/pull-request/1/assign', headers=headers)
+            "/api/0/somenamespace/test3/pull-request/1/assign", headers=headers
+        )
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
-            {'error': 'Invalid or expired token. Please visit '
-                      'http://localhost.localdomain/settings#api-keys to get or renew your '
-                      'API token.',
-             'error_code': 'EINVALIDTOK'}
-
+            {
+                "error": "Invalid or expired token. Please visit "
+                "http://localhost.localdomain/settings#api-keys to get or renew your "
+                "API token.",
+                "error_code": "EINVALIDTOK",
+            },
         )
         )
 
 
     def test_api_assign_pr_invalid_project(self):
     def test_api_assign_pr_invalid_project(self):
         """ Test api_pull_request_assign method when the project doesn't exist.
         """ Test api_pull_request_assign method when the project doesn't exist.
         """
         """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # Invalid project
         # Invalid project
-        output = self.app.post('/api/0/foo/pull-request/1/assign', headers=headers)
+        output = self.app.post(
+            "/api/0/foo/pull-request/1/assign", headers=headers
+        )
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
-            data,
-            {
-              "error": "Project not found",
-              "error_code": "ENOPROJECT",
-            }
+            data, {"error": "Project not found", "error_code": "ENOPROJECT"}
         )
         )
 
 
     def test_api_assign_pr_invalid_project_token(self):
     def test_api_assign_pr_invalid_project_token(self):
@@ -144,102 +143,96 @@ class PagureFlaskApiForkAssigntests(tests.SimplePagureTest):
         to the project.
         to the project.
         """
         """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # Valid token, wrong project
         # Valid token, wrong project
-        output = self.app.post('/api/0/test2/pull-request/1/assign', headers=headers)
+        output = self.app.post(
+            "/api/0/test2/pull-request/1/assign", headers=headers
+        )
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(sorted(data.keys()), ['error', 'error_code'])
-        self.assertEqual(
-            pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
+        self.assertEqual(sorted(data.keys()), ["error", "error_code"])
+        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
         self.assertEqual(
         self.assertEqual(
-            pagure.api.APIERROR.EINVALIDTOK.name, data['error_code'])
+            pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
+        )
 
 
     def test_api_assign_pr_invalid_pr(self):
     def test_api_assign_pr_invalid_pr(self):
         """ Test api_pull_request_assign method when asking for an invalid PR
         """ Test api_pull_request_assign method when asking for an invalid PR
         """
         """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # No input
         # No input
-        output = self.app.post('/api/0/test/pull-request/404/assign', headers=headers)
+        output = self.app.post(
+            "/api/0/test/pull-request/404/assign", headers=headers
+        )
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
-            data,
-            {'error': 'Pull-Request not found', 'error_code': 'ENOREQ'}
+            data, {"error": "Pull-Request not found", "error_code": "ENOREQ"}
         )
         )
 
 
     def test_api_assign_pr_no_input(self):
     def test_api_assign_pr_no_input(self):
         """ Test api_pull_request_assign method when no input is specified
         """ Test api_pull_request_assign method when no input is specified
         """
         """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # No input
         # No input
-        output = self.app.post('/api/0/test/pull-request/1/assign', headers=headers)
+        output = self.app.post(
+            "/api/0/test/pull-request/1/assign", headers=headers
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertDictEqual(
-            data,
-            {'message': 'Nothing to change'}
-        )
+        self.assertDictEqual(data, {"message": "Nothing to change"})
 
 
     def test_api_assign_pr_assigned(self):
     def test_api_assign_pr_assigned(self):
         """ Test api_pull_request_assign method when with valid input
         """ Test api_pull_request_assign method when with valid input
         """
         """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
-        data = {
-            'assignee': 'pingou',
-        }
+        data = {"assignee": "pingou"}
 
 
         # Valid request
         # Valid request
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/pull-request/1/assign', data=data, headers=headers)
+            "/api/0/test/pull-request/1/assign", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertDictEqual(
-            data,
-            {'message': 'Request assigned'}
-        )
+        self.assertDictEqual(data, {"message": "Request assigned"})
 
 
     def test_api_assign_pr_unassigned(self):
     def test_api_assign_pr_unassigned(self):
         """ Test api_pull_request_assign method when unassigning
         """ Test api_pull_request_assign method when unassigning
         """
         """
         self.test_api_assign_pr_assigned()
         self.test_api_assign_pr_assigned()
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
         data = {}
         data = {}
 
 
         # Un-assign
         # Un-assign
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/pull-request/1/assign', data=data, headers=headers)
+            "/api/0/test/pull-request/1/assign", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertDictEqual(
-            data,
-            {'message': 'Request assignee reset'}
-        )
+        self.assertDictEqual(data, {"message": "Request assignee reset"})
 
 
     def test_api_assign_pr_unassigned_twice(self):
     def test_api_assign_pr_unassigned_twice(self):
         """ Test api_pull_request_assign method when unassigning
         """ Test api_pull_request_assign method when unassigning
         """
         """
         self.test_api_assign_pr_unassigned()
         self.test_api_assign_pr_unassigned()
-        headers = {'Authorization': 'token aaabbbcccddd'}
-        data = {'assignee': None}
+        headers = {"Authorization": "token aaabbbcccddd"}
+        data = {"assignee": None}
 
 
         # Un-assign
         # Un-assign
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/pull-request/1/assign', data=data, headers=headers)
+            "/api/0/test/pull-request/1/assign", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertDictEqual(
-            data,
-            {'message': 'Nothing to change'}
-        )
+        self.assertDictEqual(data, {"message": "Nothing to change"})
 
 
     def test_api_assign_pr_unassigned_empty_string(self):
     def test_api_assign_pr_unassigned_empty_string(self):
         """ Test api_pull_request_assign method when unassigning with an
         """ Test api_pull_request_assign method when unassigning with an
@@ -247,19 +240,17 @@ class PagureFlaskApiForkAssigntests(tests.SimplePagureTest):
         """
         """
         self.test_api_assign_pr_assigned()
         self.test_api_assign_pr_assigned()
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # Un-assign
         # Un-assign
-        data = {'assignee': ''}
+        data = {"assignee": ""}
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/pull-request/1/assign', data=data, headers=headers)
+            "/api/0/test/pull-request/1/assign", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertDictEqual(
-            data,
-            {'message': 'Request assignee reset'}
-        )
+        self.assertDictEqual(data, {"message": "Request assignee reset"})
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 445 - 394
tests/test_pagure_flask_api_fork_update.py

@@ -25,8 +25,9 @@ import munch
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 from sqlalchemy.exc import SQLAlchemyError
 from sqlalchemy.exc import SQLAlchemyError
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import tests
 import tests
@@ -37,40 +38,39 @@ class PagureFlaskApiForkUpdatetests(tests.SimplePagureTest):
 
 
     maxDiff = None
     maxDiff = None
 
 
-    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.git.update_git", MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def setUp(self):
     def setUp(self):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(PagureFlaskApiForkUpdatetests, self).setUp()
         super(PagureFlaskApiForkUpdatetests, self).setUp()
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         tests.add_content_git_repo(
         tests.add_content_git_repo(
-            os.path.join(self.path, "repos", "test.git"))
+            os.path.join(self.path, "repos", "test.git")
+        )
 
 
         # Fork
         # Fork
-        project = pagure.lib.query.get_authorized_project(
-            self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         task = pagure.lib.query.fork_project(
         task = pagure.lib.query.fork_project(
-            session=self.session,
-            user='pingou',
-            repo=project,
+            session=self.session, user="pingou", repo=project
         )
         )
         self.session.commit()
         self.session.commit()
         self.assertEqual(
         self.assertEqual(
             task.get(),
             task.get(),
-            {'endpoint': 'ui_ns.view_repo',
-             'repo': 'test',
-             'namespace': None,
-             'username': 'pingou'})
+            {
+                "endpoint": "ui_ns.view_repo",
+                "repo": "test",
+                "namespace": None,
+                "username": "pingou",
+            },
+        )
 
 
         tests.add_readme_git_repo(
         tests.add_readme_git_repo(
-            os.path.join(self.path, "repos", "forks", "pingou", "test.git"))
-        project = pagure.lib.query.get_authorized_project(
-            self.session, 'test')
+            os.path.join(self.path, "repos", "forks", "pingou", "test.git")
+        )
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         fork = pagure.lib.query.get_authorized_project(
         fork = pagure.lib.query.get_authorized_project(
-            self.session,
-            'test',
-            user='pingou',
+            self.session, "test", user="pingou"
         )
         )
 
 
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
@@ -79,64 +79,61 @@ class PagureFlaskApiForkUpdatetests(tests.SimplePagureTest):
         req = pagure.lib.query.new_pull_request(
         req = pagure.lib.query.new_pull_request(
             session=self.session,
             session=self.session,
             repo_from=fork,
             repo_from=fork,
-            branch_from='master',
+            branch_from="master",
             repo_to=project,
             repo_to=project,
-            branch_to='master',
-            title='test pull-request',
-            user='pingou',
+            branch_to="master",
+            title="test pull-request",
+            user="pingou",
         )
         )
         self.session.commit()
         self.session.commit()
         self.assertEqual(req.id, 1)
         self.assertEqual(req.id, 1)
-        self.assertEqual(req.title, 'test pull-request')
+        self.assertEqual(req.title, "test pull-request")
 
 
         # Assert the PR is open
         # Assert the PR is open
         self.session = pagure.lib.query.create_session(self.dbpath)
         self.session = pagure.lib.query.create_session(self.dbpath)
-        project = pagure.lib.query.get_authorized_project(
-            self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(project.requests), 1)
         self.assertEqual(len(project.requests), 1)
         self.assertEqual(project.requests[0].status, "Open")
         self.assertEqual(project.requests[0].status, "Open")
         # Check how the PR renders in the API and the UI
         # Check how the PR renders in the API and the UI
-        output = self.app.get('/api/0/test/pull-request/1')
+        output = self.app.get("/api/0/test/pull-request/1")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
-        output = self.app.get('/test/pull-request/1')
+        output = self.app.get("/test/pull-request/1")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
 
 
     def test_api_pull_request_update_invalid_project_namespace(self):
     def test_api_pull_request_update_invalid_project_namespace(self):
         """ Test api_pull_request_update method when the project doesn't exist.
         """ Test api_pull_request_update method when the project doesn't exist.
         """
         """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # Valid token, wrong project
         # Valid token, wrong project
         output = self.app.post(
         output = self.app.post(
-            '/api/0/somenamespace/test3/pull-request/1', headers=headers)
+            "/api/0/somenamespace/test3/pull-request/1", headers=headers
+        )
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
-            {'error': 'Invalid or expired token. Please visit '
-                      'http://localhost.localdomain/settings#api-keys to get or renew your '
-                      'API token.',
-             'error_code': 'EINVALIDTOK'}
-
+            {
+                "error": "Invalid or expired token. Please visit "
+                "http://localhost.localdomain/settings#api-keys to get or renew your "
+                "API token.",
+                "error_code": "EINVALIDTOK",
+            },
         )
         )
 
 
     def test_api_pull_request_update_invalid_project(self):
     def test_api_pull_request_update_invalid_project(self):
         """ Test api_pull_request_update method when the project doesn't exist.
         """ Test api_pull_request_update method when the project doesn't exist.
         """
         """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # Invalid project
         # Invalid project
-        output = self.app.post('/api/0/foo/pull-request/1', headers=headers)
+        output = self.app.post("/api/0/foo/pull-request/1", headers=headers)
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
-            data,
-            {
-              "error": "Project not found",
-              "error_code": "ENOPROJECT",
-            }
+            data, {"error": "Project not found", "error_code": "ENOPROJECT"}
         )
         )
 
 
     def test_api_pull_request_update_invalid_project_token(self):
     def test_api_pull_request_update_invalid_project_token(self):
@@ -144,324 +141,360 @@ class PagureFlaskApiForkUpdatetests(tests.SimplePagureTest):
         to the project.
         to the project.
         """
         """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # Valid token, wrong project
         # Valid token, wrong project
-        output = self.app.post('/api/0/test2/pull-request/1', headers=headers)
+        output = self.app.post("/api/0/test2/pull-request/1", headers=headers)
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(sorted(data.keys()), ['error', 'error_code'])
+        self.assertEqual(sorted(data.keys()), ["error", "error_code"])
+        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
         self.assertEqual(
         self.assertEqual(
-            pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
-        self.assertEqual(
-            pagure.api.APIERROR.EINVALIDTOK.name, data['error_code'])
+            pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
+        )
 
 
     def test_api_pull_request_update_invalid_pr(self):
     def test_api_pull_request_update_invalid_pr(self):
         """ Test api_assign_pull_request method when asking for an invalid PR
         """ Test api_assign_pull_request method when asking for an invalid PR
         """
         """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # Invalid PR id
         # Invalid PR id
-        output = self.app.post('/api/0/test/pull-request/404', headers=headers)
+        output = self.app.post("/api/0/test/pull-request/404", headers=headers)
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
-            data,
-            {'error': 'Pull-Request not found', 'error_code': 'ENOREQ'}
+            data, {"error": "Pull-Request not found", "error_code": "ENOREQ"}
         )
         )
 
 
     def test_api_pull_request_update_no_input(self):
     def test_api_pull_request_update_no_input(self):
         """ Test api_assign_pull_request method when no input is specified
         """ Test api_assign_pull_request method when no input is specified
         """
         """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # No input
         # No input
-        output = self.app.post('/api/0/test/pull-request/1', headers=headers)
+        output = self.app.post("/api/0/test/pull-request/1", headers=headers)
         self.assertEqual(output.status_code, 400)
         self.assertEqual(output.status_code, 400)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
             {
             {
-                'error': 'Invalid or incomplete input submitted',
-                'error_code': 'EINVALIDREQ',
-                'errors': {'title': ['This field is required.']}
-            }
+                "error": "Invalid or incomplete input submitted",
+                "error_code": "EINVALIDREQ",
+                "errors": {"title": ["This field is required."]},
+            },
         )
         )
 
 
     def test_api_pull_request_update_insufficient_input(self):
     def test_api_pull_request_update_insufficient_input(self):
         """ Test api_assign_pull_request method when no input is specified
         """ Test api_assign_pull_request method when no input is specified
         """
         """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
-        data = {'initial_comment': 'will not work'}
+        headers = {"Authorization": "token aaabbbcccddd"}
+        data = {"initial_comment": "will not work"}
 
 
         # Missing the required title field
         # Missing the required title field
-        output = self.app.post('/api/0/test/pull-request/1', data=data, headers=headers)
+        output = self.app.post(
+            "/api/0/test/pull-request/1", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 400)
         self.assertEqual(output.status_code, 400)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
-             {
-                'error': 'Invalid or incomplete input submitted',
-                'error_code': 'EINVALIDREQ',
-                'errors': {'title': ['This field is required.']}
-            }
+            {
+                "error": "Invalid or incomplete input submitted",
+                "error_code": "EINVALIDREQ",
+                "errors": {"title": ["This field is required."]},
+            },
         )
         )
 
 
     def test_api_pull_request_update_edited(self):
     def test_api_pull_request_update_edited(self):
         """ Test api_assign_pull_request method when with valid input
         """ Test api_assign_pull_request method when with valid input
         """
         """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         data = {
         data = {
-            'title': 'edited test PR',
-            'initial_comment': 'Edited initial comment',
+            "title": "edited test PR",
+            "initial_comment": "Edited initial comment",
         }
         }
 
 
         # Valid request
         # Valid request
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/pull-request/1', data=data, headers=headers)
+            "/api/0/test/pull-request/1", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         # Hard-code all the values that will change from a test to another
         # Hard-code all the values that will change from a test to another
         # because either random or time-based
         # because either random or time-based
-        data['date_created'] = '1551276260'
-        data['last_updated'] = '1551276261'
-        data['updated_on'] = '1551276260'
-        data['commit_start'] = '5f5d609db65d447f77ba00e25afd17ba5053344b'
-        data['commit_stop'] = '5f5d609db65d447f77ba00e25afd17ba5053344b'
-        data['project']['date_created'] = '1551276259'
-        data['project']['date_modified'] = '1551276259'
-        data['repo_from']['date_created'] = '1551276259'
-        data['repo_from']['date_modified'] = '1551276259'
-        data['repo_from']['parent']['date_created'] = '1551276259'
-        data['repo_from']['parent']['date_modified'] = '1551276259'
-        data['uid'] = 'a2bddecc8ea548e88c22a0df77670092'
+        data["date_created"] = "1551276260"
+        data["last_updated"] = "1551276261"
+        data["updated_on"] = "1551276260"
+        data["commit_start"] = "5f5d609db65d447f77ba00e25afd17ba5053344b"
+        data["commit_stop"] = "5f5d609db65d447f77ba00e25afd17ba5053344b"
+        data["project"]["date_created"] = "1551276259"
+        data["project"]["date_modified"] = "1551276259"
+        data["repo_from"]["date_created"] = "1551276259"
+        data["repo_from"]["date_modified"] = "1551276259"
+        data["repo_from"]["parent"]["date_created"] = "1551276259"
+        data["repo_from"]["parent"]["date_modified"] = "1551276259"
+        data["uid"] = "a2bddecc8ea548e88c22a0df77670092"
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
             {
             {
-                'assignee': None,
-                'branch': 'master',
-                'branch_from': 'master',
-                'cached_merge_status': 'unknown',
-                'closed_at': None,
-                'closed_by': None,
-                'comments': [],
-                'commit_start': '5f5d609db65d447f77ba00e25afd17ba5053344b',
-                'commit_stop': '5f5d609db65d447f77ba00e25afd17ba5053344b',
-                'date_created': '1551276260',
-                'id': 1,
-                'initial_comment': 'Edited initial comment',
-                'last_updated': '1551276261',
-                'project': {'access_groups': {'admin': [], 'commit': [], 'ticket': []},
-                         'access_users': {'admin': [],
-                                          'commit': [],
-                                          'owner': ['pingou'],
-                                          'ticket': []},
-                         'close_status': ['Invalid',
-                                          'Insufficient data',
-                                          'Fixed',
-                                          'Duplicate'],
-                         'custom_keys': [],
-                         'date_created': '1551276259',
-                         'date_modified': '1551276259',
-                         'description': 'test project #1',
-                         'fullname': 'test',
-                         'id': 1,
-                         'milestones': {},
-                         'name': 'test',
-                         'namespace': None,
-                         'parent': None,
-                         'priorities': {},
-                         'tags': [],
-                         'url_path': 'test',
-                         'user': {'fullname': 'PY C', 'name': 'pingou'}},
-                'remote_git': None,
-                'repo_from': {'access_groups': {'admin': [], 'commit': [], 'ticket': []},
-                           'access_users': {'admin': [],
-                                            'commit': [],
-                                            'owner': ['pingou'],
-                                            'ticket': []},
-                           'close_status': [],
-                           'custom_keys': [],
-                           'date_created': '1551276259',
-                           'date_modified': '1551276259',
-                           'description': 'test project #1',
-                           'fullname': 'forks/pingou/test',
-                           'id': 4,
-                           'milestones': {},
-                           'name': 'test',
-                           'namespace': None,
-                           'parent': {'access_groups': {'admin': [],
-                                                        'commit': [],
-                                                        'ticket': []},
-                                      'access_users': {'admin': [],
-                                                       'commit': [],
-                                                       'owner': ['pingou'],
-                                                       'ticket': []},
-                                      'close_status': ['Invalid',
-                                                       'Insufficient data',
-                                                       'Fixed',
-                                                       'Duplicate'],
-                                      'custom_keys': [],
-                                      'date_created': '1551276259',
-                                      'date_modified': '1551276259',
-                                      'description': 'test project #1',
-                                      'fullname': 'test',
-                                      'id': 1,
-                                      'milestones': {},
-                                      'name': 'test',
-                                      'namespace': None,
-                                      'parent': None,
-                                      'priorities': {},
-                                      'tags': [],
-                                      'url_path': 'test',
-                                      'user': {'fullname': 'PY C', 'name': 'pingou'}},
-                           'priorities': {},
-                           'tags': [],
-                           'url_path': 'fork/pingou/test',
-                           'user': {'fullname': 'PY C', 'name': 'pingou'}},
-                'status': 'Open',
-                'tags': [],
-                'threshold_reached': None,
-                'title': 'edited test PR',
-                'uid': 'a2bddecc8ea548e88c22a0df77670092',
-                'updated_on': '1551276260',
-                'user': {'fullname': 'PY C', 'name': 'pingou'}
-            }
+                "assignee": None,
+                "branch": "master",
+                "branch_from": "master",
+                "cached_merge_status": "unknown",
+                "closed_at": None,
+                "closed_by": None,
+                "comments": [],
+                "commit_start": "5f5d609db65d447f77ba00e25afd17ba5053344b",
+                "commit_stop": "5f5d609db65d447f77ba00e25afd17ba5053344b",
+                "date_created": "1551276260",
+                "id": 1,
+                "initial_comment": "Edited initial comment",
+                "last_updated": "1551276261",
+                "project": {
+                    "access_groups": {"admin": [], "commit": [], "ticket": []},
+                    "access_users": {
+                        "admin": [],
+                        "commit": [],
+                        "owner": ["pingou"],
+                        "ticket": [],
+                    },
+                    "close_status": [
+                        "Invalid",
+                        "Insufficient data",
+                        "Fixed",
+                        "Duplicate",
+                    ],
+                    "custom_keys": [],
+                    "date_created": "1551276259",
+                    "date_modified": "1551276259",
+                    "description": "test project #1",
+                    "fullname": "test",
+                    "id": 1,
+                    "milestones": {},
+                    "name": "test",
+                    "namespace": None,
+                    "parent": None,
+                    "priorities": {},
+                    "tags": [],
+                    "url_path": "test",
+                    "user": {"fullname": "PY C", "name": "pingou"},
+                },
+                "remote_git": None,
+                "repo_from": {
+                    "access_groups": {"admin": [], "commit": [], "ticket": []},
+                    "access_users": {
+                        "admin": [],
+                        "commit": [],
+                        "owner": ["pingou"],
+                        "ticket": [],
+                    },
+                    "close_status": [],
+                    "custom_keys": [],
+                    "date_created": "1551276259",
+                    "date_modified": "1551276259",
+                    "description": "test project #1",
+                    "fullname": "forks/pingou/test",
+                    "id": 4,
+                    "milestones": {},
+                    "name": "test",
+                    "namespace": None,
+                    "parent": {
+                        "access_groups": {
+                            "admin": [],
+                            "commit": [],
+                            "ticket": [],
+                        },
+                        "access_users": {
+                            "admin": [],
+                            "commit": [],
+                            "owner": ["pingou"],
+                            "ticket": [],
+                        },
+                        "close_status": [
+                            "Invalid",
+                            "Insufficient data",
+                            "Fixed",
+                            "Duplicate",
+                        ],
+                        "custom_keys": [],
+                        "date_created": "1551276259",
+                        "date_modified": "1551276259",
+                        "description": "test project #1",
+                        "fullname": "test",
+                        "id": 1,
+                        "milestones": {},
+                        "name": "test",
+                        "namespace": None,
+                        "parent": None,
+                        "priorities": {},
+                        "tags": [],
+                        "url_path": "test",
+                        "user": {"fullname": "PY C", "name": "pingou"},
+                    },
+                    "priorities": {},
+                    "tags": [],
+                    "url_path": "fork/pingou/test",
+                    "user": {"fullname": "PY C", "name": "pingou"},
+                },
+                "status": "Open",
+                "tags": [],
+                "threshold_reached": None,
+                "title": "edited test PR",
+                "uid": "a2bddecc8ea548e88c22a0df77670092",
+                "updated_on": "1551276260",
+                "user": {"fullname": "PY C", "name": "pingou"},
+            },
         )
         )
 
 
     def test_api_pull_request_update_edited_no_comment(self):
     def test_api_pull_request_update_edited_no_comment(self):
         """ Test api_assign_pull_request method when with valid input
         """ Test api_assign_pull_request method when with valid input
         """
         """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
-        data = {
-            'title': 'edited test PR',
-        }
+        data = {"title": "edited test PR"}
 
 
         # Valid request
         # Valid request
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/pull-request/1', data=data, headers=headers)
+            "/api/0/test/pull-request/1", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         # Hard-code all the values that will change from a test to another
         # Hard-code all the values that will change from a test to another
         # because either random or time-based
         # because either random or time-based
-        data['date_created'] = '1551276260'
-        data['last_updated'] = '1551276261'
-        data['updated_on'] = '1551276260'
-        data['commit_start'] = '5f5d609db65d447f77ba00e25afd17ba5053344b'
-        data['commit_stop'] = '5f5d609db65d447f77ba00e25afd17ba5053344b'
-        data['project']['date_created'] = '1551276259'
-        data['project']['date_modified'] = '1551276259'
-        data['repo_from']['date_created'] = '1551276259'
-        data['repo_from']['date_modified'] = '1551276259'
-        data['repo_from']['parent']['date_created'] = '1551276259'
-        data['repo_from']['parent']['date_modified'] = '1551276259'
-        data['uid'] = 'a2bddecc8ea548e88c22a0df77670092'
+        data["date_created"] = "1551276260"
+        data["last_updated"] = "1551276261"
+        data["updated_on"] = "1551276260"
+        data["commit_start"] = "5f5d609db65d447f77ba00e25afd17ba5053344b"
+        data["commit_stop"] = "5f5d609db65d447f77ba00e25afd17ba5053344b"
+        data["project"]["date_created"] = "1551276259"
+        data["project"]["date_modified"] = "1551276259"
+        data["repo_from"]["date_created"] = "1551276259"
+        data["repo_from"]["date_modified"] = "1551276259"
+        data["repo_from"]["parent"]["date_created"] = "1551276259"
+        data["repo_from"]["parent"]["date_modified"] = "1551276259"
+        data["uid"] = "a2bddecc8ea548e88c22a0df77670092"
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
             {
             {
-                'assignee': None,
-                'branch': 'master',
-                'branch_from': 'master',
-                'cached_merge_status': 'unknown',
-                'closed_at': None,
-                'closed_by': None,
-                'comments': [],
-                'commit_start': '5f5d609db65d447f77ba00e25afd17ba5053344b',
-                'commit_stop': '5f5d609db65d447f77ba00e25afd17ba5053344b',
-                'date_created': '1551276260',
-                'id': 1,
-                'initial_comment': '',
-                'last_updated': '1551276261',
-                'project': {'access_groups': {'admin': [], 'commit': [], 'ticket': []},
-                         'access_users': {'admin': [],
-                                          'commit': [],
-                                          'owner': ['pingou'],
-                                          'ticket': []},
-                         'close_status': ['Invalid',
-                                          'Insufficient data',
-                                          'Fixed',
-                                          'Duplicate'],
-                         'custom_keys': [],
-                         'date_created': '1551276259',
-                         'date_modified': '1551276259',
-                         'description': 'test project #1',
-                         'fullname': 'test',
-                         'id': 1,
-                         'milestones': {},
-                         'name': 'test',
-                         'namespace': None,
-                         'parent': None,
-                         'priorities': {},
-                         'tags': [],
-                         'url_path': 'test',
-                         'user': {'fullname': 'PY C', 'name': 'pingou'}},
-                'remote_git': None,
-                'repo_from': {'access_groups': {'admin': [], 'commit': [], 'ticket': []},
-                           'access_users': {'admin': [],
-                                            'commit': [],
-                                            'owner': ['pingou'],
-                                            'ticket': []},
-                           'close_status': [],
-                           'custom_keys': [],
-                           'date_created': '1551276259',
-                           'date_modified': '1551276259',
-                           'description': 'test project #1',
-                           'fullname': 'forks/pingou/test',
-                           'id': 4,
-                           'milestones': {},
-                           'name': 'test',
-                           'namespace': None,
-                           'parent': {'access_groups': {'admin': [],
-                                                        'commit': [],
-                                                        'ticket': []},
-                                      'access_users': {'admin': [],
-                                                       'commit': [],
-                                                       'owner': ['pingou'],
-                                                       'ticket': []},
-                                      'close_status': ['Invalid',
-                                                       'Insufficient data',
-                                                       'Fixed',
-                                                       'Duplicate'],
-                                      'custom_keys': [],
-                                      'date_created': '1551276259',
-                                      'date_modified': '1551276259',
-                                      'description': 'test project #1',
-                                      'fullname': 'test',
-                                      'id': 1,
-                                      'milestones': {},
-                                      'name': 'test',
-                                      'namespace': None,
-                                      'parent': None,
-                                      'priorities': {},
-                                      'tags': [],
-                                      'url_path': 'test',
-                                      'user': {'fullname': 'PY C', 'name': 'pingou'}},
-                           'priorities': {},
-                           'tags': [],
-                           'url_path': 'fork/pingou/test',
-                           'user': {'fullname': 'PY C', 'name': 'pingou'}},
-                'status': 'Open',
-                'tags': [],
-                'threshold_reached': None,
-                'title': 'edited test PR',
-                'uid': 'a2bddecc8ea548e88c22a0df77670092',
-                'updated_on': '1551276260',
-                'user': {'fullname': 'PY C', 'name': 'pingou'}
-            }
+                "assignee": None,
+                "branch": "master",
+                "branch_from": "master",
+                "cached_merge_status": "unknown",
+                "closed_at": None,
+                "closed_by": None,
+                "comments": [],
+                "commit_start": "5f5d609db65d447f77ba00e25afd17ba5053344b",
+                "commit_stop": "5f5d609db65d447f77ba00e25afd17ba5053344b",
+                "date_created": "1551276260",
+                "id": 1,
+                "initial_comment": "",
+                "last_updated": "1551276261",
+                "project": {
+                    "access_groups": {"admin": [], "commit": [], "ticket": []},
+                    "access_users": {
+                        "admin": [],
+                        "commit": [],
+                        "owner": ["pingou"],
+                        "ticket": [],
+                    },
+                    "close_status": [
+                        "Invalid",
+                        "Insufficient data",
+                        "Fixed",
+                        "Duplicate",
+                    ],
+                    "custom_keys": [],
+                    "date_created": "1551276259",
+                    "date_modified": "1551276259",
+                    "description": "test project #1",
+                    "fullname": "test",
+                    "id": 1,
+                    "milestones": {},
+                    "name": "test",
+                    "namespace": None,
+                    "parent": None,
+                    "priorities": {},
+                    "tags": [],
+                    "url_path": "test",
+                    "user": {"fullname": "PY C", "name": "pingou"},
+                },
+                "remote_git": None,
+                "repo_from": {
+                    "access_groups": {"admin": [], "commit": [], "ticket": []},
+                    "access_users": {
+                        "admin": [],
+                        "commit": [],
+                        "owner": ["pingou"],
+                        "ticket": [],
+                    },
+                    "close_status": [],
+                    "custom_keys": [],
+                    "date_created": "1551276259",
+                    "date_modified": "1551276259",
+                    "description": "test project #1",
+                    "fullname": "forks/pingou/test",
+                    "id": 4,
+                    "milestones": {},
+                    "name": "test",
+                    "namespace": None,
+                    "parent": {
+                        "access_groups": {
+                            "admin": [],
+                            "commit": [],
+                            "ticket": [],
+                        },
+                        "access_users": {
+                            "admin": [],
+                            "commit": [],
+                            "owner": ["pingou"],
+                            "ticket": [],
+                        },
+                        "close_status": [
+                            "Invalid",
+                            "Insufficient data",
+                            "Fixed",
+                            "Duplicate",
+                        ],
+                        "custom_keys": [],
+                        "date_created": "1551276259",
+                        "date_modified": "1551276259",
+                        "description": "test project #1",
+                        "fullname": "test",
+                        "id": 1,
+                        "milestones": {},
+                        "name": "test",
+                        "namespace": None,
+                        "parent": None,
+                        "priorities": {},
+                        "tags": [],
+                        "url_path": "test",
+                        "user": {"fullname": "PY C", "name": "pingou"},
+                    },
+                    "priorities": {},
+                    "tags": [],
+                    "url_path": "fork/pingou/test",
+                    "user": {"fullname": "PY C", "name": "pingou"},
+                },
+                "status": "Open",
+                "tags": [],
+                "threshold_reached": None,
+                "title": "edited test PR",
+                "uid": "a2bddecc8ea548e88c22a0df77670092",
+                "updated_on": "1551276260",
+                "user": {"fullname": "PY C", "name": "pingou"},
+            },
         )
         )
 
 
     def test_api_pull_request_update_edited_linked(self):
     def test_api_pull_request_update_edited_linked(self):
         """ Test api_assign_pull_request method when with valid input
         """ Test api_assign_pull_request method when with valid input
         """
         """
-        project = pagure.lib.query.get_authorized_project(
-            self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(project.requests), 1)
         self.assertEqual(len(project.requests), 1)
         self.assertEqual(len(project.requests[0].related_issues), 0)
         self.assertEqual(len(project.requests[0].related_issues), 0)
         self.assertEqual(len(project.issues), 0)
         self.assertEqual(len(project.issues), 0)
@@ -470,142 +503,160 @@ class PagureFlaskApiForkUpdatetests(tests.SimplePagureTest):
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=project,
             repo=project,
-            title='tést íssüé',
-            content='We should work on this',
-            user='pingou',
+            title="tést íssüé",
+            content="We should work on this",
+            user="pingou",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg.title, 'tést íssüé')
+        self.assertEqual(msg.title, "tést íssüé")
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         data = {
         data = {
-            'title': 'edited test PR',
-            'initial_comment': 'Edited initial comment\n\n'
-                'this PR fixes #2 \n\nThanks',
+            "title": "edited test PR",
+            "initial_comment": "Edited initial comment\n\n"
+            "this PR fixes #2 \n\nThanks",
         }
         }
 
 
         # Valid request
         # Valid request
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/pull-request/1', data=data, headers=headers)
+            "/api/0/test/pull-request/1", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         # Hard-code all the values that will change from a test to another
         # Hard-code all the values that will change from a test to another
         # because either random or time-based
         # because either random or time-based
-        data['date_created'] = '1551276260'
-        data['last_updated'] = '1551276261'
-        data['updated_on'] = '1551276260'
-        data['commit_start'] = '5f5d609db65d447f77ba00e25afd17ba5053344b'
-        data['commit_stop'] = '5f5d609db65d447f77ba00e25afd17ba5053344b'
-        data['project']['date_created'] = '1551276259'
-        data['project']['date_modified'] = '1551276259'
-        data['repo_from']['date_created'] = '1551276259'
-        data['repo_from']['date_modified'] = '1551276259'
-        data['repo_from']['parent']['date_created'] = '1551276259'
-        data['repo_from']['parent']['date_modified'] = '1551276259'
-        data['uid'] = 'a2bddecc8ea548e88c22a0df77670092'
+        data["date_created"] = "1551276260"
+        data["last_updated"] = "1551276261"
+        data["updated_on"] = "1551276260"
+        data["commit_start"] = "5f5d609db65d447f77ba00e25afd17ba5053344b"
+        data["commit_stop"] = "5f5d609db65d447f77ba00e25afd17ba5053344b"
+        data["project"]["date_created"] = "1551276259"
+        data["project"]["date_modified"] = "1551276259"
+        data["repo_from"]["date_created"] = "1551276259"
+        data["repo_from"]["date_modified"] = "1551276259"
+        data["repo_from"]["parent"]["date_created"] = "1551276259"
+        data["repo_from"]["parent"]["date_modified"] = "1551276259"
+        data["uid"] = "a2bddecc8ea548e88c22a0df77670092"
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
             {
             {
-                'assignee': None,
-                'branch': 'master',
-                'branch_from': 'master',
-                'cached_merge_status': 'unknown',
-                'closed_at': None,
-                'closed_by': None,
-                'comments': [],
-                'commit_start': '5f5d609db65d447f77ba00e25afd17ba5053344b',
-                'commit_stop': '5f5d609db65d447f77ba00e25afd17ba5053344b',
-                'date_created': '1551276260',
-                'id': 1,
-                'initial_comment': 'Edited initial comment\n\nthis PR '
-                    'fixes #2 \n\nThanks',
-                'last_updated': '1551276261',
-                'project': {'access_groups': {'admin': [], 'commit': [], 'ticket': []},
-                         'access_users': {'admin': [],
-                                          'commit': [],
-                                          'owner': ['pingou'],
-                                          'ticket': []},
-                         'close_status': ['Invalid',
-                                          'Insufficient data',
-                                          'Fixed',
-                                          'Duplicate'],
-                         'custom_keys': [],
-                         'date_created': '1551276259',
-                         'date_modified': '1551276259',
-                         'description': 'test project #1',
-                         'fullname': 'test',
-                         'id': 1,
-                         'milestones': {},
-                         'name': 'test',
-                         'namespace': None,
-                         'parent': None,
-                         'priorities': {},
-                         'tags': [],
-                         'url_path': 'test',
-                         'user': {'fullname': 'PY C', 'name': 'pingou'}},
-                'remote_git': None,
-                'repo_from': {'access_groups': {'admin': [], 'commit': [], 'ticket': []},
-                           'access_users': {'admin': [],
-                                            'commit': [],
-                                            'owner': ['pingou'],
-                                            'ticket': []},
-                           'close_status': [],
-                           'custom_keys': [],
-                           'date_created': '1551276259',
-                           'date_modified': '1551276259',
-                           'description': 'test project #1',
-                           'fullname': 'forks/pingou/test',
-                           'id': 4,
-                           'milestones': {},
-                           'name': 'test',
-                           'namespace': None,
-                           'parent': {'access_groups': {'admin': [],
-                                                        'commit': [],
-                                                        'ticket': []},
-                                      'access_users': {'admin': [],
-                                                       'commit': [],
-                                                       'owner': ['pingou'],
-                                                       'ticket': []},
-                                      'close_status': ['Invalid',
-                                                       'Insufficient data',
-                                                       'Fixed',
-                                                       'Duplicate'],
-                                      'custom_keys': [],
-                                      'date_created': '1551276259',
-                                      'date_modified': '1551276259',
-                                      'description': 'test project #1',
-                                      'fullname': 'test',
-                                      'id': 1,
-                                      'milestones': {},
-                                      'name': 'test',
-                                      'namespace': None,
-                                      'parent': None,
-                                      'priorities': {},
-                                      'tags': [],
-                                      'url_path': 'test',
-                                      'user': {'fullname': 'PY C', 'name': 'pingou'}},
-                           'priorities': {},
-                           'tags': [],
-                           'url_path': 'fork/pingou/test',
-                           'user': {'fullname': 'PY C', 'name': 'pingou'}},
-                'status': 'Open',
-                'tags': [],
-                'threshold_reached': None,
-                'title': 'edited test PR',
-                'uid': 'a2bddecc8ea548e88c22a0df77670092',
-                'updated_on': '1551276260',
-                'user': {'fullname': 'PY C', 'name': 'pingou'}
-            }
+                "assignee": None,
+                "branch": "master",
+                "branch_from": "master",
+                "cached_merge_status": "unknown",
+                "closed_at": None,
+                "closed_by": None,
+                "comments": [],
+                "commit_start": "5f5d609db65d447f77ba00e25afd17ba5053344b",
+                "commit_stop": "5f5d609db65d447f77ba00e25afd17ba5053344b",
+                "date_created": "1551276260",
+                "id": 1,
+                "initial_comment": "Edited initial comment\n\nthis PR "
+                "fixes #2 \n\nThanks",
+                "last_updated": "1551276261",
+                "project": {
+                    "access_groups": {"admin": [], "commit": [], "ticket": []},
+                    "access_users": {
+                        "admin": [],
+                        "commit": [],
+                        "owner": ["pingou"],
+                        "ticket": [],
+                    },
+                    "close_status": [
+                        "Invalid",
+                        "Insufficient data",
+                        "Fixed",
+                        "Duplicate",
+                    ],
+                    "custom_keys": [],
+                    "date_created": "1551276259",
+                    "date_modified": "1551276259",
+                    "description": "test project #1",
+                    "fullname": "test",
+                    "id": 1,
+                    "milestones": {},
+                    "name": "test",
+                    "namespace": None,
+                    "parent": None,
+                    "priorities": {},
+                    "tags": [],
+                    "url_path": "test",
+                    "user": {"fullname": "PY C", "name": "pingou"},
+                },
+                "remote_git": None,
+                "repo_from": {
+                    "access_groups": {"admin": [], "commit": [], "ticket": []},
+                    "access_users": {
+                        "admin": [],
+                        "commit": [],
+                        "owner": ["pingou"],
+                        "ticket": [],
+                    },
+                    "close_status": [],
+                    "custom_keys": [],
+                    "date_created": "1551276259",
+                    "date_modified": "1551276259",
+                    "description": "test project #1",
+                    "fullname": "forks/pingou/test",
+                    "id": 4,
+                    "milestones": {},
+                    "name": "test",
+                    "namespace": None,
+                    "parent": {
+                        "access_groups": {
+                            "admin": [],
+                            "commit": [],
+                            "ticket": [],
+                        },
+                        "access_users": {
+                            "admin": [],
+                            "commit": [],
+                            "owner": ["pingou"],
+                            "ticket": [],
+                        },
+                        "close_status": [
+                            "Invalid",
+                            "Insufficient data",
+                            "Fixed",
+                            "Duplicate",
+                        ],
+                        "custom_keys": [],
+                        "date_created": "1551276259",
+                        "date_modified": "1551276259",
+                        "description": "test project #1",
+                        "fullname": "test",
+                        "id": 1,
+                        "milestones": {},
+                        "name": "test",
+                        "namespace": None,
+                        "parent": None,
+                        "priorities": {},
+                        "tags": [],
+                        "url_path": "test",
+                        "user": {"fullname": "PY C", "name": "pingou"},
+                    },
+                    "priorities": {},
+                    "tags": [],
+                    "url_path": "fork/pingou/test",
+                    "user": {"fullname": "PY C", "name": "pingou"},
+                },
+                "status": "Open",
+                "tags": [],
+                "threshold_reached": None,
+                "title": "edited test PR",
+                "uid": "a2bddecc8ea548e88c22a0df77670092",
+                "updated_on": "1551276260",
+                "user": {"fullname": "PY C", "name": "pingou"},
+            },
         )
         )
 
 
-        project = pagure.lib.query.get_authorized_project(
-            self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(project.requests), 1)
         self.assertEqual(len(project.requests), 1)
         self.assertEqual(len(project.requests[0].related_issues), 1)
         self.assertEqual(len(project.requests[0].related_issues), 1)
         self.assertEqual(len(project.issues), 1)
         self.assertEqual(len(project.issues), 1)
         self.assertEqual(len(project.issues[0].related_prs), 1)
         self.assertEqual(len(project.issues[0].related_prs), 1)
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 154 - 209
tests/test_pagure_flask_api_group.py

@@ -16,8 +16,9 @@ import sys
 import os
 import os
 import json
 import json
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.api
 import pagure.api
 import pagure.lib.query
 import pagure.lib.query
@@ -33,15 +34,15 @@ class PagureFlaskApiGroupTests(tests.SimplePagureTest):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(PagureFlaskApiGroupTests, self).setUp()
         super(PagureFlaskApiGroupTests, self).setUp()
 
 
-        pagure.config.config['REQUESTS_FOLDER'] = None
+        pagure.config.config["REQUESTS_FOLDER"] = None
 
 
         msg = pagure.lib.query.add_group(
         msg = pagure.lib.query.add_group(
             self.session,
             self.session,
-            group_name='some_group',
-            display_name='Some Group',
+            group_name="some_group",
+            display_name="Some Group",
             description=None,
             description=None,
-            group_type='bar',
-            user='pingou',
+            group_type="bar",
+            user="pingou",
             is_admin=False,
             is_admin=False,
             blacklist=[],
             blacklist=[],
         )
         )
@@ -49,110 +50,101 @@ class PagureFlaskApiGroupTests(tests.SimplePagureTest):
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
 
 
-        project = pagure.lib.query._get_project(self.session, 'test2')
+        project = pagure.lib.query._get_project(self.session, "test2")
         msg = pagure.lib.query.add_group_to_project(
         msg = pagure.lib.query.add_group_to_project(
             session=self.session,
             session=self.session,
             project=project,
             project=project,
-            new_group='some_group',
-            user='pingou',
+            new_group="some_group",
+            user="pingou",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'Group added')
+        self.assertEqual(msg, "Group added")
 
 
     def test_api_groups(self):
     def test_api_groups(self):
         """ Test the api_groups function.  """
         """ Test the api_groups function.  """
 
 
         # Add a couple of groups so that we can list them
         # Add a couple of groups so that we can list them
         item = pagure.lib.model.PagureGroup(
         item = pagure.lib.model.PagureGroup(
-            group_name='group1',
-            group_type='user',
-            display_name='User group',
+            group_name="group1",
+            group_type="user",
+            display_name="User group",
             user_id=1,  # pingou
             user_id=1,  # pingou
         )
         )
         self.session.add(item)
         self.session.add(item)
 
 
         item = pagure.lib.model.PagureGroup(
         item = pagure.lib.model.PagureGroup(
-            group_name='rel-eng',
-            group_type='user',
-            display_name='Release engineering group',
+            group_name="rel-eng",
+            group_type="user",
+            display_name="Release engineering group",
             user_id=1,  # pingou
             user_id=1,  # pingou
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
 
 
-        output = self.app.get('/api/0/groups')
+        output = self.app.get("/api/0/groups")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(data['groups'], ['some_group', 'group1', 'rel-eng'])
+        self.assertEqual(data["groups"], ["some_group", "group1", "rel-eng"])
         self.assertEqual(
         self.assertEqual(
-            sorted(data.keys()),
-            ['groups', 'pagination', 'total_groups'])
-        self.assertEqual(data['total_groups'], 3)
+            sorted(data.keys()), ["groups", "pagination", "total_groups"]
+        )
+        self.assertEqual(data["total_groups"], 3)
 
 
-        output = self.app.get('/api/0/groups?pattern=re')
+        output = self.app.get("/api/0/groups?pattern=re")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(data['groups'], ['rel-eng'])
+        self.assertEqual(data["groups"], ["rel-eng"])
         self.assertEqual(
         self.assertEqual(
-            sorted(data.keys()),
-            ['groups', 'pagination', 'total_groups'])
-        self.assertEqual(data['total_groups'], 1)
+            sorted(data.keys()), ["groups", "pagination", "total_groups"]
+        )
+        self.assertEqual(data["total_groups"], 1)
 
 
     def test_api_groups_extended(self):
     def test_api_groups_extended(self):
         """ Test the api_groups function.  """
         """ Test the api_groups function.  """
 
 
         # Add a couple of groups so that we can list them
         # Add a couple of groups so that we can list them
         item = pagure.lib.model.PagureGroup(
         item = pagure.lib.model.PagureGroup(
-            group_name='group1',
-            group_type='user',
-            display_name='User group',
+            group_name="group1",
+            group_type="user",
+            display_name="User group",
             user_id=1,  # pingou
             user_id=1,  # pingou
         )
         )
         self.session.add(item)
         self.session.add(item)
 
 
         item = pagure.lib.model.PagureGroup(
         item = pagure.lib.model.PagureGroup(
-            group_name='rel-eng',
-            group_type='user',
-            display_name='Release engineering group',
+            group_name="rel-eng",
+            group_type="user",
+            display_name="Release engineering group",
             user_id=1,  # pingou
             user_id=1,  # pingou
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
 
 
-        output = self.app.get('/api/0/groups?extended=1')
+        output = self.app.get("/api/0/groups?extended=1")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        for k in ['first', 'last']:
-            self.assertIsNotNone(data['pagination'][k])
-            data['pagination'][k] = 'http://localhost...'
+        for k in ["first", "last"]:
+            self.assertIsNotNone(data["pagination"][k])
+            data["pagination"][k] = "http://localhost..."
         self.assertEqual(
         self.assertEqual(
             data,
             data,
             {
             {
                 "groups": [
                 "groups": [
-                    {
-                        "description": None,
-                        "name": "some_group"
-                    },
-                    {
-                        "description": None,
-                        "name": "group1"
-                    },
-                    {
-                        "description": None,
-                        "name": "rel-eng"
-                    }
+                    {"description": None, "name": "some_group"},
+                    {"description": None, "name": "group1"},
+                    {"description": None, "name": "rel-eng"},
                 ],
                 ],
-                u'pagination': {
-                    u'first': u'http://localhost...',
-                    u'last': u'http://localhost...',
-                    u'next': None,
-                    u'page': 1,
-                    u'pages': 1,
-                    u'per_page': 20,
-                    u'prev': None
+                "pagination": {
+                    "first": "http://localhost...",
+                    "last": "http://localhost...",
+                    "next": None,
+                    "page": 1,
+                    "pages": 1,
+                    "per_page": 20,
+                    "prev": None,
                 },
                 },
-                "total_groups": 3
-            }
+                "total_groups": 3,
+            },
         )
         )
 
 
     def test_api_view_group_authenticated(self):
     def test_api_view_group_authenticated(self):
@@ -162,8 +154,8 @@ class PagureFlaskApiGroupTests(tests.SimplePagureTest):
         """
         """
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
-        output = self.app.get('/api/0/group/some_group', headers=headers)
+        headers = {"Authorization": "token aaabbbcccddd"}
+        output = self.app.get("/api/0/group/some_group", headers=headers)
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         exp = {
         exp = {
             "display_name": "Some Group",
             "display_name": "Some Group",
@@ -171,19 +163,16 @@ class PagureFlaskApiGroupTests(tests.SimplePagureTest):
             "creator": {
             "creator": {
                 "fullname": "PY C",
                 "fullname": "PY C",
                 "default_email": "bar@pingou.com",
                 "default_email": "bar@pingou.com",
-                "emails": [
-                    "bar@pingou.com",
-                    "foo@pingou.com"
-                ],
-                "name": "pingou"
+                "emails": ["bar@pingou.com", "foo@pingou.com"],
+                "name": "pingou",
             },
             },
             "members": ["pingou"],
             "members": ["pingou"],
             "date_created": "1492020239",
             "date_created": "1492020239",
             "group_type": "user",
             "group_type": "user",
-            "name": "some_group"
+            "name": "some_group",
         }
         }
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        data['date_created'] = '1492020239'
+        data["date_created"] = "1492020239"
         self.assertDictEqual(data, exp)
         self.assertDictEqual(data, exp)
 
 
     def test_api_view_group_unauthenticated(self):
     def test_api_view_group_unauthenticated(self):
@@ -191,22 +180,19 @@ class PagureFlaskApiGroupTests(tests.SimplePagureTest):
             Test the api_view_group method of the flask api with an
             Test the api_view_group method of the flask api with an
             unauthenticated user. The tested group has one member.
             unauthenticated user. The tested group has one member.
         """
         """
-        output = self.app.get('/api/0/group/some_group')
+        output = self.app.get("/api/0/group/some_group")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         exp = {
         exp = {
             "display_name": "Some Group",
             "display_name": "Some Group",
             "description": None,
             "description": None,
-            "creator": {
-                "fullname": "PY C",
-                "name": "pingou"
-            },
+            "creator": {"fullname": "PY C", "name": "pingou"},
             "members": ["pingou"],
             "members": ["pingou"],
             "date_created": "1492020239",
             "date_created": "1492020239",
             "group_type": "user",
             "group_type": "user",
-            "name": "some_group"
+            "name": "some_group",
         }
         }
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        data['date_created'] = '1492020239'
+        data["date_created"] = "1492020239"
         self.assertDictEqual(data, exp)
         self.assertDictEqual(data, exp)
 
 
     def test_api_view_group_two_members_authenticated(self):
     def test_api_view_group_two_members_authenticated(self):
@@ -215,24 +201,28 @@ class PagureFlaskApiGroupTests(tests.SimplePagureTest):
             authenticated user. The tested group has two members.
             authenticated user. The tested group has two members.
         """
         """
         user = pagure.lib.model.User(
         user = pagure.lib.model.User(
-            user='mprahl',
-            fullname='Matt Prahl',
-            password='foo',
-            default_email='mprahl@redhat.com',
+            user="mprahl",
+            fullname="Matt Prahl",
+            password="foo",
+            default_email="mprahl@redhat.com",
         )
         )
         self.session.add(user)
         self.session.add(user)
         self.session.commit()
         self.session.commit()
-        group = pagure.lib.query.search_groups(self.session, group_name='some_group')
+        group = pagure.lib.query.search_groups(
+            self.session, group_name="some_group"
+        )
         result = pagure.lib.query.add_user_to_group(
         result = pagure.lib.query.add_user_to_group(
-            self.session, user.username, group, user.username, True)
+            self.session, user.username, group, user.username, True
+        )
         self.assertEqual(
         self.assertEqual(
-            result, 'User `mprahl` added to the group `some_group`.')
+            result, "User `mprahl` added to the group `some_group`."
+        )
         self.session.commit()
         self.session.commit()
 
 
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
-        output = self.app.get('/api/0/group/some_group', headers=headers)
+        headers = {"Authorization": "token aaabbbcccddd"}
+        output = self.app.get("/api/0/group/some_group", headers=headers)
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         exp = {
         exp = {
             "display_name": "Some Group",
             "display_name": "Some Group",
@@ -240,20 +230,17 @@ class PagureFlaskApiGroupTests(tests.SimplePagureTest):
             "creator": {
             "creator": {
                 "fullname": "PY C",
                 "fullname": "PY C",
                 "default_email": "bar@pingou.com",
                 "default_email": "bar@pingou.com",
-                "emails": [
-                    "bar@pingou.com",
-                    "foo@pingou.com"
-                ],
-                "name": "pingou"
+                "emails": ["bar@pingou.com", "foo@pingou.com"],
+                "name": "pingou",
             },
             },
             "members": ["pingou", "mprahl"],
             "members": ["pingou", "mprahl"],
             "date_created": "1492020239",
             "date_created": "1492020239",
             "group_type": "user",
             "group_type": "user",
-            "name": "some_group"
+            "name": "some_group",
         }
         }
         self.maxDiff = None
         self.maxDiff = None
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        data['date_created'] = '1492020239'
+        data["date_created"] = "1492020239"
         self.assertDictEqual(data, exp)
         self.assertDictEqual(data, exp)
 
 
     def test_api_view_group_no_group_error(self):
     def test_api_view_group_no_group_error(self):
@@ -264,8 +251,8 @@ class PagureFlaskApiGroupTests(tests.SimplePagureTest):
         output = self.app.get("/api/0/group/some_group3")
         output = self.app.get("/api/0/group/some_group3")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(data['error'], 'Group not found')
-        self.assertEqual(data['error_code'], 'ENOGROUP')
+        self.assertEqual(data["error"], "Group not found")
+        self.assertEqual(data["error_code"], "ENOGROUP")
 
 
     def test_api_view_group_w_projects_and_acl(self):
     def test_api_view_group_w_projects_and_acl(self):
         """
         """
@@ -274,9 +261,10 @@ class PagureFlaskApiGroupTests(tests.SimplePagureTest):
         """
         """
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
         output = self.app.get(
         output = self.app.get(
-            '/api/0/group/some_group?projects=1', headers=headers)
+            "/api/0/group/some_group?projects=1", headers=headers
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         exp = {
         exp = {
             "display_name": "Some Group",
             "display_name": "Some Group",
@@ -284,11 +272,8 @@ class PagureFlaskApiGroupTests(tests.SimplePagureTest):
             "creator": {
             "creator": {
                 "fullname": "PY C",
                 "fullname": "PY C",
                 "default_email": "bar@pingou.com",
                 "default_email": "bar@pingou.com",
-                "emails": [
-                    "bar@pingou.com",
-                    "foo@pingou.com"
-                ],
-                "name": "pingou"
+                "emails": ["bar@pingou.com", "foo@pingou.com"],
+                "name": "pingou",
             },
             },
             "members": ["pingou"],
             "members": ["pingou"],
             "date_created": "1492020239",
             "date_created": "1492020239",
@@ -297,25 +282,21 @@ class PagureFlaskApiGroupTests(tests.SimplePagureTest):
             "projects": [
             "projects": [
                 {
                 {
                     "access_groups": {
                     "access_groups": {
-                        "admin": [
-                            "some_group"
-                        ],
+                        "admin": ["some_group"],
                         "commit": [],
                         "commit": [],
-                        "ticket": []
+                        "ticket": [],
                     },
                     },
                     "access_users": {
                     "access_users": {
                         "admin": [],
                         "admin": [],
                         "commit": [],
                         "commit": [],
-                        "owner": [
-                            "pingou"
-                        ],
-                        "ticket": []
+                        "owner": ["pingou"],
+                        "ticket": [],
                     },
                     },
                     "close_status": [
                     "close_status": [
                         "Invalid",
                         "Invalid",
                         "Insufficient data",
                         "Insufficient data",
                         "Fixed",
                         "Fixed",
-                        "Duplicate"
+                        "Duplicate",
                     ],
                     ],
                     "custom_keys": [],
                     "custom_keys": [],
                     "date_created": "1492020239",
                     "date_created": "1492020239",
@@ -330,28 +311,26 @@ class PagureFlaskApiGroupTests(tests.SimplePagureTest):
                     "priorities": {},
                     "priorities": {},
                     "tags": [],
                     "tags": [],
                     "url_path": "test2",
                     "url_path": "test2",
-                    "user": {
-                        "fullname": "PY C",
-                        "name": "pingou"
-                    }
+                    "user": {"fullname": "PY C", "name": "pingou"},
                 }
                 }
-            ]
+            ],
         }
         }
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        data['date_created'] = '1492020239'
+        data["date_created"] = "1492020239"
         projects = []
         projects = []
-        for p in data['projects']:
-            p['date_created'] = '1492020239'
-            p['date_modified'] = '1492020239'
+        for p in data["projects"]:
+            p["date_created"] = "1492020239"
+            p["date_modified"] = "1492020239"
             projects.append(p)
             projects.append(p)
-        data['projects'] = projects
+        data["projects"] = projects
         self.assertDictEqual(data, exp)
         self.assertDictEqual(data, exp)
 
 
         output2 = self.app.get(
         output2 = self.app.get(
-            '/api/0/group/some_group?projects=1&acl=admin', headers=headers)
+            "/api/0/group/some_group?projects=1&acl=admin", headers=headers
+        )
         self.assertListEqual(
         self.assertListEqual(
-            output.get_data(as_text=True).split('\n'),
-            output2.get_data(as_text=True).split('\n')
+            output.get_data(as_text=True).split("\n"),
+            output2.get_data(as_text=True).split("\n"),
         )
         )
 
 
     def test_api_view_group_w_projects_and_acl_commit(self):
     def test_api_view_group_w_projects_and_acl_commit(self):
@@ -360,16 +339,12 @@ class PagureFlaskApiGroupTests(tests.SimplePagureTest):
             to the commit ACL
             to the commit ACL
         """
         """
 
 
-        output = self.app.get(
-            '/api/0/group/some_group?projects=1&acl=commit')
+        output = self.app.get("/api/0/group/some_group?projects=1&acl=commit")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         exp = {
         exp = {
             "display_name": "Some Group",
             "display_name": "Some Group",
             "description": None,
             "description": None,
-            "creator": {
-                "fullname": "PY C",
-                "name": "pingou"
-            },
+            "creator": {"fullname": "PY C", "name": "pingou"},
             "members": ["pingou"],
             "members": ["pingou"],
             "date_created": "1492020239",
             "date_created": "1492020239",
             "group_type": "user",
             "group_type": "user",
@@ -377,25 +352,21 @@ class PagureFlaskApiGroupTests(tests.SimplePagureTest):
             "projects": [
             "projects": [
                 {
                 {
                     "access_groups": {
                     "access_groups": {
-                        "admin": [
-                            "some_group"
-                        ],
+                        "admin": ["some_group"],
                         "commit": [],
                         "commit": [],
-                        "ticket": []
+                        "ticket": [],
                     },
                     },
                     "access_users": {
                     "access_users": {
                         "admin": [],
                         "admin": [],
                         "commit": [],
                         "commit": [],
-                        "owner": [
-                            "pingou"
-                        ],
-                        "ticket": []
+                        "owner": ["pingou"],
+                        "ticket": [],
                     },
                     },
                     "close_status": [
                     "close_status": [
                         "Invalid",
                         "Invalid",
                         "Insufficient data",
                         "Insufficient data",
                         "Fixed",
                         "Fixed",
-                        "Duplicate"
+                        "Duplicate",
                     ],
                     ],
                     "custom_keys": [],
                     "custom_keys": [],
                     "date_created": "1492020239",
                     "date_created": "1492020239",
@@ -410,21 +381,18 @@ class PagureFlaskApiGroupTests(tests.SimplePagureTest):
                     "priorities": {},
                     "priorities": {},
                     "tags": [],
                     "tags": [],
                     "url_path": "test2",
                     "url_path": "test2",
-                    "user": {
-                        "fullname": "PY C",
-                        "name": "pingou"
-                    }
+                    "user": {"fullname": "PY C", "name": "pingou"},
                 }
                 }
-            ]
+            ],
         }
         }
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        data['date_created'] = '1492020239'
+        data["date_created"] = "1492020239"
         projects = []
         projects = []
-        for p in data['projects']:
-            p['date_created'] = '1492020239'
-            p['date_modified'] = '1492020239'
+        for p in data["projects"]:
+            p["date_created"] = "1492020239"
+            p["date_modified"] = "1492020239"
             projects.append(p)
             projects.append(p)
-        data['projects'] = projects
+        data["projects"] = projects
         self.assertDictEqual(data, exp)
         self.assertDictEqual(data, exp)
 
 
     def test_api_view_group_w_projects_and_acl_ticket(self):
     def test_api_view_group_w_projects_and_acl_ticket(self):
@@ -433,16 +401,12 @@ class PagureFlaskApiGroupTests(tests.SimplePagureTest):
             to the ticket ACL
             to the ticket ACL
         """
         """
 
 
-        output = self.app.get(
-            '/api/0/group/some_group?projects=1&acl=ticket')
+        output = self.app.get("/api/0/group/some_group?projects=1&acl=ticket")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         exp = {
         exp = {
             "display_name": "Some Group",
             "display_name": "Some Group",
             "description": None,
             "description": None,
-            "creator": {
-                "fullname": "PY C",
-                "name": "pingou"
-            },
+            "creator": {"fullname": "PY C", "name": "pingou"},
             "members": ["pingou"],
             "members": ["pingou"],
             "date_created": "1492020239",
             "date_created": "1492020239",
             "group_type": "user",
             "group_type": "user",
@@ -450,25 +414,21 @@ class PagureFlaskApiGroupTests(tests.SimplePagureTest):
             "projects": [
             "projects": [
                 {
                 {
                     "access_groups": {
                     "access_groups": {
-                        "admin": [
-                            "some_group"
-                        ],
+                        "admin": ["some_group"],
                         "commit": [],
                         "commit": [],
-                        "ticket": []
+                        "ticket": [],
                     },
                     },
                     "access_users": {
                     "access_users": {
                         "admin": [],
                         "admin": [],
                         "commit": [],
                         "commit": [],
-                        "owner": [
-                            "pingou"
-                        ],
-                        "ticket": []
+                        "owner": ["pingou"],
+                        "ticket": [],
                     },
                     },
                     "close_status": [
                     "close_status": [
                         "Invalid",
                         "Invalid",
                         "Insufficient data",
                         "Insufficient data",
                         "Fixed",
                         "Fixed",
-                        "Duplicate"
+                        "Duplicate",
                     ],
                     ],
                     "custom_keys": [],
                     "custom_keys": [],
                     "date_created": "1492020239",
                     "date_created": "1492020239",
@@ -483,21 +443,18 @@ class PagureFlaskApiGroupTests(tests.SimplePagureTest):
                     "priorities": {},
                     "priorities": {},
                     "tags": [],
                     "tags": [],
                     "url_path": "test2",
                     "url_path": "test2",
-                    "user": {
-                        "fullname": "PY C",
-                        "name": "pingou"
-                    }
+                    "user": {"fullname": "PY C", "name": "pingou"},
                 }
                 }
-            ]
+            ],
         }
         }
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        data['date_created'] = '1492020239'
+        data["date_created"] = "1492020239"
         projects = []
         projects = []
-        for p in data['projects']:
-            p['date_created'] = '1492020239'
-            p['date_modified'] = '1492020239'
+        for p in data["projects"]:
+            p["date_created"] = "1492020239"
+            p["date_modified"] = "1492020239"
             projects.append(p)
             projects.append(p)
-        data['projects'] = projects
+        data["projects"] = projects
         self.assertDictEqual(data, exp)
         self.assertDictEqual(data, exp)
 
 
     def test_api_view_group_w_projects_and_acl_admin_no_project(self):
     def test_api_view_group_w_projects_and_acl_admin_no_project(self):
@@ -507,35 +464,31 @@ class PagureFlaskApiGroupTests(tests.SimplePagureTest):
         """
         """
 
 
         # Make the group having only commit access
         # Make the group having only commit access
-        project = pagure.lib.query._get_project(self.session, 'test2')
+        project = pagure.lib.query._get_project(self.session, "test2")
         msg = pagure.lib.query.add_group_to_project(
         msg = pagure.lib.query.add_group_to_project(
             session=self.session,
             session=self.session,
             project=project,
             project=project,
-            new_group='some_group',
-            user='pingou',
-            access='commit',
+            new_group="some_group",
+            user="pingou",
+            access="commit",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'Group access updated')
+        self.assertEqual(msg, "Group access updated")
 
 
-        output = self.app.get(
-            '/api/0/group/some_group?projects=1&acl=admin')
+        output = self.app.get("/api/0/group/some_group?projects=1&acl=admin")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         exp = {
         exp = {
             "display_name": "Some Group",
             "display_name": "Some Group",
             "description": None,
             "description": None,
-            "creator": {
-                "fullname": "PY C",
-                "name": "pingou"
-            },
+            "creator": {"fullname": "PY C", "name": "pingou"},
             "members": ["pingou"],
             "members": ["pingou"],
             "date_created": "1492020239",
             "date_created": "1492020239",
             "group_type": "user",
             "group_type": "user",
             "name": "some_group",
             "name": "some_group",
-            "projects": []
+            "projects": [],
         }
         }
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        data['date_created'] = '1492020239'
+        data["date_created"] = "1492020239"
         self.assertDictEqual(data, exp)
         self.assertDictEqual(data, exp)
 
 
     def test_api_view_group_w_projects_and_acl_commit_no_project(self):
     def test_api_view_group_w_projects_and_acl_commit_no_project(self):
@@ -545,35 +498,31 @@ class PagureFlaskApiGroupTests(tests.SimplePagureTest):
         """
         """
 
 
         # Make the group having only ticket access
         # Make the group having only ticket access
-        project = pagure.lib.query._get_project(self.session, 'test2')
+        project = pagure.lib.query._get_project(self.session, "test2")
         msg = pagure.lib.query.add_group_to_project(
         msg = pagure.lib.query.add_group_to_project(
             session=self.session,
             session=self.session,
             project=project,
             project=project,
-            new_group='some_group',
-            user='pingou',
-            access='ticket',
+            new_group="some_group",
+            user="pingou",
+            access="ticket",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'Group access updated')
+        self.assertEqual(msg, "Group access updated")
 
 
-        output = self.app.get(
-            '/api/0/group/some_group?projects=1&acl=commit')
+        output = self.app.get("/api/0/group/some_group?projects=1&acl=commit")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         exp = {
         exp = {
             "display_name": "Some Group",
             "display_name": "Some Group",
             "description": None,
             "description": None,
-            "creator": {
-                "fullname": "PY C",
-                "name": "pingou"
-            },
+            "creator": {"fullname": "PY C", "name": "pingou"},
             "members": ["pingou"],
             "members": ["pingou"],
             "date_created": "1492020239",
             "date_created": "1492020239",
             "group_type": "user",
             "group_type": "user",
             "name": "some_group",
             "name": "some_group",
-            "projects": []
+            "projects": [],
         }
         }
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        data['date_created'] = '1492020239'
+        data["date_created"] = "1492020239"
         self.assertDictEqual(data, exp)
         self.assertDictEqual(data, exp)
 
 
     def test_api_view_group_w_projects_and_acl_ticket_no_project(self):
     def test_api_view_group_w_projects_and_acl_ticket_no_project(self):
@@ -584,32 +533,28 @@ class PagureFlaskApiGroupTests(tests.SimplePagureTest):
 
 
         # Create a group not linked to any project
         # Create a group not linked to any project
         item = pagure.lib.model.PagureGroup(
         item = pagure.lib.model.PagureGroup(
-            group_name='rel-eng',
-            group_type='user',
-            display_name='Release engineering group',
+            group_name="rel-eng",
+            group_type="user",
+            display_name="Release engineering group",
             user_id=1,  # pingou
             user_id=1,  # pingou
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
 
 
-        output = self.app.get(
-            '/api/0/group/rel-eng?projects=1&acl=ticket')
+        output = self.app.get("/api/0/group/rel-eng?projects=1&acl=ticket")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         exp = {
         exp = {
             "display_name": "Release engineering group",
             "display_name": "Release engineering group",
             "description": None,
             "description": None,
-            "creator": {
-                "fullname": "PY C",
-                "name": "pingou"
-            },
+            "creator": {"fullname": "PY C", "name": "pingou"},
             "members": [],
             "members": [],
             "date_created": "1492020239",
             "date_created": "1492020239",
             "group_type": "user",
             "group_type": "user",
             "name": "rel-eng",
             "name": "rel-eng",
-            "projects": []
+            "projects": [],
         }
         }
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        data['date_created'] = '1492020239'
+        data["date_created"] = "1492020239"
         self.assertDictEqual(data, exp)
         self.assertDictEqual(data, exp)
 
 
 
 

File diff suppressed because it is too large
+ 847 - 916
tests/test_pagure_flask_api_issue.py


+ 109 - 126
tests/test_pagure_flask_api_issue_change_status.py

@@ -21,8 +21,9 @@ import os
 import json
 import json
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import pagure.lib.model
 import pagure.lib.model
@@ -34,284 +35,267 @@ class PagureFlaskApiIssueChangeStatustests(tests.Modeltests):
     issue
     issue
     """
     """
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def setUp(self):
     def setUp(self):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(PagureFlaskApiIssueChangeStatustests, self).setUp()
         super(PagureFlaskApiIssueChangeStatustests, self).setUp()
 
 
-        pagure.config.config['TICKETS_FOLDER'] = None
+        pagure.config.config["TICKETS_FOLDER"] = None
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'tickets'))
+        tests.create_projects_git(os.path.join(self.path, "tickets"))
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
         tests.create_tokens_acl(self.session)
         tests.create_tokens_acl(self.session)
 
 
         # Create normal issue
         # Create normal issue
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
-            title='Test issue #1',
-            content='We should work on this',
-            user='pingou',
+            title="Test issue #1",
+            content="We should work on this",
+            user="pingou",
             private=False,
             private=False,
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg.title, 'Test issue #1')
+        self.assertEqual(msg.title, "Test issue #1")
 
 
         # Create private issue
         # Create private issue
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
-            title='Test issue #2',
-            content='We should work on this',
-            user='foo',
+            title="Test issue #2",
+            content="We should work on this",
+            user="foo",
             private=True,
             private=True,
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg.title, 'Test issue #2')
+        self.assertEqual(msg.title, "Test issue #2")
 
 
         # Create project-less token for user foo
         # Create project-less token for user foo
         item = pagure.lib.model.Token(
         item = pagure.lib.model.Token(
-            id='project-less-foo',
+            id="project-less-foo",
             user_id=2,
             user_id=2,
             project_id=None,
             project_id=None,
             expiration=datetime.datetime.utcnow()
             expiration=datetime.datetime.utcnow()
-            + datetime.timedelta(days=30)
+            + datetime.timedelta(days=30),
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
-        tests.create_tokens_acl(self.session, token_id='project-less-foo')
+        tests.create_tokens_acl(self.session, token_id="project-less-foo")
 
 
         # Create project-less token for user pingou
         # Create project-less token for user pingou
         item = pagure.lib.model.Token(
         item = pagure.lib.model.Token(
-            id='project-less-pingou',
+            id="project-less-pingou",
             user_id=1,
             user_id=1,
             project_id=None,
             project_id=None,
             expiration=datetime.datetime.utcnow()
             expiration=datetime.datetime.utcnow()
-            + datetime.timedelta(days=30)
+            + datetime.timedelta(days=30),
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
-        tests.create_tokens_acl(self.session, token_id='project-less-pingou')
+        tests.create_tokens_acl(self.session, token_id="project-less-pingou")
 
 
     def test_api_change_status_issue_invalid_project(self):
     def test_api_change_status_issue_invalid_project(self):
         """ Test the api_change_status_issue method of the flask api. """
         """ Test the api_change_status_issue method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # Invalid project
         # Invalid project
-        output = self.app.post(
-            '/api/0/foobar/issue/1/status', headers=headers)
+        output = self.app.post("/api/0/foobar/issue/1/status", headers=headers)
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
-            data,
-            {
-              "error": "Project not found",
-              "error_code": "ENOPROJECT",
-            }
+            data, {"error": "Project not found", "error_code": "ENOPROJECT"}
         )
         )
 
 
     def test_api_change_status_issue_token_not_for_project(self):
     def test_api_change_status_issue_token_not_for_project(self):
         """ Test the api_change_status_issue method of the flask api. """
         """ Test the api_change_status_issue method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # Valid token, wrong project
         # Valid token, wrong project
-        output = self.app.post('/api/0/test2/issue/1/status', headers=headers)
+        output = self.app.post("/api/0/test2/issue/1/status", headers=headers)
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
-                         data['error_code'])
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
+        self.assertEqual(
+            pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
+        )
+        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
 
 
     def test_api_change_status_issue_invalid_issue(self):
     def test_api_change_status_issue_invalid_issue(self):
         """ Test the api_change_status_issue method of the flask api. """
         """ Test the api_change_status_issue method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # No issue
         # No issue
-        output = self.app.post('/api/0/test/issue/42/status', headers=headers)
+        output = self.app.post("/api/0/test/issue/42/status", headers=headers)
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
-            data,
-            {
-              "error": "Issue not found",
-              "error_code": "ENOISSUE",
-            }
+            data, {"error": "Issue not found", "error_code": "ENOISSUE"}
         )
         )
 
 
     def test_api_change_status_issue_incomplete(self):
     def test_api_change_status_issue_incomplete(self):
         """ Test the api_change_status_issue method of the flask api. """
         """ Test the api_change_status_issue method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # Check status before
         # Check status before
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
-        self.assertEqual(issue.status, 'Open')
+        self.assertEqual(issue.status, "Open")
 
 
-        data = {
-            'title': 'test issue',
-        }
+        data = {"title": "test issue"}
 
 
         # Incomplete request
         # Incomplete request
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/issue/1/status', data=data, headers=headers)
+            "/api/0/test/issue/1/status", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 400)
         self.assertEqual(output.status_code, 400)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
             {
             {
-              "error": "Invalid or incomplete input submitted",
-              "error_code": "EINVALIDREQ",
-              "errors": {"status": ["Not a valid choice"]}
-            }
+                "error": "Invalid or incomplete input submitted",
+                "error_code": "EINVALIDREQ",
+                "errors": {"status": ["Not a valid choice"]},
+            },
         )
         )
 
 
         # No change
         # No change
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
-        self.assertEqual(issue.status, 'Open')
+        self.assertEqual(issue.status, "Open")
 
 
     def test_api_change_status_issue_no_change(self):
     def test_api_change_status_issue_no_change(self):
         """ Test the api_change_status_issue method of the flask api. """
         """ Test the api_change_status_issue method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
-        data = {
-            'status': 'Open',
-        }
+        data = {"status": "Open"}
 
 
         # Valid request but no change
         # Valid request but no change
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/issue/1/status', data=data, headers=headers)
+            "/api/0/test/issue/1/status", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertDictEqual(
-            data,
-            {'message': 'No changes'}
-        )
+        self.assertDictEqual(data, {"message": "No changes"})
 
 
         # No change
         # No change
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
-        self.assertEqual(issue.status, 'Open')
+        self.assertEqual(issue.status, "Open")
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     @patch(
     @patch(
-        'pagure.lib.query.edit_issue',
-        MagicMock(side_effect=pagure.exceptions.PagureException('error')))
+        "pagure.lib.query.edit_issue",
+        MagicMock(side_effect=pagure.exceptions.PagureException("error")),
+    )
     def test_api_change_status_issue_raise_error(self):
     def test_api_change_status_issue_raise_error(self):
         """ Test the api_change_status_issue method of the flask api. """
         """ Test the api_change_status_issue method of the flask api. """
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         close_status = repo.close_status
         close_status = repo.close_status
-        close_status = ['Fixed', 'Upstream', 'Invalid']
+        close_status = ["Fixed", "Upstream", "Invalid"]
         repo.close_status = close_status
         repo.close_status = close_status
         self.session.add(repo)
         self.session.add(repo)
         self.session.commit()
         self.session.commit()
 
 
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
-
-        data = {
-            'status': 'Closed',
-            'close_status': 'Fixed'
-        }
+        data = {"status": "Closed", "close_status": "Fixed"}
 
 
         # Valid request
         # Valid request
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/issue/1/status', data=data, headers=headers)
+            "/api/0/test/issue/1/status", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 400)
         self.assertEqual(output.status_code, 400)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
 
 
-        self.assertDictEqual(
-            data,
-            {u'error': u'error', u'error_code': u'ENOCODE'}
-        )
+        self.assertDictEqual(data, {"error": "error", "error_code": "ENOCODE"})
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_api_change_status_issue(self):
     def test_api_change_status_issue(self):
         """ Test the api_change_status_issue method of the flask api. """
         """ Test the api_change_status_issue method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
-        data = {
-            'status': 'Fixed',
-        }
+        data = {"status": "Fixed"}
 
 
         # Valid request
         # Valid request
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/issue/1/status', data=data, headers=headers)
+            "/api/0/test/issue/1/status", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
 
 
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
-            {'message':[
-                'Issue status updated to: Closed (was: Open)',
-                'Issue close_status updated to: Fixed'
-            ]}
+            {
+                "message": [
+                    "Issue status updated to: Closed (was: Open)",
+                    "Issue close_status updated to: Fixed",
+                ]
+            },
         )
         )
 
 
-        headers = {'Authorization': 'token pingou_foo'}
+        headers = {"Authorization": "token pingou_foo"}
 
 
         # Un-authorized issue
         # Un-authorized issue
         output = self.app.post(
         output = self.app.post(
-            '/api/0/foo/issue/1/status', data=data, headers=headers)
+            "/api/0/foo/issue/1/status", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
-                         data['error_code'])
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
+        self.assertEqual(
+            pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
+        )
+        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_api_change_status_issue_closed_status(self):
     def test_api_change_status_issue_closed_status(self):
         """ Test the api_change_status_issue method of the flask api. """
         """ Test the api_change_status_issue method of the flask api. """
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         close_status = repo.close_status
         close_status = repo.close_status
-        close_status = ['Fixed', 'Upstream', 'Invalid']
+        close_status = ["Fixed", "Upstream", "Invalid"]
         repo.close_status = close_status
         repo.close_status = close_status
         self.session.add(repo)
         self.session.add(repo)
         self.session.commit()
         self.session.commit()
 
 
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
-
-        data = {
-            'status': 'Closed',
-            'close_status': 'Fixed'
-        }
+        data = {"status": "Closed", "close_status": "Fixed"}
 
 
         # Valid request
         # Valid request
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/issue/1/status', data=data, headers=headers)
+            "/api/0/test/issue/1/status", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
 
 
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
-            {'message':[
-                'Issue status updated to: Closed (was: Open)',
-                'Issue close_status updated to: Fixed'
-            ]}
+            {
+                "message": [
+                    "Issue status updated to: Closed (was: Open)",
+                    "Issue close_status updated to: Fixed",
+                ]
+            },
         )
         )
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_api_change_status_issue_no_ticket_project_less(self):
     def test_api_change_status_issue_no_ticket_project_less(self):
         """ Test the api_change_status_issue method of the flask api. """
         """ Test the api_change_status_issue method of the flask api. """
 
 
-        headers = {'Authorization': 'token project-less-foo'}
+        headers = {"Authorization": "token project-less-foo"}
 
 
-        data = {
-            'status': 'Fixed',
-        }
+        data = {"status": "Fixed"}
 
 
         # Valid request
         # Valid request
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/issue/1/status', data=data, headers=headers)
+            "/api/0/test/issue/1/status", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 403)
         self.assertEqual(output.status_code, 403)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
 
 
@@ -319,23 +303,22 @@ class PagureFlaskApiIssueChangeStatustests(tests.Modeltests):
             data,
             data,
             {
             {
                 "error": "You are not allowed to view this issue",
                 "error": "You are not allowed to view this issue",
-                "error_code": "EISSUENOTALLOWED"
-            }
+                "error_code": "EISSUENOTALLOWED",
+            },
         )
         )
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_api_change_status_issue_project_less(self):
     def test_api_change_status_issue_project_less(self):
         """ Test the api_change_status_issue method of the flask api. """
         """ Test the api_change_status_issue method of the flask api. """
 
 
-        headers = {'Authorization': 'token project-less-pingou'}
+        headers = {"Authorization": "token project-less-pingou"}
 
 
-        data = {
-            'status': 'Fixed',
-        }
+        data = {"status": "Fixed"}
 
 
         # Valid request
         # Valid request
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/issue/1/status', data=data, headers=headers)
+            "/api/0/test/issue/1/status", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
 
 
@@ -344,11 +327,11 @@ class PagureFlaskApiIssueChangeStatustests(tests.Modeltests):
             {
             {
                 "message": [
                 "message": [
                     "Issue status updated to: Closed (was: Open)",
                     "Issue status updated to: Closed (was: Open)",
-                    "Issue close_status updated to: Fixed"
+                    "Issue close_status updated to: Fixed",
                 ]
                 ]
-            }
+            },
         )
         )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 127 - 141
tests/test_pagure_flask_api_issue_comment.py

@@ -19,8 +19,9 @@ import os
 import json
 import json
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query  # noqa: E402
 import pagure.lib.query  # noqa: E402
 import tests  # noqa: E402
 import tests  # noqa: E402
@@ -31,117 +32,109 @@ class PagureFlaskApiIssueCommenttests(tests.Modeltests):
     issue
     issue
     """
     """
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def setUp(self):
     def setUp(self):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(PagureFlaskApiIssueCommenttests, self).setUp()
         super(PagureFlaskApiIssueCommenttests, self).setUp()
 
 
-        pagure.config.config['TICKETS_FOLDER'] = None
+        pagure.config.config["TICKETS_FOLDER"] = None
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'tickets'))
+        tests.create_projects_git(os.path.join(self.path, "tickets"))
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
         tests.create_tokens_acl(self.session)
         tests.create_tokens_acl(self.session)
 
 
         # Create normal issue
         # Create normal issue
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
-            title='Test issue #1',
-            content='We should work on this',
-            user='pingou',
+            title="Test issue #1",
+            content="We should work on this",
+            user="pingou",
             private=False,
             private=False,
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg.title, 'Test issue #1')
+        self.assertEqual(msg.title, "Test issue #1")
 
 
         # Create private issue
         # Create private issue
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
-            title='Test issue #2',
-            content='We should work on this',
-            user='foo',
+            title="Test issue #2",
+            content="We should work on this",
+            user="foo",
             private=True,
             private=True,
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg.title, 'Test issue #2')
+        self.assertEqual(msg.title, "Test issue #2")
 
 
         # Create project-less token for user foo
         # Create project-less token for user foo
         item = pagure.lib.model.Token(
         item = pagure.lib.model.Token(
-            id='project-less-foo',
+            id="project-less-foo",
             user_id=2,
             user_id=2,
             project_id=None,
             project_id=None,
             expiration=datetime.datetime.utcnow()
             expiration=datetime.datetime.utcnow()
-            + datetime.timedelta(days=30)
+            + datetime.timedelta(days=30),
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
-        tests.create_tokens_acl(self.session, token_id='project-less-foo')
+        tests.create_tokens_acl(self.session, token_id="project-less-foo")
 
 
     def test_api_comment_issue_invalid_project(self):
     def test_api_comment_issue_invalid_project(self):
         """ Test the api_comment_issue method of the flask api. """
         """ Test the api_comment_issue method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # Invalid project
         # Invalid project
-        output = self.app.post('/api/0/foo/issue/1/comment', headers=headers)
+        output = self.app.post("/api/0/foo/issue/1/comment", headers=headers)
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
-            data,
-            {
-                "error": "Project not found",
-                "error_code": "ENOPROJECT",
-            }
+            data, {"error": "Project not found", "error_code": "ENOPROJECT"}
         )
         )
 
 
     def test_api_comment_issue_invalid_project_token(self):
     def test_api_comment_issue_invalid_project_token(self):
         """ Test the api_comment_issue method of the flask api. """
         """ Test the api_comment_issue method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # Valid token, wrong project
         # Valid token, wrong project
-        output = self.app.post('/api/0/test2/issue/1/comment', headers=headers)
+        output = self.app.post("/api/0/test2/issue/1/comment", headers=headers)
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
-                         data['error_code'])
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
+        self.assertEqual(
+            pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
+        )
+        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
 
 
     def test_api_comment_issue_invalid_issue(self):
     def test_api_comment_issue_invalid_issue(self):
         """ Test the api_comment_issue method of the flask api. """
         """ Test the api_comment_issue method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
         # Invalid issue
         # Invalid issue
-        output = self.app.post('/api/0/test/issue/10/comment', headers=headers)
+        output = self.app.post("/api/0/test/issue/10/comment", headers=headers)
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
-            data,
-            {
-                "error": "Issue not found",
-                "error_code": "ENOISSUE",
-            }
+            data, {"error": "Issue not found", "error_code": "ENOISSUE"}
         )
         )
 
 
     def test_api_comment_issue_incomplete_request(self):
     def test_api_comment_issue_incomplete_request(self):
         """ Test the api_comment_issue method of the flask api. """
         """ Test the api_comment_issue method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
         # Check comments before
         # Check comments before
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         self.assertEqual(len(issue.comments), 0)
         self.assertEqual(len(issue.comments), 0)
 
 
-        data = {
-            'title': 'test issue',
-        }
+        data = {"title": "test issue"}
 
 
         # Incomplete request
         # Incomplete request
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/issue/1/comment', data=data, headers=headers)
+            "/api/0/test/issue/1/comment", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 400)
         self.assertEqual(output.status_code, 400)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
@@ -149,39 +142,40 @@ class PagureFlaskApiIssueCommenttests(tests.Modeltests):
             {
             {
                 "error": "Invalid or incomplete input submitted",
                 "error": "Invalid or incomplete input submitted",
                 "error_code": "EINVALIDREQ",
                 "error_code": "EINVALIDREQ",
-                "errors": {"comment": ["This field is required."]}
-            }
+                "errors": {"comment": ["This field is required."]},
+            },
         )
         )
 
 
         # No change
         # No change
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
-        self.assertEqual(issue.status, 'Open')
+        self.assertEqual(issue.status, "Open")
 
 
     def test_api_comment_issue(self):
     def test_api_comment_issue(self):
         """ Test the api_comment_issue method of the flask api. """
         """ Test the api_comment_issue method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
-        data = {
-            'comment': 'This is a very interesting question',
-        }
+        data = {"comment": "This is a very interesting question"}
 
 
         # Valid request
         # Valid request
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/issue/1/comment', data=data, headers=headers)
+            "/api/0/test/issue/1/comment", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
         data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
-            {'message': 'Comment added',
-             'avatar_url': 'https://seccdn.libravatar.org/avatar/...',
-             'user': 'pingou'}
+            {
+                "message": "Comment added",
+                "avatar_url": "https://seccdn.libravatar.org/avatar/...",
+                "user": "pingou",
+            },
         )
         )
 
 
         # One comment added
         # One comment added
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         self.assertEqual(len(issue.comments), 1)
         self.assertEqual(len(issue.comments), 1)
 
 
@@ -189,128 +183,117 @@ class PagureFlaskApiIssueCommenttests(tests.Modeltests):
         """ Test the api_comment_issue method of the flask api. """
         """ Test the api_comment_issue method of the flask api. """
 
 
         # Check before
         # Check before
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
         self.assertEqual(len(issue.comments), 0)
         self.assertEqual(len(issue.comments), 0)
 
 
-        data = {
-            'comment': 'This is a very interesting question',
-        }
-        headers = {'Authorization': 'token pingou_foo'}
+        data = {"comment": "This is a very interesting question"}
+        headers = {"Authorization": "token pingou_foo"}
 
 
         # Valid request but un-authorized
         # Valid request but un-authorized
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/issue/2/comment', data=data, headers=headers)
+            "/api/0/test/issue/2/comment", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
-                         data['error_code'])
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
+        self.assertEqual(
+            pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
+        )
+        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
 
 
         # No comment added
         # No comment added
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
         self.assertEqual(len(issue.comments), 0)
         self.assertEqual(len(issue.comments), 0)
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_api_comment_issue_private(self):
     def test_api_comment_issue_private(self):
         """ Test the api_comment_issue method of the flask api. """
         """ Test the api_comment_issue method of the flask api. """
 
 
         # Create token for user foo
         # Create token for user foo
         item = pagure.lib.model.Token(
         item = pagure.lib.model.Token(
-            id='foo_token2',
+            id="foo_token2",
             user_id=2,
             user_id=2,
             project_id=1,
             project_id=1,
-            expiration=datetime.datetime.utcnow() + datetime.timedelta(days=30)
+            expiration=datetime.datetime.utcnow()
+            + datetime.timedelta(days=30),
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
-        tests.create_tokens_acl(self.session, token_id='foo_token2')
+        tests.create_tokens_acl(self.session, token_id="foo_token2")
 
 
-        data = {
-            'comment': 'This is a very interesting question',
-        }
-        headers = {'Authorization': 'token foo_token2'}
+        data = {"comment": "This is a very interesting question"}
+        headers = {"Authorization": "token foo_token2"}
 
 
         # Valid request and authorized
         # Valid request and authorized
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/issue/2/comment', data=data, headers=headers)
+            "/api/0/test/issue/2/comment", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
         data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
-            {'message': 'Comment added',
-             'avatar_url': 'https://seccdn.libravatar.org/avatar/...',
-             'user': 'foo'}
+            {
+                "message": "Comment added",
+                "avatar_url": "https://seccdn.libravatar.org/avatar/...",
+                "user": "foo",
+            },
         )
         )
 
 
     def test_api_comment_issue_invalid_project_project_less(self):
     def test_api_comment_issue_invalid_project_project_less(self):
         """ Test the api_comment_issue method of the flask api. """
         """ Test the api_comment_issue method of the flask api. """
 
 
-        headers = {'Authorization': 'token project-less-foo'}
+        headers = {"Authorization": "token project-less-foo"}
 
 
         # Invalid project
         # Invalid project
-        output = self.app.post('/api/0/foo/issue/1/comment', headers=headers)
+        output = self.app.post("/api/0/foo/issue/1/comment", headers=headers)
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
-            data,
-            {
-                "error": "Project not found",
-                "error_code": "ENOPROJECT",
-            }
+            data, {"error": "Project not found", "error_code": "ENOPROJECT"}
         )
         )
 
 
     def test_api_comment_issue_invalid_project_token_project_less(self):
     def test_api_comment_issue_invalid_project_token_project_less(self):
         """ Test the api_comment_issue method of the flask api. """
         """ Test the api_comment_issue method of the flask api. """
 
 
-        headers = {'Authorization': 'token project-less-foo'}
+        headers = {"Authorization": "token project-less-foo"}
 
 
         # Valid token, no such issue, project-less token so different failure
         # Valid token, no such issue, project-less token so different failure
-        output = self.app.post('/api/0/test2/issue/1/comment', headers=headers)
+        output = self.app.post("/api/0/test2/issue/1/comment", headers=headers)
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
-            data,
-            {
-                "error": "Issue not found",
-                "error_code": "ENOISSUE",
-            }
+            data, {"error": "Issue not found", "error_code": "ENOISSUE"}
         )
         )
 
 
     def test_api_comment_issue_invalid_issue_project_less(self):
     def test_api_comment_issue_invalid_issue_project_less(self):
         """ Test the api_comment_issue method of the flask api. """
         """ Test the api_comment_issue method of the flask api. """
 
 
-        headers = {'Authorization': 'token project-less-foo'}
+        headers = {"Authorization": "token project-less-foo"}
         # Invalid issue
         # Invalid issue
-        output = self.app.post('/api/0/test/issue/10/comment', headers=headers)
+        output = self.app.post("/api/0/test/issue/10/comment", headers=headers)
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
-            data,
-            {
-                "error": "Issue not found",
-                "error_code": "ENOISSUE",
-            }
+            data, {"error": "Issue not found", "error_code": "ENOISSUE"}
         )
         )
 
 
     def test_api_comment_issue_incomplete_request_project_less(self):
     def test_api_comment_issue_incomplete_request_project_less(self):
         """ Test the api_comment_issue method of the flask api. """
         """ Test the api_comment_issue method of the flask api. """
 
 
-        headers = {'Authorization': 'token project-less-foo'}
+        headers = {"Authorization": "token project-less-foo"}
         # Check comments before
         # Check comments before
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         self.assertEqual(len(issue.comments), 0)
         self.assertEqual(len(issue.comments), 0)
 
 
-        data = {
-            'title': 'test issue',
-        }
+        data = {"title": "test issue"}
 
 
         # Incomplete request
         # Incomplete request
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/issue/1/comment', data=data, headers=headers)
+            "/api/0/test/issue/1/comment", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 400)
         self.assertEqual(output.status_code, 400)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
@@ -318,40 +301,41 @@ class PagureFlaskApiIssueCommenttests(tests.Modeltests):
             {
             {
                 "error": "Invalid or incomplete input submitted",
                 "error": "Invalid or incomplete input submitted",
                 "error_code": "EINVALIDREQ",
                 "error_code": "EINVALIDREQ",
-                "errors": {"comment": ["This field is required."]}
-            }
+                "errors": {"comment": ["This field is required."]},
+            },
         )
         )
 
 
         # No change
         # No change
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
-        self.assertEqual(issue.status, 'Open')
+        self.assertEqual(issue.status, "Open")
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_api_comment_issue_project_less(self):
     def test_api_comment_issue_project_less(self):
         """ Test the api_comment_issue method of the flask api. """
         """ Test the api_comment_issue method of the flask api. """
 
 
-        headers = {'Authorization': 'token project-less-foo'}
+        headers = {"Authorization": "token project-less-foo"}
 
 
-        data = {
-            'comment': 'This is a very interesting question',
-        }
+        data = {"comment": "This is a very interesting question"}
 
 
         # Valid request
         # Valid request
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/issue/1/comment', data=data, headers=headers)
+            "/api/0/test/issue/1/comment", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
         data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
-            {'message': 'Comment added',
-             'avatar_url': 'https://seccdn.libravatar.org/avatar/...',
-             'user': 'foo'}
+            {
+                "message": "Comment added",
+                "avatar_url": "https://seccdn.libravatar.org/avatar/...",
+                "user": "foo",
+            },
         )
         )
 
 
         # One comment added
         # One comment added
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         self.assertEqual(len(issue.comments), 1)
         self.assertEqual(len(issue.comments), 1)
 
 
@@ -359,62 +343,64 @@ class PagureFlaskApiIssueCommenttests(tests.Modeltests):
         """ Test the api_comment_issue method of the flask api. """
         """ Test the api_comment_issue method of the flask api. """
 
 
         # Check before
         # Check before
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
         self.assertEqual(len(issue.comments), 0)
         self.assertEqual(len(issue.comments), 0)
 
 
-        data = {
-            'comment': 'This is a very interesting question',
-        }
-        headers = {'Authorization': 'token pingou_foo'}
+        data = {"comment": "This is a very interesting question"}
+        headers = {"Authorization": "token pingou_foo"}
 
 
         # Valid request but un-authorized
         # Valid request but un-authorized
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/issue/2/comment', data=data, headers=headers)
+            "/api/0/test/issue/2/comment", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
-                         data['error_code'])
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
+        self.assertEqual(
+            pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
+        )
+        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
 
 
         # No comment added
         # No comment added
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
         self.assertEqual(len(issue.comments), 0)
         self.assertEqual(len(issue.comments), 0)
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_api_comment_issue_private_project_less(self):
     def test_api_comment_issue_private_project_less(self):
         """ Test the api_comment_issue method of the flask api. """
         """ Test the api_comment_issue method of the flask api. """
 
 
         # Create token for user foo
         # Create token for user foo
         item = pagure.lib.model.Token(
         item = pagure.lib.model.Token(
-            id='foo_token2',
+            id="foo_token2",
             user_id=2,
             user_id=2,
             project_id=None,
             project_id=None,
-            expiration=datetime.datetime.utcnow() + datetime.timedelta(days=30)
+            expiration=datetime.datetime.utcnow()
+            + datetime.timedelta(days=30),
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
-        tests.create_tokens_acl(self.session, token_id='foo_token2')
+        tests.create_tokens_acl(self.session, token_id="foo_token2")
 
 
-        data = {
-            'comment': 'This is a very interesting question',
-        }
-        headers = {'Authorization': 'token foo_token2'}
+        data = {"comment": "This is a very interesting question"}
+        headers = {"Authorization": "token foo_token2"}
 
 
         # Valid request and authorized
         # Valid request and authorized
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/issue/2/comment', data=data, headers=headers)
+            "/api/0/test/issue/2/comment", data=data, headers=headers
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
         data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
-            {'message': 'Comment added',
-             'avatar_url': 'https://seccdn.libravatar.org/avatar/...',
-             'user': 'foo'}
+            {
+                "message": "Comment added",
+                "avatar_url": "https://seccdn.libravatar.org/avatar/...",
+                "user": "foo",
+            },
         )
         )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 131 - 150
tests/test_pagure_flask_api_issue_create.py

@@ -18,8 +18,9 @@ import json
 
 
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query  # noqa: E402
 import pagure.lib.query  # noqa: E402
 import tests  # noqa: E402
 import tests  # noqa: E402
@@ -29,42 +30,41 @@ class PagureFlaskApiIssueCreatetests(tests.Modeltests):
     """ Tests for the flask API of pagure for creating an issue
     """ Tests for the flask API of pagure for creating an issue
     """
     """
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def setUp(self):
     def setUp(self):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(PagureFlaskApiIssueCreatetests, self).setUp()
         super(PagureFlaskApiIssueCreatetests, self).setUp()
 
 
-        pagure.config.config['TICKETS_FOLDER'] = None
+        pagure.config.config["TICKETS_FOLDER"] = None
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'tickets'))
+        tests.create_projects_git(os.path.join(self.path, "tickets"))
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
         tests.create_tokens_acl(self.session)
         tests.create_tokens_acl(self.session)
 
 
         # Create project-less token for user foo
         # Create project-less token for user foo
         item = pagure.lib.model.Token(
         item = pagure.lib.model.Token(
-            id='project-less-foo',
+            id="project-less-foo",
             user_id=2,
             user_id=2,
             project_id=None,
             project_id=None,
             expiration=datetime.datetime.utcnow()
             expiration=datetime.datetime.utcnow()
-            + datetime.timedelta(days=30)
+            + datetime.timedelta(days=30),
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
-        tests.create_tokens_acl(self.session, token_id='project-less-foo')
+        tests.create_tokens_acl(self.session, token_id="project-less-foo")
 
 
         # Create project-specific token for user foo
         # Create project-specific token for user foo
         item = pagure.lib.model.Token(
         item = pagure.lib.model.Token(
-            id='project-specific-foo',
+            id="project-specific-foo",
             user_id=2,
             user_id=2,
             project_id=1,
             project_id=1,
             expiration=datetime.datetime.utcnow()
             expiration=datetime.datetime.utcnow()
-            + datetime.timedelta(days=30)
+            + datetime.timedelta(days=30),
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
-        tests.create_tokens_acl(
-            self.session, token_id='project-specific-foo')
+        tests.create_tokens_acl(self.session, token_id="project-specific-foo")
 
 
     def test_create_issue_own_project_no_data(self):
     def test_create_issue_own_project_no_data(self):
         """ Test creating a new ticket on a project for which you're the
         """ Test creating a new ticket on a project for which you're the
@@ -72,22 +72,22 @@ class PagureFlaskApiIssueCreatetests(tests.Modeltests):
         """
         """
 
 
         # pingou's token with all the ACLs
         # pingou's token with all the ACLs
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # Create an issue on /test/ where pingou is the main admin
         # Create an issue on /test/ where pingou is the main admin
-        output = self.app.post('/api/0/test/new_issue', headers=headers)
+        output = self.app.post("/api/0/test/new_issue", headers=headers)
         self.assertEqual(output.status_code, 400)
         self.assertEqual(output.status_code, 400)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertEqual(
         self.assertEqual(
-            pagure.api.APIERROR.EINVALIDREQ.name, data['error_code'])
-        self.assertEqual(
-            pagure.api.APIERROR.EINVALIDREQ.value, data['error'])
+            pagure.api.APIERROR.EINVALIDREQ.name, data["error_code"]
+        )
+        self.assertEqual(pagure.api.APIERROR.EINVALIDREQ.value, data["error"])
         self.assertEqual(
         self.assertEqual(
-            data['errors'],
+            data["errors"],
             {
             {
-                'issue_content': ['This field is required.'],
-                'title': ['This field is required.']
-            }
+                "issue_content": ["This field is required."],
+                "title": ["This field is required."],
+            },
         )
         )
 
 
     def test_create_issue_own_project_incomplete_data(self):
     def test_create_issue_own_project_incomplete_data(self):
@@ -96,29 +96,23 @@ class PagureFlaskApiIssueCreatetests(tests.Modeltests):
         """
         """
 
 
         # pingou's token with all the ACLs
         # pingou's token with all the ACLs
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # complete data set
         # complete data set
-        data = {
-            'title': 'test issue',
-        }
+        data = {"title": "test issue"}
 
 
         # Create an issue on /test/ where pingou is the main admin
         # Create an issue on /test/ where pingou is the main admin
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/new_issue',
-            headers=headers,
-            data=data)
+            "/api/0/test/new_issue", headers=headers, data=data
+        )
         self.assertEqual(output.status_code, 400)
         self.assertEqual(output.status_code, 400)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertEqual(
         self.assertEqual(
-            pagure.api.APIERROR.EINVALIDREQ.name, data['error_code'])
-        self.assertEqual(
-            pagure.api.APIERROR.EINVALIDREQ.value, data['error'])
+            pagure.api.APIERROR.EINVALIDREQ.name, data["error_code"]
+        )
+        self.assertEqual(pagure.api.APIERROR.EINVALIDREQ.value, data["error"])
         self.assertEqual(
         self.assertEqual(
-            data['errors'],
-            {
-                'issue_content': ['This field is required.']
-            }
+            data["errors"], {"issue_content": ["This field is required."]}
         )
         )
 
 
     def test_create_issue_own_project(self):
     def test_create_issue_own_project(self):
@@ -127,191 +121,178 @@ class PagureFlaskApiIssueCreatetests(tests.Modeltests):
         """
         """
 
 
         # pingou's token with all the ACLs
         # pingou's token with all the ACLs
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # complete data set
         # complete data set
         data = {
         data = {
-            'title': 'test issue',
-            'issue_content': 'This issue needs attention',
+            "title": "test issue",
+            "issue_content": "This issue needs attention",
         }
         }
 
 
         # Create an issue on /test/ where pingou is the main admin
         # Create an issue on /test/ where pingou is the main admin
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/new_issue',
-            headers=headers,
-            data=data)
+            "/api/0/test/new_issue", headers=headers, data=data
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        data['issue']['date_created'] = '1431414800'
-        data['issue']['last_updated'] = '1431414800'
+        data["issue"]["date_created"] = "1431414800"
+        data["issue"]["last_updated"] = "1431414800"
         self.assertEqual(
         self.assertEqual(
             data,
             data,
             {
             {
-              "issue": {
-                "assignee": None,
-                "blocks": [],
-                "close_status": None,
-                "closed_at": None,
-                "closed_by": None,
-                "comments": [],
-                "content": "This issue needs attention",
-                "custom_fields": [],
-                "date_created": "1431414800",
-                "depends": [],
-                "id": 1,
-                "last_updated": "1431414800",
-                "milestone": None,
-                "priority": None,
-                "private": False,
-                "status": "Open",
-                "tags": [],
-                "title": "test issue",
-                "user": {
-                  "fullname": "PY C",
-                  "name": "pingou"
-                }
-              },
-              "message": "Issue created"
-            }
+                "issue": {
+                    "assignee": None,
+                    "blocks": [],
+                    "close_status": None,
+                    "closed_at": None,
+                    "closed_by": None,
+                    "comments": [],
+                    "content": "This issue needs attention",
+                    "custom_fields": [],
+                    "date_created": "1431414800",
+                    "depends": [],
+                    "id": 1,
+                    "last_updated": "1431414800",
+                    "milestone": None,
+                    "priority": None,
+                    "private": False,
+                    "status": "Open",
+                    "tags": [],
+                    "title": "test issue",
+                    "user": {"fullname": "PY C", "name": "pingou"},
+                },
+                "message": "Issue created",
+            },
         )
         )
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_create_issue_someone_else_project_project_less_token(self):
     def test_create_issue_someone_else_project_project_less_token(self):
         """ Test creating a new ticket on a project with which you have
         """ Test creating a new ticket on a project with which you have
         nothing to do.
         nothing to do.
         """
         """
 
 
         # pingou's token with all the ACLs
         # pingou's token with all the ACLs
-        headers = {'Authorization': 'token project-less-foo'}
+        headers = {"Authorization": "token project-less-foo"}
 
 
         # complete data set
         # complete data set
         data = {
         data = {
-            'title': 'test issue',
-            'issue_content': 'This issue needs attention',
+            "title": "test issue",
+            "issue_content": "This issue needs attention",
         }
         }
 
 
         # Create an issue on /test/ where pingou is the main admin
         # Create an issue on /test/ where pingou is the main admin
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/new_issue',
-            headers=headers,
-            data=data)
+            "/api/0/test/new_issue", headers=headers, data=data
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        data['issue']['date_created'] = '1431414800'
-        data['issue']['last_updated'] = '1431414800'
+        data["issue"]["date_created"] = "1431414800"
+        data["issue"]["last_updated"] = "1431414800"
         self.assertEqual(
         self.assertEqual(
             data,
             data,
             {
             {
-              "issue": {
-                "assignee": None,
-                "blocks": [],
-                "close_status": None,
-                "closed_at": None,
-                "closed_by": None,
-                "comments": [],
-                "content": "This issue needs attention",
-                "custom_fields": [],
-                "date_created": "1431414800",
-                "depends": [],
-                "id": 1,
-                "last_updated": "1431414800",
-                "milestone": None,
-                "priority": None,
-                "private": False,
-                "status": "Open",
-                "tags": [],
-                "title": "test issue",
-                "user": {
-                  "fullname": "foo bar",
-                  "name": "foo"
-                }
-              },
-              "message": "Issue created"
-            }
+                "issue": {
+                    "assignee": None,
+                    "blocks": [],
+                    "close_status": None,
+                    "closed_at": None,
+                    "closed_by": None,
+                    "comments": [],
+                    "content": "This issue needs attention",
+                    "custom_fields": [],
+                    "date_created": "1431414800",
+                    "depends": [],
+                    "id": 1,
+                    "last_updated": "1431414800",
+                    "milestone": None,
+                    "priority": None,
+                    "private": False,
+                    "status": "Open",
+                    "tags": [],
+                    "title": "test issue",
+                    "user": {"fullname": "foo bar", "name": "foo"},
+                },
+                "message": "Issue created",
+            },
         )
         )
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_create_issue_project_specific_token(self):
     def test_create_issue_project_specific_token(self):
         """ Test creating a new ticket on a project with a regular
         """ Test creating a new ticket on a project with a regular
         project-specific token.
         project-specific token.
         """
         """
 
 
         # pingou's token with all the ACLs
         # pingou's token with all the ACLs
-        headers = {'Authorization': 'token project-specific-foo'}
+        headers = {"Authorization": "token project-specific-foo"}
 
 
         # complete data set
         # complete data set
         data = {
         data = {
-            'title': 'test issue',
-            'issue_content': 'This issue needs attention',
+            "title": "test issue",
+            "issue_content": "This issue needs attention",
         }
         }
 
 
         # Create an issue on /test/ where pingou is the main admin
         # Create an issue on /test/ where pingou is the main admin
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/new_issue',
-            headers=headers,
-            data=data)
+            "/api/0/test/new_issue", headers=headers, data=data
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        data['issue']['date_created'] = '1431414800'
-        data['issue']['last_updated'] = '1431414800'
+        data["issue"]["date_created"] = "1431414800"
+        data["issue"]["last_updated"] = "1431414800"
         self.assertEqual(
         self.assertEqual(
             data,
             data,
             {
             {
-              "issue": {
-                "assignee": None,
-                "blocks": [],
-                "close_status": None,
-                "closed_at": None,
-                "closed_by": None,
-                "comments": [],
-                "content": "This issue needs attention",
-                "custom_fields": [],
-                "date_created": "1431414800",
-                "depends": [],
-                "id": 1,
-                "last_updated": "1431414800",
-                "milestone": None,
-                "priority": None,
-                "private": False,
-                "status": "Open",
-                "tags": [],
-                "title": "test issue",
-                "user": {
-                  "fullname": "foo bar",
-                  "name": "foo"
-                }
-              },
-              "message": "Issue created"
-            }
+                "issue": {
+                    "assignee": None,
+                    "blocks": [],
+                    "close_status": None,
+                    "closed_at": None,
+                    "closed_by": None,
+                    "comments": [],
+                    "content": "This issue needs attention",
+                    "custom_fields": [],
+                    "date_created": "1431414800",
+                    "depends": [],
+                    "id": 1,
+                    "last_updated": "1431414800",
+                    "milestone": None,
+                    "priority": None,
+                    "private": False,
+                    "status": "Open",
+                    "tags": [],
+                    "title": "test issue",
+                    "user": {"fullname": "foo bar", "name": "foo"},
+                },
+                "message": "Issue created",
+            },
         )
         )
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_create_issue_invalid_project_specific_token(self):
     def test_create_issue_invalid_project_specific_token(self):
         """ Test creating a new ticket on a project with a regular
         """ Test creating a new ticket on a project with a regular
         project-specific token but for another project.
         project-specific token but for another project.
         """
         """
 
 
         # pingou's token with all the ACLs
         # pingou's token with all the ACLs
-        headers = {'Authorization': 'token project-specific-foo'}
+        headers = {"Authorization": "token project-specific-foo"}
 
 
         # complete data set
         # complete data set
         data = {
         data = {
-            'title': 'test issue',
-            'issue_content': 'This issue needs attention',
+            "title": "test issue",
+            "issue_content": "This issue needs attention",
         }
         }
 
 
         # Create an issue on /test/ where pingou is the main admin
         # Create an issue on /test/ where pingou is the main admin
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test2/new_issue',
-            headers=headers,
-            data=data)
+            "/api/0/test2/new_issue", headers=headers, data=data
+        )
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertEqual(
         self.assertEqual(
-            pagure.api.APIERROR.EINVALIDTOK.name, data['error_code'])
-        self.assertEqual(
-            pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
+            pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
+        )
+        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 93 - 61
tests/test_pagure_flask_api_issue_custom_fields.py

@@ -15,8 +15,9 @@ import json
 
 
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query  # noqa: E402
 import pagure.lib.query  # noqa: E402
 import tests  # noqa: E402
 import tests  # noqa: E402
@@ -30,21 +31,21 @@ class PagureFlaskApiCustomFieldIssuetests(tests.Modeltests):
         self.maxDiff = None
         self.maxDiff = None
         super(PagureFlaskApiCustomFieldIssuetests, self).setUp()
         super(PagureFlaskApiCustomFieldIssuetests, self).setUp()
 
 
-        pagure.config.config['TICKETS_FOLDER'] = None
+        pagure.config.config["TICKETS_FOLDER"] = None
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'tickets'))
+        tests.create_projects_git(os.path.join(self.path, "tickets"))
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
         tests.create_tokens_acl(self.session)
         tests.create_tokens_acl(self.session)
 
 
         # Create normal issue
         # Create normal issue
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         pagure.lib.query.new_issue(
         pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
-            title='Test issue #1',
-            content='We should work on this',
-            user='pingou',
+            title="Test issue #1",
+            content="We should work on this",
+            user="pingou",
             private=False,
             private=False,
         )
         )
         self.session.commit()
         self.session.commit()
@@ -54,12 +55,13 @@ class PagureFlaskApiCustomFieldIssuetests(tests.Modeltests):
         This test that a badly form request returns the correct error.
         This test that a badly form request returns the correct error.
         """
         """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # Request is not formated correctly (EMPTY)
         # Request is not formated correctly (EMPTY)
         payload = {}
         payload = {}
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/issue/1/custom', headers=headers, data=payload)
+            "/api/0/test/issue/1/custom", headers=headers, data=payload
+        )
         self.assertEqual(output.status_code, 400)
         self.assertEqual(output.status_code, 400)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
@@ -67,7 +69,7 @@ class PagureFlaskApiCustomFieldIssuetests(tests.Modeltests):
             {
             {
                 "error": "Invalid or incomplete input submitted",
                 "error": "Invalid or incomplete input submitted",
                 "error_code": "EINVALIDREQ",
                 "error_code": "EINVALIDREQ",
-            }
+            },
         )
         )
 
 
     def test_api_update_custom_field_wrong_field(self):
     def test_api_update_custom_field_wrong_field(self):
@@ -75,11 +77,12 @@ class PagureFlaskApiCustomFieldIssuetests(tests.Modeltests):
         This test that an invalid field retruns the correct error.
         This test that an invalid field retruns the correct error.
         """
         """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
         # Project does not have this custom field
         # Project does not have this custom field
-        payload = {'foo': 'bar'}
+        payload = {"foo": "bar"}
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/issue/1/custom', headers=headers, data=payload)
+            "/api/0/test/issue/1/custom", headers=headers, data=payload
+        )
         self.assertEqual(output.status_code, 400)
         self.assertEqual(output.status_code, 400)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
@@ -87,59 +90,77 @@ class PagureFlaskApiCustomFieldIssuetests(tests.Modeltests):
             {
             {
                 "error": "Invalid custom field submitted",
                 "error": "Invalid custom field submitted",
                 "error_code": "EINVALIDISSUEFIELD",
                 "error_code": "EINVALIDISSUEFIELD",
-            }
+            },
         )
         )
 
 
     @patch(
     @patch(
-        'pagure.lib.query.set_custom_key_value',
-        MagicMock(side_effect=pagure.exceptions.PagureException('error')))
+        "pagure.lib.query.set_custom_key_value",
+        MagicMock(side_effect=pagure.exceptions.PagureException("error")),
+    )
     def test_api_update_custom_field_raise_error(self):
     def test_api_update_custom_field_raise_error(self):
         """ Test the api_update_custom_field method of the flask api.
         """ Test the api_update_custom_field method of the flask api.
         This test the successful requests scenarii.
         This test the successful requests scenarii.
         """
         """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # Set some custom fields
         # Set some custom fields
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         msg = pagure.lib.query.set_custom_key_fields(
         msg = pagure.lib.query.set_custom_key_fields(
-            self.session, repo,
-            ['bugzilla', 'upstream', 'reviewstatus'],
-            ['link', 'boolean', 'list'],
-            ['unused data for non-list type', '', 'ack', 'nack', 'needs review'],
-            [None, None, None])
+            self.session,
+            repo,
+            ["bugzilla", "upstream", "reviewstatus"],
+            ["link", "boolean", "list"],
+            [
+                "unused data for non-list type",
+                "",
+                "ack",
+                "nack",
+                "needs review",
+            ],
+            [None, None, None],
+        )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'List of custom fields updated')
+        self.assertEqual(msg, "List of custom fields updated")
 
 
-        payload = {'bugzilla': '', 'upstream': True}
+        payload = {"bugzilla": "", "upstream": True}
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/issue/1/custom', headers=headers, data=payload)
+            "/api/0/test/issue/1/custom", headers=headers, data=payload
+        )
         self.assertEqual(output.status_code, 400)
         self.assertEqual(output.status_code, 400)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertDictEqual(
-            data, {u'error': u'error', u'error_code': u'ENOCODE'})
+        self.assertDictEqual(data, {"error": "error", "error_code": "ENOCODE"})
 
 
     def test_api_update_custom_field(self):
     def test_api_update_custom_field(self):
         """ Test the api_update_custom_field method of the flask api.
         """ Test the api_update_custom_field method of the flask api.
         This test the successful requests scenarii.
         This test the successful requests scenarii.
         """
         """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # Set some custom fields
         # Set some custom fields
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         msg = pagure.lib.query.set_custom_key_fields(
         msg = pagure.lib.query.set_custom_key_fields(
-            self.session, repo,
-            ['bugzilla', 'upstream', 'reviewstatus'],
-            ['link', 'boolean', 'list'],
-            ['unused data for non-list type', '', 'ack', 'nack', 'needs review'],
-            [None, None, None])
+            self.session,
+            repo,
+            ["bugzilla", "upstream", "reviewstatus"],
+            ["link", "boolean", "list"],
+            [
+                "unused data for non-list type",
+                "",
+                "ack",
+                "nack",
+                "needs review",
+            ],
+            [None, None, None],
+        )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'List of custom fields updated')
+        self.assertEqual(msg, "List of custom fields updated")
 
 
-        payload = {'bugzilla': '', 'upstream': True}
+        payload = {"bugzilla": "", "upstream": True}
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/issue/1/custom', headers=headers, data=payload)
+            "/api/0/test/issue/1/custom", headers=headers, data=payload
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         data["messages"].sort(key=lambda d: list(d.keys())[0])
         data["messages"].sort(key=lambda d: list(d.keys())[0])
@@ -150,20 +171,22 @@ class PagureFlaskApiCustomFieldIssuetests(tests.Modeltests):
                     {"bugzilla": "No changes"},
                     {"bugzilla": "No changes"},
                     {"upstream": "Custom field upstream adjusted to True"},
                     {"upstream": "Custom field upstream adjusted to True"},
                 ]
                 ]
-            }
+            },
         )
         )
 
 
         self.session.commit()
         self.session.commit()
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         self.assertEqual(len(issue.other_fields), 1)
         self.assertEqual(len(issue.other_fields), 1)
 
 
-        payload = {'bugzilla': 'https://bugzilla.redhat.com/1234',
-                   'upstream': False,
-                   'reviewstatus': 'ack'}
+        payload = {
+            "bugzilla": "https://bugzilla.redhat.com/1234",
+            "upstream": False,
+            "reviewstatus": "ack",
+        }
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/issue/1/custom', headers=headers,
-            data=payload)
+            "/api/0/test/issue/1/custom", headers=headers, data=payload
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         data["messages"].sort(key=lambda d: list(d.keys())[0])
         data["messages"].sort(key=lambda d: list(d.keys())[0])
@@ -171,25 +194,30 @@ class PagureFlaskApiCustomFieldIssuetests(tests.Modeltests):
             data,
             data,
             {
             {
                 "messages": [
                 "messages": [
-                    {"bugzilla": "Custom field bugzilla adjusted to "
-                                 "https://bugzilla.redhat.com/1234"},
-                    {"reviewstatus": "Custom field reviewstatus adjusted to ack"},
-                    {"upstream": "Custom field upstream adjusted to False (was: True)"},
-
+                    {
+                        "bugzilla": "Custom field bugzilla adjusted to "
+                        "https://bugzilla.redhat.com/1234"
+                    },
+                    {
+                        "reviewstatus": "Custom field reviewstatus adjusted to ack"
+                    },
+                    {
+                        "upstream": "Custom field upstream adjusted to False (was: True)"
+                    },
                 ]
                 ]
-            }
+            },
         )
         )
 
 
         self.session.commit()
         self.session.commit()
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         self.assertEqual(len(issue.other_fields), 3)
         self.assertEqual(len(issue.other_fields), 3)
 
 
         # Reset the value
         # Reset the value
-        payload = {'bugzilla': '', 'upstream': '', 'reviewstatus': ''}
+        payload = {"bugzilla": "", "upstream": "", "reviewstatus": ""}
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/issue/1/custom', headers=headers,
-            data=payload)
+            "/api/0/test/issue/1/custom", headers=headers, data=payload
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         data["messages"].sort(key=lambda d: list(d.keys())[0])
         data["messages"].sort(key=lambda d: list(d.keys())[0])
@@ -197,14 +225,18 @@ class PagureFlaskApiCustomFieldIssuetests(tests.Modeltests):
             data,
             data,
             {
             {
                 "messages": [
                 "messages": [
-                    {"bugzilla": "Custom field bugzilla reset "
-                                 "(from https://bugzilla.redhat.com/1234)"},
-                    {"reviewstatus": "Custom field reviewstatus reset (from ack)"},
+                    {
+                        "bugzilla": "Custom field bugzilla reset "
+                        "(from https://bugzilla.redhat.com/1234)"
+                    },
+                    {
+                        "reviewstatus": "Custom field reviewstatus reset (from ack)"
+                    },
                     {"upstream": "Custom field upstream reset (from False)"},
                     {"upstream": "Custom field upstream reset (from False)"},
                 ]
                 ]
-            }
+            },
         )
         )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

File diff suppressed because it is too large
+ 344 - 318
tests/test_pagure_flask_api_pr_flag.py


File diff suppressed because it is too large
+ 292 - 346
tests/test_pagure_flask_api_project.py


+ 16 - 17
tests/test_pagure_flask_api_project_blockuser.py

@@ -45,8 +45,7 @@ class PagureFlaskApiProjectBlockuserTests(tests.SimplePagureTest):
         super(PagureFlaskApiProjectBlockuserTests, self).setUp()
         super(PagureFlaskApiProjectBlockuserTests, self).setUp()
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(
-            os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
         tests.create_tokens_acl(self.session)
         tests.create_tokens_acl(self.session)
 
 
@@ -65,7 +64,9 @@ class PagureFlaskApiProjectBlockuserTests(tests.SimplePagureTest):
         self.assertEqual(project.block_users, [])
         self.assertEqual(project.block_users, [])
         self.blocked_users = []
         self.blocked_users = []
 
 
-        project = pagure.lib.query.get_authorized_project(self.session, "test2")
+        project = pagure.lib.query.get_authorized_project(
+            self.session, "test2"
+        )
         project.block_users = ["foo"]
         project.block_users = ["foo"]
         self.session.add(project)
         self.session.add(project)
         self.session.commit()
         self.session.commit()
@@ -225,9 +226,9 @@ class PagureFlaskApiProjectBlockuserTests(tests.SimplePagureTest):
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
             {
             {
-                "error":"You have been blocked from this project",
-                "error_code":"EUBLOCKED"
-            }
+                "error": "You have been blocked from this project",
+                "error_code": "EUBLOCKED",
+            },
         )
         )
 
 
     def test_ui_new_issue_user_blocked(self):
     def test_ui_new_issue_user_blocked(self):
@@ -237,27 +238,25 @@ class PagureFlaskApiProjectBlockuserTests(tests.SimplePagureTest):
         user = tests.FakeUser(username="foo")
         user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
-            output = self.app.get('/test2/new_issue')
+            output = self.app.get("/test2/new_issue")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
-            self.assertIn(
-                'New Issue',
-                output.get_data(as_text=True))
+            self.assertIn("New Issue", output.get_data(as_text=True))
 
 
             csrf_token = self.get_csrf(output=output)
             csrf_token = self.get_csrf(output=output)
 
 
             data = {
             data = {
-                'title': 'Test issue',
-                'issue_content': 'We really should improve on this issue',
-                'status': 'Open',
-                'csrf_token': csrf_token,
+                "title": "Test issue",
+                "issue_content": "We really should improve on this issue",
+                "status": "Open",
+                "csrf_token": csrf_token,
             }
             }
 
 
-            output = self.app.post('/test2/new_issue', data=data)
+            output = self.app.post("/test2/new_issue", data=data)
             self.assertEqual(output.status_code, 403)
             self.assertEqual(output.status_code, 403)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<p>You have been blocked from this project</p>',
-                output_text)
+                "<p>You have been blocked from this project</p>", output_text
+            )
 
 
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":

+ 90 - 107
tests/test_pagure_flask_api_project_update_watch.py

@@ -21,8 +21,9 @@ import os
 import json
 import json
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import tests
 import tests
@@ -33,262 +34,244 @@ class PagureFlaskApiProjectUpdateWatchTests(tests.Modeltests):
     a project via the API
     a project via the API
     """
     """
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def setUp(self):
     def setUp(self):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(PagureFlaskApiProjectUpdateWatchTests, self).setUp()
         super(PagureFlaskApiProjectUpdateWatchTests, self).setUp()
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'tickets'))
+        tests.create_projects_git(os.path.join(self.path, "tickets"))
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
         tests.create_tokens_acl(self.session)
         tests.create_tokens_acl(self.session)
 
 
         # Create normal issue
         # Create normal issue
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
-            title='Test issue #1',
-            content='We should work on this',
-            user='pingou',
+            title="Test issue #1",
+            content="We should work on this",
+            user="pingou",
             private=False,
             private=False,
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg.title, 'Test issue #1')
+        self.assertEqual(msg.title, "Test issue #1")
 
 
         # Create project-less token for user foo
         # Create project-less token for user foo
         item = pagure.lib.model.Token(
         item = pagure.lib.model.Token(
-            id='project-less-foo',
+            id="project-less-foo",
             user_id=1,
             user_id=1,
             project_id=None,
             project_id=None,
             expiration=datetime.datetime.utcnow()
             expiration=datetime.datetime.utcnow()
-            + datetime.timedelta(days=30)
+            + datetime.timedelta(days=30),
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
-        tests.create_tokens_acl(self.session, token_id='project-less-foo')
+        tests.create_tokens_acl(self.session, token_id="project-less-foo")
 
 
     def test_api_update_project_watchers_invalid_project(self):
     def test_api_update_project_watchers_invalid_project(self):
         """ Test the api_update_project_watchers method of the flask api. """
         """ Test the api_update_project_watchers method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # Invalid project
         # Invalid project
         output = self.app.post(
         output = self.app.post(
-            '/api/0/foobar/watchers/update', headers=headers)
+            "/api/0/foobar/watchers/update", headers=headers
+        )
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
-            data,
-            {
-              "error": "Project not found",
-              "error_code": "ENOPROJECT",
-            }
+            data, {"error": "Project not found", "error_code": "ENOPROJECT"}
         )
         )
 
 
     def test_api_change_status_issue_token_not_for_project(self):
     def test_api_change_status_issue_token_not_for_project(self):
         """ Test the api_update_project_watchers method of the flask api. """
         """ Test the api_update_project_watchers method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
         # Valid token, wrong project
         # Valid token, wrong project
-        output = self.app.post(
-            '/api/0/test2/watchers/update', headers=headers)
+        output = self.app.post("/api/0/test2/watchers/update", headers=headers)
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
-                         data['error_code'])
-        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
+        self.assertEqual(
+            pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
+        )
+        self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
 
 
     def test_api_update_project_watchers_no_user_watching(self):
     def test_api_update_project_watchers_no_user_watching(self):
         """ Test the api_update_project_watchers method of the flask api. """
         """ Test the api_update_project_watchers method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
-        data = {
-            'status': '42',
-        }
+        headers = {"Authorization": "token aaabbbcccddd"}
+        data = {"status": "42"}
 
 
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/watchers/update', headers=headers, data=data)
+            "/api/0/test/watchers/update", headers=headers, data=data
+        )
         self.assertEqual(output.status_code, 400)
         self.assertEqual(output.status_code, 400)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
             {
             {
-                u'error': u'Invalid or incomplete input submitted',
-                u'error_code': u'EINVALIDREQ'
-            }
+                "error": "Invalid or incomplete input submitted",
+                "error_code": "EINVALIDREQ",
+            },
         )
         )
 
 
     def test_api_update_project_watchers_no_watch_status(self):
     def test_api_update_project_watchers_no_watch_status(self):
         """ Test the api_update_project_watchers method of the flask api. """
         """ Test the api_update_project_watchers method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
-        data = {
-            'watcher': 'pingou',
-        }
+        headers = {"Authorization": "token aaabbbcccddd"}
+        data = {"watcher": "pingou"}
 
 
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/watchers/update', headers=headers, data=data)
+            "/api/0/test/watchers/update", headers=headers, data=data
+        )
         self.assertEqual(output.status_code, 400)
         self.assertEqual(output.status_code, 400)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
             {
             {
-                u'error': u'The watch value of "None" is invalid',
-                u'error_code': u'ENOCODE'
-            }
+                "error": 'The watch value of "None" is invalid',
+                "error_code": "ENOCODE",
+            },
         )
         )
 
 
     def test_api_update_project_watchers_invalid_status(self):
     def test_api_update_project_watchers_invalid_status(self):
         """ Test the api_update_project_watchers method of the flask api. """
         """ Test the api_update_project_watchers method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
-        data = {
-            'watcher': 'pingou',
-            'status': '42',
-        }
+        headers = {"Authorization": "token aaabbbcccddd"}
+        data = {"watcher": "pingou", "status": "42"}
 
 
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/watchers/update', headers=headers, data=data)
+            "/api/0/test/watchers/update", headers=headers, data=data
+        )
         self.assertEqual(output.status_code, 400)
         self.assertEqual(output.status_code, 400)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
             {
             {
-                u'error': u'The watch value of "42" is invalid',
-                u'error_code': u'ENOCODE'
-            }
+                "error": 'The watch value of "42" is invalid',
+                "error_code": "ENOCODE",
+            },
         )
         )
 
 
     def test_api_update_project_watchers_invalid_user(self):
     def test_api_update_project_watchers_invalid_user(self):
         """ Test the api_update_project_watchers method of the flask api. """
         """ Test the api_update_project_watchers method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
-        data = {
-            'watcher': 'example',
-            'status': '2',
-        }
+        headers = {"Authorization": "token aaabbbcccddd"}
+        data = {"watcher": "example", "status": "2"}
 
 
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/watchers/update', headers=headers, data=data)
+            "/api/0/test/watchers/update", headers=headers, data=data
+        )
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
             {
             {
-                u'error': u'You are not allowed to modify this project',
-                u'error_code': u'EMODIFYPROJECTNOTALLOWED'
-            }
+                "error": "You are not allowed to modify this project",
+                "error_code": "EMODIFYPROJECTNOTALLOWED",
+            },
         )
         )
 
 
     def test_api_update_project_watchers_other_user(self):
     def test_api_update_project_watchers_other_user(self):
         """ Test the api_update_project_watchers method of the flask api. """
         """ Test the api_update_project_watchers method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
-        data = {
-            'watcher': 'foo',
-            'status': '2',
-        }
+        headers = {"Authorization": "token aaabbbcccddd"}
+        data = {"watcher": "foo", "status": "2"}
 
 
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/watchers/update', headers=headers, data=data)
+            "/api/0/test/watchers/update", headers=headers, data=data
+        )
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
             {
             {
-                u'error': u'You are not allowed to modify this project',
-                u'error_code': u'EMODIFYPROJECTNOTALLOWED'
-            }
+                "error": "You are not allowed to modify this project",
+                "error_code": "EMODIFYPROJECTNOTALLOWED",
+            },
         )
         )
 
 
     def test_api_update_project_watchers_all_good(self):
     def test_api_update_project_watchers_all_good(self):
         """ Test the api_update_project_watchers method of the flask api. """
         """ Test the api_update_project_watchers method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
-        data = {
-            'watcher': 'pingou',
-            'status': 1,
-        }
+        headers = {"Authorization": "token aaabbbcccddd"}
+        data = {"watcher": "pingou", "status": 1}
 
 
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/watchers/update', headers=headers, data=data)
+            "/api/0/test/watchers/update", headers=headers, data=data
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
             {
             {
-                u'message': u'You are now watching issues and PRs on this project',
-                u'status': u'ok'
-            }
+                "message": "You are now watching issues and PRs on this project",
+                "status": "ok",
+            },
         )
         )
 
 
-    @patch('pagure.utils.is_admin', MagicMock(return_value=True))
+    @patch("pagure.utils.is_admin", MagicMock(return_value=True))
     def test_api_update_project_watchers_other_user_admin(self):
     def test_api_update_project_watchers_other_user_admin(self):
         """ Test the api_update_project_watchers method of the flask api. """
         """ Test the api_update_project_watchers method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
-        data = {
-            'watcher': 'foo',
-            'status': '2',
-        }
+        headers = {"Authorization": "token aaabbbcccddd"}
+        data = {"watcher": "foo", "status": "2"}
 
 
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/watchers/update', headers=headers, data=data)
+            "/api/0/test/watchers/update", headers=headers, data=data
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
             {
             {
-                u'message': u'You are now watching commits on this project',
-                u'status': u'ok'
-            }
+                "message": "You are now watching commits on this project",
+                "status": "ok",
+            },
         )
         )
 
 
-    @patch('pagure.utils.is_admin', MagicMock(return_value=True))
+    @patch("pagure.utils.is_admin", MagicMock(return_value=True))
     def test_api_update_project_watchers_invalid_user_admin(self):
     def test_api_update_project_watchers_invalid_user_admin(self):
         """ Test the api_update_project_watchers method of the flask api. """
         """ Test the api_update_project_watchers method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
-        data = {
-            'watcher': 'example',
-            'status': '2',
-        }
+        headers = {"Authorization": "token aaabbbcccddd"}
+        data = {"watcher": "example", "status": "2"}
 
 
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/watchers/update', headers=headers, data=data)
+            "/api/0/test/watchers/update", headers=headers, data=data
+        )
         self.assertEqual(output.status_code, 400)
         self.assertEqual(output.status_code, 400)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
             {
             {
-                u'error': u'Invalid or incomplete input submitted',
-                u'error_code': u'EINVALIDREQ'
-            }
+                "error": "Invalid or incomplete input submitted",
+                "error_code": "EINVALIDREQ",
+            },
         )
         )
 
 
-    @patch('pagure.utils.is_admin', MagicMock(return_value=True))
+    @patch("pagure.utils.is_admin", MagicMock(return_value=True))
     def test_api_update_project_watchers_missing_user_admin(self):
     def test_api_update_project_watchers_missing_user_admin(self):
         """ Test the api_update_project_watchers method of the flask api. """
         """ Test the api_update_project_watchers method of the flask api. """
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
-        data = {
-            'status': '2',
-        }
+        headers = {"Authorization": "token aaabbbcccddd"}
+        data = {"status": "2"}
 
 
         output = self.app.post(
         output = self.app.post(
-            '/api/0/test/watchers/update', headers=headers, data=data)
+            "/api/0/test/watchers/update", headers=headers, data=data
+        )
         self.assertEqual(output.status_code, 400)
         self.assertEqual(output.status_code, 400)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertDictEqual(
         self.assertDictEqual(
             data,
             data,
             {
             {
-                u'error': u'Invalid or incomplete input submitted',
-                u'error_code': u'EINVALIDREQ'
-            }
+                "error": "Invalid or incomplete input submitted",
+                "error_code": "EINVALIDREQ",
+            },
         )
         )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

File diff suppressed because it is too large
+ 257 - 242
tests/test_pagure_flask_api_ui_private_repo.py


File diff suppressed because it is too large
+ 776 - 620
tests/test_pagure_flask_api_user.py


+ 91 - 74
tests/test_pagure_flask_docs.py

@@ -20,8 +20,9 @@ import mock
 import pygit2
 import pygit2
 from mock import patch
 from mock import patch
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.docs_server
 import pagure.docs_server
 import pagure.lib.query
 import pagure.lib.query
@@ -36,68 +37,70 @@ class PagureFlaskDocstests(tests.SimplePagureTest):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(PagureFlaskDocstests, self).setUp()
         super(PagureFlaskDocstests, self).setUp()
 
 
-        pagure.docs_server.APP.config['TESTING'] = True
+        pagure.docs_server.APP.config["TESTING"] = True
         pagure.docs_server.SESSION = self.session
         pagure.docs_server.SESSION = self.session
 
 
-        pagure.docs_server.APP.config['GIT_FOLDER'] = os.path.join(
-            self.path, 'repos')
-        pagure.docs_server.APP.config['TICKETS_FOLDER'] = os.path.join(
-            self.path, 'tickets')
-        pagure.docs_server.APP.config['DOCS_FOLDER'] = os.path.join(
-            self.path, 'repos', 'docs')
+        pagure.docs_server.APP.config["GIT_FOLDER"] = os.path.join(
+            self.path, "repos"
+        )
+        pagure.docs_server.APP.config["TICKETS_FOLDER"] = os.path.join(
+            self.path, "tickets"
+        )
+        pagure.docs_server.APP.config["DOCS_FOLDER"] = os.path.join(
+            self.path, "repos", "docs"
+        )
         self.app = pagure.docs_server.APP.test_client()
         self.app = pagure.docs_server.APP.test_client()
 
 
     def _set_up_doc(self):
     def _set_up_doc(self):
         # forked doc repo
         # forked doc repo
-        docrepo = os.path.join(self.path, 'repos', 'docs', 'test', 'test.git')
+        docrepo = os.path.join(self.path, "repos", "docs", "test", "test.git")
         repo = pygit2.init_repository(docrepo)
         repo = pygit2.init_repository(docrepo)
 
 
         # Create files in that git repo
         # Create files in that git repo
-        with open(os.path.join(docrepo, 'sources'), 'w') as stream:
-            stream.write('foo\n bar')
-        repo.index.add('sources')
+        with open(os.path.join(docrepo, "sources"), "w") as stream:
+            stream.write("foo\n bar")
+        repo.index.add("sources")
         repo.index.write()
         repo.index.write()
 
 
-        folderpart = os.path.join(docrepo, 'folder1', 'folder2')
+        folderpart = os.path.join(docrepo, "folder1", "folder2")
         os.makedirs(folderpart)
         os.makedirs(folderpart)
-        with open(os.path.join(folderpart, 'test_file'), 'w') as stream:
-            stream.write('row1\nrow2\nrow3')
-        repo.index.add(os.path.join('folder1', 'folder2', 'test_file'))
+        with open(os.path.join(folderpart, "test_file"), "w") as stream:
+            stream.write("row1\nrow2\nrow3")
+        repo.index.add(os.path.join("folder1", "folder2", "test_file"))
         repo.index.write()
         repo.index.write()
 
 
         # Commits the files added
         # Commits the files added
         tree = repo.index.write_tree()
         tree = repo.index.write_tree()
-        author = pygit2.Signature(
-            'Alice Author', 'alice@authors.tld')
-        committer = pygit2.Signature(
-            'Cecil Committer', 'cecil@committers.tld')
+        author = pygit2.Signature("Alice Author", "alice@authors.tld")
+        committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
         repo.create_commit(
         repo.create_commit(
-            'refs/heads/master',  # the name of the reference to update
+            "refs/heads/master",  # the name of the reference to update
             author,
             author,
             committer,
             committer,
-            'Add test files and folder',
+            "Add test files and folder",
             # binary string representing the tree object ID
             # binary string representing the tree object ID
             tree,
             tree,
             # list of binary strings representing parents of the new commit
             # list of binary strings representing parents of the new commit
-            []
+            [],
         )
         )
 
 
         # Push the changes to the bare repo
         # Push the changes to the bare repo
         remote = repo.create_remote(
         remote = repo.create_remote(
-            'origin', os.path.join(self.path, 'repos', 'docs', 'test.git'))
+            "origin", os.path.join(self.path, "repos", "docs", "test.git")
+        )
 
 
-        PagureRepo.push(remote, 'refs/heads/master:refs/heads/master')
+        PagureRepo.push(remote, "refs/heads/master:refs/heads/master")
 
 
         # Turn on the docs project since it's off by default
         # Turn on the docs project since it's off by default
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
-        repo.settings = {'project_documentation': True}
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
+        repo.settings = {"project_documentation": True}
         self.session.add(repo)
         self.session.add(repo)
         self.session.commit()
         self.session.commit()
 
 
     def test_view_docs_no_project(self):
     def test_view_docs_no_project(self):
         """ Test the view_docs endpoint with no project. """
         """ Test the view_docs endpoint with no project. """
 
 
-        output = self.app.get('/foo/docs')
+        output = self.app.get("/foo/docs")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
     def test_view_docs_project_no_git(self):
     def test_view_docs_project_no_git(self):
@@ -107,145 +110,159 @@ class PagureFlaskDocstests(tests.SimplePagureTest):
         tests.create_projects(self.session)
         tests.create_projects(self.session)
 
 
         # Turn on the docs project since it's off by default
         # Turn on the docs project since it's off by default
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
-        repo.settings = {'project_documentation': True}
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
+        repo.settings = {"project_documentation": True}
         self.session.add(repo)
         self.session.add(repo)
         self.session.commit()
         self.session.commit()
 
 
-        output = self.app.get('/test/docs', follow_redirects=True)
+        output = self.app.get("/test/docs", follow_redirects=True)
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
         self.assertTrue(
         self.assertTrue(
-            '<p>Documentation not found</p>' in output.get_data(as_text=True))
+            "<p>Documentation not found</p>" in output.get_data(as_text=True)
+        )
 
 
-        output = self.app.get('/test', follow_redirects=True)
+        output = self.app.get("/test", follow_redirects=True)
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
         self.assertTrue(
         self.assertTrue(
-            '<p>Documentation not found</p>' in output.get_data(as_text=True))
+            "<p>Documentation not found</p>" in output.get_data(as_text=True)
+        )
 
 
     def test_view_docs_project_no_docs(self):
     def test_view_docs_project_no_docs(self):
         """ Test the view_docs endpoint with a project that disabled the
         """ Test the view_docs endpoint with a project that disabled the
         docs.
         docs.
         """
         """
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
-        tests.create_projects_git(os.path.join(self.path, 'repos', 'docs'))
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
+        tests.create_projects_git(os.path.join(self.path, "repos", "docs"))
 
 
-        output = self.app.get('/test/docs')
+        output = self.app.get("/test/docs")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
-        repo.settings = {'project_documentation': False}
+        repo.settings = {"project_documentation": False}
         self.session.add(repo)
         self.session.add(repo)
         self.session.commit()
         self.session.commit()
 
 
-        output = self.app.get('/test/docs', follow_redirects=True)
+        output = self.app.get("/test/docs", follow_redirects=True)
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
     def test_view_docs_empty_repo(self):
     def test_view_docs_empty_repo(self):
         """ Test the view_docs endpoint when the git repo is empty. """
         """ Test the view_docs endpoint when the git repo is empty. """
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         repo = pygit2.init_repository(
         repo = pygit2.init_repository(
-            os.path.join(self.path, 'repos', 'docs', 'test.git'), bare=True)
+            os.path.join(self.path, "repos", "docs", "test.git"), bare=True
+        )
 
 
         # Turn on the docs project since it's off by default
         # Turn on the docs project since it's off by default
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
-        repo.settings = {'project_documentation': True}
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
+        repo.settings = {"project_documentation": True}
         self.session.add(repo)
         self.session.add(repo)
         self.session.commit()
         self.session.commit()
 
 
-        output = self.app.get('/test/docs')
+        output = self.app.get("/test/docs")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
         self.assertIn(
         self.assertIn(
-            '<p>No content found in the repository, you may want to read '
+            "<p>No content found in the repository, you may want to read "
             'the <a href="https://docs.pagure.org/pagure/usage/'
             'the <a href="https://docs.pagure.org/pagure/usage/'
             'using_doc.html">Using the doc repository of your project</a> '
             'using_doc.html">Using the doc repository of your project</a> '
-            'documentation.</p>', output.get_data(as_text=True))
+            "documentation.</p>",
+            output.get_data(as_text=True),
+        )
 
 
     def test_view_docs(self):
     def test_view_docs(self):
         """ Test the view_docs endpoint. """
         """ Test the view_docs endpoint. """
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         repo = pygit2.init_repository(
         repo = pygit2.init_repository(
-            os.path.join(self.path, 'repos', 'docs', 'test.git'), bare=True)
+            os.path.join(self.path, "repos", "docs", "test.git"), bare=True
+        )
 
 
-        output = self.app.get('/test/docs')
+        output = self.app.get("/test/docs")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
         self._set_up_doc()
         self._set_up_doc()
 
 
         # Now check the UI
         # Now check the UI
 
 
-        output = self.app.get('/test/docs')
+        output = self.app.get("/test/docs")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
-        output = self.app.get('/test/sources')
+        output = self.app.get("/test/sources")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
-        self.assertEqual('<pre>foo\n bar</pre>', output.get_data(as_text=True))
+        self.assertEqual("<pre>foo\n bar</pre>", output.get_data(as_text=True))
 
 
-        output = self.app.get('/test/folder1/folder2')
+        output = self.app.get("/test/folder1/folder2")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         self.assertTrue(
         self.assertTrue(
             '<li><ul><a href="test_file">test_file</a></ul></li>'
             '<li><ul><a href="test_file">test_file</a></ul></li>'
-            in output.get_data(as_text=True))
+            in output.get_data(as_text=True)
+        )
 
 
-        output = self.app.get('/test/folder1/folder2/test_file')
+        output = self.app.get("/test/folder1/folder2/test_file")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
-        self.assertEqual('<pre>row1\nrow2\nrow3</pre>', output.get_data(as_text=True))
+        self.assertEqual(
+            "<pre>row1\nrow2\nrow3</pre>", output.get_data(as_text=True)
+        )
 
 
-        output = self.app.get('/test/folder1')
+        output = self.app.get("/test/folder1")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         self.assertTrue(
         self.assertTrue(
             '<li><ul><a href="folder2/">folder2/</a></ul></li>'
             '<li><ul><a href="folder2/">folder2/</a></ul></li>'
-            in output.get_data(as_text=True))
+            in output.get_data(as_text=True)
+        )
 
 
-        output = self.app.get('/test/folder1/foo')
+        output = self.app.get("/test/folder1/foo")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
-        output = self.app.get('/test/folder1/foo/folder2')
+        output = self.app.get("/test/folder1/foo/folder2")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
     @mock.patch(
     @mock.patch(
-        'pagure.lib.encoding_utils.decode',
-        mock.MagicMock(side_effect=pagure.exceptions.PagureEncodingException))
+        "pagure.lib.encoding_utils.decode",
+        mock.MagicMock(side_effect=pagure.exceptions.PagureEncodingException),
+    )
     def test_view_docs_encoding_error(self):
     def test_view_docs_encoding_error(self):
         """ Test viewing a file of which we cannot find the encoding. """
         """ Test viewing a file of which we cannot find the encoding. """
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         repo = pygit2.init_repository(
         repo = pygit2.init_repository(
-            os.path.join(self.path, 'repos', 'docs', 'test.git'), bare=True)
+            os.path.join(self.path, "repos", "docs", "test.git"), bare=True
+        )
 
 
-        output = self.app.get('/test/docs')
+        output = self.app.get("/test/docs")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
         self._set_up_doc()
         self._set_up_doc()
 
 
-        output = self.app.get('/test/sources')
+        output = self.app.get("/test/sources")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
-        self.assertEqual('foo\n bar', output.get_data(as_text=True))
+        self.assertEqual("foo\n bar", output.get_data(as_text=True))
 
 
-        output = self.app.get('/test/folder1')
+        output = self.app.get("/test/folder1")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         self.assertTrue(
         self.assertTrue(
             '<li><ul><a href="folder2/">folder2/</a></ul></li>'
             '<li><ul><a href="folder2/">folder2/</a></ul></li>'
-            in output.get_data(as_text=True))
+            in output.get_data(as_text=True)
+        )
 
 
     @mock.patch(
     @mock.patch(
-        'pagure.lib.encoding_utils.decode',
-        mock.MagicMock(side_effect=IOError))
+        "pagure.lib.encoding_utils.decode", mock.MagicMock(side_effect=IOError)
+    )
     def test_view_docs_unknown_error(self):
     def test_view_docs_unknown_error(self):
         """ Test viewing a file of which we cannot find the encoding. """
         """ Test viewing a file of which we cannot find the encoding. """
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         repo = pygit2.init_repository(
         repo = pygit2.init_repository(
-            os.path.join(self.path, 'repos', 'docs', 'test.git'), bare=True)
+            os.path.join(self.path, "repos", "docs", "test.git"), bare=True
+        )
 
 
-        output = self.app.get('/test/docs')
+        output = self.app.get("/test/docs")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
         self._set_up_doc()
         self._set_up_doc()
 
 
-        output = self.app.get('/test/sources')
+        output = self.app.get("/test/sources")
         self.assertEqual(output.status_code, 500)
         self.assertEqual(output.status_code, 500)
 
 
-        output = self.app.get('/test/folder1')
+        output = self.app.get("/test/folder1")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 61 - 59
tests/test_pagure_flask_dump_load_ticket.py

@@ -21,8 +21,9 @@ import os
 import pygit2
 import pygit2
 from mock import patch
 from mock import patch
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import tests
 import tests
@@ -33,8 +34,8 @@ class PagureFlaskDumpLoadTicketTests(tests.Modeltests):
     a ticket.
     a ticket.
     """
     """
 
 
-    @patch('pagure.lib.notify.send_email')
-    @patch('pagure.lib.git._maybe_wait')
+    @patch("pagure.lib.notify.send_email")
+    @patch("pagure.lib.git._maybe_wait")
     def test_dumping_reloading_ticket(self, mw, send_email):
     def test_dumping_reloading_ticket(self, mw, send_email):
         """ Test dumping a ticket into a JSON blob. """
         """ Test dumping a ticket into a JSON blob. """
         mw.side_effect = lambda result: result.get()
         mw.side_effect = lambda result: result.get()
@@ -43,39 +44,39 @@ class PagureFlaskDumpLoadTicketTests(tests.Modeltests):
         tests.create_projects(self.session)
         tests.create_projects(self.session)
 
 
         # Create repo
         # Create repo
-        self.gitrepo = os.path.join(self.path, 'repos', 'tickets', 'test.git')
-        repopath = os.path.join(self.path, 'repos', 'tickets')
+        self.gitrepo = os.path.join(self.path, "repos", "tickets", "test.git")
+        repopath = os.path.join(self.path, "repos", "tickets")
         os.makedirs(self.gitrepo)
         os.makedirs(self.gitrepo)
         repo_obj = pygit2.init_repository(self.gitrepo, bare=True)
         repo_obj = pygit2.init_repository(self.gitrepo, bare=True)
 
 
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         # Create an issue to play with
         # Create an issue to play with
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
-            title='Test issue',
-            content='We should work on this',
-            user='pingou',
+            title="Test issue",
+            content="We should work on this",
+            user="pingou",
         )
         )
-        self.assertEqual(msg.title, 'Test issue')
+        self.assertEqual(msg.title, "Test issue")
 
 
         # Need another two issue to test the dependencie chain
         # Need another two issue to test the dependencie chain
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
-            title='Test issue #2',
-            content='Another bug',
-            user='pingou',
+            title="Test issue #2",
+            content="Another bug",
+            user="pingou",
         )
         )
-        self.assertEqual(msg.title, 'Test issue #2')
+        self.assertEqual(msg.title, "Test issue #2")
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
-            title='Test issue #3',
-            content='That would be nice feature no?',
-            user='foo',
+            title="Test issue #3",
+            content="That would be nice feature no?",
+            user="foo",
         )
         )
-        self.assertEqual(msg.title, 'Test issue #3')
+        self.assertEqual(msg.title, "Test issue #3")
 
 
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         issue2 = pagure.lib.query.search_issues(self.session, repo, issueid=2)
         issue2 = pagure.lib.query.search_issues(self.session, repo, issueid=2)
@@ -85,76 +86,75 @@ class PagureFlaskDumpLoadTicketTests(tests.Modeltests):
         msg = pagure.lib.query.add_issue_comment(
         msg = pagure.lib.query.add_issue_comment(
             session=self.session,
             session=self.session,
             issue=issue,
             issue=issue,
-            comment='Hey look a comment!',
-            user='foo',
+            comment="Hey look a comment!",
+            user="foo",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'Comment added')
+        self.assertEqual(msg, "Comment added")
         msg = pagure.lib.query.add_issue_comment(
         msg = pagure.lib.query.add_issue_comment(
             session=self.session,
             session=self.session,
             issue=issue,
             issue=issue,
-            comment='crazy right?',
-            user='pingou',
+            comment="crazy right?",
+            user="pingou",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'Comment added')
+        self.assertEqual(msg, "Comment added")
         # Assign the ticket to someone
         # Assign the ticket to someone
         msg = pagure.lib.query.add_issue_assignee(
         msg = pagure.lib.query.add_issue_assignee(
-            session=self.session,
-            issue=issue,
-            assignee='pingou',
-            user='pingou',
+            session=self.session, issue=issue, assignee="pingou", user="pingou"
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'Issue assigned to pingou')
+        self.assertEqual(msg, "Issue assigned to pingou")
         # Add a couple of tags on the ticket
         # Add a couple of tags on the ticket
         msg = pagure.lib.query.add_tag_obj(
         msg = pagure.lib.query.add_tag_obj(
             session=self.session,
             session=self.session,
             obj=issue,
             obj=issue,
-            tags=[' feature ', 'future '],
-            user='pingou',
+            tags=[" feature ", "future "],
+            user="pingou",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'Issue tagged with: feature, future')
+        self.assertEqual(msg, "Issue tagged with: feature, future")
         # Add dependencies
         # Add dependencies
         msg = pagure.lib.query.add_issue_dependency(
         msg = pagure.lib.query.add_issue_dependency(
             session=self.session,
             session=self.session,
             issue=issue,
             issue=issue,
             issue_blocked=issue2,
             issue_blocked=issue2,
-            user='pingou',
+            user="pingou",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'Issue marked as depending on: #2')
+        self.assertEqual(msg, "Issue marked as depending on: #2")
         msg = pagure.lib.query.add_issue_dependency(
         msg = pagure.lib.query.add_issue_dependency(
-            session=self.session,
-            issue=issue3,
-            issue_blocked=issue,
-            user='foo',
+            session=self.session, issue=issue3, issue_blocked=issue, user="foo"
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'Issue marked as depending on: #1')
+        self.assertEqual(msg, "Issue marked as depending on: #1")
 
 
         # Dump the JSON
         # Dump the JSON
         pagure.lib.git.update_git(issue, repo).wait()
         pagure.lib.git.update_git(issue, repo).wait()
         repo = pygit2.Repository(self.gitrepo)
         repo = pygit2.Repository(self.gitrepo)
-        cnt = len([commit
-            for commit in repo.walk(
-                repo.head.target, pygit2.GIT_SORT_TOPOLOGICAL)])
+        cnt = len(
+            [
+                commit
+                for commit in repo.walk(
+                    repo.head.target, pygit2.GIT_SORT_TOPOLOGICAL
+                )
+            ]
+        )
         self.assertIn(cnt, (9, 10))
         self.assertIn(cnt, (9, 10))
 
 
-        last_commit = repo.revparse_single('HEAD')
+        last_commit = repo.revparse_single("HEAD")
         patch = pagure.lib.git.commit_to_patch(repo, last_commit)
         patch = pagure.lib.git.commit_to_patch(repo, last_commit)
-        for line in patch.split('\n'):
-            if line.startswith('--- a/'):
-                fileid = line.split('--- a/')[1]
+        for line in patch.split("\n"):
+            if line.startswith("--- a/"):
+                fileid = line.split("--- a/")[1]
                 break
                 break
 
 
-        newpath = tempfile.mkdtemp(prefix='pagure-dump-load')
+        newpath = tempfile.mkdtemp(prefix="pagure-dump-load")
         clone_repo = pygit2.clone_repository(self.gitrepo, newpath)
         clone_repo = pygit2.clone_repository(self.gitrepo, newpath)
 
 
         self.assertEqual(len(os.listdir(newpath)), 4)
         self.assertEqual(len(os.listdir(newpath)), 4)
 
 
-        ticket_json = os.path.join(self.path, 'test_ticket.json')
+        ticket_json = os.path.join(self.path, "test_ticket.json")
         self.assertFalse(os.path.exists(ticket_json))
         self.assertFalse(os.path.exists(ticket_json))
         shutil.copyfile(os.path.join(newpath, fileid), ticket_json)
         shutil.copyfile(os.path.join(newpath, fileid), ticket_json)
         self.assertTrue(os.path.exists(ticket_json))
         self.assertTrue(os.path.exists(ticket_json))
@@ -171,35 +171,37 @@ class PagureFlaskDumpLoadTicketTests(tests.Modeltests):
         tests.create_projects(self.session)
         tests.create_projects(self.session)
 
 
         # Create repo
         # Create repo
-        self.gitrepo = os.path.join(self.path, 'tickets', 'test.git')
-        repopath = os.path.join(self.path, 'tickets')
+        self.gitrepo = os.path.join(self.path, "tickets", "test.git")
+        repopath = os.path.join(self.path, "tickets")
         os.makedirs(self.gitrepo)
         os.makedirs(self.gitrepo)
         pygit2.init_repository(self.gitrepo, bare=True)
         pygit2.init_repository(self.gitrepo, bare=True)
 
 
         pagure.lib.git.update_ticket_from_git(
         pagure.lib.git.update_ticket_from_git(
             self.session,
             self.session,
-            reponame='test',
+            reponame="test",
             namespace=None,
             namespace=None,
             username=None,
             username=None,
-            issue_uid='foobar',
+            issue_uid="foobar",
             json_data=jsondata,
             json_data=jsondata,
-            agent='pingou',
+            agent="pingou",
         )
         )
 
 
         # Post loading
         # Post loading
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(repo.issues), 1)
         self.assertEqual(len(repo.issues), 1)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
 
 
         # Check after re-loading
         # Check after re-loading
         self.assertEqual(len(issue.comments), 3)
         self.assertEqual(len(issue.comments), 3)
         self.assertEqual(len(issue.tags), 2)
         self.assertEqual(len(issue.tags), 2)
-        self.assertEqual(sorted(issue.tags_text), sorted(['future', 'feature']))
-        self.assertEqual(issue.assignee.username, 'pingou')
+        self.assertEqual(
+            sorted(issue.tags_text), sorted(["future", "feature"])
+        )
+        self.assertEqual(issue.assignee.username, "pingou")
         self.assertEqual(issue.children, [])
         self.assertEqual(issue.children, [])
         self.assertEqual(issue.parents, [])
         self.assertEqual(issue.parents, [])
-        self.assertEqual(issue.status, 'Open')
+        self.assertEqual(issue.status, "Open")
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 45 - 41
tests/test_pagure_flask_form.py

@@ -20,8 +20,9 @@ import flask
 import flask_wtf
 import flask_wtf
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.forms
 import pagure.forms
 import tests
 import tests
@@ -30,28 +31,30 @@ import tests
 class PagureFlaskFormTests(tests.SimplePagureTest):
 class PagureFlaskFormTests(tests.SimplePagureTest):
     """ Tests for forms of the flask application """
     """ Tests for forms of the flask application """
 
 
-    @patch.dict('pagure.config.config', {'SERVER_NAME': 'localhost.localdomain'})
+    @patch.dict(
+        "pagure.config.config", {"SERVER_NAME": "localhost.localdomain"}
+    )
     def setUp(self):
     def setUp(self):
         super(PagureFlaskFormTests, self).setUp()
         super(PagureFlaskFormTests, self).setUp()
 
 
     def test_csrf_form_no_input(self):
     def test_csrf_form_no_input(self):
         """ Test the CSRF validation if not CSRF is specified. """
         """ Test the CSRF validation if not CSRF is specified. """
-        with self.app.application.test_request_context(method='POST'):
+        with self.app.application.test_request_context(method="POST"):
             flask.g.session = MagicMock()
             flask.g.session = MagicMock()
             form = pagure.forms.ConfirmationForm()
             form = pagure.forms.ConfirmationForm()
             self.assertFalse(form.validate_on_submit())
             self.assertFalse(form.validate_on_submit())
 
 
     def test_csrf_form_w_invalid_input(self):
     def test_csrf_form_w_invalid_input(self):
         """ Test the CSRF validation with an invalid CSRF specified. """
         """ Test the CSRF validation with an invalid CSRF specified. """
-        with self.app.application.test_request_context(method='POST'):
+        with self.app.application.test_request_context(method="POST"):
             flask.g.session = MagicMock()
             flask.g.session = MagicMock()
             form = pagure.forms.ConfirmationForm()
             form = pagure.forms.ConfirmationForm()
-            form.csrf_token.data = 'foobar'
+            form.csrf_token.data = "foobar"
             self.assertFalse(form.validate_on_submit())
             self.assertFalse(form.validate_on_submit())
 
 
     def test_csrf_form_w_input(self):
     def test_csrf_form_w_input(self):
         """ Test the CSRF validation with a valid CSRF specified. """
         """ Test the CSRF validation with a valid CSRF specified. """
-        with self.app.application.test_request_context(method='POST'):
+        with self.app.application.test_request_context(method="POST"):
             flask.g.session = MagicMock()
             flask.g.session = MagicMock()
             form = pagure.forms.ConfirmationForm()
             form = pagure.forms.ConfirmationForm()
             form.csrf_token.data = form.csrf_token.current_token
             form.csrf_token.data = form.csrf_token.current_token
@@ -59,101 +62,102 @@ class PagureFlaskFormTests(tests.SimplePagureTest):
 
 
     def test_csrf_form_w_expired_input(self):
     def test_csrf_form_w_expired_input(self):
         """ Test the CSRF validation with an expired CSRF specified. """
         """ Test the CSRF validation with an expired CSRF specified. """
-        with self.app.application.test_request_context(method='POST'):
+        with self.app.application.test_request_context(method="POST"):
             flask.g.session = MagicMock()
             flask.g.session = MagicMock()
             form = pagure.forms.ConfirmationForm()
             form = pagure.forms.ConfirmationForm()
             data = form.csrf_token.current_token
             data = form.csrf_token.current_token
 
 
             # CSRF token expired
             # CSRF token expired
-            if hasattr(flask_wtf, '__version__') and \
-                    tuple(
-                        [int(v) for v in flask_wtf.__version__.split('.')]
-                    ) < (0, 10, 0):
+            if hasattr(flask_wtf, "__version__") and tuple(
+                [int(v) for v in flask_wtf.__version__.split(".")]
+            ) < (0, 10, 0):
                 expires = time.time() - 1
                 expires = time.time() - 1
             else:
             else:
                 expires = (
                 expires = (
                     datetime.datetime.now() - datetime.timedelta(minutes=1)
                     datetime.datetime.now() - datetime.timedelta(minutes=1)
-                ).strftime('%Y%m%d%H%M%S')
+                ).strftime("%Y%m%d%H%M%S")
 
 
             # Change the CSRF format
             # Change the CSRF format
-            if hasattr(flask_wtf, '__version__') and \
-                    tuple([int(e) for e in flask_wtf.__version__.split('.')]
-                    ) >= (0,14,0):
+            if hasattr(flask_wtf, "__version__") and tuple(
+                [int(e) for e in flask_wtf.__version__.split(".")]
+            ) >= (0, 14, 0):
                 import itsdangerous
                 import itsdangerous
-                try:   # ItsDangerous-1.0
+
+                try:  # ItsDangerous-1.0
                     timestamp = itsdangerous.base64_encode(
                     timestamp = itsdangerous.base64_encode(
-                        itsdangerous.encoding.int_to_bytes(int(expires)))
-                except AttributeError: # ItsDangerous-0.24
+                        itsdangerous.encoding.int_to_bytes(int(expires))
+                    )
+                except AttributeError:  # ItsDangerous-0.24
                     timestamp = itsdangerous.base64_encode(
                     timestamp = itsdangerous.base64_encode(
-                        itsdangerous.int_to_bytes(int(expires)))
+                        itsdangerous.int_to_bytes(int(expires))
+                    )
                 timestamp = timestamp.decode("ascii")
                 timestamp = timestamp.decode("ascii")
-                part1, _, part2 = data.split('.', 2)
-                form.csrf_token.data = '.'.join([part1, timestamp, part2])
+                part1, _, part2 = data.split(".", 2)
+                form.csrf_token.data = ".".join([part1, timestamp, part2])
             else:
             else:
-                _, hmac_csrf = data.split('##', 1)
-                form.csrf_token.data = '%s##%s' % (expires, hmac_csrf)
+                _, hmac_csrf = data.split("##", 1)
+                form.csrf_token.data = "%s##%s" % (expires, hmac_csrf)
 
 
             self.assertFalse(form.validate_on_submit())
             self.assertFalse(form.validate_on_submit())
 
 
     def test_csrf_form_w_unexpiring_input(self):
     def test_csrf_form_w_unexpiring_input(self):
         """ Test the CSRF validation with a CSRF not expiring. """
         """ Test the CSRF validation with a CSRF not expiring. """
-        pagure.config.config['WTF_CSRF_TIME_LIMIT'] = None
-        with self.app.application.test_request_context(method='POST'):
+        pagure.config.config["WTF_CSRF_TIME_LIMIT"] = None
+        with self.app.application.test_request_context(method="POST"):
             flask.g.session = MagicMock()
             flask.g.session = MagicMock()
             form = pagure.forms.ConfirmationForm()
             form = pagure.forms.ConfirmationForm()
             data = form.csrf_token.current_token
             data = form.csrf_token.current_token
 
 
-            if hasattr(flask_wtf, '__version__') and \
-                    tuple([int(e) for e in flask_wtf.__version__.split('.')]
-                    ) >= (0,14,0):
+            if hasattr(flask_wtf, "__version__") and tuple(
+                [int(e) for e in flask_wtf.__version__.split(".")]
+            ) >= (0, 14, 0):
                 form.csrf_token.data = data
                 form.csrf_token.data = data
             else:
             else:
-                _, hmac_csrf = data.split('##', 1)
+                _, hmac_csrf = data.split("##", 1)
                 # CSRF can no longer expire, they have no expiration info
                 # CSRF can no longer expire, they have no expiration info
-                form.csrf_token.data = '##%s' % hmac_csrf
+                form.csrf_token.data = "##%s" % hmac_csrf
             self.assertTrue(form.validate_on_submit())
             self.assertTrue(form.validate_on_submit())
 
 
     def test_add_user_form(self):
     def test_add_user_form(self):
         """ Test the AddUserForm of pagure.forms """
         """ Test the AddUserForm of pagure.forms """
-        with self.app.application.test_request_context(method='POST'):
+        with self.app.application.test_request_context(method="POST"):
             flask.g.session = MagicMock()
             flask.g.session = MagicMock()
             form = pagure.forms.AddUserForm()
             form = pagure.forms.AddUserForm()
             form.csrf_token.data = form.csrf_token.current_token
             form.csrf_token.data = form.csrf_token.current_token
             # No user or access given
             # No user or access given
             self.assertFalse(form.validate_on_submit())
             self.assertFalse(form.validate_on_submit())
             # No access given
             # No access given
-            form.user.data = 'foo'
+            form.user.data = "foo"
             self.assertFalse(form.validate_on_submit())
             self.assertFalse(form.validate_on_submit())
-            form.access.data = 'admin'
+            form.access.data = "admin"
             self.assertTrue(form.validate_on_submit())
             self.assertTrue(form.validate_on_submit())
 
 
     def test_add_user_to_group_form(self):
     def test_add_user_to_group_form(self):
         """ Test the AddUserToGroup form of pagure.forms """
         """ Test the AddUserToGroup form of pagure.forms """
-        with self.app.application.test_request_context(method='POST'):
+        with self.app.application.test_request_context(method="POST"):
             flask.g.session = MagicMock()
             flask.g.session = MagicMock()
             form = pagure.forms.AddUserToGroupForm()
             form = pagure.forms.AddUserToGroupForm()
             form.csrf_token.data = form.csrf_token.current_token
             form.csrf_token.data = form.csrf_token.current_token
             # No user given
             # No user given
             self.assertFalse(form.validate_on_submit())
             self.assertFalse(form.validate_on_submit())
-            form.user.data = 'foo'
+            form.user.data = "foo"
             # Everything given
             # Everything given
             self.assertTrue(form.validate_on_submit())
             self.assertTrue(form.validate_on_submit())
 
 
     def test_add_group_form(self):
     def test_add_group_form(self):
         """ Test the AddGroupForm form of pagure.forms """
         """ Test the AddGroupForm form of pagure.forms """
-        with self.app.application.test_request_context(method='POST'):
+        with self.app.application.test_request_context(method="POST"):
             flask.g.session = MagicMock()
             flask.g.session = MagicMock()
             form = pagure.forms.AddGroupForm()
             form = pagure.forms.AddGroupForm()
             form.csrf_token.data = form.csrf_token.current_token
             form.csrf_token.data = form.csrf_token.current_token
             # No group given
             # No group given
             self.assertFalse(form.validate_on_submit())
             self.assertFalse(form.validate_on_submit())
             # No access given
             # No access given
-            form.group.data = 'gname'
+            form.group.data = "gname"
             self.assertFalse(form.validate_on_submit())
             self.assertFalse(form.validate_on_submit())
-            form.access.data = 'admin'
+            form.access.data = "admin"
             self.assertTrue(form.validate_on_submit())
             self.assertTrue(form.validate_on_submit())
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)
-

File diff suppressed because it is too large
+ 296 - 336
tests/test_pagure_flask_internal.py


+ 171 - 148
tests/test_pagure_flask_rebase.py

@@ -19,8 +19,9 @@ import os
 import json
 import json
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import pagure.lib.tasks
 import pagure.lib.tasks
@@ -32,227 +33,238 @@ class PagureRebasetests(tests.Modeltests):
 
 
     maxDiff = None
     maxDiff = None
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def setUp(self):
     def setUp(self):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(PagureRebasetests, self).setUp()
         super(PagureRebasetests, self).setUp()
 
 
-        pagure.config.config['REQUESTS_FOLDER'] = None
+        pagure.config.config["REQUESTS_FOLDER"] = None
         tests.create_projects(self.session)
         tests.create_projects(self.session)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
         tests.create_projects_git(
         tests.create_projects_git(
-            os.path.join(self.path, 'repos'), bare=True)
-        tests.create_projects_git(
-            os.path.join(self.path, 'requests'), bare=True)
+            os.path.join(self.path, "requests"), bare=True
+        )
         tests.add_content_to_git(
         tests.add_content_to_git(
-            os.path.join(self.path, 'repos', 'test.git'),
-            branch='master', content="foobarbaz", filename="testfile")
+            os.path.join(self.path, "repos", "test.git"),
+            branch="master",
+            content="foobarbaz",
+            filename="testfile",
+        )
         tests.add_content_to_git(
         tests.add_content_to_git(
-            os.path.join(self.path, 'repos', 'test.git'),
-            branch='test', content="foobar", filename="sources")
-        tests.add_readme_git_repo(
-            os.path.join(self.path, 'repos', 'test.git'))
+            os.path.join(self.path, "repos", "test.git"),
+            branch="test",
+            content="foobar",
+            filename="sources",
+        )
+        tests.add_readme_git_repo(os.path.join(self.path, "repos", "test.git"))
 
 
         # Create a PR for these changes
         # Create a PR for these changes
-        project = pagure.lib.query.get_authorized_project(
-            self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         req = pagure.lib.query.new_pull_request(
         req = pagure.lib.query.new_pull_request(
             session=self.session,
             session=self.session,
             repo_from=project,
             repo_from=project,
-            branch_from='test',
+            branch_from="test",
             repo_to=project,
             repo_to=project,
-            branch_to='master',
-            title='PR from the test branch',
-            user='pingou',
+            branch_to="master",
+            title="PR from the test branch",
+            user="pingou",
         )
         )
         self.session.commit()
         self.session.commit()
         self.assertEqual(req.id, 1)
         self.assertEqual(req.id, 1)
-        self.assertEqual(req.title, 'PR from the test branch')
+        self.assertEqual(req.title, "PR from the test branch")
 
 
         self.project = pagure.lib.query.get_authorized_project(
         self.project = pagure.lib.query.get_authorized_project(
-            self.session, 'test')
+            self.session, "test"
+        )
         self.assertEqual(len(project.requests), 1)
         self.assertEqual(len(project.requests), 1)
         self.request = self.project.requests[0]
         self.request = self.project.requests[0]
 
 
     def test_merge_status_merge(self):
     def test_merge_status_merge(self):
         """ Test that the PR can be merged with a merge commit. """
         """ Test that the PR can be merged with a merge commit. """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            data = {'requestid': self.request.uid, 'csrf_token': self.get_csrf()}
-            output = self.app.post('/pv/pull-request/merge', data=data)
+            data = {
+                "requestid": self.request.uid,
+                "csrf_token": self.get_csrf(),
+            }
+            output = self.app.post("/pv/pull-request/merge", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
                 data,
                 data,
                 {
                 {
-                    u'code': u'MERGE',
-                    u'message': u'The pull-request can be merged with a '
-                        u'merge commit',
-                    u'short_code': u'With merge'
-                }
+                    "code": "MERGE",
+                    "message": "The pull-request can be merged with a "
+                    "merge commit",
+                    "short_code": "With merge",
+                },
             )
             )
 
 
     def test_merge_status_needsrebase(self):
     def test_merge_status_needsrebase(self):
         """ Test that the PR is marked as needing a rebase if the project
         """ Test that the PR is marked as needing a rebase if the project
         disables non-fast-forward merges. """
         disables non-fast-forward merges. """
         self.project = pagure.lib.query.get_authorized_project(
         self.project = pagure.lib.query.get_authorized_project(
-            self.session, 'test')
+            self.session, "test"
+        )
         settings = self.project.settings
         settings = self.project.settings
-        settings['disable_non_fast-forward_merges'] = True
+        settings["disable_non_fast-forward_merges"] = True
         self.project.settings = settings
         self.project.settings = settings
         self.session.add(self.project)
         self.session.add(self.project)
         self.session.commit()
         self.session.commit()
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            data = {'requestid': self.request.uid, 'csrf_token': self.get_csrf()}
-            output = self.app.post('/pv/pull-request/merge', data=data)
+            data = {
+                "requestid": self.request.uid,
+                "csrf_token": self.get_csrf(),
+            }
+            output = self.app.post("/pv/pull-request/merge", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
                 data,
                 data,
                 {
                 {
-                    u'code': u'NEEDSREBASE',
-                    u'message': u'The pull-request must be rebased before '
-                        u'merging',
-                    u'short_code': u'Needs rebase'
-                }
+                    "code": "NEEDSREBASE",
+                    "message": "The pull-request must be rebased before "
+                    "merging",
+                    "short_code": "Needs rebase",
+                },
             )
             )
 
 
     def test_rebase_task(self):
     def test_rebase_task(self):
         """ Test the rebase PR task and its outcome. """
         """ Test the rebase PR task and its outcome. """
         pagure.lib.tasks.rebase_pull_request(
         pagure.lib.tasks.rebase_pull_request(
-            'test', namespace=None, user=None, requestid=self.request.id,
-            user_rebaser='pingou')
+            "test",
+            namespace=None,
+            user=None,
+            requestid=self.request.id,
+            user_rebaser="pingou",
+        )
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            data = {'requestid': self.request.uid, 'csrf_token': self.get_csrf()}
-            output = self.app.post('/pv/pull-request/merge', data=data)
+            data = {
+                "requestid": self.request.uid,
+                "csrf_token": self.get_csrf(),
+            }
+            output = self.app.post("/pv/pull-request/merge", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
                 data,
                 data,
                 {
                 {
-                    u'code': u'FFORWARD',
-                    u'message': u'The pull-request can be merged and '
-                        u'fast-forwarded',
-                    u'short_code': u'Ok'
-                }
+                    "code": "FFORWARD",
+                    "message": "The pull-request can be merged and "
+                    "fast-forwarded",
+                    "short_code": "Ok",
+                },
             )
             )
 
 
     def test_rebase_api_ui_logged_in(self):
     def test_rebase_api_ui_logged_in(self):
         """ Test the rebase PR API endpoint when logged in from the UI and
         """ Test the rebase PR API endpoint when logged in from the UI and
         its outcome. """
         its outcome. """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             # Get the merge status first so it's cached and can be refreshed
             # Get the merge status first so it's cached and can be refreshed
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
-            data = {'requestid': self.request.uid, 'csrf_token': csrf_token}
-            output = self.app.post('/pv/pull-request/merge', data=data)
+            data = {"requestid": self.request.uid, "csrf_token": csrf_token}
+            output = self.app.post("/pv/pull-request/merge", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
                 data,
                 data,
                 {
                 {
-                    u'code': u'MERGE',
-                    u'message': u'The pull-request can be merged with '
-                        u'a merge commit',
-                    u'short_code': u'With merge'
-                }
+                    "code": "MERGE",
+                    "message": "The pull-request can be merged with "
+                    "a merge commit",
+                    "short_code": "With merge",
+                },
             )
             )
 
 
-            output = self.app.post('/api/0/test/pull-request/1/rebase')
+            output = self.app.post("/api/0/test/pull-request/1/rebase")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
-            self.assertEqual(
-                data,
-                {u'message': u'Pull-request rebased'}
-            )
+            self.assertEqual(data, {"message": "Pull-request rebased"})
 
 
-            data = {'requestid': self.request.uid, 'csrf_token': csrf_token}
-            output = self.app.post('/pv/pull-request/merge', data=data)
+            data = {"requestid": self.request.uid, "csrf_token": csrf_token}
+            output = self.app.post("/pv/pull-request/merge", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
                 data,
                 data,
                 {
                 {
-                    u'code': u'FFORWARD',
-                    u'message': u'The pull-request can be merged and '
-                        u'fast-forwarded',
-                    u'short_code': u'Ok'
-                }
+                    "code": "FFORWARD",
+                    "message": "The pull-request can be merged and "
+                    "fast-forwarded",
+                    "short_code": "Ok",
+                },
             )
             )
 
 
-            output = self.app.get('/test/pull-request/1')
+            output = self.app.get("/test/pull-request/1")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertIn('rebased onto', output_text)
-            repo = pagure.lib.query._get_project(self.session, 'test')
+            self.assertIn("rebased onto", output_text)
+            repo = pagure.lib.query._get_project(self.session, "test")
             self.assertEqual(
             self.assertEqual(
-                repo.requests[0].comments[0].user.username, 'pingou')
+                repo.requests[0].comments[0].user.username, "pingou"
+            )
 
 
     def test_rebase_api_ui_logged_in_different_user(self):
     def test_rebase_api_ui_logged_in_different_user(self):
         """ Test the rebase PR API endpoint when logged in from the UI and
         """ Test the rebase PR API endpoint when logged in from the UI and
         its outcome. """
         its outcome. """
         # Add 'foo' to the project 'test' so 'foo' can rebase the PR
         # Add 'foo' to the project 'test' so 'foo' can rebase the PR
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
         msg = pagure.lib.query.add_user_to_project(
         msg = pagure.lib.query.add_user_to_project(
-            session=self.session,
-            project=repo,
-            new_user='foo',
-            user='pingou',
+            session=self.session, project=repo, new_user="foo", user="pingou"
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'User added')
+        self.assertEqual(msg, "User added")
 
 
-        user = tests.FakeUser(username='foo')
+        user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             # Get the merge status first so it's cached and can be refreshed
             # Get the merge status first so it's cached and can be refreshed
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
-            data = {'requestid': self.request.uid, 'csrf_token': csrf_token}
-            output = self.app.post('/pv/pull-request/merge', data=data)
+            data = {"requestid": self.request.uid, "csrf_token": csrf_token}
+            output = self.app.post("/pv/pull-request/merge", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
                 data,
                 data,
                 {
                 {
-                    u'code': u'MERGE',
-                    u'message': u'The pull-request can be merged with '
-                        u'a merge commit',
-                    u'short_code': u'With merge'
-                }
+                    "code": "MERGE",
+                    "message": "The pull-request can be merged with "
+                    "a merge commit",
+                    "short_code": "With merge",
+                },
             )
             )
 
 
-            output = self.app.post('/api/0/test/pull-request/1/rebase')
+            output = self.app.post("/api/0/test/pull-request/1/rebase")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
-            self.assertEqual(
-                data,
-                {u'message': u'Pull-request rebased'}
-            )
+            self.assertEqual(data, {"message": "Pull-request rebased"})
 
 
-            data = {'requestid': self.request.uid, 'csrf_token': csrf_token}
-            output = self.app.post('/pv/pull-request/merge', data=data)
+            data = {"requestid": self.request.uid, "csrf_token": csrf_token}
+            output = self.app.post("/pv/pull-request/merge", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
                 data,
                 data,
                 {
                 {
-                    u'code': u'FFORWARD',
-                    u'message': u'The pull-request can be merged and '
-                        u'fast-forwarded',
-                    u'short_code': u'Ok'
-                }
+                    "code": "FFORWARD",
+                    "message": "The pull-request can be merged and "
+                    "fast-forwarded",
+                    "short_code": "Ok",
+                },
             )
             )
 
 
-            output = self.app.get('/test/pull-request/1')
+            output = self.app.get("/test/pull-request/1")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertIn('rebased onto', output_text)
-            repo = pagure.lib.query._get_project(self.session, 'test')
-            self.assertEqual(repo.requests[0].comments[0].user.username, 'foo')
+            self.assertIn("rebased onto", output_text)
+            repo = pagure.lib.query._get_project(self.session, "test")
+            self.assertEqual(repo.requests[0].comments[0].user.username, "foo")
 
 
     def test_rebase_api_api_logged_in(self):
     def test_rebase_api_api_logged_in(self):
         """ Test the rebase PR API endpoint when using an API token and
         """ Test the rebase PR API endpoint when using an API token and
@@ -261,65 +273,72 @@ class PagureRebasetests(tests.Modeltests):
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
         tests.create_tokens_acl(self.session)
         tests.create_tokens_acl(self.session)
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
-        output = self.app.post('/api/0/test/pull-request/1/rebase', headers=headers)
+        output = self.app.post(
+            "/api/0/test/pull-request/1/rebase", headers=headers
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
-        self.assertEqual(
-            data,
-            {u'message': u'Pull-request rebased'}
-        )
+        self.assertEqual(data, {"message": "Pull-request rebased"})
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
-            data = {'requestid': self.request.uid, 'csrf_token': self.get_csrf()}
-            output = self.app.post('/pv/pull-request/merge', data=data)
+            data = {
+                "requestid": self.request.uid,
+                "csrf_token": self.get_csrf(),
+            }
+            output = self.app.post("/pv/pull-request/merge", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
                 data,
                 data,
                 {
                 {
-                    u'code': u'FFORWARD',
-                    u'message': u'The pull-request can be merged and '
-                        u'fast-forwarded',
-                    u'short_code': u'Ok'
-                }
+                    "code": "FFORWARD",
+                    "message": "The pull-request can be merged and "
+                    "fast-forwarded",
+                    "short_code": "Ok",
+                },
             )
             )
 
 
     def test_rebase_api_conflicts(self):
     def test_rebase_api_conflicts(self):
         """ Test the rebase PR API endpoint when logged in from the UI and
         """ Test the rebase PR API endpoint when logged in from the UI and
         its outcome. """
         its outcome. """
         tests.add_content_to_git(
         tests.add_content_to_git(
-            os.path.join(self.path, 'repos', 'test.git'),
-            branch='master', content="foobar baz")
+            os.path.join(self.path, "repos", "test.git"),
+            branch="master",
+            content="foobar baz",
+        )
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post('/api/0/test/pull-request/1/rebase')
+            output = self.app.post("/api/0/test/pull-request/1/rebase")
             self.assertEqual(output.status_code, 400)
             self.assertEqual(output.status_code, 400)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
                 data,
                 data,
                 {
                 {
-                    u'error': u'Did not manage to rebase this pull-request',
-                    u'error_code': u'ENOCODE'
-                }
+                    "error": "Did not manage to rebase this pull-request",
+                    "error_code": "ENOCODE",
+                },
             )
             )
 
 
-            data = {'requestid': self.request.uid, 'csrf_token': self.get_csrf()}
-            output = self.app.post('/pv/pull-request/merge', data=data)
+            data = {
+                "requestid": self.request.uid,
+                "csrf_token": self.get_csrf(),
+            }
+            output = self.app.post("/pv/pull-request/merge", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
                 data,
                 data,
                 {
                 {
-                    u'code': u'CONFLICTS',
-                    u'message': u'The pull-request cannot be merged due '
-                        u'to conflicts',
-                    u'short_code': u'Conflicts'
-                }
+                    "code": "CONFLICTS",
+                    "message": "The pull-request cannot be merged due "
+                    "to conflicts",
+                    "short_code": "Conflicts",
+                },
             )
             )
 
 
     def test_rebase_api_api_logged_in_unknown_project(self):
     def test_rebase_api_api_logged_in_unknown_project(self):
@@ -328,14 +347,15 @@ class PagureRebasetests(tests.Modeltests):
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
         tests.create_tokens_acl(self.session)
         tests.create_tokens_acl(self.session)
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
-        output = self.app.post('/api/0/unknown/pull-request/1/rebase', headers=headers)
+        output = self.app.post(
+            "/api/0/unknown/pull-request/1/rebase", headers=headers
+        )
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertEqual(
         self.assertEqual(
-            data,
-            {u'error': u'Project not found', u'error_code': u'ENOPROJECT'}
+            data, {"error": "Project not found", "error_code": "ENOPROJECT"}
         )
         )
 
 
     def test_rebase_api_api_logged_in_unknown_pr(self):
     def test_rebase_api_api_logged_in_unknown_pr(self):
@@ -344,14 +364,15 @@ class PagureRebasetests(tests.Modeltests):
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
         tests.create_tokens_acl(self.session)
         tests.create_tokens_acl(self.session)
 
 
-        headers = {'Authorization': 'token aaabbbcccddd'}
+        headers = {"Authorization": "token aaabbbcccddd"}
 
 
-        output = self.app.post('/api/0/test/pull-request/404/rebase', headers=headers)
+        output = self.app.post(
+            "/api/0/test/pull-request/404/rebase", headers=headers
+        )
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertEqual(
         self.assertEqual(
-            data,
-            {u'error': u'Pull-Request not found', u'error_code': u'ENOREQ'}
+            data, {"error": "Pull-Request not found", "error_code": "ENOREQ"}
         )
         )
 
 
     def test_rebase_api_api_logged_in_unknown_token(self):
     def test_rebase_api_api_logged_in_unknown_token(self):
@@ -360,22 +381,24 @@ class PagureRebasetests(tests.Modeltests):
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
         tests.create_tokens_acl(self.session)
         tests.create_tokens_acl(self.session)
 
 
-        headers = {'Authorization': 'token unknown'}
+        headers = {"Authorization": "token unknown"}
 
 
-        output = self.app.post('/api/0/test/pull-request/1/rebase', headers=headers)
+        output = self.app.post(
+            "/api/0/test/pull-request/1/rebase", headers=headers
+        )
         self.assertEqual(output.status_code, 401)
         self.assertEqual(output.status_code, 401)
         data = json.loads(output.get_data(as_text=True))
         data = json.loads(output.get_data(as_text=True))
         self.assertEqual(
         self.assertEqual(
             data,
             data,
             {
             {
-                u'error': u'Invalid or expired token. Please visit '
-                    'http://localhost.localdomain/settings#api-keys to get '
-                    'or renew your API token.',
-                u'error_code': u'EINVALIDTOK',
-                u'errors': 'Invalid token',
-            }
+                "error": "Invalid or expired token. Please visit "
+                "http://localhost.localdomain/settings#api-keys to get "
+                "or renew your API token.",
+                "error_code": "EINVALIDTOK",
+                "errors": "Invalid token",
+            },
         )
         )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

File diff suppressed because it is too large
+ 579 - 397
tests/test_pagure_flask_ui_app.py


+ 166 - 179
tests/test_pagure_flask_ui_app_browse.py

@@ -16,8 +16,9 @@ import os
 
 
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import tests
 import tests
@@ -35,187 +36,176 @@ class PagureFlaskAppBrowsetests(tests.Modeltests):
         # Add a 3rd project with a long description
         # Add a 3rd project with a long description
         item = pagure.lib.model.Project(
         item = pagure.lib.model.Project(
             user_id=2,  # foo
             user_id=2,  # foo
-            name='test3',
-            description='test project #3 with a very long description',
-            hook_token='aaabbbeeefff',
+            name="test3",
+            description="test project #3 with a very long description",
+            hook_token="aaabbbeeefff",
             private=True,
             private=True,
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
 
 
-    @patch.dict('pagure.config.config', {'PRIVATE_PROJECTS': True})
+    @patch.dict("pagure.config.config", {"PRIVATE_PROJECTS": True})
     def test_browse_project_logged_in_private_project(self):
     def test_browse_project_logged_in_private_project(self):
         """ Test the browse project endpoint when logged in with a private
         """ Test the browse project endpoint when logged in with a private
         project. """
         project. """
 
 
-        user = tests.FakeUser(username='foo')
+        user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/browse/projects/')
+            output = self.app.get("/browse/projects/")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertIn(
-                '<title>Home - Pagure</title>\n',
-                output_text)
+            self.assertIn("<title>Home - Pagure</title>\n", output_text)
             self.assertIn(
             self.assertIn(
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<span class="badge badge-secondary">4</span></h3>',
                 '<span class="badge badge-secondary">4</span></h3>',
-                output_text)
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<span title="Private Project" class="text-danger '
                 '<span title="Private Project" class="text-danger '
                 'fa fa-fw fa-lock"></span>',
                 'fa fa-fw fa-lock"></span>',
-                output_text)
+                output_text,
+            )
             self.assertEqual(output_text.count('title="Private Project"'), 1)
             self.assertEqual(output_text.count('title="Private Project"'), 1)
 
 
-    @patch.dict('pagure.config.config', {'PRIVATE_PROJECTS': True})
+    @patch.dict("pagure.config.config", {"PRIVATE_PROJECTS": True})
     def test_browse_project_unauth_private_project(self):
     def test_browse_project_unauth_private_project(self):
         """ Test the browse project endpoint when logged out with a private
         """ Test the browse project endpoint when logged out with a private
         project. """
         project. """
 
 
-        output = self.app.get('/browse/projects/')
+        output = self.app.get("/browse/projects/")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
-        self.assertIn(
-            '<title>Home - Pagure</title>\n',
-            output_text)
+        self.assertIn("<title>Home - Pagure</title>\n", output_text)
         self.assertIn(
         self.assertIn(
             '<h3 class="m-0 font-weight-bold">All Projects '
             '<h3 class="m-0 font-weight-bold">All Projects '
             '<span class="badge badge-secondary">3</span></h3>',
             '<span class="badge badge-secondary">3</span></h3>',
-            output_text)
+            output_text,
+        )
         self.assertNotIn(
         self.assertNotIn(
             '<span title="Private Project" class="text-danger '
             '<span title="Private Project" class="text-danger '
             'fa fa-fw fa-lock"></span>',
             'fa fa-fw fa-lock"></span>',
-            output_text)
+            output_text,
+        )
         self.assertEqual(output_text.count('title="Private Project"'), 0)
         self.assertEqual(output_text.count('title="Private Project"'), 0)
 
 
-    @patch.dict('pagure.config.config', {'PRIVATE_PROJECTS': True})
+    @patch.dict("pagure.config.config", {"PRIVATE_PROJECTS": True})
     def test_browse_project_logged_in_no_access_private_project(self):
     def test_browse_project_logged_in_no_access_private_project(self):
         """ Test the browse project endpoint when logged in as an user that
         """ Test the browse project endpoint when logged in as an user that
         has no access to the private project. """
         has no access to the private project. """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/browse/projects/')
+            output = self.app.get("/browse/projects/")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertIn(
-                '<title>Home - Pagure</title>\n',
-                output_text)
+            self.assertIn("<title>Home - Pagure</title>\n", output_text)
             self.assertIn(
             self.assertIn(
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<span class="badge badge-secondary">3</span></h3>',
                 '<span class="badge badge-secondary">3</span></h3>',
-                output_text)
+                output_text,
+            )
             self.assertNotIn(
             self.assertNotIn(
                 '<span title="Private Project" class="text-danger '
                 '<span title="Private Project" class="text-danger '
                 'fa fa-fw fa-lock"></span>',
                 'fa fa-fw fa-lock"></span>',
-                output_text)
+                output_text,
+            )
             self.assertEqual(output_text.count('title="Private Project"'), 0)
             self.assertEqual(output_text.count('title="Private Project"'), 0)
 
 
-    @patch.dict('pagure.config.config', {'PRIVATE_PROJECTS': True})
+    @patch.dict("pagure.config.config", {"PRIVATE_PROJECTS": True})
     def test_browse_project_logged_in_ticket_private_project(self):
     def test_browse_project_logged_in_ticket_private_project(self):
         """ Test the browse project endpoint when logged in as an user that
         """ Test the browse project endpoint when logged in as an user that
         has no access to the private project. """
         has no access to the private project. """
 
 
         # Add user 'pingou' with ticket access on repo
         # Add user 'pingou' with ticket access on repo
-        repo = pagure.lib.query._get_project(self.session, 'test3')
+        repo = pagure.lib.query._get_project(self.session, "test3")
         msg = pagure.lib.query.add_user_to_project(
         msg = pagure.lib.query.add_user_to_project(
-            self.session,
-            repo,
-            new_user='pingou',
-            user='foo',
-            access='ticket',
+            self.session, repo, new_user="pingou", user="foo", access="ticket"
         )
         )
-        self.assertEqual(msg, 'User added')
+        self.assertEqual(msg, "User added")
         self.session.commit()
         self.session.commit()
 
 
         # Ticket access level isn't sufficient to access private projects
         # Ticket access level isn't sufficient to access private projects
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/browse/projects/')
+            output = self.app.get("/browse/projects/")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertIn(
-                '<title>Home - Pagure</title>\n',
-                output_text)
+            self.assertIn("<title>Home - Pagure</title>\n", output_text)
             self.assertIn(
             self.assertIn(
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<span class="badge badge-secondary">3</span></h3>',
                 '<span class="badge badge-secondary">3</span></h3>',
-                output_text)
+                output_text,
+            )
             self.assertNotIn(
             self.assertNotIn(
                 '<span title="Private Project" class="text-danger '
                 '<span title="Private Project" class="text-danger '
                 'fa fa-fw fa-lock"></span>',
                 'fa fa-fw fa-lock"></span>',
-                output_text)
+                output_text,
+            )
             self.assertEqual(output_text.count('title="Private Project"'), 0)
             self.assertEqual(output_text.count('title="Private Project"'), 0)
 
 
-    @patch.dict('pagure.config.config', {'PRIVATE_PROJECTS': True})
+    @patch.dict("pagure.config.config", {"PRIVATE_PROJECTS": True})
     def test_browse_project_logged_in_commit_private_project(self):
     def test_browse_project_logged_in_commit_private_project(self):
         """ Test the browse project endpoint when logged in as an user that
         """ Test the browse project endpoint when logged in as an user that
         has no access to the private project. """
         has no access to the private project. """
 
 
         # Add user 'pingou' with commit access on repo
         # Add user 'pingou' with commit access on repo
-        repo = pagure.lib.query._get_project(self.session, 'test3')
+        repo = pagure.lib.query._get_project(self.session, "test3")
         msg = pagure.lib.query.add_user_to_project(
         msg = pagure.lib.query.add_user_to_project(
-            self.session,
-            repo,
-            new_user='pingou',
-            user='foo',
-            access='commit',
+            self.session, repo, new_user="pingou", user="foo", access="commit"
         )
         )
-        self.assertEqual(msg, 'User added')
+        self.assertEqual(msg, "User added")
         self.session.commit()
         self.session.commit()
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/browse/projects/')
+            output = self.app.get("/browse/projects/")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertIn(
-                '<title>Home - Pagure</title>\n',
-                output_text)
+            self.assertIn("<title>Home - Pagure</title>\n", output_text)
             self.assertIn(
             self.assertIn(
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<span class="badge badge-secondary">4</span></h3>',
                 '<span class="badge badge-secondary">4</span></h3>',
-                output_text)
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<span title="Private Project" class="text-danger '
                 '<span title="Private Project" class="text-danger '
                 'fa fa-fw fa-lock"></span>',
                 'fa fa-fw fa-lock"></span>',
-                output_text)
+                output_text,
+            )
             self.assertEqual(output_text.count('title="Private Project"'), 1)
             self.assertEqual(output_text.count('title="Private Project"'), 1)
 
 
-    @patch.dict('pagure.config.config', {'PRIVATE_PROJECTS': True})
+    @patch.dict("pagure.config.config", {"PRIVATE_PROJECTS": True})
     def test_browse_project_logged_in_admin_private_project(self):
     def test_browse_project_logged_in_admin_private_project(self):
         """ Test the browse project endpoint when logged in as an user that
         """ Test the browse project endpoint when logged in as an user that
         has no access to the private project. """
         has no access to the private project. """
 
 
         # Add user 'pingou' with admin access on repo
         # Add user 'pingou' with admin access on repo
-        repo = pagure.lib.query._get_project(self.session, 'test3')
+        repo = pagure.lib.query._get_project(self.session, "test3")
         msg = pagure.lib.query.add_user_to_project(
         msg = pagure.lib.query.add_user_to_project(
-            self.session,
-            repo,
-            new_user='pingou',
-            user='foo',
-            access='admin',
+            self.session, repo, new_user="pingou", user="foo", access="admin"
         )
         )
-        self.assertEqual(msg, 'User added')
+        self.assertEqual(msg, "User added")
         self.session.commit()
         self.session.commit()
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/browse/projects/')
+            output = self.app.get("/browse/projects/")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertIn(
-                '<title>Home - Pagure</title>\n',
-                output_text)
+            self.assertIn("<title>Home - Pagure</title>\n", output_text)
             self.assertIn(
             self.assertIn(
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<span class="badge badge-secondary">4</span></h3>',
                 '<span class="badge badge-secondary">4</span></h3>',
-                output_text)
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<span title="Private Project" class="text-danger '
                 '<span title="Private Project" class="text-danger '
                 'fa fa-fw fa-lock"></span>',
                 'fa fa-fw fa-lock"></span>',
-                output_text)
+                output_text,
+            )
             self.assertEqual(output_text.count('title="Private Project"'), 1)
             self.assertEqual(output_text.count('title="Private Project"'), 1)
 
 
+
 class PagureFlaskAppBrowseGroupAdmintests(tests.Modeltests):
 class PagureFlaskAppBrowseGroupAdmintests(tests.Modeltests):
     """ Tests for the browse pages of flask app controller of pagure """
     """ Tests for the browse pages of flask app controller of pagure """
 
 
@@ -228,9 +218,9 @@ class PagureFlaskAppBrowseGroupAdmintests(tests.Modeltests):
         # Add a 3rd project with a long description
         # Add a 3rd project with a long description
         item = pagure.lib.model.Project(
         item = pagure.lib.model.Project(
             user_id=2,  # foo
             user_id=2,  # foo
-            name='test3',
-            description='test project #3 with a very long description',
-            hook_token='aaabbbeeefff',
+            name="test3",
+            description="test project #3 with a very long description",
+            hook_token="aaabbbeeefff",
             private=True,
             private=True,
         )
         )
         self.session.add(item)
         self.session.add(item)
@@ -239,85 +229,84 @@ class PagureFlaskAppBrowseGroupAdmintests(tests.Modeltests):
         # Create a group
         # Create a group
         msg = pagure.lib.query.add_group(
         msg = pagure.lib.query.add_group(
             self.session,
             self.session,
-            group_name='JL',
-            display_name='Justice League',
-            description='Nope, it\'s not JLA anymore',
-            group_type='user',
-            user='foo',
+            group_name="JL",
+            display_name="Justice League",
+            description="Nope, it's not JLA anymore",
+            group_type="user",
+            user="foo",
             is_admin=False,
             is_admin=False,
-            blacklist=pagure.config.config.get('BLACKLISTED_PROJECTS')
+            blacklist=pagure.config.config.get("BLACKLISTED_PROJECTS"),
         )
         )
 
 
-        self.assertEqual(msg, 'User `foo` added to the group `JL`.')
+        self.assertEqual(msg, "User `foo` added to the group `JL`.")
 
 
         # Add the group to project we just created, test3
         # Add the group to project we just created, test3
         # Add it with admin ACL
         # Add it with admin ACL
-        project = pagure.lib.query._get_project(self.session, 'test3')
+        project = pagure.lib.query._get_project(self.session, "test3")
         msg = pagure.lib.query.add_group_to_project(
         msg = pagure.lib.query.add_group_to_project(
             self.session,
             self.session,
             project=project,
             project=project,
-            new_group='JL',
-            user='foo',
-            access='admin'
+            new_group="JL",
+            user="foo",
+            access="admin",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'Group added')
+        self.assertEqual(msg, "Group added")
 
 
-    @patch.dict('pagure.config.config', {'PRIVATE_PROJECTS': True})
+    @patch.dict("pagure.config.config", {"PRIVATE_PROJECTS": True})
     def test_browse_project_user_not_in_group(self):
     def test_browse_project_user_not_in_group(self):
         """ Test the browse project endpoint when logged in as an user that
         """ Test the browse project endpoint when logged in as an user that
         has no access to the private project via a group as admin. """
         has no access to the private project via a group as admin. """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/browse/projects/')
+            output = self.app.get("/browse/projects/")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertIn(
-                '<title>Home - Pagure</title>\n',
-                output_text)
+            self.assertIn("<title>Home - Pagure</title>\n", output_text)
             self.assertIn(
             self.assertIn(
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<span class="badge badge-secondary">3</span></h3>',
                 '<span class="badge badge-secondary">3</span></h3>',
-                output_text)
+                output_text,
+            )
             self.assertNotIn(
             self.assertNotIn(
                 '<span title="Private project" class="text-danger '
                 '<span title="Private project" class="text-danger '
                 'fa fa-fw fa-lock"></span>',
                 'fa fa-fw fa-lock"></span>',
-                output_text)
+                output_text,
+            )
             self.assertEqual(output_text.count('title="Private project"'), 0)
             self.assertEqual(output_text.count('title="Private project"'), 0)
 
 
-    @patch.dict('pagure.config.config', {'PRIVATE_PROJECTS': True})
+    @patch.dict("pagure.config.config", {"PRIVATE_PROJECTS": True})
     def test_browse_project_user_in_group(self):
     def test_browse_project_user_in_group(self):
         """ Test the browse project endpoint when logged in as an user that
         """ Test the browse project endpoint when logged in as an user that
         has no access to the private project via a group as admin. """
         has no access to the private project via a group as admin. """
-        group = pagure.lib.query.search_groups(
-            self.session, group_name='JL')
+        group = pagure.lib.query.search_groups(self.session, group_name="JL")
 
 
         pagure.lib.query.add_user_to_group(
         pagure.lib.query.add_user_to_group(
             session=self.session,
             session=self.session,
-            username='pingou',
+            username="pingou",
             group=group,
             group=group,
-            user='foo',
+            user="foo",
             is_admin=False,
             is_admin=False,
         )
         )
         self.session.commit()
         self.session.commit()
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/browse/projects/')
+            output = self.app.get("/browse/projects/")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertIn(
-                '<title>Home - Pagure</title>\n',
-                output_text)
+            self.assertIn("<title>Home - Pagure</title>\n", output_text)
             self.assertIn(
             self.assertIn(
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<span class="badge badge-secondary">4</span></h3>',
                 '<span class="badge badge-secondary">4</span></h3>',
-                output_text)
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<span title="Private Project" class="text-danger '
                 '<span title="Private Project" class="text-danger '
                 'fa fa-fw fa-lock"></span>',
                 'fa fa-fw fa-lock"></span>',
-                output_text)
+                output_text,
+            )
             self.assertEqual(output_text.count('title="Private Project"'), 1)
             self.assertEqual(output_text.count('title="Private Project"'), 1)
 
 
 
 
@@ -333,9 +322,9 @@ class PagureFlaskAppBrowseGroupCommittests(tests.Modeltests):
         # Add a 3rd project with a long description
         # Add a 3rd project with a long description
         item = pagure.lib.model.Project(
         item = pagure.lib.model.Project(
             user_id=2,  # foo
             user_id=2,  # foo
-            name='test3',
-            description='test project #3 with a very long description',
-            hook_token='aaabbbeeefff',
+            name="test3",
+            description="test project #3 with a very long description",
+            hook_token="aaabbbeeefff",
             private=True,
             private=True,
         )
         )
         self.session.add(item)
         self.session.add(item)
@@ -344,85 +333,84 @@ class PagureFlaskAppBrowseGroupCommittests(tests.Modeltests):
         # Create a group
         # Create a group
         msg = pagure.lib.query.add_group(
         msg = pagure.lib.query.add_group(
             self.session,
             self.session,
-            group_name='JL',
-            display_name='Justice League',
-            description='Nope, it\'s not JLA anymore',
-            group_type='user',
-            user='foo',
+            group_name="JL",
+            display_name="Justice League",
+            description="Nope, it's not JLA anymore",
+            group_type="user",
+            user="foo",
             is_admin=False,
             is_admin=False,
-            blacklist=pagure.config.config.get('BLACKLISTED_PROJECTS')
+            blacklist=pagure.config.config.get("BLACKLISTED_PROJECTS"),
         )
         )
 
 
-        self.assertEqual(msg, 'User `foo` added to the group `JL`.')
+        self.assertEqual(msg, "User `foo` added to the group `JL`.")
 
 
         # Add the group to project we just created, test3
         # Add the group to project we just created, test3
         # Add it with commit ACL
         # Add it with commit ACL
-        project = pagure.lib.query._get_project(self.session, 'test3')
+        project = pagure.lib.query._get_project(self.session, "test3")
         msg = pagure.lib.query.add_group_to_project(
         msg = pagure.lib.query.add_group_to_project(
             self.session,
             self.session,
             project=project,
             project=project,
-            new_group='JL',
-            user='foo',
-            access='commit'
+            new_group="JL",
+            user="foo",
+            access="commit",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'Group added')
+        self.assertEqual(msg, "Group added")
 
 
-    @patch.dict('pagure.config.config', {'PRIVATE_PROJECTS': True})
+    @patch.dict("pagure.config.config", {"PRIVATE_PROJECTS": True})
     def test_browse_project_user_not_in_group(self):
     def test_browse_project_user_not_in_group(self):
         """ Test the browse project endpoint when logged in as an user that
         """ Test the browse project endpoint when logged in as an user that
         has no access to the private project via a group as admin. """
         has no access to the private project via a group as admin. """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/browse/projects/')
+            output = self.app.get("/browse/projects/")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertIn(
-                '<title>Home - Pagure</title>\n',
-                output_text)
+            self.assertIn("<title>Home - Pagure</title>\n", output_text)
             self.assertIn(
             self.assertIn(
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<span class="badge badge-secondary">3</span></h3>',
                 '<span class="badge badge-secondary">3</span></h3>',
-                output_text)
+                output_text,
+            )
             self.assertNotIn(
             self.assertNotIn(
                 '<span title="Private project" class="text-danger '
                 '<span title="Private project" class="text-danger '
                 'fa fa-fw fa-lock"></span>',
                 'fa fa-fw fa-lock"></span>',
-                output_text)
+                output_text,
+            )
             self.assertEqual(output_text.count('title="Private project"'), 0)
             self.assertEqual(output_text.count('title="Private project"'), 0)
 
 
-    @patch.dict('pagure.config.config', {'PRIVATE_PROJECTS': True})
+    @patch.dict("pagure.config.config", {"PRIVATE_PROJECTS": True})
     def test_browse_project_user_in_group(self):
     def test_browse_project_user_in_group(self):
         """ Test the browse project endpoint when logged in as an user that
         """ Test the browse project endpoint when logged in as an user that
         has no access to the private project via a group as admin. """
         has no access to the private project via a group as admin. """
-        group = pagure.lib.query.search_groups(
-            self.session, group_name='JL')
+        group = pagure.lib.query.search_groups(self.session, group_name="JL")
 
 
         pagure.lib.query.add_user_to_group(
         pagure.lib.query.add_user_to_group(
             session=self.session,
             session=self.session,
-            username='pingou',
+            username="pingou",
             group=group,
             group=group,
-            user='foo',
+            user="foo",
             is_admin=False,
             is_admin=False,
         )
         )
         self.session.commit()
         self.session.commit()
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/browse/projects/')
+            output = self.app.get("/browse/projects/")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertIn(
-                '<title>Home - Pagure</title>\n',
-                output_text)
+            self.assertIn("<title>Home - Pagure</title>\n", output_text)
             self.assertIn(
             self.assertIn(
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<span class="badge badge-secondary">4</span></h3>',
                 '<span class="badge badge-secondary">4</span></h3>',
-                output_text)
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<span title="Private Project" class="text-danger '
                 '<span title="Private Project" class="text-danger '
                 'fa fa-fw fa-lock"></span>',
                 'fa fa-fw fa-lock"></span>',
-                output_text)
+                output_text,
+            )
             self.assertEqual(output_text.count('title="Private Project"'), 1)
             self.assertEqual(output_text.count('title="Private Project"'), 1)
 
 
 
 
@@ -438,9 +426,9 @@ class PagureFlaskAppBrowseGroupTickettests(tests.Modeltests):
         # Add a 3rd project with a long description
         # Add a 3rd project with a long description
         item = pagure.lib.model.Project(
         item = pagure.lib.model.Project(
             user_id=2,  # foo
             user_id=2,  # foo
-            name='test3',
-            description='test project #3 with a very long description',
-            hook_token='aaabbbeeefff',
+            name="test3",
+            description="test project #3 with a very long description",
+            hook_token="aaabbbeeefff",
             private=True,
             private=True,
         )
         )
         self.session.add(item)
         self.session.add(item)
@@ -449,88 +437,87 @@ class PagureFlaskAppBrowseGroupTickettests(tests.Modeltests):
         # Create a group
         # Create a group
         msg = pagure.lib.query.add_group(
         msg = pagure.lib.query.add_group(
             self.session,
             self.session,
-            group_name='JL',
-            display_name='Justice League',
-            description='Nope, it\'s not JLA anymore',
-            group_type='user',
-            user='foo',
+            group_name="JL",
+            display_name="Justice League",
+            description="Nope, it's not JLA anymore",
+            group_type="user",
+            user="foo",
             is_admin=False,
             is_admin=False,
-            blacklist=pagure.config.config.get('BLACKLISTED_PROJECTS')
+            blacklist=pagure.config.config.get("BLACKLISTED_PROJECTS"),
         )
         )
 
 
-        self.assertEqual(msg, 'User `foo` added to the group `JL`.')
+        self.assertEqual(msg, "User `foo` added to the group `JL`.")
 
 
         # Add the group to project we just created, test3
         # Add the group to project we just created, test3
         # Add it with ticket ACL
         # Add it with ticket ACL
-        project = pagure.lib.query._get_project(self.session, 'test3')
+        project = pagure.lib.query._get_project(self.session, "test3")
         msg = pagure.lib.query.add_group_to_project(
         msg = pagure.lib.query.add_group_to_project(
             self.session,
             self.session,
             project=project,
             project=project,
-            new_group='JL',
-            user='foo',
-            access='ticket'
+            new_group="JL",
+            user="foo",
+            access="ticket",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'Group added')
+        self.assertEqual(msg, "Group added")
 
 
-    @patch.dict('pagure.config.config', {'PRIVATE_PROJECTS': True})
+    @patch.dict("pagure.config.config", {"PRIVATE_PROJECTS": True})
     def test_browse_project_user_not_in_group(self):
     def test_browse_project_user_not_in_group(self):
         """ Test the browse project endpoint when logged in as an user that
         """ Test the browse project endpoint when logged in as an user that
         has no access to the private project via a group as admin. """
         has no access to the private project via a group as admin. """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/browse/projects/')
+            output = self.app.get("/browse/projects/")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertIn(
-                '<title>Home - Pagure</title>\n',
-                output_text)
+            self.assertIn("<title>Home - Pagure</title>\n", output_text)
             self.assertIn(
             self.assertIn(
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<span class="badge badge-secondary">3</span></h3>',
                 '<span class="badge badge-secondary">3</span></h3>',
-                output_text)
+                output_text,
+            )
             self.assertNotIn(
             self.assertNotIn(
                 '<span title="Private Project" class="text-danger '
                 '<span title="Private Project" class="text-danger '
                 'fa fa-fw fa-lock"></span>',
                 'fa fa-fw fa-lock"></span>',
-                output_text)
+                output_text,
+            )
             self.assertEqual(output_text.count('title="Private Project"'), 0)
             self.assertEqual(output_text.count('title="Private Project"'), 0)
 
 
-    @patch.dict('pagure.config.config', {'PRIVATE_PROJECTS': True})
+    @patch.dict("pagure.config.config", {"PRIVATE_PROJECTS": True})
     def test_browse_project_user_in_group(self):
     def test_browse_project_user_in_group(self):
         """ Test the browse project endpoint when logged in as an user that
         """ Test the browse project endpoint when logged in as an user that
         has no access to the private project via a group as admin. """
         has no access to the private project via a group as admin. """
-        group = pagure.lib.query.search_groups(
-            self.session, group_name='JL')
+        group = pagure.lib.query.search_groups(self.session, group_name="JL")
 
 
         pagure.lib.query.add_user_to_group(
         pagure.lib.query.add_user_to_group(
             session=self.session,
             session=self.session,
-            username='pingou',
+            username="pingou",
             group=group,
             group=group,
-            user='foo',
+            user="foo",
             is_admin=False,
             is_admin=False,
         )
         )
         self.session.commit()
         self.session.commit()
 
 
         # Ticket ACL isn't enough to grant you access
         # Ticket ACL isn't enough to grant you access
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/browse/projects/')
+            output = self.app.get("/browse/projects/")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertIn(
-                '<title>Home - Pagure</title>\n',
-                output_text)
+            self.assertIn("<title>Home - Pagure</title>\n", output_text)
             self.assertIn(
             self.assertIn(
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<span class="badge badge-secondary">3</span></h3>',
                 '<span class="badge badge-secondary">3</span></h3>',
-                output_text)
+                output_text,
+            )
             self.assertNotIn(
             self.assertNotIn(
                 '<span title="Private Project" class="text-danger '
                 '<span title="Private Project" class="text-danger '
                 'fa fa-fw fa-lock"></span>',
                 'fa fa-fw fa-lock"></span>',
-                output_text)
+                output_text,
+            )
             self.assertEqual(output_text.count('title="Private Project"'), 0)
             self.assertEqual(output_text.count('title="Private Project"'), 0)
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 152 - 146
tests/test_pagure_flask_ui_app_give_project.py

@@ -18,8 +18,9 @@ import os
 
 
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure
 import pagure
 import pagure.lib.query
 import pagure.lib.query
@@ -33,48 +34,50 @@ class PagureFlaskGiveRepotests(tests.SimplePagureTest):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(PagureFlaskGiveRepotests, self).setUp()
         super(PagureFlaskGiveRepotests, self).setUp()
 
 
-        pagure.config.config['VIRUS_SCAN_ATTACHMENTS'] = False
-        pagure.config.config['UPLOAD_FOLDER_URL'] = '/releases/'
-        pagure.config.config['UPLOAD_FOLDER_PATH'] = os.path.join(
-            self.path, 'releases')
+        pagure.config.config["VIRUS_SCAN_ATTACHMENTS"] = False
+        pagure.config.config["UPLOAD_FOLDER_URL"] = "/releases/"
+        pagure.config.config["UPLOAD_FOLDER_PATH"] = os.path.join(
+            self.path, "releases"
+        )
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
-        self._check_user(user='pingou')
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
+        self._check_user(user="pingou")
 
 
-    def _check_user(self, user='pingou'):
+    def _check_user(self, user="pingou"):
         self.session.commit()
         self.session.commit()
         project = pagure.lib.query.get_authorized_project(
         project = pagure.lib.query.get_authorized_project(
-            self.session, project_name='test')
+            self.session, project_name="test"
+        )
         self.assertEqual(project.user.user, user)
         self.assertEqual(project.user.user, user)
 
 
     def test_give_project_no_project(self):
     def test_give_project_no_project(self):
         """ Test the give_project endpoint. """
         """ Test the give_project endpoint. """
 
 
         # No such project
         # No such project
-        output = self.app.post('/test42/give')
+        output = self.app.post("/test42/give")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
     def test_give_project_no_csrf(self):
     def test_give_project_no_csrf(self):
         """ Test the give_project endpoint. """
         """ Test the give_project endpoint. """
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
             self._check_user()
             self._check_user()
 
 
             # Missing CSRF
             # Missing CSRF
-            data = {
-                'user': 'foo',
-            }
+            data = {"user": "foo"}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/give', data=data, follow_redirects=True)
+                "/test/give", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                '<title>Overview - test - Pagure</title>',
-                output.get_data(as_text=True))
+                "<title>Overview - test - Pagure</title>",
+                output.get_data(as_text=True),
+            )
 
 
             self._check_user()
             self._check_user()
 
 
@@ -82,24 +85,23 @@ class PagureFlaskGiveRepotests(tests.SimplePagureTest):
         """ Test the give_project endpoint. """
         """ Test the give_project endpoint. """
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             self._check_user()
             self._check_user()
 
 
             # Invalid user
             # Invalid user
-            data = {
-                'user': 'foobar',
-                'csrf_token': csrf_token,
-            }
+            data = {"user": "foobar", "csrf_token": csrf_token}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/give', data=data, follow_redirects=True)
+                "/test/give", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
             self.assertIn(
             self.assertIn(
-                '<p>No such user foobar found</p>',
-                output.get_data(as_text=True))
+                "<p>No such user foobar found</p>",
+                output.get_data(as_text=True),
+            )
 
 
             self._check_user()
             self._check_user()
 
 
@@ -107,21 +109,22 @@ class PagureFlaskGiveRepotests(tests.SimplePagureTest):
         """ Test the give_project endpoint. """
         """ Test the give_project endpoint. """
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             self._check_user()
             self._check_user()
 
 
             # No user
             # No user
-            data = {
-                'csrf_token': csrf_token,
-            }
+            data = {"csrf_token": csrf_token}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/give', data=data, follow_redirects=True)
+                "/test/give", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
-            self.assertIn('<p>No user specified</p>', output.get_data(as_text=True))
+            self.assertIn(
+                "<p>No user specified</p>", output.get_data(as_text=True)
+            )
 
 
             self._check_user()
             self._check_user()
 
 
@@ -129,24 +132,24 @@ class PagureFlaskGiveRepotests(tests.SimplePagureTest):
         """ Test the give_project endpoint. """
         """ Test the give_project endpoint. """
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'foo'
+        user.username = "foo"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             self._check_user()
             self._check_user()
 
 
             # User isn't the admin
             # User isn't the admin
-            data = {
-                'user': 'foo',
-                'csrf_token': csrf_token,
-            }
+            data = {"user": "foo", "csrf_token": csrf_token}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/give', data=data, follow_redirects=True)
+                "/test/give", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 403)
             self.assertEqual(output.status_code, 403)
             self.assertIn(
             self.assertIn(
-                '<p>You are not allowed to change the settings for this '
-                'project</p>', output.get_data(as_text=True))
+                "<p>You are not allowed to change the settings for this "
+                "project</p>",
+                output.get_data(as_text=True),
+            )
 
 
             self._check_user()
             self._check_user()
 
 
@@ -154,65 +157,66 @@ class PagureFlaskGiveRepotests(tests.SimplePagureTest):
         """ Test the give_project endpoint. """
         """ Test the give_project endpoint. """
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'foo'
+        user.username = "foo"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             self._check_user()
             self._check_user()
 
 
             # User isn't the admin
             # User isn't the admin
-            data = {
-                'user': 'foo',
-                'csrf_token': csrf_token,
-            }
+            data = {"user": "foo", "csrf_token": csrf_token}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/give', data=data, follow_redirects=True)
+                "/test/give", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 403)
             self.assertEqual(output.status_code, 403)
             self.assertIn(
             self.assertIn(
-                '<p>You are not allowed to change the settings for this '
-                'project</p>', output.get_data(as_text=True))
+                "<p>You are not allowed to change the settings for this "
+                "project</p>",
+                output.get_data(as_text=True),
+            )
 
 
             self._check_user()
             self._check_user()
 
 
     def test_give_project_not_owner_but_is_admin(self):
     def test_give_project_not_owner_but_is_admin(self):
         """ Test the give_project endpoint. """
         """ Test the give_project endpoint. """
         project = pagure.lib.query.get_authorized_project(
         project = pagure.lib.query.get_authorized_project(
-            self.session, project_name='test')
+            self.session, project_name="test"
+        )
 
 
         msg = pagure.lib.query.add_user_to_project(
         msg = pagure.lib.query.add_user_to_project(
             self.session,
             self.session,
             project=project,
             project=project,
-            new_user='foo',
-            user='pingou',
-            access='admin')
+            new_user="foo",
+            user="pingou",
+            access="admin",
+        )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'User added')
+        self.assertEqual(msg, "User added")
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'foo'
+        user.username = "foo"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             self._check_user()
             self._check_user()
 
 
             # User isn't the owner
             # User isn't the owner
-            data = {
-                'user': 'foo',
-                'csrf_token': csrf_token,
-            }
+            data = {"user": "foo", "csrf_token": csrf_token}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/give', data=data, follow_redirects=True)
+                "/test/give", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 403)
             self.assertEqual(output.status_code, 403)
             self.assertIn(
             self.assertIn(
-                '<p>You are not allowed to give this project</p>',
-                output.get_data(as_text=True))
+                "<p>You are not allowed to give this project</p>",
+                output.get_data(as_text=True),
+            )
 
 
             self._check_user()
             self._check_user()
 
 
-    @patch.dict('pagure.config.config', {'PAGURE_ADMIN_USERS': 'foo'})
-    @patch('pagure.lib.git.generate_gitolite_acls', MagicMock())
+    @patch.dict("pagure.config.config", {"PAGURE_ADMIN_USERS": "foo"})
+    @patch("pagure.lib.git.generate_gitolite_acls", MagicMock())
     def test_give_project_not_owner_but_admin(self):
     def test_give_project_not_owner_but_admin(self):
         """ Test the give_project endpoint.
         """ Test the give_project endpoint.
 
 
@@ -221,194 +225,196 @@ class PagureFlaskGiveRepotests(tests.SimplePagureTest):
         """
         """
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'foo'
+        user.username = "foo"
         user.cla_done = True
         user.cla_done = True
-        user.groups = ['foo']
+        user.groups = ["foo"]
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             self._check_user()
             self._check_user()
 
 
             # User isn't the owner but is an instance admin
             # User isn't the owner but is an instance admin
-            data = {
-                'user': 'foo',
-                'csrf_token': csrf_token,
-            }
+            data = {"user": "foo", "csrf_token": csrf_token}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/give', data=data, follow_redirects=True)
+                "/test/give", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                'The project has been '
-                'transferred to foo',
-                output.get_data(as_text=True))
+                "The project has been " "transferred to foo",
+                output.get_data(as_text=True),
+            )
 
 
-            self._check_user('foo')
+            self._check_user("foo")
 
 
-    @patch.dict('pagure.config.config', {'PAGURE_ADMIN_USERS': 'foo'})
-    @patch('pagure.lib.git.generate_gitolite_acls', MagicMock())
+    @patch.dict("pagure.config.config", {"PAGURE_ADMIN_USERS": "foo"})
+    @patch("pagure.lib.git.generate_gitolite_acls", MagicMock())
     def test_give_project(self):
     def test_give_project(self):
         """ Test the give_project endpoint. """
         """ Test the give_project endpoint. """
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             self._check_user()
             self._check_user()
 
 
             # All good
             # All good
-            data = {
-                'user': 'foo',
-                'csrf_token': csrf_token,
-            }
+            data = {"user": "foo", "csrf_token": csrf_token}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/give', data=data, follow_redirects=True)
+                "/test/give", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                'The project has been '
-                'transferred to foo',
-                output.get_data(as_text=True))
+                "The project has been " "transferred to foo",
+                output.get_data(as_text=True),
+            )
 
 
-            self._check_user('foo')
+            self._check_user("foo")
             # Make sure that the user giving the project is still an admin
             # Make sure that the user giving the project is still an admin
             project = pagure.lib.query.get_authorized_project(
             project = pagure.lib.query.get_authorized_project(
-                self.session, project_name='test')
+                self.session, project_name="test"
+            )
             self.assertEqual(len(project.users), 1)
             self.assertEqual(len(project.users), 1)
-            self.assertEqual(project.users[0].user, 'pingou')
+            self.assertEqual(project.users[0].user, "pingou")
 
 
-    @patch.dict('pagure.config.config', {'PAGURE_ADMIN_USERS': 'foo'})
-    @patch('pagure.lib.git.generate_gitolite_acls', MagicMock())
+    @patch.dict("pagure.config.config", {"PAGURE_ADMIN_USERS": "foo"})
+    @patch("pagure.lib.git.generate_gitolite_acls", MagicMock())
     def test_give_project_already_user(self):
     def test_give_project_already_user(self):
         """ Test the give_project endpoint when the new main_admin is already
         """ Test the give_project endpoint when the new main_admin is already
         a committer on the project. """
         a committer on the project. """
 
 
-        project = pagure.lib.query._get_project(self.session, 'test')
+        project = pagure.lib.query._get_project(self.session, "test")
         pagure.lib.query.add_user_to_project(
         pagure.lib.query.add_user_to_project(
-            self.session, project,
-            new_user='foo',
-            user='pingou',
-            access='commit'
+            self.session,
+            project,
+            new_user="foo",
+            user="pingou",
+            access="commit",
         )
         )
         self.session.commit()
         self.session.commit()
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             self._check_user()
             self._check_user()
 
 
             # All good
             # All good
-            data = {
-                'user': 'foo',
-                'csrf_token': csrf_token,
-            }
+            data = {"user": "foo", "csrf_token": csrf_token}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/give', data=data, follow_redirects=True)
+                "/test/give", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                'The project has been '
-                'transferred to foo',
-                output.get_data(as_text=True))
+                "The project has been " "transferred to foo",
+                output.get_data(as_text=True),
+            )
 
 
-            self._check_user('foo')
+            self._check_user("foo")
             # Make sure that the user giving the project is still an admin
             # Make sure that the user giving the project is still an admin
             project = pagure.lib.query.get_authorized_project(
             project = pagure.lib.query.get_authorized_project(
-                self.session, project_name='test')
+                self.session, project_name="test"
+            )
             self.assertEqual(len(project.users), 1)
             self.assertEqual(len(project.users), 1)
-            self.assertEqual(project.users[0].user, 'pingou')
+            self.assertEqual(project.users[0].user, "pingou")
 
 
-    @patch.dict('pagure.config.config', {'REQUIRED_GROUPS': {'*': ['packager']}})
-    @patch.dict('pagure.config.config', {'PAGURE_ADMIN_USERS': 'foo'})
-    @patch('pagure.lib.git.generate_gitolite_acls', MagicMock())
+    @patch.dict(
+        "pagure.config.config", {"REQUIRED_GROUPS": {"*": ["packager"]}}
+    )
+    @patch.dict("pagure.config.config", {"PAGURE_ADMIN_USERS": "foo"})
+    @patch("pagure.lib.git.generate_gitolite_acls", MagicMock())
     def test_give_project_not_in_required_group(self):
     def test_give_project_not_in_required_group(self):
         """ Test the give_project endpoint. """
         """ Test the give_project endpoint. """
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             self._check_user()
             self._check_user()
 
 
             # User not a packager
             # User not a packager
-            data = {
-                'user': 'foo',
-                'csrf_token': csrf_token,
-            }
+            data = {"user": "foo", "csrf_token": csrf_token}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/give', data=data, follow_redirects=True)
+                "/test/give", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                '</i> This user must be in one of the following groups to '
-                'be allowed to be added to this project: packager</div>',
-                output.get_data(as_text=True))
-
-            self._check_user(user='pingou')
-
-    @patch.dict('pagure.config.config', {'REQUIRED_GROUPS': {'*': ['packager']}})
-    @patch.dict('pagure.config.config', {'PAGURE_ADMIN_USERS': 'foo'})
-    @patch('pagure.lib.git.generate_gitolite_acls', MagicMock())
+                "</i> This user must be in one of the following groups to "
+                "be allowed to be added to this project: packager</div>",
+                output.get_data(as_text=True),
+            )
+
+            self._check_user(user="pingou")
+
+    @patch.dict(
+        "pagure.config.config", {"REQUIRED_GROUPS": {"*": ["packager"]}}
+    )
+    @patch.dict("pagure.config.config", {"PAGURE_ADMIN_USERS": "foo"})
+    @patch("pagure.lib.git.generate_gitolite_acls", MagicMock())
     def test_give_project_in_required_group(self):
     def test_give_project_in_required_group(self):
         """ Test the give_project endpoint. """
         """ Test the give_project endpoint. """
 
 
         # Create the packager group
         # Create the packager group
         msg = pagure.lib.query.add_group(
         msg = pagure.lib.query.add_group(
             self.session,
             self.session,
-            group_name='packager',
-            display_name='packager group',
+            group_name="packager",
+            display_name="packager group",
             description=None,
             description=None,
-            group_type='user',
-            user='pingou',
+            group_type="user",
+            user="pingou",
             is_admin=False,
             is_admin=False,
             blacklist=[],
             blacklist=[],
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'User `pingou` added to the group `packager`.')
+        self.assertEqual(msg, "User `pingou` added to the group `packager`.")
 
 
         # Add foo to the packager group
         # Add foo to the packager group
-        group = pagure.lib.query.search_groups(self.session, group_name='packager')
+        group = pagure.lib.query.search_groups(
+            self.session, group_name="packager"
+        )
         msg = pagure.lib.query.add_user_to_group(
         msg = pagure.lib.query.add_user_to_group(
             self.session,
             self.session,
-            username='foo',
+            username="foo",
             group=group,
             group=group,
-            user='pingou',
+            user="pingou",
             is_admin=False,
             is_admin=False,
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'User `foo` added to the group `packager`.')
+        self.assertEqual(msg, "User `foo` added to the group `packager`.")
 
 
         # pingou transferts test to foo
         # pingou transferts test to foo
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             self._check_user()
             self._check_user()
 
 
             # User not a packager
             # User not a packager
-            data = {
-                'user': 'foo',
-                'csrf_token': csrf_token,
-            }
+            data = {"user": "foo", "csrf_token": csrf_token}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/give', data=data, follow_redirects=True)
+                "/test/give", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                '</i> The project has been transferred to foo</div>',
-                output.get_data(as_text=True))
+                "</i> The project has been transferred to foo</div>",
+                output.get_data(as_text=True),
+            )
 
 
-            self._check_user('foo')
+            self._check_user("foo")
             # Make sure that the user giving the project is still an admin
             # Make sure that the user giving the project is still an admin
             project = pagure.lib.query.get_authorized_project(
             project = pagure.lib.query.get_authorized_project(
-                self.session, project_name='test')
+                self.session, project_name="test"
+            )
             self.assertEqual(len(project.users), 1)
             self.assertEqual(len(project.users), 1)
-            self.assertEqual(project.users[0].user, 'pingou')
+            self.assertEqual(project.users[0].user, "pingou")
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 21 - 16
tests/test_pagure_flask_ui_app_index.py

@@ -21,8 +21,9 @@ import json
 import pygit2
 import pygit2
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import tests
 import tests
@@ -34,23 +35,25 @@ class PagureFlaskAppIndextests(tests.Modeltests):
     def test_index_logged_out(self):
     def test_index_logged_out(self):
         """ Test the index endpoint when logged out. """
         """ Test the index endpoint when logged out. """
 
 
-        output = self.app.get('/')
+        output = self.app.get("/")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
-        self.assertIn('<title>Home - Pagure</title>', output_text)
+        self.assertIn("<title>Home - Pagure</title>", output_text)
         self.assertIn(
         self.assertIn(
             '<h3 class="m-0 font-weight-bold">All Projects '
             '<h3 class="m-0 font-weight-bold">All Projects '
             '<span class="badge badge-secondary">0</span></h3>',
             '<span class="badge badge-secondary">0</span></h3>',
-            output_text)
+            output_text,
+        )
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
 
 
-        output = self.app.get('/?page=abc')
+        output = self.app.get("/?page=abc")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         self.assertIn(
         self.assertIn(
             '<h3 class="m-0 font-weight-bold">All Projects '
             '<h3 class="m-0 font-weight-bold">All Projects '
             '<span class="badge badge-secondary">3</span></h3>',
             '<span class="badge badge-secondary">3</span></h3>',
-            output.get_data(as_text=True))
+            output.get_data(as_text=True),
+        )
 
 
     def test_index_logged_in(self):
     def test_index_logged_in(self):
         """
         """
@@ -62,28 +65,30 @@ class PagureFlaskAppIndextests(tests.Modeltests):
         # Add a 3rd project with a long description
         # Add a 3rd project with a long description
         item = pagure.lib.model.Project(
         item = pagure.lib.model.Project(
             user_id=2,  # foo
             user_id=2,  # foo
-            name='test3',
-            description='test project #3 with a very long description',
-            hook_token='aaabbbeeefff',
+            name="test3",
+            description="test project #3 with a very long description",
+            hook_token="aaabbbeeefff",
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
 
 
-        user = tests.FakeUser(username='foo')
+        user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/', follow_redirects=True)
+            output = self.app.get("/", follow_redirects=True)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<span class="btn btn-outline-secondary disabled '
                 '<span class="btn btn-outline-secondary disabled '
                 'opacity-100 border-0 ml-auto font-weight-bold">'
                 'opacity-100 border-0 ml-auto font-weight-bold">'
-                '1 Projects</span>\n',
-                output_text)
+                "1 Projects</span>\n",
+                output_text,
+            )
             self.assertNotIn(
             self.assertNotIn(
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<h3 class="m-0 font-weight-bold">All Projects '
                 '<span class="badge badge-secondary">3</span></h3>',
                 '<span class="badge badge-secondary">3</span></h3>',
-                output_text)
+                output_text,
+            )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 113 - 93
tests/test_pagure_flask_ui_app_userdash.py

@@ -21,8 +21,9 @@ import json
 import pygit2
 import pygit2
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import tests
 import tests
@@ -39,48 +40,51 @@ class PagureFlaskAppUserdashTests(tests.Modeltests):
         # Add a 3rd project just for foo
         # Add a 3rd project just for foo
         item = pagure.lib.model.Project(
         item = pagure.lib.model.Project(
             user_id=2,  # foo
             user_id=2,  # foo
-            name='test3',
-            description='test project #3 with a very long description',
-            hook_token='aaabbbeeefff',
+            name="test3",
+            description="test project #3 with a very long description",
+            hook_token="aaabbbeeefff",
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
 
 
-        user = tests.FakeUser(username='foo')
+        user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             # Before
             # Before
-            output = self.app.get('/dashboard/projects?acl=commit')
+            output = self.app.get("/dashboard/projects?acl=commit")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<span class="btn btn-outline-secondary disabled opacity-100'
                 '<span class="btn btn-outline-secondary disabled opacity-100'
                 ' border-0 ml-auto font-weight-bold">1 Projects</span>',
                 ' border-0 ml-auto font-weight-bold">1 Projects</span>',
-                output_text)
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<div class="text-center">No Projects match this filter</div>',
                 '<div class="text-center">No Projects match this filter</div>',
-                output_text)
-
-
+                output_text,
+            )
 
 
             # Add foo to test with admin level
             # Add foo to test with admin level
-            project = pagure.lib.query._get_project(self.session, 'test')
+            project = pagure.lib.query._get_project(self.session, "test")
             msg = pagure.lib.query.add_user_to_project(
             msg = pagure.lib.query.add_user_to_project(
                 self.session,
                 self.session,
                 project=project,
                 project=project,
-                new_user='foo',
-                user='pingou',
-                access='admin')
+                new_user="foo",
+                user="pingou",
+                access="admin",
+            )
             self.session.commit()
             self.session.commit()
-            self.assertEqual(msg, 'User added')
+            self.assertEqual(msg, "User added")
 
 
             # After
             # After
             self.assertIn(
             self.assertIn(
                 '<span class="btn btn-outline-secondary disabled opacity-100'
                 '<span class="btn btn-outline-secondary disabled opacity-100'
                 ' border-0 ml-auto font-weight-bold">1 Projects</span>',
                 ' border-0 ml-auto font-weight-bold">1 Projects</span>',
-                output_text)
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<div class="text-center">No Projects match this filter</div>',
                 '<div class="text-center">No Projects match this filter</div>',
-                output_text)
+                output_text,
+            )
 
 
     def test_index_commit_access_while_commit(self):
     def test_index_commit_access_while_commit(self):
         """ Test the index endpoint filter for commit access only when user
         """ Test the index endpoint filter for commit access only when user
@@ -90,45 +94,48 @@ class PagureFlaskAppUserdashTests(tests.Modeltests):
         # Add a 3rd project just for foo
         # Add a 3rd project just for foo
         item = pagure.lib.model.Project(
         item = pagure.lib.model.Project(
             user_id=2,  # foo
             user_id=2,  # foo
-            name='test3',
-            description='test project #3 with a very long description',
-            hook_token='aaabbbeeefff',
+            name="test3",
+            description="test project #3 with a very long description",
+            hook_token="aaabbbeeefff",
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
 
 
-        user = tests.FakeUser(username='foo')
+        user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             # Before
             # Before
-            output = self.app.get('/dashboard/projects?acl=commit')
+            output = self.app.get("/dashboard/projects?acl=commit")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '          <span class="btn btn-outline-secondary disabled'
                 '          <span class="btn btn-outline-secondary disabled'
                 ' opacity-100 border-0 ml-auto font-weight-bold">1 Projects</span>\n',
                 ' opacity-100 border-0 ml-auto font-weight-bold">1 Projects</span>\n',
-                output_text)
+                output_text,
+            )
 
 
             # Add foo to test with commit level
             # Add foo to test with commit level
-            project = pagure.lib.query._get_project(self.session, 'test')
+            project = pagure.lib.query._get_project(self.session, "test")
             msg = pagure.lib.query.add_user_to_project(
             msg = pagure.lib.query.add_user_to_project(
                 self.session,
                 self.session,
                 project=project,
                 project=project,
-                new_user='foo',
-                user='pingou',
-                access='commit')
+                new_user="foo",
+                user="pingou",
+                access="commit",
+            )
             self.session.commit()
             self.session.commit()
-            self.assertEqual(msg, 'User added')
+            self.assertEqual(msg, "User added")
 
 
             # After
             # After
-            output = self.app.get('/dashboard/projects?acl=commit')
+            output = self.app.get("/dashboard/projects?acl=commit")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '          <span class="btn btn-outline-secondary disabled'
                 '          <span class="btn btn-outline-secondary disabled'
                 ' opacity-100 border-0 ml-auto font-weight-bold">2 Projects</span>\n',
                 ' opacity-100 border-0 ml-auto font-weight-bold">2 Projects</span>\n',
-                output_text)
+                output_text,
+            )
 
 
     def test_index_commit_access_while_ticket(self):
     def test_index_commit_access_while_ticket(self):
         """ Test the index endpoint filter for commit access only when user
         """ Test the index endpoint filter for commit access only when user
@@ -138,45 +145,48 @@ class PagureFlaskAppUserdashTests(tests.Modeltests):
         # Add a 3rd project just for foo
         # Add a 3rd project just for foo
         item = pagure.lib.model.Project(
         item = pagure.lib.model.Project(
             user_id=2,  # foo
             user_id=2,  # foo
-            name='test3',
-            description='test project #3 with a very long description',
-            hook_token='aaabbbeeefff',
+            name="test3",
+            description="test project #3 with a very long description",
+            hook_token="aaabbbeeefff",
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
 
 
-        user = tests.FakeUser(username='foo')
+        user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             # Before
             # Before
-            output = self.app.get('/dashboard/projects?acl=ticket')
+            output = self.app.get("/dashboard/projects?acl=ticket")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '          <span class="btn btn-outline-secondary disabled'
                 '          <span class="btn btn-outline-secondary disabled'
                 ' opacity-100 border-0 ml-auto font-weight-bold">1 Projects</span>\n',
                 ' opacity-100 border-0 ml-auto font-weight-bold">1 Projects</span>\n',
-                output_text)
+                output_text,
+            )
 
 
             # Add foo to test with ticket level
             # Add foo to test with ticket level
-            project = pagure.lib.query._get_project(self.session, 'test')
+            project = pagure.lib.query._get_project(self.session, "test")
             msg = pagure.lib.query.add_user_to_project(
             msg = pagure.lib.query.add_user_to_project(
                 self.session,
                 self.session,
                 project=project,
                 project=project,
-                new_user='foo',
-                user='pingou',
-                access='ticket')
+                new_user="foo",
+                user="pingou",
+                access="ticket",
+            )
             self.session.commit()
             self.session.commit()
-            self.assertEqual(msg, 'User added')
+            self.assertEqual(msg, "User added")
 
 
             # After  -  projects with ticket access aren't shown
             # After  -  projects with ticket access aren't shown
-            output = self.app.get('/dashboard/projects?acl=ticket')
+            output = self.app.get("/dashboard/projects?acl=ticket")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '          <span class="btn btn-outline-secondary disabled'
                 '          <span class="btn btn-outline-secondary disabled'
                 ' opacity-100 border-0 ml-auto font-weight-bold">2 Projects</span>\n',
                 ' opacity-100 border-0 ml-auto font-weight-bold">2 Projects</span>\n',
-                output_text)
+                output_text,
+            )
 
 
     def test_index_admin_access_while_admin(self):
     def test_index_admin_access_while_admin(self):
         """ Test the index endpoint filter for admin access only when user
         """ Test the index endpoint filter for admin access only when user
@@ -186,45 +196,48 @@ class PagureFlaskAppUserdashTests(tests.Modeltests):
         # Add a 3rd project just for foo
         # Add a 3rd project just for foo
         item = pagure.lib.model.Project(
         item = pagure.lib.model.Project(
             user_id=2,  # foo
             user_id=2,  # foo
-            name='test3',
-            description='test project #3 with a very long description',
-            hook_token='aaabbbeeefff',
+            name="test3",
+            description="test project #3 with a very long description",
+            hook_token="aaabbbeeefff",
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
 
 
-        user = tests.FakeUser(username='foo')
+        user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             # Before
             # Before
-            output = self.app.get('/dashboard/projects?acl=admin')
+            output = self.app.get("/dashboard/projects?acl=admin")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '          <span class="btn btn-outline-secondary disabled'
                 '          <span class="btn btn-outline-secondary disabled'
                 ' opacity-100 border-0 ml-auto font-weight-bold">1 Projects</span>\n',
                 ' opacity-100 border-0 ml-auto font-weight-bold">1 Projects</span>\n',
-                output_text)
+                output_text,
+            )
 
 
             # Add foo to test with admin level
             # Add foo to test with admin level
-            project = pagure.lib.query._get_project(self.session, 'test')
+            project = pagure.lib.query._get_project(self.session, "test")
             msg = pagure.lib.query.add_user_to_project(
             msg = pagure.lib.query.add_user_to_project(
                 self.session,
                 self.session,
                 project=project,
                 project=project,
-                new_user='foo',
-                user='pingou',
-                access='admin')
+                new_user="foo",
+                user="pingou",
+                access="admin",
+            )
             self.session.commit()
             self.session.commit()
-            self.assertEqual(msg, 'User added')
+            self.assertEqual(msg, "User added")
 
 
             # After
             # After
-            output = self.app.get('/dashboard/projects?acl=admin')
+            output = self.app.get("/dashboard/projects?acl=admin")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '          <span class="btn btn-outline-secondary disabled'
                 '          <span class="btn btn-outline-secondary disabled'
                 ' opacity-100 border-0 ml-auto font-weight-bold">2 Projects</span>\n',
                 ' opacity-100 border-0 ml-auto font-weight-bold">2 Projects</span>\n',
-                output_text)
+                output_text,
+            )
 
 
     def test_index_admin_access_while_commit(self):
     def test_index_admin_access_while_commit(self):
         """ Test the index endpoint filter for admin access only when user
         """ Test the index endpoint filter for admin access only when user
@@ -234,38 +247,40 @@ class PagureFlaskAppUserdashTests(tests.Modeltests):
         # Add a 3rd project just for foo
         # Add a 3rd project just for foo
         item = pagure.lib.model.Project(
         item = pagure.lib.model.Project(
             user_id=2,  # foo
             user_id=2,  # foo
-            name='test3',
-            description='test project #3 with a very long description',
-            hook_token='aaabbbeeefff',
+            name="test3",
+            description="test project #3 with a very long description",
+            hook_token="aaabbbeeefff",
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
 
 
-        user = tests.FakeUser(username='foo')
+        user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             # Before
             # Before
-            output = self.app.get('/dashboard/projects?acl=commit')
+            output = self.app.get("/dashboard/projects?acl=commit")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '          <span class="btn btn-outline-secondary disabled'
                 '          <span class="btn btn-outline-secondary disabled'
                 ' opacity-100 border-0 ml-auto font-weight-bold">1 Projects</span>\n',
                 ' opacity-100 border-0 ml-auto font-weight-bold">1 Projects</span>\n',
-                output_text)
+                output_text,
+            )
 
 
             # Add foo to test with commit level
             # Add foo to test with commit level
-            project = pagure.lib.query._get_project(self.session, 'test')
+            project = pagure.lib.query._get_project(self.session, "test")
             msg = pagure.lib.query.add_user_to_project(
             msg = pagure.lib.query.add_user_to_project(
                 self.session,
                 self.session,
                 project=project,
                 project=project,
-                new_user='foo',
-                user='pingou',
-                access='commit')
+                new_user="foo",
+                user="pingou",
+                access="commit",
+            )
             self.session.commit()
             self.session.commit()
-            self.assertEqual(msg, 'User added')
+            self.assertEqual(msg, "User added")
 
 
             # After
             # After
-            output = self.app.get('/dashboard/projects?acl=commit')
+            output = self.app.get("/dashboard/projects?acl=commit")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # The total number no longer changes
             # The total number no longer changes
@@ -273,7 +288,8 @@ class PagureFlaskAppUserdashTests(tests.Modeltests):
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '          <span class="btn btn-outline-secondary disabled'
                 '          <span class="btn btn-outline-secondary disabled'
                 ' opacity-100 border-0 ml-auto font-weight-bold">2 Projects</span>\n',
                 ' opacity-100 border-0 ml-auto font-weight-bold">2 Projects</span>\n',
-                output_text)
+                output_text,
+            )
 
 
     def test_index_main_admin_access_while_commit(self):
     def test_index_main_admin_access_while_commit(self):
         """ Test the index endpoint filter for main admin access only when
         """ Test the index endpoint filter for main admin access only when
@@ -283,48 +299,50 @@ class PagureFlaskAppUserdashTests(tests.Modeltests):
         # Add a 3rd project just for foo
         # Add a 3rd project just for foo
         item = pagure.lib.model.Project(
         item = pagure.lib.model.Project(
             user_id=2,  # foo
             user_id=2,  # foo
-            name='test3',
-            description='test project #3 with a very long description',
-            hook_token='aaabbbeeefff',
+            name="test3",
+            description="test project #3 with a very long description",
+            hook_token="aaabbbeeefff",
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
 
 
-        user = tests.FakeUser(username='foo')
+        user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             # Before
             # Before
-            output = self.app.get('/dashboard/projects?acl=main admin')
+            output = self.app.get("/dashboard/projects?acl=main admin")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '          <span class="btn btn-outline-secondary disabled'
                 '          <span class="btn btn-outline-secondary disabled'
                 ' opacity-100 border-0 ml-auto font-weight-bold">1 Projects</span>\n',
                 ' opacity-100 border-0 ml-auto font-weight-bold">1 Projects</span>\n',
-                output_text)
+                output_text,
+            )
 
 
             # Add foo to test with commit level
             # Add foo to test with commit level
-            project = pagure.lib.query._get_project(self.session, 'test')
+            project = pagure.lib.query._get_project(self.session, "test")
             msg = pagure.lib.query.add_user_to_project(
             msg = pagure.lib.query.add_user_to_project(
                 self.session,
                 self.session,
                 project=project,
                 project=project,
-                new_user='foo',
-                user='pingou',
-                access='commit')
+                new_user="foo",
+                user="pingou",
+                access="commit",
+            )
             self.session.commit()
             self.session.commit()
-            self.assertEqual(msg, 'User added')
+            self.assertEqual(msg, "User added")
 
 
             # After
             # After
-            output = self.app.get('/dashboard/projects?acl=main admin')
+            output = self.app.get("/dashboard/projects?acl=main admin")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '          <span class="btn btn-outline-secondary disabled'
                 '          <span class="btn btn-outline-secondary disabled'
                 ' opacity-100 border-0 ml-auto font-weight-bold">2 Projects</span>\n',
                 ' opacity-100 border-0 ml-auto font-weight-bold">2 Projects</span>\n',
-                output_text)
-
+                output_text,
+            )
 
 
-    @patch.dict('pagure.config.config', {'PRIVATE_PROJECTS': True})
+    @patch.dict("pagure.config.config", {"PRIVATE_PROJECTS": True})
     def test_index_logged_in_private_project(self):
     def test_index_logged_in_private_project(self):
         """ Test the index endpoint when logged in with a private project. """
         """ Test the index endpoint when logged in with a private project. """
         tests.create_projects(self.session)
         tests.create_projects(self.session)
@@ -332,30 +350,32 @@ class PagureFlaskAppUserdashTests(tests.Modeltests):
         # Add a 3rd project with a long description
         # Add a 3rd project with a long description
         item = pagure.lib.model.Project(
         item = pagure.lib.model.Project(
             user_id=2,  # foo
             user_id=2,  # foo
-            name='test3',
-            description='test project #3 with a very long description',
-            hook_token='aaabbbeeefff',
+            name="test3",
+            description="test project #3 with a very long description",
+            hook_token="aaabbbeeefff",
             private=True,
             private=True,
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
 
 
-        user = tests.FakeUser(username='foo')
+        user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/dashboard/projects')
+            output = self.app.get("/dashboard/projects")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '<h4 class="font-weight-bold mb-0">My Projects</h4>\n'
                 '          <span class="btn btn-outline-secondary disabled'
                 '          <span class="btn btn-outline-secondary disabled'
                 ' opacity-100 border-0 ml-auto font-weight-bold">1 Projects</span>\n',
                 ' opacity-100 border-0 ml-auto font-weight-bold">1 Projects</span>\n',
-                output_text)
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<span title="Private project" class="text-danger '
                 '<span title="Private project" class="text-danger '
                 'fa fa-fw fa-lock"></span>',
                 'fa fa-fw fa-lock"></span>',
-                output_text)
+                output_text,
+            )
             self.assertEqual(output_text.count('title="Private project"'), 1)
             self.assertEqual(output_text.count('title="Private project"'), 1)
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 170 - 122
tests/test_pagure_flask_ui_archives.py

@@ -18,8 +18,9 @@ import time
 import mock
 import mock
 import pygit2
 import pygit2
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.git
 import pagure.lib.git
 import pagure.lib.query
 import pagure.lib.query
@@ -30,67 +31,75 @@ from tests.test_pagure_lib_git_get_tags_objects import add_repo_tag
 class PagureFlaskUiArchivesTest(tests.Modeltests):
 class PagureFlaskUiArchivesTest(tests.Modeltests):
     """ Tests checking the archiving mechanism. """
     """ Tests checking the archiving mechanism. """
 
 
-
     def setUp(self):
     def setUp(self):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(PagureFlaskUiArchivesTest, self).setUp()
         super(PagureFlaskUiArchivesTest, self).setUp()
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
-        project = pagure.lib.query._get_project(self.session, 'test')
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
+        project = pagure.lib.query._get_project(self.session, "test")
 
 
         # test has both commits and tags
         # test has both commits and tags
-        repopath = os.path.join(self.path, 'repos', 'test.git')
+        repopath = os.path.join(self.path, "repos", "test.git")
         tests.add_readme_git_repo(repopath)
         tests.add_readme_git_repo(repopath)
         repo = pygit2.Repository(repopath)
         repo = pygit2.Repository(repopath)
-        add_repo_tag(self.path, repo, ['v1.0', 'v1.1'], 'test.git')
+        add_repo_tag(self.path, repo, ["v1.0", "v1.1"], "test.git")
 
 
         # test2 has only commits
         # test2 has only commits
-        tests.add_readme_git_repo(os.path.join(
-            self.path, 'repos', 'test2.git'))
+        tests.add_readme_git_repo(
+            os.path.join(self.path, "repos", "test2.git")
+        )
 
 
         # somenamespace/test3 has neither commits nor tags
         # somenamespace/test3 has neither commits nor tags
 
 
         # Create the archive folder:
         # Create the archive folder:
-        self.archive_path = os.path.join(self.path, 'archives')
+        self.archive_path = os.path.join(self.path, "archives")
         os.mkdir(self.archive_path)
         os.mkdir(self.archive_path)
 
 
     def test_project_no_conf(self):
     def test_project_no_conf(self):
         """ Test getting the archive when pagure isn't configured. """
         """ Test getting the archive when pagure isn't configured. """
         output = self.app.get(
         output = self.app.get(
-            '/somenamespace/test3/archive/tag1/test3-tag1.zip',
-            follow_redirects=True)
+            "/somenamespace/test3/archive/tag1/test3-tag1.zip",
+            follow_redirects=True,
+        )
 
 
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
         self.assertIn(
         self.assertIn(
             "This pagure instance isn&#39;t configured to support "
             "This pagure instance isn&#39;t configured to support "
-            "this feature", output.get_data(as_text=True))
+            "this feature",
+            output.get_data(as_text=True),
+        )
 
 
         self.assertEqual(os.listdir(self.archive_path), [])
         self.assertEqual(os.listdir(self.archive_path), [])
 
 
     def test_project_invalid_conf(self):
     def test_project_invalid_conf(self):
         """ Test getting the archive when pagure is wrongly configured. """
         """ Test getting the archive when pagure is wrongly configured. """
         with mock.patch.dict(
         with mock.patch.dict(
-                'pagure.config.config',
-                {'ARCHIVE_FOLDER': os.path.join(self.path, 'invalid')}):
+            "pagure.config.config",
+            {"ARCHIVE_FOLDER": os.path.join(self.path, "invalid")},
+        ):
             output = self.app.get(
             output = self.app.get(
-                '/somenamespace/test3/archive/tag1/test3-tag1.zip',
-                follow_redirects=True)
+                "/somenamespace/test3/archive/tag1/test3-tag1.zip",
+                follow_redirects=True,
+            )
 
 
             self.assertEqual(output.status_code, 500)
             self.assertEqual(output.status_code, 500)
             self.assertIn(
             self.assertIn(
                 "Incorrect configuration, please contact your admin",
                 "Incorrect configuration, please contact your admin",
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
 
 
         self.assertEqual(os.listdir(self.archive_path), [])
         self.assertEqual(os.listdir(self.archive_path), [])
 
 
     def test_project_invalid_format(self):
     def test_project_invalid_format(self):
         """ Test getting the archive when the format provided is invalid. """
         """ Test getting the archive when the format provided is invalid. """
         with mock.patch.dict(
         with mock.patch.dict(
-                'pagure.config.config',
-                {'ARCHIVE_FOLDER': os.path.join(self.path, 'archives')}):
+            "pagure.config.config",
+            {"ARCHIVE_FOLDER": os.path.join(self.path, "archives")},
+        ):
             output = self.app.get(
             output = self.app.get(
-                '/somenamespace/test3/archive/tag1/test3-tag1.unzip',
-                follow_redirects=True)
+                "/somenamespace/test3/archive/tag1/test3-tag1.unzip",
+                follow_redirects=True,
+            )
 
 
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
@@ -99,16 +108,18 @@ class PagureFlaskUiArchivesTest(tests.Modeltests):
     def test_project_no_commit(self):
     def test_project_no_commit(self):
         """ Test getting the archive of an empty project. """
         """ Test getting the archive of an empty project. """
         with mock.patch.dict(
         with mock.patch.dict(
-                'pagure.config.config',
-                {'ARCHIVE_FOLDER': os.path.join(self.path, 'archives')}):
+            "pagure.config.config",
+            {"ARCHIVE_FOLDER": os.path.join(self.path, "archives")},
+        ):
             output = self.app.get(
             output = self.app.get(
-                '/somenamespace/test3/archive/tag1/test3-tag1.zip',
-                follow_redirects=True)
+                "/somenamespace/test3/archive/tag1/test3-tag1.zip",
+                follow_redirects=True,
+            )
 
 
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
             self.assertIn(
             self.assertIn(
-                "<p>Invalid commit provided</p>",
-                output.get_data(as_text=True))
+                "<p>Invalid commit provided</p>", output.get_data(as_text=True)
+            )
 
 
         self.assertEqual(os.listdir(self.archive_path), [])
         self.assertEqual(os.listdir(self.archive_path), [])
 
 
@@ -116,184 +127,221 @@ class PagureFlaskUiArchivesTest(tests.Modeltests):
         """ Test getting the archive of a non-empty project but without
         """ Test getting the archive of a non-empty project but without
         tags. """
         tags. """
         with mock.patch.dict(
         with mock.patch.dict(
-                'pagure.config.config',
-                {'ARCHIVE_FOLDER': os.path.join(self.path, 'archives')}):
+            "pagure.config.config",
+            {"ARCHIVE_FOLDER": os.path.join(self.path, "archives")},
+        ):
             output = self.app.get(
             output = self.app.get(
-                '/test2/archive/tag1/test2-tag1.zip',
-                follow_redirects=True)
+                "/test2/archive/tag1/test2-tag1.zip", follow_redirects=True
+            )
 
 
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
             self.assertIn(
             self.assertIn(
-                "<p>Invalid commit provided</p>",
-                output.get_data(as_text=True))
+                "<p>Invalid commit provided</p>", output.get_data(as_text=True)
+            )
 
 
         self.assertEqual(os.listdir(self.archive_path), [])
         self.assertEqual(os.listdir(self.archive_path), [])
 
 
     def test_project_no_tag(self):
     def test_project_no_tag(self):
         """ Test getting the archive of an empty project. """
         """ Test getting the archive of an empty project. """
         with mock.patch.dict(
         with mock.patch.dict(
-                'pagure.config.config',
-                {'ARCHIVE_FOLDER': os.path.join(self.path, 'archives')}):
+            "pagure.config.config",
+            {"ARCHIVE_FOLDER": os.path.join(self.path, "archives")},
+        ):
             output = self.app.get(
             output = self.app.get(
-                '/test2/archive/tag1/test2-tag1.zip',
-                follow_redirects=True)
+                "/test2/archive/tag1/test2-tag1.zip", follow_redirects=True
+            )
 
 
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
             self.assertIn(
             self.assertIn(
-                "<p>Invalid commit provided</p>",
-                output.get_data(as_text=True))
+                "<p>Invalid commit provided</p>", output.get_data(as_text=True)
+            )
 
 
         self.assertEqual(os.listdir(self.archive_path), [])
         self.assertEqual(os.listdir(self.archive_path), [])
 
 
     def test_project_w_tag_zip(self):
     def test_project_w_tag_zip(self):
         """ Test getting the archive from a tag. """
         """ Test getting the archive from a tag. """
         with mock.patch.dict(
         with mock.patch.dict(
-                'pagure.config.config',
-                {'ARCHIVE_FOLDER': os.path.join(self.path, 'archives')}):
+            "pagure.config.config",
+            {"ARCHIVE_FOLDER": os.path.join(self.path, "archives")},
+        ):
             output = self.app.get(
             output = self.app.get(
-                '/test/archive/v1.0/test-v1.0.zip',
-                follow_redirects=True)
+                "/test/archive/v1.0/test-v1.0.zip", follow_redirects=True
+            )
 
 
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
 
 
+        self.assertEqual(os.listdir(self.archive_path), ["test"])
         self.assertEqual(
         self.assertEqual(
-            os.listdir(self.archive_path), ['test'])
-        self.assertEqual(
-            os.listdir(os.path.join(self.archive_path, 'test')),
-            ['tags'])
+            os.listdir(os.path.join(self.archive_path, "test")), ["tags"]
+        )
         self.assertEqual(
         self.assertEqual(
-            os.listdir(os.path.join(self.archive_path, 'test', 'tags')),
-            ['v1.0'])
+            os.listdir(os.path.join(self.archive_path, "test", "tags")),
+            ["v1.0"],
+        )
 
 
         self.assertEqual(
         self.assertEqual(
-            len(os.listdir(os.path.join(
-                self.archive_path, 'test', 'tags', 'v1.0'))),
-            1)
-
-        files = os.listdir(os.path.join(
-                self.archive_path, 'test', 'tags', 'v1.0'))
+            len(
+                os.listdir(
+                    os.path.join(self.archive_path, "test", "tags", "v1.0")
+                )
+            ),
+            1,
+        )
+
+        files = os.listdir(
+            os.path.join(self.archive_path, "test", "tags", "v1.0")
+        )
         self.assertEqual(
         self.assertEqual(
-            os.listdir(os.path.join(
-                self.archive_path, 'test', 'tags', 'v1.0', files[0])),
-            ['test-v1.0.zip'])
+            os.listdir(
+                os.path.join(
+                    self.archive_path, "test", "tags", "v1.0", files[0]
+                )
+            ),
+            ["test-v1.0.zip"],
+        )
 
 
     def test_project_w_tag_tar(self):
     def test_project_w_tag_tar(self):
         """ Test getting the archive from a tag. """
         """ Test getting the archive from a tag. """
         with mock.patch.dict(
         with mock.patch.dict(
-                'pagure.config.config',
-                {'ARCHIVE_FOLDER': os.path.join(self.path, 'archives')}):
+            "pagure.config.config",
+            {"ARCHIVE_FOLDER": os.path.join(self.path, "archives")},
+        ):
             output = self.app.get(
             output = self.app.get(
-                '/test/archive/v1.0/test-v1.0.tar',
-                follow_redirects=True)
+                "/test/archive/v1.0/test-v1.0.tar", follow_redirects=True
+            )
 
 
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
 
 
+        self.assertEqual(os.listdir(self.archive_path), ["test"])
         self.assertEqual(
         self.assertEqual(
-            os.listdir(self.archive_path), ['test'])
+            os.listdir(os.path.join(self.archive_path, "test")), ["tags"]
+        )
         self.assertEqual(
         self.assertEqual(
-            os.listdir(os.path.join(self.archive_path, 'test')),
-            ['tags'])
-        self.assertEqual(
-            os.listdir(os.path.join(self.archive_path, 'test', 'tags')),
-            ['v1.0'])
+            os.listdir(os.path.join(self.archive_path, "test", "tags")),
+            ["v1.0"],
+        )
 
 
         self.assertEqual(
         self.assertEqual(
-            len(os.listdir(os.path.join(
-                self.archive_path, 'test', 'tags', 'v1.0'))),
-            1)
-
-        files = os.listdir(os.path.join(
-                self.archive_path, 'test', 'tags', 'v1.0'))
+            len(
+                os.listdir(
+                    os.path.join(self.archive_path, "test", "tags", "v1.0")
+                )
+            ),
+            1,
+        )
+
+        files = os.listdir(
+            os.path.join(self.archive_path, "test", "tags", "v1.0")
+        )
         self.assertEqual(
         self.assertEqual(
-            os.listdir(os.path.join(
-                self.archive_path, 'test', 'tags', 'v1.0', files[0])),
-            ['test-v1.0.tar'])
+            os.listdir(
+                os.path.join(
+                    self.archive_path, "test", "tags", "v1.0", files[0]
+                )
+            ),
+            ["test-v1.0.tar"],
+        )
 
 
     def test_project_w_tag_tar_gz(self):
     def test_project_w_tag_tar_gz(self):
         """ Test getting the archive from a tag. """
         """ Test getting the archive from a tag. """
         with mock.patch.dict(
         with mock.patch.dict(
-                'pagure.config.config',
-                {'ARCHIVE_FOLDER': os.path.join(self.path, 'archives')}):
+            "pagure.config.config",
+            {"ARCHIVE_FOLDER": os.path.join(self.path, "archives")},
+        ):
             output = self.app.get(
             output = self.app.get(
-                '/test/archive/v1.0/test-v1.0.tar.gz',
-                follow_redirects=True)
+                "/test/archive/v1.0/test-v1.0.tar.gz", follow_redirects=True
+            )
 
 
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
 
 
+        self.assertEqual(os.listdir(self.archive_path), ["test"])
         self.assertEqual(
         self.assertEqual(
-            os.listdir(self.archive_path), ['test'])
+            os.listdir(os.path.join(self.archive_path, "test")), ["tags"]
+        )
         self.assertEqual(
         self.assertEqual(
-            os.listdir(os.path.join(self.archive_path, 'test')),
-            ['tags'])
-        self.assertEqual(
-            os.listdir(os.path.join(self.archive_path, 'test', 'tags')),
-            ['v1.0'])
+            os.listdir(os.path.join(self.archive_path, "test", "tags")),
+            ["v1.0"],
+        )
 
 
         self.assertEqual(
         self.assertEqual(
-            len(os.listdir(os.path.join(
-                self.archive_path, 'test', 'tags', 'v1.0'))),
-            1)
-
-        files = os.listdir(os.path.join(
-                self.archive_path, 'test', 'tags', 'v1.0'))
+            len(
+                os.listdir(
+                    os.path.join(self.archive_path, "test", "tags", "v1.0")
+                )
+            ),
+            1,
+        )
+
+        files = os.listdir(
+            os.path.join(self.archive_path, "test", "tags", "v1.0")
+        )
         self.assertEqual(
         self.assertEqual(
-            os.listdir(os.path.join(
-                self.archive_path, 'test', 'tags', 'v1.0', files[0])),
-            ['test-v1.0.tar.gz'])
+            os.listdir(
+                os.path.join(
+                    self.archive_path, "test", "tags", "v1.0", files[0]
+                )
+            ),
+            ["test-v1.0.tar.gz"],
+        )
 
 
     def test_project_w_commit_tar_gz(self):
     def test_project_w_commit_tar_gz(self):
         """ Test getting the archive from a commit. """
         """ Test getting the archive from a commit. """
-        repopath = os.path.join(self.path, 'repos', 'test.git')
+        repopath = os.path.join(self.path, "repos", "test.git")
         repo = pygit2.Repository(repopath)
         repo = pygit2.Repository(repopath)
         commit = repo.head.target.hex
         commit = repo.head.target.hex
         with mock.patch.dict(
         with mock.patch.dict(
-                'pagure.config.config',
-                {'ARCHIVE_FOLDER': os.path.join(self.path, 'archives')}):
+            "pagure.config.config",
+            {"ARCHIVE_FOLDER": os.path.join(self.path, "archives")},
+        ):
             output = self.app.get(
             output = self.app.get(
-                '/test/archive/%s/test-v1.0.tar.gz' % commit,
-                follow_redirects=True)
+                "/test/archive/%s/test-v1.0.tar.gz" % commit,
+                follow_redirects=True,
+            )
 
 
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
 
 
+        self.assertEqual(os.listdir(self.archive_path), ["test"])
         self.assertEqual(
         self.assertEqual(
-            os.listdir(self.archive_path), ['test'])
+            os.listdir(os.path.join(self.archive_path, "test")), [commit]
+        )
         self.assertEqual(
         self.assertEqual(
-            os.listdir(os.path.join(self.archive_path, 'test')),
-            [commit])
-        self.assertEqual(
-            os.listdir(os.path.join(self.archive_path, 'test', commit)),
-            ['test-v1.0.tar.gz'])
+            os.listdir(os.path.join(self.archive_path, "test", commit)),
+            ["test-v1.0.tar.gz"],
+        )
 
 
     def test_project_w_commit_tar_gz_twice(self):
     def test_project_w_commit_tar_gz_twice(self):
         """ Test getting the archive from a commit twice, so we hit the
         """ Test getting the archive from a commit twice, so we hit the
         disk cache. """
         disk cache. """
-        repopath = os.path.join(self.path, 'repos', 'test.git')
+        repopath = os.path.join(self.path, "repos", "test.git")
         repo = pygit2.Repository(repopath)
         repo = pygit2.Repository(repopath)
         commit = repo.head.target.hex
         commit = repo.head.target.hex
         with mock.patch.dict(
         with mock.patch.dict(
-                'pagure.config.config',
-                {'ARCHIVE_FOLDER': os.path.join(self.path, 'archives')}):
+            "pagure.config.config",
+            {"ARCHIVE_FOLDER": os.path.join(self.path, "archives")},
+        ):
             output = self.app.get(
             output = self.app.get(
-                '/test/archive/%s/test-v1.0.tar.gz' % commit,
-                follow_redirects=True)
+                "/test/archive/%s/test-v1.0.tar.gz" % commit,
+                follow_redirects=True,
+            )
 
 
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
 
 
             output = self.app.get(
             output = self.app.get(
-                '/test/archive/%s/test-v1.0.tar.gz' % commit,
-                follow_redirects=True)
+                "/test/archive/%s/test-v1.0.tar.gz" % commit,
+                follow_redirects=True,
+            )
 
 
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
 
 
+        self.assertEqual(os.listdir(self.archive_path), ["test"])
         self.assertEqual(
         self.assertEqual(
-            os.listdir(self.archive_path), ['test'])
-        self.assertEqual(
-            os.listdir(os.path.join(self.archive_path, 'test')),
-            [commit])
+            os.listdir(os.path.join(self.archive_path, "test")), [commit]
+        )
         self.assertEqual(
         self.assertEqual(
-            os.listdir(os.path.join(self.archive_path, 'test', commit)),
-            ['test-v1.0.tar.gz'])
+            os.listdir(os.path.join(self.archive_path, "test", commit)),
+            ["test-v1.0.tar.gz"],
+        )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 93 - 63
tests/test_pagure_flask_ui_clone.py

@@ -22,8 +22,9 @@ import json
 import pygit2
 import pygit2
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import tests
 import tests
@@ -38,134 +39,163 @@ class PagureFlaskAppClonetests(tests.Modeltests):
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
         tests.create_tokens_acl(self.session)
         tests.create_tokens_acl(self.session)
-        self.create_project_full('clonetest', {"create_readme": "y"})
+        self.create_project_full("clonetest", {"create_readme": "y"})
 
 
-    @patch.dict('pagure.config.config', {'ALLOW_HTTP_PULL_PUSH': False})
+    @patch.dict("pagure.config.config", {"ALLOW_HTTP_PULL_PUSH": False})
     def test_http_clone_disabled(self):
     def test_http_clone_disabled(self):
         """ Test that the HTTP clone endpoint gets correctly closed. """
         """ Test that the HTTP clone endpoint gets correctly closed. """
-        output = self.app.get('/clonetest.git/info/refs?service=git-upload-pack')
+        output = self.app.get(
+            "/clonetest.git/info/refs?service=git-upload-pack"
+        )
         self.assertEqual(output.status_code, 403)
         self.assertEqual(output.status_code, 403)
-        self.assertIn('not allowed', output.get_data(as_text=True))
+        self.assertIn("not allowed", output.get_data(as_text=True))
 
 
-    @patch.dict('pagure.config.config', {'ALLOW_HTTP_PULL_PUSH': True})
+    @patch.dict("pagure.config.config", {"ALLOW_HTTP_PULL_PUSH": True})
     def test_http_clone_invalid_service(self):
     def test_http_clone_invalid_service(self):
         """ Test that the HTTP endpoint refuses invalid services. """
         """ Test that the HTTP endpoint refuses invalid services. """
-        output = self.app.get('/clonetest.git/info/refs?service=myservice')
+        output = self.app.get("/clonetest.git/info/refs?service=myservice")
         self.assertEqual(output.status_code, 400)
         self.assertEqual(output.status_code, 400)
-        self.assertIn('Unknown service', output.get_data(as_text=True))
+        self.assertIn("Unknown service", output.get_data(as_text=True))
 
 
-    @patch.dict('pagure.config.config', {'ALLOW_HTTP_PULL_PUSH': True})
+    @patch.dict("pagure.config.config", {"ALLOW_HTTP_PULL_PUSH": True})
     def test_http_clone_invalid_project(self):
     def test_http_clone_invalid_project(self):
         """ Test that the HTTP endpoint refuses invalid projects. """
         """ Test that the HTTP endpoint refuses invalid projects. """
-        output = self.app.get('/nosuchrepo.git/info/refs?service=git-upload-pack')
+        output = self.app.get(
+            "/nosuchrepo.git/info/refs?service=git-upload-pack"
+        )
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
-        self.assertIn('Project not found', output.get_data(as_text=True))
+        self.assertIn("Project not found", output.get_data(as_text=True))
 
 
-    @patch.dict('pagure.config.config', {'ALLOW_HTTP_PULL_PUSH': True})
+    @patch.dict("pagure.config.config", {"ALLOW_HTTP_PULL_PUSH": True})
     def test_http_clone_dumb(self):
     def test_http_clone_dumb(self):
         """ Test that the HTTP endpoint refuses dumb service request. """
         """ Test that the HTTP endpoint refuses dumb service request. """
-        output = self.app.get('/clonetest.git/info/refs')
+        output = self.app.get("/clonetest.git/info/refs")
         self.assertEqual(output.status_code, 400)
         self.assertEqual(output.status_code, 400)
-        self.assertIn('Please switch', output.get_data(as_text=True))
-
-    @patch.dict('pagure.config.config', {
-        'ALLOW_HTTP_PULL_PUSH': True,
-        'ALLOW_HTTP_PUSH': False,
-        'HTTP_REPO_ACCESS_GITOLITE': None,
-    })
+        self.assertIn("Please switch", output.get_data(as_text=True))
+
+    @patch.dict(
+        "pagure.config.config",
+        {
+            "ALLOW_HTTP_PULL_PUSH": True,
+            "ALLOW_HTTP_PUSH": False,
+            "HTTP_REPO_ACCESS_GITOLITE": None,
+        },
+    )
     def test_http_push_disabled(self):
     def test_http_push_disabled(self):
         """ Test that the HTTP push gets refused. """
         """ Test that the HTTP push gets refused. """
-        output = self.app.get('/clonetest.git/info/refs?service=git-receive-pack')
+        output = self.app.get(
+            "/clonetest.git/info/refs?service=git-receive-pack"
+        )
         self.assertEqual(output.status_code, 403)
         self.assertEqual(output.status_code, 403)
-        self.assertIn('pushing disabled', output.get_data(as_text=True))
-        output = self.app.post('/clonetest.git/git-receive-pack')
+        self.assertIn("pushing disabled", output.get_data(as_text=True))
+        output = self.app.post("/clonetest.git/git-receive-pack")
         self.assertEqual(output.status_code, 403)
         self.assertEqual(output.status_code, 403)
-        self.assertIn('pushing disabled', output.get_data(as_text=True))
-
-    @patch.dict('pagure.config.config', {
-        'ALLOW_HTTP_PULL_PUSH': True,
-        'ALLOW_HTTP_PUSH': True,
-        'HTTP_REPO_ACCESS_GITOLITE': None,
-    })
+        self.assertIn("pushing disabled", output.get_data(as_text=True))
+
+    @patch.dict(
+        "pagure.config.config",
+        {
+            "ALLOW_HTTP_PULL_PUSH": True,
+            "ALLOW_HTTP_PUSH": True,
+            "HTTP_REPO_ACCESS_GITOLITE": None,
+        },
+    )
     def test_http_push_unauthed(self):
     def test_http_push_unauthed(self):
         """ Test that the HTTP push gets refused unauthed. """
         """ Test that the HTTP push gets refused unauthed. """
-        output = self.app.get('/clonetest.git/info/refs?service=git-receive-pack')
+        output = self.app.get(
+            "/clonetest.git/info/refs?service=git-receive-pack"
+        )
         self.assertEqual(output.status_code, 403)
         self.assertEqual(output.status_code, 403)
-        self.assertIn('Unauthenticated push', output.get_data(as_text=True))
+        self.assertIn("Unauthenticated push", output.get_data(as_text=True))
 
 
-    @patch.dict('pagure.config.config', {'ALLOW_HTTP_PULL_PUSH': True})
+    @patch.dict("pagure.config.config", {"ALLOW_HTTP_PULL_PUSH": True})
     def test_http_clone_private_project_unauthed(self):
     def test_http_clone_private_project_unauthed(self):
         """ Test that the HTTP endpoint enforced project.private. """
         """ Test that the HTTP endpoint enforced project.private. """
-        project = pagure.lib.query._get_project(self.session, 'clonetest')
+        project = pagure.lib.query._get_project(self.session, "clonetest")
         project.private = True
         project.private = True
         self.session.add(project)
         self.session.add(project)
         self.session.commit()
         self.session.commit()
 
 
-        output = self.app.get('/clonetest.git/info/refs?service=git-upload-pack')
+        output = self.app.get(
+            "/clonetest.git/info/refs?service=git-upload-pack"
+        )
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
-        self.assertIn('Project not found', output.get_data(as_text=True))
-
-    @patch.dict('pagure.config.config', {
-        'ALLOW_HTTP_PULL_PUSH': True,
-        'ALLOW_HTTP_PUSH': False,
-        'HTTP_REPO_ACCESS_GITOLITE': None,
-    })
+        self.assertIn("Project not found", output.get_data(as_text=True))
+
+    @patch.dict(
+        "pagure.config.config",
+        {
+            "ALLOW_HTTP_PULL_PUSH": True,
+            "ALLOW_HTTP_PUSH": False,
+            "HTTP_REPO_ACCESS_GITOLITE": None,
+        },
+    )
     def test_http_clone(self):
     def test_http_clone(self):
         """ Test that HTTP cloning gives reasonable output. """
         """ Test that HTTP cloning gives reasonable output. """
         # Unfortunately, actually testing a git clone would need the app to
         # Unfortunately, actually testing a git clone would need the app to
         # run on a TCP port, which the test environment doesn't do.
         # run on a TCP port, which the test environment doesn't do.
 
 
-        output = self.app.get('/clonetest.git/info/refs?service=git-upload-pack')
+        output = self.app.get(
+            "/clonetest.git/info/refs?service=git-upload-pack"
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn("# service=git-upload-pack", output_text)
         self.assertIn("# service=git-upload-pack", output_text)
         self.assertIn(" refs/heads/master\n0000", output_text)
         self.assertIn(" refs/heads/master\n0000", output_text)
 
 
         output = self.app.post(
         output = self.app.post(
-            '/clonetest.git/git-upload-pack',
-            headers={'Content-Type': 'application/x-git-upload-pack-request'},
+            "/clonetest.git/git-upload-pack",
+            headers={"Content-Type": "application/x-git-upload-pack-request"},
         )
         )
         # Git 2.17 returns 415, older return 200
         # Git 2.17 returns 415, older return 200
         # Either means we didn't fully crash when returning the response
         # Either means we didn't fully crash when returning the response
         self.assertIn(output.status_code, (200, 415))
         self.assertIn(output.status_code, (200, 415))
 
 
-    @patch.dict('pagure.config.config', {
-        'ALLOW_HTTP_PULL_PUSH': True,
-        'ALLOW_HTTP_PUSH': False,
-        'HTTP_REPO_ACCESS_GITOLITE': None,
-    })
+    @patch.dict(
+        "pagure.config.config",
+        {
+            "ALLOW_HTTP_PULL_PUSH": True,
+            "ALLOW_HTTP_PUSH": False,
+            "HTTP_REPO_ACCESS_GITOLITE": None,
+        },
+    )
     def test_http_clone_private(self):
     def test_http_clone_private(self):
         """ Test that HTTP cloning gives reasonable output with project.private. """
         """ Test that HTTP cloning gives reasonable output with project.private. """
         # Unfortunately, actually testing a git clone would need the app to
         # Unfortunately, actually testing a git clone would need the app to
         # run on a TCP port, which the test environment doesn't do.
         # run on a TCP port, which the test environment doesn't do.
-        project = pagure.lib.query._get_project(self.session, 'clonetest')
+        project = pagure.lib.query._get_project(self.session, "clonetest")
         project.private = True
         project.private = True
         self.session.add(project)
         self.session.add(project)
         self.session.commit()
         self.session.commit()
 
 
-        output = self.app.get('/clonetest.git/info/refs?service=git-upload-pack')
+        output = self.app.get(
+            "/clonetest.git/info/refs?service=git-upload-pack"
+        )
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
-        self.assertIn('Project not found', output.get_data(as_text=True))
+        self.assertIn("Project not found", output.get_data(as_text=True))
 
 
         output = self.app.get(
         output = self.app.get(
-            '/clonetest.git/info/refs?service=git-upload-pack',
-            environ_overrides={'REMOTE_USER': 'pingou'},
+            "/clonetest.git/info/refs?service=git-upload-pack",
+            environ_overrides={"REMOTE_USER": "pingou"},
         )
         )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn("# service=git-upload-pack", output_text)
         self.assertIn("# service=git-upload-pack", output_text)
         self.assertIn(" refs/heads/master\n0000", output_text)
         self.assertIn(" refs/heads/master\n0000", output_text)
 
 
-    @patch.dict('pagure.config.config', {
-        'ALLOW_HTTP_PULL_PUSH': True,
-        'ALLOW_HTTP_PUSH': True,
-        'HTTP_REPO_ACCESS_GITOLITE': None,
-    })
+    @patch.dict(
+        "pagure.config.config",
+        {
+            "ALLOW_HTTP_PULL_PUSH": True,
+            "ALLOW_HTTP_PUSH": True,
+            "HTTP_REPO_ACCESS_GITOLITE": None,
+        },
+    )
     def test_http_push(self):
     def test_http_push(self):
         """ Test that the HTTP push gets accepted. """
         """ Test that the HTTP push gets accepted. """
         output = self.app.get(
         output = self.app.get(
-            '/clonetest.git/info/refs?service=git-receive-pack',
-            environ_overrides={'REMOTE_USER': 'pingou'},
+            "/clonetest.git/info/refs?service=git-receive-pack",
+            environ_overrides={"REMOTE_USER": "pingou"},
         )
         )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)

File diff suppressed because it is too large
+ 393 - 295
tests/test_pagure_flask_ui_fork.py


+ 343 - 219
tests/test_pagure_flask_ui_groups.py

@@ -18,8 +18,9 @@ import os
 import json
 import json
 from mock import patch
 from mock import patch
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.config
 import pagure.config
 import tests
 import tests
@@ -30,435 +31,525 @@ class PagureFlaskGroupstests(tests.Modeltests):
 
 
     def test_group_lists(self):
     def test_group_lists(self):
         """ Test the group_lists endpoint. """
         """ Test the group_lists endpoint. """
-        output = self.app.get('/groups')
+        output = self.app.get("/groups")
         self.assertIn(
         self.assertIn(
             '<h3 class="font-weight-bold">\n'
             '<h3 class="font-weight-bold">\n'
             '      Groups <span class="badge badge-secondary">0</span>',
             '      Groups <span class="badge badge-secondary">0</span>',
-            output.get_data(as_text=True))
+            output.get_data(as_text=True),
+        )
 
 
     def test_add_group(self):
     def test_add_group(self):
         """ Test the add_group endpoint. """
         """ Test the add_group endpoint. """
-        output = self.app.get('/group/add')
+        output = self.app.get("/group/add")
         self.assertEqual(output.status_code, 302)
         self.assertEqual(output.status_code, 302)
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/group/add')
+            output = self.app.get("/group/add")
             self.assertEqual(output.status_code, 403)
             self.assertEqual(output.status_code, 403)
 
 
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/group/add')
+            output = self.app.get("/group/add")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
-            self.assertIn('<strong>Create new group</strong>', output.get_data(as_text=True))
+            self.assertIn(
+                "<strong>Create new group</strong>",
+                output.get_data(as_text=True),
+            )
             self.assertNotIn(
             self.assertNotIn(
-                '<option value="admin">admin</option>', output.get_data(as_text=True))
+                '<option value="admin">admin</option>',
+                output.get_data(as_text=True),
+            )
 
 
-            csrf_token = output.get_data(as_text=True).split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+            csrf_token = (
+                output.get_data(as_text=True)
+                .split('name="csrf_token" type="hidden" value="')[1]
+                .split('">')[0]
+            )
 
 
-            data = {
-            }
+            data = {}
 
 
             # Insufficient input
             # Insufficient input
-            output = self.app.post('/group/add', data=data)
+            output = self.app.post("/group/add", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
-            self.assertIn('<strong>Create new group</strong>', output.get_data(as_text=True))
-            self.assertEqual(output.get_data(as_text=True).count(
-                'This field is required.'), 3)
+            self.assertIn(
+                "<strong>Create new group</strong>",
+                output.get_data(as_text=True),
+            )
+            self.assertEqual(
+                output.get_data(as_text=True).count("This field is required."),
+                3,
+            )
 
 
             data = {
             data = {
-                'group_name': 'test_group',
-                'display_name': 'Test Group',
-                'description': 'This is a group for the tests',
+                "group_name": "test_group",
+                "display_name": "Test Group",
+                "description": "This is a group for the tests",
             }
             }
 
 
             # Missing CSRF
             # Missing CSRF
-            output = self.app.post('/group/add', data=data)
+            output = self.app.post("/group/add", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
-            self.assertIn('<strong>Create new group</strong>', output.get_data(as_text=True))
-            self.assertEqual(output.get_data(as_text=True).count(
-                'This field is required.'), 0)
+            self.assertIn(
+                "<strong>Create new group</strong>",
+                output.get_data(as_text=True),
+            )
+            self.assertEqual(
+                output.get_data(as_text=True).count("This field is required."),
+                0,
+            )
 
 
-            data['csrf_token'] = csrf_token
+            data["csrf_token"] = csrf_token
 
 
             # All good
             # All good
             output = self.app.post(
             output = self.app.post(
-                '/group/add', data=data, follow_redirects=True)
+                "/group/add", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                'User `pingou` added to '
-                'the group `test_group`.', output.get_data(as_text=True))
+                "User `pingou` added to " "the group `test_group`.",
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
-                'Group `test_group` created.',
-                output.get_data(as_text=True))
+                "Group `test_group` created.", output.get_data(as_text=True)
+            )
             self.assertIn(
             self.assertIn(
                 '<h3 class="font-weight-bold">\n'
                 '<h3 class="font-weight-bold">\n'
                 '      Groups <span class="badge badge-secondary">1</span>',
                 '      Groups <span class="badge badge-secondary">1</span>',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
 
 
         user = tests.FakeUser(
         user = tests.FakeUser(
-            username='pingou',
-            groups=pagure.config.config['ADMIN_GROUP'])
+            username="pingou", groups=pagure.config.config["ADMIN_GROUP"]
+        )
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/group/add')
+            output = self.app.get("/group/add")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
-            self.assertIn('<strong>Create new group</strong>', output.get_data(as_text=True))
-            self.assertIn('<option value="admin">admin</option>', output.get_data(as_text=True))
+            self.assertIn(
+                "<strong>Create new group</strong>",
+                output.get_data(as_text=True),
+            )
+            self.assertIn(
+                '<option value="admin">admin</option>',
+                output.get_data(as_text=True),
+            )
 
 
             data = {
             data = {
-                'group_name': 'test_admin_group',
-                'group_type': 'admin',
-                'display_name': 'Test Admin Group',
-                'description': 'This is another group for the tests',
-                'csrf_token': csrf_token,
+                "group_name": "test_admin_group",
+                "group_type": "admin",
+                "display_name": "Test Admin Group",
+                "description": "This is another group for the tests",
+                "csrf_token": csrf_token,
             }
             }
 
 
             # All good
             # All good
             output = self.app.post(
             output = self.app.post(
-                '/group/add', data=data, follow_redirects=True)
+                "/group/add", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                'User `pingou` added to '
-                'the group `test_admin_group`.', output.get_data(as_text=True))
+                "User `pingou` added to " "the group `test_admin_group`.",
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
-                'Group `test_admin_group` '
-                'created.',output.get_data(as_text=True))
+                "Group `test_admin_group` " "created.",
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
                 '<h3 class="font-weight-bold">\n'
                 '<h3 class="font-weight-bold">\n'
                 '      Groups <span class="badge badge-secondary">2</span>',
                 '      Groups <span class="badge badge-secondary">2</span>',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
 
 
     def test_edit_group(self):
     def test_edit_group(self):
         """ Test the edit_group endpoint. """
         """ Test the edit_group endpoint. """
 
 
-        output = self.app.get('/group/test_group/edit')
+        output = self.app.get("/group/test_group/edit")
         self.assertEqual(output.status_code, 302)
         self.assertEqual(output.status_code, 302)
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/group/test_group/edit')
+            output = self.app.get("/group/test_group/edit")
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
-            self.assertIn('<p>Group not found</p>', output.get_data(as_text=True))
+            self.assertIn(
+                "<p>Group not found</p>", output.get_data(as_text=True)
+            )
 
 
         self.test_add_group()
         self.test_add_group()
 
 
-        user.username = 'foo'
+        user.username = "foo"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/group/foo/edit')
+            output = self.app.get("/group/foo/edit")
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
-            self.assertIn('<p>Group not found</p>', output.get_data(as_text=True))
+            self.assertIn(
+                "<p>Group not found</p>", output.get_data(as_text=True)
+            )
 
 
-            output = self.app.get('/group/test_group/edit')
+            output = self.app.get("/group/test_group/edit")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                '<title>Edit group: test_group - Pagure</title>',
-                output.get_data(as_text=True))
+                "<title>Edit group: test_group - Pagure</title>",
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
                 '<form action="/group/test_group/edit" method="post">',
                 '<form action="/group/test_group/edit" method="post">',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
                 '<strong><label for="description">Description'
                 '<strong><label for="description">Description'
-                '</label></strong>', output.get_data(as_text=True))
+                "</label></strong>",
+                output.get_data(as_text=True),
+            )
 
 
-            csrf_token = output.get_data(as_text=True).split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+            csrf_token = (
+                output.get_data(as_text=True)
+                .split('name="csrf_token" type="hidden" value="')[1]
+                .split('">')[0]
+            )
 
 
             # Missing CSRF
             # Missing CSRF
             data = {
             data = {
-                'group_name': 'test_group',
-                'display_name': 'Test Group edited',
-                'description': 'This is a group for the tests edited',
+                "group_name": "test_group",
+                "display_name": "Test Group edited",
+                "description": "This is a group for the tests edited",
             }
             }
 
 
             output = self.app.post(
             output = self.app.post(
-                '/group/test_group/edit', data=data, follow_redirects=True)
+                "/group/test_group/edit", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                '<title>Edit group: test_group - Pagure</title>',
-                output.get_data(as_text=True))
+                "<title>Edit group: test_group - Pagure</title>",
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
                 '<form action="/group/test_group/edit" method="post">',
                 '<form action="/group/test_group/edit" method="post">',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
                 '<strong><label for="description">Description'
                 '<strong><label for="description">Description'
-                '</label></strong>', output.get_data(as_text=True))
+                "</label></strong>",
+                output.get_data(as_text=True),
+            )
 
 
             # User not allowed
             # User not allowed
-            data['csrf_token'] = csrf_token
+            data["csrf_token"] = csrf_token
 
 
             output = self.app.post(
             output = self.app.post(
-                '/group/test_group/edit', data=data, follow_redirects=True)
+                "/group/test_group/edit", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                '<title>Group test_group - Pagure</title>',
-                output.get_data(as_text=True))
+                "<title>Group test_group - Pagure</title>",
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
-                'You are not '
-                'allowed to edit this group', output.get_data(as_text=True))
+                "You are not " "allowed to edit this group",
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
                 '<h3 class="mb-0 font-weight-bold">Test Group</h3>',
                 '<h3 class="mb-0 font-weight-bold">Test Group</h3>',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
 
 
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             # Invalid repo
             # Invalid repo
             output = self.app.post(
             output = self.app.post(
-                '/group/bar/edit', data=data, follow_redirects=True)
+                "/group/bar/edit", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
-            self.assertIn('<p>Group not found</p>', output.get_data(as_text=True))
+            self.assertIn(
+                "<p>Group not found</p>", output.get_data(as_text=True)
+            )
 
 
             output = self.app.post(
             output = self.app.post(
-                '/group/test_group/edit', data=data, follow_redirects=True)
+                "/group/test_group/edit", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                '<title>Group test_group - Pagure</title>', output.get_data(as_text=True))
+                "<title>Group test_group - Pagure</title>",
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
                 '<h3 class="mb-0 font-weight-bold">Test Group edited</h3>',
                 '<h3 class="mb-0 font-weight-bold">Test Group edited</h3>',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
-                'Group &#34;Test Group edited&#34; (test_group) edited',
-                output.get_data(as_text=True))
+                "Group &#34;Test Group edited&#34; (test_group) edited",
+                output.get_data(as_text=True),
+            )
 
 
     def test_give_group(self):
     def test_give_group(self):
         """ Test the give_group endpoint. """
         """ Test the give_group endpoint. """
 
 
-        output = self.app.post('/group/test_group/give')
+        output = self.app.post("/group/test_group/give")
         self.assertEqual(output.status_code, 302)
         self.assertEqual(output.status_code, 302)
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post('/group/test_group/give')
+            output = self.app.post("/group/test_group/give")
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
-            self.assertIn('<p>Group not found</p>', output.get_data(as_text=True))
+            self.assertIn(
+                "<p>Group not found</p>", output.get_data(as_text=True)
+            )
 
 
         self.test_add_group()
         self.test_add_group()
 
 
-        user.username = 'foo'
+        user.username = "foo"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post('/group/foo/give')
+            output = self.app.post("/group/foo/give")
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
-            self.assertIn('<p>Group not found</p>', output.get_data(as_text=True))
+            self.assertIn(
+                "<p>Group not found</p>", output.get_data(as_text=True)
+            )
 
 
-            output = self.app.post('/group/test_group/give')
+            output = self.app.post("/group/test_group/give")
             self.assertEqual(output.status_code, 403)
             self.assertEqual(output.status_code, 403)
 
 
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             # Missing CSRF
             # Missing CSRF
-            data = {
-                'username': 'invalid',
-            }
+            data = {"username": "invalid"}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/group/test_group/give', data=data, follow_redirects=True)
+                "/group/test_group/give", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Group test_group - Pagure</title>', output_text)
+                "<title>Group test_group - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 'administered by <a href="/user/pingou">pingou</a>',
                 'administered by <a href="/user/pingou">pingou</a>',
-                output_text)
+                output_text,
+            )
 
 
             # User not found
             # User not found
-            data['csrf_token'] = csrf_token
+            data["csrf_token"] = csrf_token
             output = self.app.post(
             output = self.app.post(
-                '/group/test_group/give', data=data, follow_redirects=True)
+                "/group/test_group/give", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Group test_group - Pagure</title>', output_text)
+                "<title>Group test_group - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
-                '</i> No user invalid found to give this group to</div>',
-                output_text)
+                "</i> No user invalid found to give this group to</div>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 'administered by <a href="/user/pingou">pingou</a>',
                 'administered by <a href="/user/pingou">pingou</a>',
-                output_text)
+                output_text,
+            )
 
 
             # Working
             # Working
             data["username"] = "foo"
             data["username"] = "foo"
 
 
             output = self.app.post(
             output = self.app.post(
-                '/group/test_group/give', data=data, follow_redirects=True)
+                "/group/test_group/give", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Group test_group - Pagure</title>', output_text)
-            self.assertIn('</i> Group given</div>', output_text)
+                "<title>Group test_group - Pagure</title>", output_text
+            )
+            self.assertIn("</i> Group given</div>", output_text)
             self.assertIn(
             self.assertIn(
-                'administered by <a href="/user/foo">foo</a>', output_text)
+                'administered by <a href="/user/foo">foo</a>', output_text
+            )
 
 
     def test_group_delete(self):
     def test_group_delete(self):
         """ Test the group_delete endpoint. """
         """ Test the group_delete endpoint. """
-        output = self.app.post('/group/foo/delete')
+        output = self.app.post("/group/foo/delete")
         self.assertEqual(output.status_code, 302)
         self.assertEqual(output.status_code, 302)
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post('/group/foo/delete', follow_redirects=True)
+            output = self.app.post("/group/foo/delete", follow_redirects=True)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                '<p>No groups have been created on this pagure instance '
-                'yet</p>', output.get_data(as_text=True))
+                "<p>No groups have been created on this pagure instance "
+                "yet</p>",
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
                 '<h3 class="font-weight-bold">\n'
                 '<h3 class="font-weight-bold">\n'
                 '      Groups <span class="badge badge-secondary">0</span>',
                 '      Groups <span class="badge badge-secondary">0</span>',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
 
 
         self.test_add_group()
         self.test_add_group()
 
 
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post('/group/foo/delete', follow_redirects=True)
+            output = self.app.post("/group/foo/delete", follow_redirects=True)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
                 '<h3 class="font-weight-bold">\n'
                 '<h3 class="font-weight-bold">\n'
                 '      Groups <span class="badge badge-secondary">1</span>',
                 '      Groups <span class="badge badge-secondary">1</span>',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
 
 
-            output = self.app.get('/new/')
-            csrf_token = output.get_data(as_text=True).split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+            output = self.app.get("/new/")
+            csrf_token = (
+                output.get_data(as_text=True)
+                .split('name="csrf_token" type="hidden" value="')[1]
+                .split('">')[0]
+            )
 
 
-        user.username = 'foo'
+        user.username = "foo"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
-            data = {
-                'csrf_token': csrf_token,
-            }
+            data = {"csrf_token": csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/group/bar/delete', data=data, follow_redirects=True)
+                "/group/bar/delete", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                'No group `bar` found',
-                output.get_data(as_text=True))
+                "No group `bar` found", output.get_data(as_text=True)
+            )
             self.assertIn(
             self.assertIn(
                 '<h3 class="font-weight-bold">\n'
                 '<h3 class="font-weight-bold">\n'
                 '      Groups <span class="badge badge-secondary">1</span>',
                 '      Groups <span class="badge badge-secondary">1</span>',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
 
 
             output = self.app.post(
             output = self.app.post(
-                '/group/test_group/delete', data=data, follow_redirects=True)
+                "/group/test_group/delete", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                'You are not allowed to '
-                'delete the group test_group', output.get_data(as_text=True))
+                "You are not allowed to " "delete the group test_group",
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
                 '<h3 class="font-weight-bold">\n'
                 '<h3 class="font-weight-bold">\n'
                 '      Groups <span class="badge badge-secondary">1</span>',
                 '      Groups <span class="badge badge-secondary">1</span>',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
 
 
-        user.username = 'bar'
+        user.username = "bar"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
             output = self.app.post(
             output = self.app.post(
-                '/group/test_group/delete', data=data, follow_redirects=True)
+                "/group/test_group/delete", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
             output = self.app.post(
             output = self.app.post(
-                '/group/test_group/delete', data=data, follow_redirects=True)
+                "/group/test_group/delete", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                'Group `test_group` has '
-                'been deleted', output.get_data(as_text=True))
+                "Group `test_group` has " "been deleted",
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
                 '<h3 class="font-weight-bold">\n'
                 '<h3 class="font-weight-bold">\n'
                 '      Groups <span class="badge badge-secondary">0</span>',
                 '      Groups <span class="badge badge-secondary">0</span>',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
 
 
     def test_view_group(self):
     def test_view_group(self):
         """ Test the view_group endpoint. """
         """ Test the view_group endpoint. """
-        output = self.app.get('/group/foo')
+        output = self.app.get("/group/foo")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
         self.test_add_group()
         self.test_add_group()
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/group/test_group')
+            output = self.app.get("/group/test_group")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
                 '<h3 class="mb-0 font-weight-bold">Test Group</h3>',
                 '<h3 class="mb-0 font-weight-bold">Test Group</h3>',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
 
 
-            output = self.app.get('/group/test_admin_group')
+            output = self.app.get("/group/test_admin_group")
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
         user = tests.FakeUser(
         user = tests.FakeUser(
-            username='pingou',
-            groups=pagure.config.config['ADMIN_GROUP'])
+            username="pingou", groups=pagure.config.config["ADMIN_GROUP"]
+        )
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             # Admin can see group of type admins
             # Admin can see group of type admins
-            output = self.app.get('/group/test_admin_group')
+            output = self.app.get("/group/test_admin_group")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
                 '<h3 class="mb-0 font-weight-bold">Test Admin Group</h3>',
                 '<h3 class="mb-0 font-weight-bold">Test Admin Group</h3>',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
             self.assertEqual(
             self.assertEqual(
-                output.get_data(as_text=True).count('<a href="/user/'), 2)
+                output.get_data(as_text=True).count('<a href="/user/'), 2
+            )
 
 
-            csrf_token = output.get_data(as_text=True).split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+            csrf_token = (
+                output.get_data(as_text=True)
+                .split('name="csrf_token" type="hidden" value="')[1]
+                .split('">')[0]
+            )
 
 
             # No CSRF
             # No CSRF
-            data = {
-                'user': 'bar'
-            }
+            data = {"user": "bar"}
 
 
-            output = self.app.post('/group/test_admin_group', data=data)
+            output = self.app.post("/group/test_admin_group", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
                 '<h3 class="mb-0 font-weight-bold">Test Admin Group</h3>',
                 '<h3 class="mb-0 font-weight-bold">Test Admin Group</h3>',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
             self.assertEqual(
             self.assertEqual(
-                output.get_data(as_text=True).count('<a href="/user/'), 2)
+                output.get_data(as_text=True).count('<a href="/user/'), 2
+            )
 
 
             # Invalid user
             # Invalid user
-            data = {
-                'user': 'bar',
-                'csrf_token': csrf_token,
-            }
+            data = {"user": "bar", "csrf_token": csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/group/test_admin_group', data=data, follow_redirects=True)
+                "/group/test_admin_group", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
-            self.assertIn(
-                'No user `bar` found',
-                output.get_data(as_text=True))
+            self.assertIn("No user `bar` found", output.get_data(as_text=True))
             self.assertIn(
             self.assertIn(
                 '<h3 class="mb-0 font-weight-bold">Test Admin Group</h3>',
                 '<h3 class="mb-0 font-weight-bold">Test Admin Group</h3>',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
             self.assertEqual(
             self.assertEqual(
-                output.get_data(as_text=True).count('<a href="/user/'), 2)
+                output.get_data(as_text=True).count('<a href="/user/'), 2
+            )
 
 
             # All good
             # All good
-            data = {
-                'user': 'foo',
-                'csrf_token': csrf_token,
-            }
-            output = self.app.post('/group/test_admin_group', data=data)
+            data = {"user": "foo", "csrf_token": csrf_token}
+            output = self.app.post("/group/test_admin_group", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                'User `foo` added to the '
-                'group `test_admin_group`.', output.get_data(as_text=True))
+                "User `foo` added to the " "group `test_admin_group`.",
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
                 '<h3 class="mb-0 font-weight-bold">Test Admin Group</h3>',
                 '<h3 class="mb-0 font-weight-bold">Test Admin Group</h3>',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
             self.assertEqual(
             self.assertEqual(
-                output.get_data(as_text=True).count('<a href="/user/'), 3)
+                output.get_data(as_text=True).count('<a href="/user/'), 3
+            )
 
 
     def test_group_user_delete(self):
     def test_group_user_delete(self):
         """ Test the group_user_delete endpoint. """
         """ Test the group_user_delete endpoint. """
-        output = self.app.post('/group/foo/bar/delete')
+        output = self.app.post("/group/foo/bar/delete")
         self.assertEqual(output.status_code, 302)
         self.assertEqual(output.status_code, 302)
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             output = self.app.post(
             output = self.app.post(
-                '/group/foo/bar/delete', follow_redirects=True)
+                "/group/foo/bar/delete", follow_redirects=True
+            )
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
         self.test_add_group()
         self.test_add_group()
@@ -466,100 +557,133 @@ class PagureFlaskGroupstests(tests.Modeltests):
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             output = self.app.post(
             output = self.app.post(
-                '/group/test_group/bar/delete', follow_redirects=True)
+                "/group/test_group/bar/delete", follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
                 '<h3 class="mb-0 font-weight-bold">Test Group</h3>',
                 '<h3 class="mb-0 font-weight-bold">Test Group</h3>',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
             self.assertEqual(
             self.assertEqual(
-                output.get_data(as_text=True).count('<a href="/user/'), 2)
+                output.get_data(as_text=True).count('<a href="/user/'), 2
+            )
 
 
-            output = self.app.get('/new/')
-            csrf_token = output.get_data(as_text=True).split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+            output = self.app.get("/new/")
+            csrf_token = (
+                output.get_data(as_text=True)
+                .split('name="csrf_token" type="hidden" value="')[1]
+                .split('">')[0]
+            )
 
 
-            data = {'csrf_token': csrf_token}
+            data = {"csrf_token": csrf_token}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/group/test_group/bar/delete', data=data, follow_redirects=True)
+                "/group/test_group/bar/delete",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
-            self.assertIn(
-                'No user `bar` found',
-                output.get_data(as_text=True))
+            self.assertIn("No user `bar` found", output.get_data(as_text=True))
             self.assertIn(
             self.assertIn(
                 '<h3 class="mb-0 font-weight-bold">Test Group</h3>',
                 '<h3 class="mb-0 font-weight-bold">Test Group</h3>',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
             self.assertEqual(
             self.assertEqual(
-                output.get_data(as_text=True).count('<a href="/user/'), 2)
+                output.get_data(as_text=True).count('<a href="/user/'), 2
+            )
 
 
             output = self.app.post(
             output = self.app.post(
-                '/group/test_group/foo/delete', data=data, follow_redirects=True)
+                "/group/test_group/foo/delete",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                'Could not find user '
-                'username', output.get_data(as_text=True))
+                "Could not find user " "username",
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
                 '<h3 class="mb-0 font-weight-bold">Test Group</h3>',
                 '<h3 class="mb-0 font-weight-bold">Test Group</h3>',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
             self.assertEqual(
             self.assertEqual(
-                output.get_data(as_text=True).count('<a href="/user/'), 2)
+                output.get_data(as_text=True).count('<a href="/user/'), 2
+            )
 
 
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             # User not in the group
             # User not in the group
             output = self.app.post(
             output = self.app.post(
-                '/group/test_group/foo/delete', data=data, follow_redirects=True)
+                "/group/test_group/foo/delete",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                'User `foo` could not be '
-                'found in the group `test_group`', output.get_data(as_text=True))
+                "User `foo` could not be " "found in the group `test_group`",
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
                 '<h3 class="mb-0 font-weight-bold">Test Group</h3>',
                 '<h3 class="mb-0 font-weight-bold">Test Group</h3>',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
             self.assertEqual(
             self.assertEqual(
-                output.get_data(as_text=True).count('<a href="/user/'), 2)
+                output.get_data(as_text=True).count('<a href="/user/'), 2
+            )
 
 
             # Cannot delete creator
             # Cannot delete creator
             output = self.app.post(
             output = self.app.post(
-                '/group/test_group/foo/delete', data=data, follow_redirects=True)
+                "/group/test_group/foo/delete",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                'User `foo` could not be '
-                'found in the group `test_group`', output.get_data(as_text=True))
+                "User `foo` could not be " "found in the group `test_group`",
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
                 '<h3 class="mb-0 font-weight-bold">Test Group</h3>',
                 '<h3 class="mb-0 font-weight-bold">Test Group</h3>',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
             self.assertEqual(
             self.assertEqual(
-                output.get_data(as_text=True).count('<a href="/user/'), 2)
+                output.get_data(as_text=True).count('<a href="/user/'), 2
+            )
 
 
             # Add user foo
             # Add user foo
-            data = {
-                'user': 'foo',
-                'csrf_token': csrf_token,
-            }
-            output = self.app.post('/group/test_group', data=data)
+            data = {"user": "foo", "csrf_token": csrf_token}
+            output = self.app.post("/group/test_group", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                'User `foo` added to the '
-                'group `test_group`.', output.get_data(as_text=True))
+                "User `foo` added to the " "group `test_group`.",
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
                 '<h3 class="mb-0 font-weight-bold">Test Group</h3>',
                 '<h3 class="mb-0 font-weight-bold">Test Group</h3>',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
             self.assertEqual(
             self.assertEqual(
-                output.get_data(as_text=True).count('<a href="/user/'), 3)
+                output.get_data(as_text=True).count('<a href="/user/'), 3
+            )
 
 
             output = self.app.post(
             output = self.app.post(
-                '/group/test_group/foo/delete', data=data, follow_redirects=True)
+                "/group/test_group/foo/delete",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                'User `foo` removed from '
-                'the group `test_group`', output.get_data(as_text=True))
+                "User `foo` removed from " "the group `test_group`",
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
                 '<h3 class="mb-0 font-weight-bold">Test Group</h3>',
                 '<h3 class="mb-0 font-weight-bold">Test Group</h3>',
-                output.get_data(as_text=True))
+                output.get_data(as_text=True),
+            )
             self.assertEqual(
             self.assertEqual(
-                output.get_data(as_text=True).count('<a href="/user/'), 2)
+                output.get_data(as_text=True).count('<a href="/user/'), 2
+            )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 50 - 47
tests/test_pagure_flask_ui_issue_pr_link.py

@@ -23,8 +23,9 @@ import os
 import pygit2
 import pygit2
 from mock import ANY, patch, MagicMock
 from mock import ANY, patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import pagure.lib.tasks
 import pagure.lib.tasks
@@ -43,86 +44,89 @@ class PagureFlaskPrIssueLinkTest(tests.Modeltests):
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         tests.create_projects(
         tests.create_projects(
-            self.session, is_fork=True, user_id=2, hook_token_suffix='bar')
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
-        tests.create_projects_git(os.path.join(
-            self.path, 'repos', 'forks', 'foo'), bare=True)
+            self.session, is_fork=True, user_id=2, hook_token_suffix="bar"
+        )
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
+        tests.create_projects_git(
+            os.path.join(self.path, "repos", "forks", "foo"), bare=True
+        )
 
 
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
 
 
         # Create issues to play with
         # Create issues to play with
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
-            title='tést íssüé',
-            content='We should work on this',
-            user='pingou',
+            title="tést íssüé",
+            content="We should work on this",
+            user="pingou",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg.title, 'tést íssüé')
+        self.assertEqual(msg.title, "tést íssüé")
 
 
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
-            title='tést íssüé #2',
-            content='We should still work on this',
-            user='foo',
+            title="tést íssüé #2",
+            content="We should still work on this",
+            user="foo",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg.title, 'tést íssüé #2')
+        self.assertEqual(msg.title, "tést íssüé #2")
 
 
         # Add a commit to the fork
         # Add a commit to the fork
 
 
-        newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
-        repopath = os.path.join(newpath, 'test')
-        clone_repo = pygit2.clone_repository(os.path.join(
-            self.path, 'repos', 'forks', 'foo', 'test.git'), repopath)
+        newpath = tempfile.mkdtemp(prefix="pagure-fork-test")
+        repopath = os.path.join(newpath, "test")
+        clone_repo = pygit2.clone_repository(
+            os.path.join(self.path, "repos", "forks", "foo", "test.git"),
+            repopath,
+        )
 
 
         # Create a file in that git repo
         # Create a file in that git repo
-        with open(os.path.join(repopath, 'sources'), 'w') as stream:
-            stream.write('foo\n bar')
-        clone_repo.index.add('sources')
+        with open(os.path.join(repopath, "sources"), "w") as stream:
+            stream.write("foo\n bar")
+        clone_repo.index.add("sources")
         clone_repo.index.write()
         clone_repo.index.write()
 
 
         try:
         try:
-            com = repo.revparse_single('HEAD')
+            com = repo.revparse_single("HEAD")
             prev_commit = [com.oid.hex]
             prev_commit = [com.oid.hex]
         except:
         except:
             prev_commit = []
             prev_commit = []
 
 
         # Commits the files added
         # Commits the files added
         tree = clone_repo.index.write_tree()
         tree = clone_repo.index.write_tree()
-        author = pygit2.Signature(
-            'Alice Author', 'alice@authors.tld')
-        committer = pygit2.Signature(
-            'Cecil Committer', 'cecil@committers.tld')
+        author = pygit2.Signature("Alice Author", "alice@authors.tld")
+        committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
         clone_repo.create_commit(
         clone_repo.create_commit(
-            'refs/heads/master',  # the name of the reference to update
+            "refs/heads/master",  # the name of the reference to update
             author,
             author,
             committer,
             committer,
-            'Add sources file for testing\n\n Relates to #2',
+            "Add sources file for testing\n\n Relates to #2",
             # binary string representing the tree object ID
             # binary string representing the tree object ID
             tree,
             tree,
             # list of binary strings representing parents of the new commit
             # list of binary strings representing parents of the new commit
-            prev_commit
+            prev_commit,
         )
         )
-        refname = 'refs/heads/master:refs/heads/master'
+        refname = "refs/heads/master:refs/heads/master"
         ori_remote = clone_repo.remotes[0]
         ori_remote = clone_repo.remotes[0]
         PagureRepo.push(ori_remote, refname)
         PagureRepo.push(ori_remote, refname)
 
 
         # Create the corresponding PR
         # Create the corresponding PR
 
 
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         fork_repo = pagure.lib.query.get_authorized_project(
         fork_repo = pagure.lib.query.get_authorized_project(
-            self.session, 'test', user='foo')
+            self.session, "test", user="foo"
+        )
 
 
         request = pagure.lib.query.new_pull_request(
         request = pagure.lib.query.new_pull_request(
             self.session,
             self.session,
-            branch_from='master',
+            branch_from="master",
             repo_to=repo,
             repo_to=repo,
-            branch_to='master',
-            title='test PR',
-            user='foo',
+            branch_to="master",
+            title="test PR",
+            user="foo",
             initial_comment=None,
             initial_comment=None,
             repo_from=fork_repo,
             repo_from=fork_repo,
         )
         )
@@ -134,25 +138,23 @@ class PagureFlaskPrIssueLinkTest(tests.Modeltests):
     def test_ticket_no_link(self):
     def test_ticket_no_link(self):
         """ Test that no Related PR(s) block is showing in the issue page.
         """ Test that no Related PR(s) block is showing in the issue page.
         """
         """
-        output = self.app.get('/test/issue/1')
+        output = self.app.get("/test/issue/1")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         self.assertNotIn(
         self.assertNotIn(
-            'Related Pull Requests',
-            output.get_data(as_text=True))
+            "Related Pull Requests", output.get_data(as_text=True)
+        )
 
 
     def test_ticket_link(self):
     def test_ticket_link(self):
         """ Test that a Related PR(s) block is showing in the issue page.
         """ Test that a Related PR(s) block is showing in the issue page.
         """
         """
-        output = self.app.get('/test/issue/2')
+        output = self.app.get("/test/issue/2")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
-        self.assertIn(
-            'Related Pull Requests',
-            output.get_data(as_text=True))
+        self.assertIn("Related Pull Requests", output.get_data(as_text=True))
 
 
     def test_pr_link_issue_list(self):
     def test_pr_link_issue_list(self):
         """ Test that the related PR(s) shows in the page listing issues
         """ Test that the related PR(s) shows in the page listing issues
         """
         """
-        output = self.app.get('/test/issues')
+        output = self.app.get("/test/issues")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         self.assertIn(
         self.assertIn(
             '<span title="Related to PR#3" class="badge font-weight-bold '
             '<span title="Related to PR#3" class="badge font-weight-bold '
@@ -160,8 +162,9 @@ class PagureFlaskPrIssueLinkTest(tests.Modeltests):
             '                            <i class="fa fa-link"></i>\n'
             '                            <i class="fa fa-link"></i>\n'
             '                            <a href="/test/pull-request/3" '
             '                            <a href="/test/pull-request/3" '
             'class="notblue">PR#3</a>\n                          </span>',
             'class="notblue">PR#3</a>\n                          </span>',
-            output.get_data(as_text=True))
+            output.get_data(as_text=True),
+        )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

File diff suppressed because it is too large
+ 454 - 415
tests/test_pagure_flask_ui_issues.py


File diff suppressed because it is too large
+ 273 - 268
tests/test_pagure_flask_ui_issues_acl_checks.py


File diff suppressed because it is too large
+ 360 - 334
tests/test_pagure_flask_ui_issues_open_access.py


+ 118 - 104
tests/test_pagure_flask_ui_issues_private.py

@@ -16,8 +16,9 @@ import os
 
 
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query  # noqa
 import pagure.lib.query  # noqa
 import tests  # noqa
 import tests  # noqa
@@ -27,182 +28,187 @@ class PagureFlaskIssuesPrivatetests(tests.Modeltests):
     """ Tests for flask issues controller of pagure with private tickets
     """ Tests for flask issues controller of pagure with private tickets
     """
     """
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def setUp(self):
     def setUp(self):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(PagureFlaskIssuesPrivatetests, self).setUp()
         super(PagureFlaskIssuesPrivatetests, self).setUp()
 
 
         # Create a 3rd user
         # Create a 3rd user
         item = pagure.lib.model.User(
         item = pagure.lib.model.User(
-            user='random',
-            fullname='Random user',
-            password='foo',
-            default_email='random@bar.com',
+            user="random",
+            fullname="Random user",
+            password="foo",
+            default_email="random@bar.com",
         )
         )
         self.session.add(item)
         self.session.add(item)
-        item = pagure.lib.model.UserEmail(
-            user_id=3,
-            email='random@bar.com')
+        item = pagure.lib.model.UserEmail(user_id=3, email="random@bar.com")
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'))
+        tests.create_projects_git(os.path.join(self.path, "repos"))
 
 
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
-            title='Test issue #1',
-            content='We should work on this for the second time',
-            user='foo',
-            status='Open',
+            title="Test issue #1",
+            content="We should work on this for the second time",
+            user="foo",
+            status="Open",
             private=True,
             private=True,
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg.title, 'Test issue #1')
+        self.assertEqual(msg.title, "Test issue #1")
 
 
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
-            title='Test issue #2',
-            content='We should work on this for the second time',
-            user='foo',
-            status='Open',
+            title="Test issue #2",
+            content="We should work on this for the second time",
+            user="foo",
+            status="Open",
             private=False,
             private=False,
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg.title, 'Test issue #2')
+        self.assertEqual(msg.title, "Test issue #2")
 
 
     def test_issue_list_anonymous(self):
     def test_issue_list_anonymous(self):
         """ Test the list of issues when user is logged out. """
         """ Test the list of issues when user is logged out. """
 
 
-        output = self.app.get('/test/issues')
+        output = self.app.get("/test/issues")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
+        self.assertIn("<title>Issues - test - Pagure</title>", output_text)
         self.assertIn(
         self.assertIn(
-            '<title>Issues - test - Pagure</title>', output_text)
-        self.assertIn(
-            '<span class="fa fa-fw fa-exclamation-circle"></span> 1 Open Issues\n', output_text)
+            '<span class="fa fa-fw fa-exclamation-circle"></span> 1 Open Issues\n',
+            output_text,
+        )
 
 
     def test_issue_list_admin(self):
     def test_issue_list_admin(self):
         """ Test the list of issues when user is an admin of the project.
         """ Test the list of issues when user is an admin of the project.
         """
         """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/issues')
+            output = self.app.get("/test/issues")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
+            self.assertIn("<title>Issues - test - Pagure</title>", output_text)
             self.assertIn(
             self.assertIn(
-                '<title>Issues - test - Pagure</title>', output_text)
-            self.assertIn(
-                '<span class="fa fa-fw fa-exclamation-circle"></span> 2 Open Issues\n', output_text)
+                '<span class="fa fa-fw fa-exclamation-circle"></span> 2 Open Issues\n',
+                output_text,
+            )
 
 
     def test_issue_list_author(self):
     def test_issue_list_author(self):
         """ Test the list of issues when user is an admin of the project.
         """ Test the list of issues when user is an admin of the project.
         """
         """
 
 
-        user = tests.FakeUser(username='foo')
+        user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/issues')
+            output = self.app.get("/test/issues")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
+            self.assertIn("<title>Issues - test - Pagure</title>", output_text)
             self.assertIn(
             self.assertIn(
-                '<title>Issues - test - Pagure</title>', output_text)
-            self.assertIn(
-                '<span class="fa fa-fw fa-exclamation-circle"></span> 2 Open Issues\n', output_text)
+                '<span class="fa fa-fw fa-exclamation-circle"></span> 2 Open Issues\n',
+                output_text,
+            )
 
 
     def test_issue_list_authenticated(self):
     def test_issue_list_authenticated(self):
         """ Test the list of issues when user is authenticated but has no
         """ Test the list of issues when user is authenticated but has no
         special access to the project.
         special access to the project.
         """
         """
 
 
-        user = tests.FakeUser(username='random')
+        user = tests.FakeUser(username="random")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/issues')
+            output = self.app.get("/test/issues")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
+            self.assertIn("<title>Issues - test - Pagure</title>", output_text)
             self.assertIn(
             self.assertIn(
-                '<title>Issues - test - Pagure</title>', output_text)
-            self.assertIn(
-                '<span class="fa fa-fw fa-exclamation-circle"></span> 1 Open Issues\n', output_text)
+                '<span class="fa fa-fw fa-exclamation-circle"></span> 1 Open Issues\n',
+                output_text,
+            )
 
 
     def test_issue_list_authenticated_ticket(self):
     def test_issue_list_authenticated_ticket(self):
         """ Test the list of issues when user is authenticated but has
         """ Test the list of issues when user is authenticated but has
         ticket level access to the project.
         ticket level access to the project.
         """
         """
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
         msg = pagure.lib.query.add_user_to_project(
         msg = pagure.lib.query.add_user_to_project(
             session=self.session,
             session=self.session,
             project=repo,
             project=repo,
-            new_user='random',
-            user='pingou',
-            access='ticket',
+            new_user="random",
+            user="pingou",
+            access="ticket",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'User added')
+        self.assertEqual(msg, "User added")
 
 
-        user = tests.FakeUser(username='random')
+        user = tests.FakeUser(username="random")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/issues')
+            output = self.app.get("/test/issues")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
+            self.assertIn("<title>Issues - test - Pagure</title>", output_text)
             self.assertIn(
             self.assertIn(
-                '<title>Issues - test - Pagure</title>', output_text)
-            self.assertIn(
-                '<span class="fa fa-fw fa-exclamation-circle"></span> 1 Open Issues\n', output_text)
+                '<span class="fa fa-fw fa-exclamation-circle"></span> 1 Open Issues\n',
+                output_text,
+            )
 
 
     def test_issue_list_authenticated_commit(self):
     def test_issue_list_authenticated_commit(self):
         """ Test the list of issues when user is authenticated but has
         """ Test the list of issues when user is authenticated but has
         commit level access to the project.
         commit level access to the project.
         """
         """
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
         msg = pagure.lib.query.add_user_to_project(
         msg = pagure.lib.query.add_user_to_project(
             session=self.session,
             session=self.session,
             project=repo,
             project=repo,
-            new_user='random',
-            user='pingou',
-            access='commit',
+            new_user="random",
+            user="pingou",
+            access="commit",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'User added')
+        self.assertEqual(msg, "User added")
 
 
-        user = tests.FakeUser(username='random')
+        user = tests.FakeUser(username="random")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/issues')
+            output = self.app.get("/test/issues")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
+            self.assertIn("<title>Issues - test - Pagure</title>", output_text)
             self.assertIn(
             self.assertIn(
-                '<title>Issues - test - Pagure</title>', output_text)
-            self.assertIn(
-                '<span class="fa fa-fw fa-exclamation-circle"></span> 2 Open Issues\n', output_text)
+                '<span class="fa fa-fw fa-exclamation-circle"></span> 2 Open Issues\n',
+                output_text,
+            )
 
 
     def test_issue_list_authenticated_assigned(self):
     def test_issue_list_authenticated_assigned(self):
         """ Test the list of issues when user is authenticated and is
         """ Test the list of issues when user is authenticated and is
         assigned to one of the issue.
         assigned to one of the issue.
         """
         """
 
 
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         issue.assignee_id = 3  # random
         issue.assignee_id = 3  # random
         self.session.add(issue)
         self.session.add(issue)
         self.session.commit()
         self.session.commit()
 
 
-        user = tests.FakeUser(username='random')
+        user = tests.FakeUser(username="random")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/issues')
+            output = self.app.get("/test/issues")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
+            self.assertIn("<title>Issues - test - Pagure</title>", output_text)
             self.assertIn(
             self.assertIn(
-                '<title>Issues - test - Pagure</title>', output_text)
-            self.assertIn(
-                '<span class="fa fa-fw fa-exclamation-circle"></span> 2 Open Issues\n', output_text)
+                '<span class="fa fa-fw fa-exclamation-circle"></span> 2 Open Issues\n',
+                output_text,
+            )
 
 
     def test_view_issue_anonymous(self):
     def test_view_issue_anonymous(self):
         """ Test accessing a private ticket when user is logged out. """
         """ Test accessing a private ticket when user is logged out. """
 
 
-        output = self.app.get('/test/issue/1')
+        output = self.app.get("/test/issue/1")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
     def test_view_issue_admin(self):
     def test_view_issue_admin(self):
@@ -210,118 +216,126 @@ class PagureFlaskIssuesPrivatetests(tests.Modeltests):
         project.
         project.
         """
         """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/issue/1')
+            output = self.app.get("/test/issue/1")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Issue #1: Test issue #1 - test - Pagure</title>',
-                output_text)
+                "<title>Issue #1: Test issue #1 - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<span class="fa fa-fw text-success fa-exclamation-circle pt-1"></span>\n'
                 '<span class="fa fa-fw text-success fa-exclamation-circle pt-1"></span>\n'
                 '            <span class="text-success font-weight-bold">#1</span>\n',
                 '            <span class="text-success font-weight-bold">#1</span>\n',
-                output_text)
+                output_text,
+            )
 
 
     def test_view_issue_author(self):
     def test_view_issue_author(self):
         """ Test accessing a private ticket when user opened the ticket.
         """ Test accessing a private ticket when user opened the ticket.
         """
         """
 
 
-        user = tests.FakeUser(username='foo')
+        user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/issue/1')
+            output = self.app.get("/test/issue/1")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Issue #1: Test issue #1 - test - Pagure</title>',
-                output_text)
+                "<title>Issue #1: Test issue #1 - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<span class="fa fa-fw text-success fa-exclamation-circle pt-1"></span>\n'
                 '<span class="fa fa-fw text-success fa-exclamation-circle pt-1"></span>\n'
                 '            <span class="text-success font-weight-bold">#1</span>\n',
                 '            <span class="text-success font-weight-bold">#1</span>\n',
-                output_text)
+                output_text,
+            )
 
 
     def test_view_issue_authenticated(self):
     def test_view_issue_authenticated(self):
         """ Test accessing a private ticket when user is authenticated but
         """ Test accessing a private ticket when user is authenticated but
         has no special access to the project.
         has no special access to the project.
         """
         """
 
 
-        user = tests.FakeUser(username='random')
+        user = tests.FakeUser(username="random")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/issue/1')
+            output = self.app.get("/test/issue/1")
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
     def test_view_issue_authenticated_ticket(self):
     def test_view_issue_authenticated_ticket(self):
         """ Test accessing a private ticket when user is authenticated and
         """ Test accessing a private ticket when user is authenticated and
         has ticket level access to the project.
         has ticket level access to the project.
         """
         """
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
         msg = pagure.lib.query.add_user_to_project(
         msg = pagure.lib.query.add_user_to_project(
             session=self.session,
             session=self.session,
             project=repo,
             project=repo,
-            new_user='random',
-            user='pingou',
-            access='ticket',
+            new_user="random",
+            user="pingou",
+            access="ticket",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'User added')
+        self.assertEqual(msg, "User added")
 
 
-        user = tests.FakeUser(username='random')
+        user = tests.FakeUser(username="random")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/issue/1')
+            output = self.app.get("/test/issue/1")
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
     def test_view_issue_authenticated_commit(self):
     def test_view_issue_authenticated_commit(self):
         """ Test accessing a private ticket when user is authenticated and
         """ Test accessing a private ticket when user is authenticated and
         has commit level access to the project.
         has commit level access to the project.
         """
         """
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
         msg = pagure.lib.query.add_user_to_project(
         msg = pagure.lib.query.add_user_to_project(
             session=self.session,
             session=self.session,
             project=repo,
             project=repo,
-            new_user='random',
-            user='pingou',
-            access='commit',
+            new_user="random",
+            user="pingou",
+            access="commit",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'User added')
+        self.assertEqual(msg, "User added")
 
 
-        user = tests.FakeUser(username='random')
+        user = tests.FakeUser(username="random")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/issue/1')
+            output = self.app.get("/test/issue/1")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Issue #1: Test issue #1 - test - Pagure</title>',
-                output_text)
+                "<title>Issue #1: Test issue #1 - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<span class="fa fa-fw text-success fa-exclamation-circle pt-1"></span>\n'
                 '<span class="fa fa-fw text-success fa-exclamation-circle pt-1"></span>\n'
                 '            <span class="text-success font-weight-bold">#1</span>\n',
                 '            <span class="text-success font-weight-bold">#1</span>\n',
-                output_text)
+                output_text,
+            )
 
 
     def test_view_issue_authenticated_assigned(self):
     def test_view_issue_authenticated_assigned(self):
         """ Test accessing a private ticket when user is authenticated and
         """ Test accessing a private ticket when user is authenticated and
         is assigned to one of the issue.
         is assigned to one of the issue.
         """
         """
 
 
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         issue.assignee_id = 3  # random
         issue.assignee_id = 3  # random
         self.session.add(issue)
         self.session.add(issue)
         self.session.commit()
         self.session.commit()
 
 
-        user = tests.FakeUser(username='random')
+        user = tests.FakeUser(username="random")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/issue/1')
+            output = self.app.get("/test/issue/1")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Issue #1: Test issue #1 - test - Pagure</title>',
-                output_text)
+                "<title>Issue #1: Test issue #1 - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<span class="fa fa-fw text-success fa-exclamation-circle pt-1"></span>\n'
                 '<span class="fa fa-fw text-success fa-exclamation-circle pt-1"></span>\n'
                 '            <span class="text-success font-weight-bold">#1</span>\n',
                 '            <span class="text-success font-weight-bold">#1</span>\n',
-                output_text)
+                output_text,
+            )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 149 - 126
tests/test_pagure_flask_ui_issues_read_only.py

@@ -17,8 +17,9 @@ import os
 
 
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query  # noqa
 import pagure.lib.query  # noqa
 import tests  # noqa
 import tests  # noqa
@@ -28,18 +29,18 @@ class PagureFlaskIssuesReadOnlytests(tests.Modeltests):
     """ Tests for flask issues controller of pagure with read-only tickets
     """ Tests for flask issues controller of pagure with read-only tickets
     """
     """
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def setUp(self):
     def setUp(self):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(PagureFlaskIssuesReadOnlytests, self).setUp()
         super(PagureFlaskIssuesReadOnlytests, self).setUp()
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'))
+        tests.create_projects_git(os.path.join(self.path, "repos"))
 
 
         # Make the project's issue tracker read-only
         # Make the project's issue tracker read-only
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         settings = repo.settings
         settings = repo.settings
-        settings['issue_tracker_read_only'] = True
+        settings["issue_tracker_read_only"] = True
         repo.settings = settings
         repo.settings = settings
         self.session.add(repo)
         self.session.add(repo)
         self.session.commit()
         self.session.commit()
@@ -48,154 +49,171 @@ class PagureFlaskIssuesReadOnlytests(tests.Modeltests):
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
-            title='Test issue #1',
-            content='We should work on this for the second time',
-            user='foo',
-            status='Open',
+            title="Test issue #1",
+            content="We should work on this for the second time",
+            user="foo",
+            status="Open",
             private=True,
             private=True,
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg.title, 'Test issue #1')
+        self.assertEqual(msg.title, "Test issue #1")
 
 
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
-            title='Test issue #2',
-            content='We should work on this for the second time',
-            user='foo',
-            status='Open',
+            title="Test issue #2",
+            content="We should work on this for the second time",
+            user="foo",
+            status="Open",
             private=False,
             private=False,
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg.title, 'Test issue #2')
+        self.assertEqual(msg.title, "Test issue #2")
 
 
     def test_issue_list_authenticated_commit(self):
     def test_issue_list_authenticated_commit(self):
         """ Test the list of issues when user is authenticated and has
         """ Test the list of issues when user is authenticated and has
         access to the project.
         access to the project.
         """
         """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/issues')
+            output = self.app.get("/test/issues")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertIn(
-                '<title>Issues - test - Pagure</title>', output_text)
+            self.assertIn("<title>Issues - test - Pagure</title>", output_text)
             self.assertIn(
             self.assertIn(
                 '<span class="fa fa-fw fa-exclamation-circle"></span>'
                 '<span class="fa fa-fw fa-exclamation-circle"></span>'
-                ' 2 Open Issues\n', output_text)
+                " 2 Open Issues\n",
+                output_text,
+            )
 
 
     def test_field_comment(self):
     def test_field_comment(self):
         """ Test if the field commit is present on the issue page.
         """ Test if the field commit is present on the issue page.
         """
         """
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/issue/1')
+            output = self.app.get("/test/issue/1")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Issue #1: Test issue #1 - test - Pagure</title>',
-                output_text)
+                "<title>Issue #1: Test issue #1 - test - Pagure</title>",
+                output_text,
+            )
             self.assertNotIn(
             self.assertNotIn(
                 'value="Update Issue" title="Comment and Update Metadata" '
                 'value="Update Issue" title="Comment and Update Metadata" '
-                'tabindex=2 />', output_text)
-            self.assertIn(
-                'This issue tracker is read-only.', output_text)
+                "tabindex=2 />",
+                output_text,
+            )
+            self.assertIn("This issue tracker is read-only.", output_text)
 
 
     def test_update_ticket(self):
     def test_update_ticket(self):
         """ Test updating a ticket.
         """ Test updating a ticket.
         """
         """
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             output = self.app.post(
             output = self.app.post(
-                '/test/issue/1/update', data={}, follow_redirects=True)
+                "/test/issue/1/update", data={}, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 401)
             self.assertEqual(output.status_code, 401)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Unauthorized :\'( - Pagure</title>', output_text)
+                "<title>Unauthorized :'( - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
-                '<p>The issue tracker for this project is read-only</p>',
-                output_text)
+                "<p>The issue tracker for this project is read-only</p>",
+                output_text,
+            )
 
 
     def test_edit_comment(self):
     def test_edit_comment(self):
         """ Test editing a comment from a ticket.
         """ Test editing a comment from a ticket.
         """
         """
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             output = self.app.post(
             output = self.app.post(
-                '/test/issue/1/comment/1/edit', data={},
-                follow_redirects=True)
+                "/test/issue/1/comment/1/edit", data={}, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 401)
             self.assertEqual(output.status_code, 401)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Unauthorized :\'( - Pagure</title>', output_text)
+                "<title>Unauthorized :'( - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
-                '<p>The issue tracker for this project is read-only</p>',
-                output_text)
+                "<p>The issue tracker for this project is read-only</p>",
+                output_text,
+            )
 
 
     def test_edit_ticket(self):
     def test_edit_ticket(self):
         """ Test editing a ticket.
         """ Test editing a ticket.
         """
         """
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             output = self.app.post(
             output = self.app.post(
-                '/test/issue/1/edit', data={}, follow_redirects=True)
+                "/test/issue/1/edit", data={}, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 401)
             self.assertEqual(output.status_code, 401)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Unauthorized :\'( - Pagure</title>', output_text)
+                "<title>Unauthorized :'( - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
-                '<p>The issue tracker for this project is read-only</p>',
-                output_text)
+                "<p>The issue tracker for this project is read-only</p>",
+                output_text,
+            )
 
 
     def test_new_issue(self):
     def test_new_issue(self):
         """ Test creating a new ticket.
         """ Test creating a new ticket.
         """
         """
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post('/test/new_issue/', data={})
+            output = self.app.post("/test/new_issue/", data={})
             self.assertEqual(output.status_code, 401)
             self.assertEqual(output.status_code, 401)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Unauthorized :\'( - Pagure</title>', output_text)
+                "<title>Unauthorized :'( - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
-                '<p>The issue tracker for this project is read-only</p>',
-                output_text)
+                "<p>The issue tracker for this project is read-only</p>",
+                output_text,
+            )
 
 
     def test_deleting_issue(self):
     def test_deleting_issue(self):
         """ Test deleting a new ticket.
         """ Test deleting a new ticket.
         """
         """
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post('/test/issue/1/drop', data={})
+            output = self.app.post("/test/issue/1/drop", data={})
             self.assertEqual(output.status_code, 401)
             self.assertEqual(output.status_code, 401)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Unauthorized :\'( - Pagure</title>', output_text)
+                "<title>Unauthorized :'( - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
-                '<p>The issue tracker for this project is read-only</p>',
-                output_text)
+                "<p>The issue tracker for this project is read-only</p>",
+                output_text,
+            )
 
 
     def test_uploading_to_issue(self):
     def test_uploading_to_issue(self):
         """ Test uploading to a new ticket.
         """ Test uploading to a new ticket.
         """
         """
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post('/test/issue/1/upload', data={})
+            output = self.app.post("/test/issue/1/upload", data={})
             self.assertEqual(output.status_code, 401)
             self.assertEqual(output.status_code, 401)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Unauthorized :\'( - Pagure</title>', output_text)
+                "<title>Unauthorized :'( - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
-                '<p>The issue tracker for this project is read-only</p>',
-                output_text)
+                "<p>The issue tracker for this project is read-only</p>",
+                output_text,
+            )
 
 
 
 
 class PagureFlaskAPIIssuesReadOnlytests(PagureFlaskIssuesReadOnlytests):
 class PagureFlaskAPIIssuesReadOnlytests(PagureFlaskIssuesReadOnlytests):
     """ Tests for flask API issues controller of pagure with read-only tickets
     """ Tests for flask API issues controller of pagure with read-only tickets
     """
     """
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def setUp(self):
     def setUp(self):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(PagureFlaskAPIIssuesReadOnlytests, self).setUp()
         super(PagureFlaskAPIIssuesReadOnlytests, self).setUp()
@@ -203,122 +221,122 @@ class PagureFlaskAPIIssuesReadOnlytests(PagureFlaskIssuesReadOnlytests):
     def test_api_new_issue(self):
     def test_api_new_issue(self):
         """ Test creating a new ticket.
         """ Test creating a new ticket.
         """
         """
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post('/api/0/test/new_issue', data={})
+            output = self.app.post("/api/0/test/new_issue", data={})
             self.assertEqual(output.status_code, 401)
             self.assertEqual(output.status_code, 401)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
                 data,
                 data,
                 {
                 {
-                    u'error': u'The issue tracker of this project is read-only',
-                    u'error_code': u'ETRACKERREADONLY'
-                }
+                    "error": "The issue tracker of this project is read-only",
+                    "error_code": "ETRACKERREADONLY",
+                },
             )
             )
 
 
     def test_api_change_status_issue(self):
     def test_api_change_status_issue(self):
         """ Test closing a ticket. """
         """ Test closing a ticket. """
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post('/api/0/test/issue/1/status', data={})
+            output = self.app.post("/api/0/test/issue/1/status", data={})
             self.assertEqual(output.status_code, 401)
             self.assertEqual(output.status_code, 401)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
                 data,
                 data,
                 {
                 {
-                    u'error': u'The issue tracker of this project is read-only',
-                    u'error_code': u'ETRACKERREADONLY'
-                }
+                    "error": "The issue tracker of this project is read-only",
+                    "error_code": "ETRACKERREADONLY",
+                },
             )
             )
 
 
     def test_api_change_milestone_issue(self):
     def test_api_change_milestone_issue(self):
         """ Test change the milestone of a ticket. """
         """ Test change the milestone of a ticket. """
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post('/api/0/test/issue/1/milestone', data={})
+            output = self.app.post("/api/0/test/issue/1/milestone", data={})
             self.assertEqual(output.status_code, 401)
             self.assertEqual(output.status_code, 401)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
                 data,
                 data,
                 {
                 {
-                    u'error': u'The issue tracker of this project is read-only',
-                    u'error_code': u'ETRACKERREADONLY'
-                }
+                    "error": "The issue tracker of this project is read-only",
+                    "error_code": "ETRACKERREADONLY",
+                },
             )
             )
 
 
     def test_api_comment_issue(self):
     def test_api_comment_issue(self):
         """ Test comment on a ticket. """
         """ Test comment on a ticket. """
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post('/api/0/test/issue/1/comment', data={})
+            output = self.app.post("/api/0/test/issue/1/comment", data={})
             self.assertEqual(output.status_code, 401)
             self.assertEqual(output.status_code, 401)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
                 data,
                 data,
                 {
                 {
-                    u'error': u'The issue tracker of this project is read-only',
-                    u'error_code': u'ETRACKERREADONLY'
-                }
+                    "error": "The issue tracker of this project is read-only",
+                    "error_code": "ETRACKERREADONLY",
+                },
             )
             )
 
 
     def test_api_assign_issue(self):
     def test_api_assign_issue(self):
         """ Test assigning a ticket. """
         """ Test assigning a ticket. """
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post('/api/0/test/issue/1/assign', data={})
+            output = self.app.post("/api/0/test/issue/1/assign", data={})
             self.assertEqual(output.status_code, 401)
             self.assertEqual(output.status_code, 401)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
                 data,
                 data,
                 {
                 {
-                    u'error': u'The issue tracker of this project is read-only',
-                    u'error_code': u'ETRACKERREADONLY'
-                }
+                    "error": "The issue tracker of this project is read-only",
+                    "error_code": "ETRACKERREADONLY",
+                },
             )
             )
 
 
     def test_api_subscribe_issue(self):
     def test_api_subscribe_issue(self):
         """ Test subscribing to a ticket. """
         """ Test subscribing to a ticket. """
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post('/api/0/test/issue/1/subscribe', data={})
+            output = self.app.post("/api/0/test/issue/1/subscribe", data={})
             self.assertEqual(output.status_code, 401)
             self.assertEqual(output.status_code, 401)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
                 data,
                 data,
                 {
                 {
-                    u'error': u'The issue tracker of this project is read-only',
-                    u'error_code': u'ETRACKERREADONLY'
-                }
+                    "error": "The issue tracker of this project is read-only",
+                    "error_code": "ETRACKERREADONLY",
+                },
             )
             )
 
 
     def test_api_update_custom_field(self):
     def test_api_update_custom_field(self):
         """ Test updating a specific custom fields on a ticket. """
         """ Test updating a specific custom fields on a ticket. """
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post('/api/0/test/issue/1/custom/foo', data={})
+            output = self.app.post("/api/0/test/issue/1/custom/foo", data={})
             self.assertEqual(output.status_code, 401)
             self.assertEqual(output.status_code, 401)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
                 data,
                 data,
                 {
                 {
-                    u'error': u'The issue tracker of this project is read-only',
-                    u'error_code': u'ETRACKERREADONLY'
-                }
+                    "error": "The issue tracker of this project is read-only",
+                    "error_code": "ETRACKERREADONLY",
+                },
             )
             )
 
 
     def test_api_update_custom_fields(self):
     def test_api_update_custom_fields(self):
         """ Test updating custom fields on a ticket. """
         """ Test updating custom fields on a ticket. """
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post('/api/0/test/issue/1/custom', data={})
+            output = self.app.post("/api/0/test/issue/1/custom", data={})
             self.assertEqual(output.status_code, 401)
             self.assertEqual(output.status_code, 401)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
                 data,
                 data,
                 {
                 {
-                    u'error': u'The issue tracker of this project is read-only',
-                    u'error_code': u'ETRACKERREADONLY'
-                }
+                    "error": "The issue tracker of this project is read-only",
+                    "error_code": "ETRACKERREADONLY",
+                },
             )
             )
 
 
 
 
@@ -327,19 +345,19 @@ class PagureFlaskIssuesAndPRDisabledtests(tests.Modeltests):
     disabled.
     disabled.
     """
     """
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def setUp(self):
     def setUp(self):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(PagureFlaskIssuesAndPRDisabledtests, self).setUp()
         super(PagureFlaskIssuesAndPRDisabledtests, self).setUp()
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'))
+        tests.create_projects_git(os.path.join(self.path, "repos"))
 
 
         # Make the project's issue tracker read-only
         # Make the project's issue tracker read-only
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         settings = repo.settings
         settings = repo.settings
-        settings['pull_requests'] = False
-        settings['issue_tracker_read_only'] = True
+        settings["pull_requests"] = False
+        settings["issue_tracker_read_only"] = True
         repo.settings = settings
         repo.settings = settings
         self.session.add(repo)
         self.session.add(repo)
         self.session.commit()
         self.session.commit()
@@ -348,54 +366,59 @@ class PagureFlaskIssuesAndPRDisabledtests(tests.Modeltests):
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
-            title='Test issue #1',
-            content='We should work on this for the second time',
-            user='foo',
-            status='Open',
+            title="Test issue #1",
+            content="We should work on this for the second time",
+            user="foo",
+            status="Open",
             private=True,
             private=True,
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg.title, 'Test issue #1')
+        self.assertEqual(msg.title, "Test issue #1")
 
 
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
-            title='Test issue #2',
-            content='We should work on this for the second time',
-            user='foo',
-            status='Open',
+            title="Test issue #2",
+            content="We should work on this for the second time",
+            user="foo",
+            status="Open",
             private=False,
             private=False,
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg.title, 'Test issue #2')
+        self.assertEqual(msg.title, "Test issue #2")
 
 
     def test_edit_tag(self):
     def test_edit_tag(self):
         """ Test editing a ticket tag.
         """ Test editing a ticket tag.
         """
         """
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post('/test/tag/tag1/edit', data={})
+            output = self.app.post("/test/tag/tag1/edit", data={})
             self.assertEqual(output.status_code, 401)
             self.assertEqual(output.status_code, 401)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Unauthorized :\'( - Pagure</title>', output_text)
+                "<title>Unauthorized :'( - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
-                '<p>The issue tracker for this project is read-only</p>',
-                output_text)
+                "<p>The issue tracker for this project is read-only</p>",
+                output_text,
+            )
 
 
     def test_drop_tags(self):
     def test_drop_tags(self):
         """ Test dropping a ticket tag.
         """ Test dropping a ticket tag.
         """
         """
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post('/test/droptag/', data={})
+            output = self.app.post("/test/droptag/", data={})
             self.assertEqual(output.status_code, 401)
             self.assertEqual(output.status_code, 401)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Unauthorized :\'( - Pagure</title>', output_text)
+                "<title>Unauthorized :'( - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
-                '<p>The issue tracker for this project is read-only</p>',
-                output_text)
+                "<p>The issue tracker for this project is read-only</p>",
+                output_text,
+            )
+
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 104 - 104
tests/test_pagure_flask_ui_issues_templates.py

@@ -18,8 +18,9 @@ import os
 import pygit2
 import pygit2
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import tests
 import tests
@@ -31,104 +32,98 @@ def create_templates(repopath):
     clone_repo = pygit2.Repository(repopath)
     clone_repo = pygit2.Repository(repopath)
 
 
     # Create the RFE template
     # Create the RFE template
-    os.mkdir(os.path.join(repopath, 'templates'))
-    template = os.path.join(repopath, 'templates', 'RFE.md')
-    with open(template, 'w') as stream:
-        stream.write('RFE\n###\n\n* Idea description')
-    clone_repo.index.add(os.path.join('templates', 'RFE.md'))
+    os.mkdir(os.path.join(repopath, "templates"))
+    template = os.path.join(repopath, "templates", "RFE.md")
+    with open(template, "w") as stream:
+        stream.write("RFE\n###\n\n* Idea description")
+    clone_repo.index.add(os.path.join("templates", "RFE.md"))
     clone_repo.index.write()
     clone_repo.index.write()
 
 
     # Commit
     # Commit
     tree = clone_repo.index.write_tree()
     tree = clone_repo.index.write_tree()
-    author = pygit2.Signature(
-        'Alice Author', 'alice@authors.tld')
-    committer = pygit2.Signature(
-        'Cecil Committer', 'cecil@committers.tld')
+    author = pygit2.Signature("Alice Author", "alice@authors.tld")
+    committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
     commit = clone_repo.create_commit(
     commit = clone_repo.create_commit(
-        'refs/heads/master',  # the name of the reference to update
+        "refs/heads/master",  # the name of the reference to update
         author,
         author,
         committer,
         committer,
-        'Add a RFE template',
+        "Add a RFE template",
         # binary string representing the tree object ID
         # binary string representing the tree object ID
         tree,
         tree,
         # list of binary strings representing parents of the new commit
         # list of binary strings representing parents of the new commit
-        []
+        [],
     )
     )
 
 
     # Create the 2018-bid.md template
     # Create the 2018-bid.md template
-    template = os.path.join(repopath, 'templates', '2018-bid.md')
-    with open(template, 'w') as stream:
-        stream.write('Bid for 2018\n############\n\n* Location:')
-    clone_repo.index.add(os.path.join('templates', '2018-bid.md'))
+    template = os.path.join(repopath, "templates", "2018-bid.md")
+    with open(template, "w") as stream:
+        stream.write("Bid for 2018\n############\n\n* Location:")
+    clone_repo.index.add(os.path.join("templates", "2018-bid.md"))
     clone_repo.index.write()
     clone_repo.index.write()
 
 
     # Commit
     # Commit
     tree = clone_repo.index.write_tree()
     tree = clone_repo.index.write_tree()
-    author = pygit2.Signature(
-        'Alice Author', 'alice@authors.tld')
-    committer = pygit2.Signature(
-        'Cecil Committer', 'cecil@committers.tld')
+    author = pygit2.Signature("Alice Author", "alice@authors.tld")
+    committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
     commit = clone_repo.create_commit(
     commit = clone_repo.create_commit(
-        'refs/heads/master',  # the name of the reference to update
+        "refs/heads/master",  # the name of the reference to update
         author,
         author,
         committer,
         committer,
-        'Add a RFE template',
+        "Add a RFE template",
         # binary string representing the tree object ID
         # binary string representing the tree object ID
         tree,
         tree,
         # list of binary strings representing parents of the new commit
         # list of binary strings representing parents of the new commit
-        [commit.hex]
+        [commit.hex],
     )
     )
 
 
     # Create the default.md template
     # Create the default.md template
-    template = os.path.join(repopath, 'templates', 'default.md')
-    with open(template, 'w') as stream:
-        stream.write('Report your issue')
-    clone_repo.index.add(os.path.join('templates', 'default.md'))
+    template = os.path.join(repopath, "templates", "default.md")
+    with open(template, "w") as stream:
+        stream.write("Report your issue")
+    clone_repo.index.add(os.path.join("templates", "default.md"))
     clone_repo.index.write()
     clone_repo.index.write()
 
 
     # Commit
     # Commit
     tree = clone_repo.index.write_tree()
     tree = clone_repo.index.write_tree()
-    author = pygit2.Signature(
-        'Alice Author', 'alice@authors.tld')
-    committer = pygit2.Signature(
-        'Cecil Committer', 'cecil@committers.tld')
+    author = pygit2.Signature("Alice Author", "alice@authors.tld")
+    committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
     clone_repo.create_commit(
     clone_repo.create_commit(
-        'refs/heads/master',  # the name of the reference to update
+        "refs/heads/master",  # the name of the reference to update
         author,
         author,
         committer,
         committer,
-        'Add a default template',
+        "Add a default template",
         # binary string representing the tree object ID
         # binary string representing the tree object ID
         tree,
         tree,
         # list of binary strings representing parents of the new commit
         # list of binary strings representing parents of the new commit
-        [commit.hex]
+        [commit.hex],
     )
     )
 
 
 
 
 class PagureFlaskIssuesTemplatetests(tests.Modeltests):
 class PagureFlaskIssuesTemplatetests(tests.Modeltests):
     """ Tests for flask issues controller of pagure """
     """ Tests for flask issues controller of pagure """
 
 
-    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.git.update_git", MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def setUp(self):
     def setUp(self):
         """ Set up the environnment, run before every tests. """
         """ Set up the environnment, run before every tests. """
         super(PagureFlaskIssuesTemplatetests, self).setUp()
         super(PagureFlaskIssuesTemplatetests, self).setUp()
 
 
-        pagure.config.config['TICKETS_FOLDER'] = os.path.join(
-            self.path, 'tickets')
+        pagure.config.config["TICKETS_FOLDER"] = os.path.join(
+            self.path, "tickets"
+        )
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(
-            os.path.join(self.path, 'repos'), bare=True)
-        tests.create_projects_git(
-            os.path.join(self.path, 'tickets'))
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "tickets"))
 
 
         # Add a couple of templates to test2
         # Add a couple of templates to test2
-        repopath = os.path.join(self.path, 'tickets', 'test2.git')
+        repopath = os.path.join(self.path, "tickets", "test2.git")
         create_templates(repopath)
         create_templates(repopath)
 
 
         # Add a couple of templates to somenamespace/test3
         # Add a couple of templates to somenamespace/test3
         repopath = os.path.join(
         repopath = os.path.join(
-            self.path, 'tickets', 'somenamespace', 'test3.git')
+            self.path, "tickets", "somenamespace", "test3.git"
+        )
         create_templates(repopath)
         create_templates(repopath)
 
 
     def test_new_issue_no_template(self):
     def test_new_issue_no_template(self):
@@ -137,69 +132,76 @@ class PagureFlaskIssuesTemplatetests(tests.Modeltests):
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/new_issue')
+            output = self.app.get("/test/new_issue")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h4 class="font-weight-bold mb-4">New Issue</h4>\n',
                 '<h4 class="font-weight-bold mb-4">New Issue</h4>\n',
-                output_text)
-            self.assertNotIn(
-                'Issue Templates',
-                output_text)
+                output_text,
+            )
+            self.assertNotIn("Issue Templates", output_text)
 
 
     def test_new_issue_w_template(self):
     def test_new_issue_w_template(self):
         """ Test the new_issue endpoint when the project has templates. """
         """ Test the new_issue endpoint when the project has templates. """
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test2/new_issue')
+            output = self.app.get("/test2/new_issue")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h4 class="font-weight-bold mb-4">New Issue</h4>\n',
                 '<h4 class="font-weight-bold mb-4">New Issue</h4>\n',
-                output_text)
-            self.assertIn(
-                'Issue Templates',
-                output_text)
+                output_text,
+            )
+            self.assertIn("Issue Templates", output_text)
             self.assertIn(
             self.assertIn(
                 '<a href="javascript:void(0)" class="issue-template dropdown-item" data-value="RFE">RFE</a>',
                 '<a href="javascript:void(0)" class="issue-template dropdown-item" data-value="RFE">RFE</a>',
-                output_text)
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<a href="javascript:void(0)" class="issue-template dropdown-item" data-value="2018-bid">2018-bid</a>',
                 '<a href="javascript:void(0)" class="issue-template dropdown-item" data-value="2018-bid">2018-bid</a>',
-                output_text)
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<a href="javascript:void(0)" class="issue-template dropdown-item" data-value="default">default</a>',
                 '<a href="javascript:void(0)" class="issue-template dropdown-item" data-value="default">default</a>',
-                output_text)
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 'placeholder="Enter your comment here" tabindex=2 required>'
                 'placeholder="Enter your comment here" tabindex=2 required>'
-                'Report your issue</textarea>', output_text)
+                "Report your issue</textarea>",
+                output_text,
+            )
 
 
     def test_new_issue_w_specific_template(self):
     def test_new_issue_w_specific_template(self):
         """ Test the new_issue endpoint when the project has templates. """
         """ Test the new_issue endpoint when the project has templates. """
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test2/new_issue?template=2018-bid')
+            output = self.app.get("/test2/new_issue?template=2018-bid")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h4 class="font-weight-bold mb-4">New Issue</h4>\n',
                 '<h4 class="font-weight-bold mb-4">New Issue</h4>\n',
-                output_text)
-            self.assertIn(
-                'Issue Templates',
-                output_text)
+                output_text,
+            )
+            self.assertIn("Issue Templates", output_text)
             self.assertIn(
             self.assertIn(
                 '<a href="javascript:void(0)" class="issue-template dropdown-item" data-value="RFE">RFE</a>',
                 '<a href="javascript:void(0)" class="issue-template dropdown-item" data-value="RFE">RFE</a>',
-                output_text)
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<a href="javascript:void(0)" class="issue-template dropdown-item" data-value="2018-bid">2018-bid</a>',
                 '<a href="javascript:void(0)" class="issue-template dropdown-item" data-value="2018-bid">2018-bid</a>',
-                output_text)
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<a href="javascript:void(0)" class="issue-template dropdown-item" data-value="default">default</a>',
                 '<a href="javascript:void(0)" class="issue-template dropdown-item" data-value="default">default</a>',
-                output_text)
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 'placeholder="Enter your comment here" tabindex=2 required>'
                 'placeholder="Enter your comment here" tabindex=2 required>'
-                'Bid for 2018\n############', output_text)
+                "Bid for 2018\n############",
+                output_text,
+            )
 
 
     def test_get_ticket_template_no_csrf(self):
     def test_get_ticket_template_no_csrf(self):
         """ Test the get_ticket_template endpoint when the project has no
         """ Test the get_ticket_template endpoint when the project has no
@@ -208,12 +210,12 @@ class PagureFlaskIssuesTemplatetests(tests.Modeltests):
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post('/pv/test/issue/template')
+            output = self.app.post("/pv/test/issue/template")
             self.assertEqual(output.status_code, 400)
             self.assertEqual(output.status_code, 400)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
-                data,
-                {"code": "ERROR", "message": "Invalid input submitted"})
+                data, {"code": "ERROR", "message": "Invalid input submitted"}
+            )
 
 
     def test_get_ticket_template_no_template_specified(self):
     def test_get_ticket_template_no_template_specified(self):
         """ Test the get_ticket_template endpoint when not specifying which
         """ Test the get_ticket_template endpoint when not specifying which
@@ -223,13 +225,13 @@ class PagureFlaskIssuesTemplatetests(tests.Modeltests):
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf = self.get_csrf()
             csrf = self.get_csrf()
-            data = {'csrf_token': csrf}
-            output = self.app.post('/pv/test/issue/template', data=data)
+            data = {"csrf_token": csrf}
+            output = self.app.post("/pv/test/issue/template", data=data)
             self.assertEqual(output.status_code, 400)
             self.assertEqual(output.status_code, 400)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
-                data,
-                {"code": "ERROR", "message": "No template provided"})
+                data, {"code": "ERROR", "message": "No template provided"}
+            )
 
 
     def test_get_ticket_template_no_project(self):
     def test_get_ticket_template_no_project(self):
         """ Test the get_ticket_template endpoint when the project does not
         """ Test the get_ticket_template endpoint when the project does not
@@ -239,9 +241,8 @@ class PagureFlaskIssuesTemplatetests(tests.Modeltests):
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf = self.get_csrf()
             csrf = self.get_csrf()
-            data = {'csrf_token': csrf}
-            output = self.app.post(
-                '/pv/foobar/issue/template', data=data)
+            data = {"csrf_token": csrf}
+            output = self.app.post("/pv/foobar/issue/template", data=data)
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
     def test_get_ticket_template_no_template(self):
     def test_get_ticket_template_no_template(self):
@@ -252,22 +253,23 @@ class PagureFlaskIssuesTemplatetests(tests.Modeltests):
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf = self.get_csrf()
             csrf = self.get_csrf()
-            data = {'csrf_token': csrf}
+            data = {"csrf_token": csrf}
             output = self.app.post(
             output = self.app.post(
-                '/pv/test/issue/template?template=RFE', data=data)
+                "/pv/test/issue/template?template=RFE", data=data
+            )
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
-                data,
-                {"code": "ERROR", "message": "No such template found"})
+                data, {"code": "ERROR", "message": "No such template found"}
+            )
 
 
     def test_get_ticket_template_issue_tracker_disabled(self):
     def test_get_ticket_template_issue_tracker_disabled(self):
         """ Test the get_ticket_template endpoint when the project has
         """ Test the get_ticket_template endpoint when the project has
         disabled its issue tracker.
         disabled its issue tracker.
         """
         """
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         settings = repo.settings
         settings = repo.settings
-        settings['issue_tracker'] = False
+        settings["issue_tracker"] = False
         repo.settings = settings
         repo.settings = settings
         self.session.add(repo)
         self.session.add(repo)
         self.session.commit()
         self.session.commit()
@@ -275,17 +277,18 @@ class PagureFlaskIssuesTemplatetests(tests.Modeltests):
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf = self.get_csrf()
             csrf = self.get_csrf()
-            data = {'csrf_token': csrf}
+            data = {"csrf_token": csrf}
             output = self.app.post(
             output = self.app.post(
-                '/pv/test/issue/template?template=RFE', data=data)
+                "/pv/test/issue/template?template=RFE", data=data
+            )
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
                 data,
                 data,
                 {
                 {
-                    u'code': u'ERROR',
-                    u'message': u'No issue tracker found for this project'
-                }
+                    "code": "ERROR",
+                    "message": "No issue tracker found for this project",
+                },
             )
             )
 
 
     def test_get_ticket_template_w_template(self):
     def test_get_ticket_template_w_template(self):
@@ -296,17 +299,15 @@ class PagureFlaskIssuesTemplatetests(tests.Modeltests):
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf = self.get_csrf()
             csrf = self.get_csrf()
-            data = {'csrf_token': csrf}
+            data = {"csrf_token": csrf}
             output = self.app.post(
             output = self.app.post(
-                '/pv/test2/issue/template?template=RFE', data=data)
+                "/pv/test2/issue/template?template=RFE", data=data
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
                 data,
                 data,
-                {
-                    "code": "OK",
-                    "message": "RFE\n###\n\n* Idea description"
-                }
+                {"code": "OK", "message": "RFE\n###\n\n* Idea description"},
             )
             )
 
 
     def test_get_ticket_template_w_template_namespace(self):
     def test_get_ticket_template_w_template_namespace(self):
@@ -317,19 +318,18 @@ class PagureFlaskIssuesTemplatetests(tests.Modeltests):
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf = self.get_csrf()
             csrf = self.get_csrf()
-            data = {'csrf_token': csrf}
+            data = {"csrf_token": csrf}
             output = self.app.post(
             output = self.app.post(
-                '/pv/somenamespace/test3/issue/template?template=RFE',
-                data=data)
+                "/pv/somenamespace/test3/issue/template?template=RFE",
+                data=data,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             data = json.loads(output.get_data(as_text=True))
             data = json.loads(output.get_data(as_text=True))
             self.assertEqual(
             self.assertEqual(
                 data,
                 data,
-                {
-                    "code": "OK",
-                    "message": "RFE\n###\n\n* Idea description"
-                }
+                {"code": "OK", "message": "RFE\n###\n\n* Idea description"},
             )
             )
 
 
-if __name__ == '__main__':
+
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

File diff suppressed because it is too large
+ 557 - 366
tests/test_pagure_flask_ui_login.py


+ 99 - 85
tests/test_pagure_flask_ui_no_master_branch.py

@@ -20,8 +20,9 @@ import os
 import pygit2
 import pygit2
 from mock import patch
 from mock import patch
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import tests
 import tests
@@ -36,68 +37,64 @@ class PagureFlaskNoMasterBranchtests(tests.SimplePagureTest):
         """ Set up the git repo to play with. """
         """ Set up the git repo to play with. """
 
 
         # Create a git repo to play with
         # Create a git repo to play with
-        gitrepo = os.path.join(self.path, 'repos', 'test.git')
+        gitrepo = os.path.join(self.path, "repos", "test.git")
         repo = pygit2.init_repository(gitrepo, bare=True)
         repo = pygit2.init_repository(gitrepo, bare=True)
 
 
-        newpath = tempfile.mkdtemp(prefix='pagure-other-test')
-        repopath = os.path.join(newpath, 'test')
+        newpath = tempfile.mkdtemp(prefix="pagure-other-test")
+        repopath = os.path.join(newpath, "test")
         clone_repo = pygit2.clone_repository(gitrepo, repopath)
         clone_repo = pygit2.clone_repository(gitrepo, repopath)
 
 
         # Create a file in that git repo
         # Create a file in that git repo
-        with open(os.path.join(repopath, 'sources'), 'w') as stream:
-            stream.write('foo\n bar')
-        clone_repo.index.add('sources')
+        with open(os.path.join(repopath, "sources"), "w") as stream:
+            stream.write("foo\n bar")
+        clone_repo.index.add("sources")
         clone_repo.index.write()
         clone_repo.index.write()
 
 
         # Commits the files added
         # Commits the files added
         tree = clone_repo.index.write_tree()
         tree = clone_repo.index.write_tree()
-        author = pygit2.Signature(
-            'Alice Author', 'alice@authors.tld')
-        committer = pygit2.Signature(
-            'Cecil Committer', 'cecil@committers.tld')
+        author = pygit2.Signature("Alice Author", "alice@authors.tld")
+        committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
         clone_repo.create_commit(
         clone_repo.create_commit(
-            'refs/heads/feature',  # the name of the reference to update
+            "refs/heads/feature",  # the name of the reference to update
             author,
             author,
             committer,
             committer,
-            'Add sources file for testing',
+            "Add sources file for testing",
             # binary string representing the tree object ID
             # binary string representing the tree object ID
             tree,
             tree,
             # list of binary strings representing parents of the new commit
             # list of binary strings representing parents of the new commit
-            []
+            [],
         )
         )
 
 
-        feature_branch = clone_repo.lookup_branch('feature')
+        feature_branch = clone_repo.lookup_branch("feature")
         first_commit = feature_branch.peel().hex
         first_commit = feature_branch.peel().hex
 
 
         # Second commit
         # Second commit
-        with open(os.path.join(repopath, '.gitignore'), 'w') as stream:
-            stream.write('*~')
-        clone_repo.index.add('.gitignore')
+        with open(os.path.join(repopath, ".gitignore"), "w") as stream:
+            stream.write("*~")
+        clone_repo.index.add(".gitignore")
         clone_repo.index.write()
         clone_repo.index.write()
 
 
         tree = clone_repo.index.write_tree()
         tree = clone_repo.index.write_tree()
-        author = pygit2.Signature(
-            'Alice Author', 'alice@authors.tld')
-        committer = pygit2.Signature(
-            'Cecil Committer', 'cecil@committers.tld')
+        author = pygit2.Signature("Alice Author", "alice@authors.tld")
+        committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
         clone_repo.create_commit(
         clone_repo.create_commit(
-            'refs/heads/feature',
+            "refs/heads/feature",
             author,
             author,
             committer,
             committer,
-            'Add .gitignore file for testing',
+            "Add .gitignore file for testing",
             # binary string representing the tree object ID
             # binary string representing the tree object ID
             tree,
             tree,
             # list of binary strings representing parents of the new commit
             # list of binary strings representing parents of the new commit
-            [first_commit]
+            [first_commit],
         )
         )
 
 
-        refname = 'refs/heads/feature'
+        refname = "refs/heads/feature"
         ori_remote = clone_repo.remotes[0]
         ori_remote = clone_repo.remotes[0]
         PagureRepo.push(ori_remote, refname)
         PagureRepo.push(ori_remote, refname)
 
 
         shutil.rmtree(newpath)
         shutil.rmtree(newpath)
 
 
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.notify.send_email")
     def test_view_repo(self, send_email):
     def test_view_repo(self, send_email):
         """ Test the view_repo endpoint when the git repo has no master
         """ Test the view_repo endpoint when the git repo has no master
         branch.
         branch.
@@ -106,22 +103,24 @@ class PagureFlaskNoMasterBranchtests(tests.SimplePagureTest):
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         # Non-existant git repo
         # Non-existant git repo
-        output = self.app.get('/test')
+        output = self.app.get("/test")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
         self.set_up_git_repo()
         self.set_up_git_repo()
 
 
         # With git repo
         # With git repo
-        output = self.app.get('/test')
+        output = self.app.get("/test")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn('<section class="no-readme">', output_text)
         self.assertIn('<section class="no-readme">', output_text)
         self.assertIn(
         self.assertIn(
             "The test project's README file is empty or unavailable.",
             "The test project's README file is empty or unavailable.",
-            output_text)
+            output_text,
+        )
         self.assertEqual(
         self.assertEqual(
             output_text.count('<a class="dropdown-item" href="/test/branch/'),
             output_text.count('<a class="dropdown-item" href="/test/branch/'),
-            0)
+            0,
+        )
 
 
     '''
     '''
     @patch('pagure.lib.notify.send_email')
     @patch('pagure.lib.notify.send_email')
@@ -149,7 +148,7 @@ class PagureFlaskNoMasterBranchtests(tests.SimplePagureTest):
             output_text)
             output_text)
     '''
     '''
 
 
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.notify.send_email")
     def test_view_commits(self, send_email):
     def test_view_commits(self, send_email):
         """ Test the view_commits endpoint when the git repo has no
         """ Test the view_commits endpoint when the git repo has no
         master branch.
         master branch.
@@ -158,36 +157,35 @@ class PagureFlaskNoMasterBranchtests(tests.SimplePagureTest):
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         # Non-existant git repo
         # Non-existant git repo
-        output = self.app.get('/test/commits')
+        output = self.app.get("/test/commits")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
         self.set_up_git_repo()
         self.set_up_git_repo()
 
 
         # With git repo
         # With git repo
-        output = self.app.get('/test/commits')
+        output = self.app.get("/test/commits")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
-            '<div class="list-group my-2">\n\n\n          </div>',
-            output_text)
-        self.assertNotIn(
-            '<div class="btn-group pull-xs-right">', output_text)
+            '<div class="list-group my-2">\n\n\n          </div>', output_text
+        )
+        self.assertNotIn('<div class="btn-group pull-xs-right">', output_text)
 
 
-        output = self.app.get('/test/commits/feature')
+        output = self.app.get("/test/commits/feature")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
             'Commits <span class="badge badge-secondary"> 2</span>',
             'Commits <span class="badge badge-secondary"> 2</span>',
-            output_text)
-        self.assertIn('Add sources file for testing', output_text)
-        self.assertIn('Add .gitignore file for testing', output_text)
+            output_text,
+        )
+        self.assertIn("Add sources file for testing", output_text)
+        self.assertIn("Add .gitignore file for testing", output_text)
         self.assertNotIn(
         self.assertNotIn(
-            '<div class="list-group my-2">\n\n\n          </div>',
-            output_text)
-        self.assertEqual(
-            output_text.count('class="list-group-item "'), 2)
+            '<div class="list-group my-2">\n\n\n          </div>', output_text
+        )
+        self.assertEqual(output_text.count('class="list-group-item "'), 2)
 
 
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.notify.send_email")
     def test_view_file(self, send_email):
     def test_view_file(self, send_email):
         """ Test the view_file endpoint when the git repo has no
         """ Test the view_file endpoint when the git repo has no
         master branch.
         master branch.
@@ -196,20 +194,20 @@ class PagureFlaskNoMasterBranchtests(tests.SimplePagureTest):
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         # Non-existant git repo
         # Non-existant git repo
-        output = self.app.get('/test/blob/master/f/sources')
+        output = self.app.get("/test/blob/master/f/sources")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
         self.set_up_git_repo()
         self.set_up_git_repo()
 
 
         # With git repo
         # With git repo
-        output = self.app.get('/test/blob/master/f/sources')
+        output = self.app.get("/test/blob/master/f/sources")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
-        output = self.app.get('/test/blob/feature/f/sources')
+        output = self.app.get("/test/blob/feature/f/sources")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
-            '''
+            """
         <ol class="breadcrumb p-0 bg-transparent mb-0">
         <ol class="breadcrumb p-0 bg-transparent mb-0">
           <li class="breadcrumb-item">
           <li class="breadcrumb-item">
             <a href="/test/tree/feature">
             <a href="/test/tree/feature">
@@ -221,14 +219,16 @@ class PagureFlaskNoMasterBranchtests(tests.SimplePagureTest):
             <span class="fa fa-file" data-glyph="">
             <span class="fa fa-file" data-glyph="">
             </span>&nbsp; sources
             </span>&nbsp; sources
           </li>
           </li>
-        </ol>''',  output_text)
+        </ol>""",
+            output_text,
+        )
         self.assertIn(
         self.assertIn(
             '<pre class="syntaxhighlightblock">'
             '<pre class="syntaxhighlightblock">'
             '<code class="lang-plaintext">foo\n bar</code></pre>',
             '<code class="lang-plaintext">foo\n bar</code></pre>',
-            output_text
+            output_text,
         )
         )
 
 
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.notify.send_email")
     def test_view_raw_file(self, send_email):
     def test_view_raw_file(self, send_email):
         """ Test the view_raw_file endpoint when the git repo has no
         """ Test the view_raw_file endpoint when the git repo has no
         master branch.
         master branch.
@@ -237,30 +237,30 @@ class PagureFlaskNoMasterBranchtests(tests.SimplePagureTest):
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         # Non-existant git repo
         # Non-existant git repo
-        output = self.app.get('/test/raw/master')
+        output = self.app.get("/test/raw/master")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
-        output = self.app.get('/test/raw/master/f/sources')
+        output = self.app.get("/test/raw/master/f/sources")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
         self.set_up_git_repo()
         self.set_up_git_repo()
 
 
         # With git repo
         # With git repo
-        output = self.app.get('/test/raw/master')
+        output = self.app.get("/test/raw/master")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
-        output = self.app.get('/test/raw/master/f/sources')
+        output = self.app.get("/test/raw/master/f/sources")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
-        output = self.app.get('/test/raw/feature')
+        output = self.app.get("/test/raw/feature")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
-        self.assertIn('diff --git a/.gitignore b/.gitignore', output_text)
-        self.assertIn('+*~', output_text)
+        self.assertIn("diff --git a/.gitignore b/.gitignore", output_text)
+        self.assertIn("+*~", output_text)
 
 
-        output = self.app.get('/test/raw/feature/f/sources')
+        output = self.app.get("/test/raw/feature/f/sources")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
-        self.assertEqual('foo\n bar', output.get_data(as_text=True))
+        self.assertEqual("foo\n bar", output.get_data(as_text=True))
 
 
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.notify.send_email")
     def test_view_tree(self, send_email):
     def test_view_tree(self, send_email):
         """ Test the view_tree endpoint when the git repo has no
         """ Test the view_tree endpoint when the git repo has no
         master branch.
         master branch.
@@ -269,30 +269,42 @@ class PagureFlaskNoMasterBranchtests(tests.SimplePagureTest):
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         # Non-existant git repo
         # Non-existant git repo
-        output = self.app.get('/test/tree/')
+        output = self.app.get("/test/tree/")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
-        output = self.app.get('/test/tree/master')
+        output = self.app.get("/test/tree/master")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
         self.set_up_git_repo()
         self.set_up_git_repo()
 
 
         # With git repo
         # With git repo
-        output = self.app.get('/test/tree/master')
+        output = self.app.get("/test/tree/master")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
-        self.assertIn('No content found in this repository', output.get_data(as_text=True))
-        output = self.app.get('/test/tree/master/sources')
+        self.assertIn(
+            "No content found in this repository",
+            output.get_data(as_text=True),
+        )
+        output = self.app.get("/test/tree/master/sources")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
-        self.assertIn('No content found in this repository', output.get_data(as_text=True))
+        self.assertIn(
+            "No content found in this repository",
+            output.get_data(as_text=True),
+        )
 
 
-        output = self.app.get('/test/tree/feature')
+        output = self.app.get("/test/tree/feature")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
-        self.assertIn('<a href="/test/blob/feature/f/sources">', output.get_data(as_text=True))
+        self.assertIn(
+            '<a href="/test/blob/feature/f/sources">',
+            output.get_data(as_text=True),
+        )
 
 
-        output = self.app.get('/test/tree/feature/sources')
+        output = self.app.get("/test/tree/feature/sources")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
-        self.assertIn('No content found in this repository', output.get_data(as_text=True))
+        self.assertIn(
+            "No content found in this repository",
+            output.get_data(as_text=True),
+        )
 
 
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.notify.send_email")
     def test_new_request_pull(self, send_email):
     def test_new_request_pull(self, send_email):
         """ Test the new_request_pull endpoint when the git repo has no
         """ Test the new_request_pull endpoint when the git repo has no
         master branch.
         master branch.
@@ -301,32 +313,34 @@ class PagureFlaskNoMasterBranchtests(tests.SimplePagureTest):
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         # Non-existant git repo
         # Non-existant git repo
-        output = self.app.get('/test/diff/master..feature')
+        output = self.app.get("/test/diff/master..feature")
         # (used to be 302 but seeing a diff is allowed even logged out)
         # (used to be 302 but seeing a diff is allowed even logged out)
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/diff/master..feature')
+            output = self.app.get("/test/diff/master..feature")
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
         self.set_up_git_repo()
         self.set_up_git_repo()
 
 
-        output = self.app.get('/test/diff/master..feature')
+        output = self.app.get("/test/diff/master..feature")
         # (used to be 302 but seeing a diff is allowed even logged out)
         # (used to be 302 but seeing a diff is allowed even logged out)
         self.assertEqual(output.status_code, 400)
         self.assertEqual(output.status_code, 400)
         self.assertIn(
         self.assertIn(
-            '<p>Branch master could not be found in the target repo</p>',
-            output.get_data(as_text=True))
+            "<p>Branch master could not be found in the target repo</p>",
+            output.get_data(as_text=True),
+        )
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/diff/master..feature')
+            output = self.app.get("/test/diff/master..feature")
             self.assertEqual(output.status_code, 400)
             self.assertEqual(output.status_code, 400)
             self.assertIn(
             self.assertIn(
-                '<p>Branch master could not be found in the target repo</p>',
-                output.get_data(as_text=True))
+                "<p>Branch master could not be found in the target repo</p>",
+                output.get_data(as_text=True),
+            )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 96 - 60
tests/test_pagure_flask_ui_old_commit.py

@@ -17,8 +17,9 @@ import os
 import pygit2
 import pygit2
 from mock import patch
 from mock import patch
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import tests
 import tests
@@ -31,136 +32,171 @@ class PagureFlaskRepoOldUrltests(tests.SimplePagureTest):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(PagureFlaskRepoOldUrltests, self).setUp()
         super(PagureFlaskRepoOldUrltests, self).setUp()
 
 
-        pagure.config.config['EMAIL_SEND'] = False
-        pagure.config.config['UPLOAD_FOLDER_PATH'] = os.path.join(
-            self.path, 'releases')
+        pagure.config.config["EMAIL_SEND"] = False
+        pagure.config.config["UPLOAD_FOLDER_PATH"] = os.path.join(
+            self.path, "releases"
+        )
 
 
-    @patch.dict('pagure.config.config', {'OLD_VIEW_COMMIT_ENABLED': True})
+    @patch.dict("pagure.config.config", {"OLD_VIEW_COMMIT_ENABLED": True})
     def test_view_commit_old_with_bogus_url(self):
     def test_view_commit_old_with_bogus_url(self):
         """ Test the view_commit_old endpoint. """
         """ Test the view_commit_old endpoint. """
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         # Add a README to the git repo - First commit
         # Add a README to the git repo - First commit
-        tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
-        pygit2.Repository(os.path.join(self.path, 'repos', 'test.git'))
+        tests.add_readme_git_repo(os.path.join(self.path, "repos", "test.git"))
+        pygit2.Repository(os.path.join(self.path, "repos", "test.git"))
 
 
         # View first commit
         # View first commit
-        output = self.app.get('/apple-touch-icon-152x152-precomposed.png')
+        output = self.app.get("/apple-touch-icon-152x152-precomposed.png")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
-    @patch.dict('pagure.config.config', {'OLD_VIEW_COMMIT_ENABLED': True})
+    @patch.dict("pagure.config.config", {"OLD_VIEW_COMMIT_ENABLED": True})
     def test_view_commit_old(self):
     def test_view_commit_old(self):
         """ Test the view_commit_old endpoint. """
         """ Test the view_commit_old endpoint. """
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         # Add a README to the git repo - First commit
         # Add a README to the git repo - First commit
-        tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
-        repo = pygit2.Repository(os.path.join(self.path, 'repos', 'test.git'))
-        commit = repo.revparse_single('HEAD')
+        tests.add_readme_git_repo(os.path.join(self.path, "repos", "test.git"))
+        repo = pygit2.Repository(os.path.join(self.path, "repos", "test.git"))
+        commit = repo.revparse_single("HEAD")
 
 
         # View first commit
         # View first commit
-        output = self.app.get('/test/%s' % commit.oid.hex)
+        output = self.app.get("/test/%s" % commit.oid.hex)
         self.assertEqual(output.status_code, 302)
         self.assertEqual(output.status_code, 302)
 
 
         output = self.app.get(
         output = self.app.get(
-            '/test/%s' % commit.oid.hex, follow_redirects=True)
+            "/test/%s" % commit.oid.hex, follow_redirects=True
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         self.assertTrue(
         self.assertTrue(
-            'href="#commit-overview-collapse"'
-            in output.get_data(as_text=True))
-        self.assertTrue('Merged by Alice Author' in output.get_data(as_text=True))
-        self.assertTrue('Committed by Cecil Committer' in output.get_data(as_text=True))
+            'href="#commit-overview-collapse"' in output.get_data(as_text=True)
+        )
+        self.assertTrue(
+            "Merged by Alice Author" in output.get_data(as_text=True)
+        )
+        self.assertTrue(
+            "Committed by Cecil Committer" in output.get_data(as_text=True)
+        )
 
 
-        self.assertTrue('title="View file as of %s"' % commit.oid.hex[0:6]
-                        in output.get_data(as_text=True))
+        self.assertTrue(
+            'title="View file as of %s"' % commit.oid.hex[0:6]
+            in output.get_data(as_text=True)
+        )
 
 
         # View first commit - with the old URL scheme
         # View first commit - with the old URL scheme
         output = self.app.get(
         output = self.app.get(
-            '/test/%s' % commit.oid.hex, follow_redirects=True)
+            "/test/%s" % commit.oid.hex, follow_redirects=True
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         self.assertTrue(
         self.assertTrue(
-            'href="#commit-overview-collapse"'
-            in output.get_data(as_text=True))
-        self.assertTrue('Merged by Alice Author' in output.get_data(as_text=True))
-        self.assertTrue('Committed by Cecil Committer' in output.get_data(as_text=True))
-
+            'href="#commit-overview-collapse"' in output.get_data(as_text=True)
+        )
+        self.assertTrue(
+            "Merged by Alice Author" in output.get_data(as_text=True)
+        )
+        self.assertTrue(
+            "Committed by Cecil Committer" in output.get_data(as_text=True)
+        )
 
 
         # Add some content to the git repo
         # Add some content to the git repo
-        tests.add_content_git_repo(os.path.join(self.path, 'repos',
-                                   'test.git'))
+        tests.add_content_git_repo(
+            os.path.join(self.path, "repos", "test.git")
+        )
 
 
-        repo = pygit2.Repository(os.path.join(self.path, 'repos', 'test.git'))
-        commit = repo.revparse_single('HEAD')
+        repo = pygit2.Repository(os.path.join(self.path, "repos", "test.git"))
+        commit = repo.revparse_single("HEAD")
 
 
         # View another commit
         # View another commit
         output = self.app.get(
         output = self.app.get(
-            '/test/%s' % commit.oid.hex, follow_redirects=True)
+            "/test/%s" % commit.oid.hex, follow_redirects=True
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         self.assertTrue(
         self.assertTrue(
-            'href="#commit-overview-collapse"'
-            in output.get_data(as_text=True))
-        self.assertTrue('Authored by Alice Author' in output.get_data(as_text=True))
-        self.assertTrue('Committed by Cecil Committer' in output.get_data(as_text=True))
+            'href="#commit-overview-collapse"' in output.get_data(as_text=True)
+        )
+        self.assertTrue(
+            "Authored by Alice Author" in output.get_data(as_text=True)
+        )
+        self.assertTrue(
+            "Committed by Cecil Committer" in output.get_data(as_text=True)
+        )
 
 
         # Add a fork of a fork
         # Add a fork of a fork
         item = pagure.lib.model.Project(
         item = pagure.lib.model.Project(
             user_id=1,  # pingou
             user_id=1,  # pingou
-            name='test3',
-            description='test project #3',
+            name="test3",
+            description="test project #3",
             is_fork=True,
             is_fork=True,
             parent_id=1,
             parent_id=1,
-            hook_token='aaabbbkkk',
+            hook_token="aaabbbkkk",
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
         forkedgit = os.path.join(
         forkedgit = os.path.join(
-            self.path, 'repos', 'forks', 'pingou', 'test3.git')
+            self.path, "repos", "forks", "pingou", "test3.git"
+        )
 
 
         tests.add_content_git_repo(forkedgit)
         tests.add_content_git_repo(forkedgit)
         tests.add_readme_git_repo(forkedgit)
         tests.add_readme_git_repo(forkedgit)
 
 
         repo = pygit2.Repository(forkedgit)
         repo = pygit2.Repository(forkedgit)
-        commit = repo.revparse_single('HEAD')
+        commit = repo.revparse_single("HEAD")
 
 
         # Commit does not exist in anothe repo :)
         # Commit does not exist in anothe repo :)
         output = self.app.get(
         output = self.app.get(
-            '/test/%s' % commit.oid.hex, follow_redirects=True)
+            "/test/%s" % commit.oid.hex, follow_redirects=True
+        )
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
         # View commit of fork
         # View commit of fork
         output = self.app.get(
         output = self.app.get(
-            '/fork/pingou/test3/%s' % commit.oid.hex, follow_redirects=True)
+            "/fork/pingou/test3/%s" % commit.oid.hex, follow_redirects=True
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         self.assertTrue(
         self.assertTrue(
-            'href="#commit-overview-collapse"'
-            in output.get_data(as_text=True))
-        self.assertTrue('  Authored by Alice Author\n' in output.get_data(as_text=True))
-        self.assertTrue('  Committed by Cecil Committer\n' in output.get_data(as_text=True))
+            'href="#commit-overview-collapse"' in output.get_data(as_text=True)
+        )
+        self.assertTrue(
+            "  Authored by Alice Author\n" in output.get_data(as_text=True)
+        )
+        self.assertTrue(
+            "  Committed by Cecil Committer\n" in output.get_data(as_text=True)
+        )
 
 
-        self.assertTrue('title="View file as of %s"' % commit.oid.hex[0:6]
-                        in output.get_data(as_text=True))
+        self.assertTrue(
+            'title="View file as of %s"' % commit.oid.hex[0:6]
+            in output.get_data(as_text=True)
+        )
 
 
         # View commit of fork - With the old URL scheme
         # View commit of fork - With the old URL scheme
         output = self.app.get(
         output = self.app.get(
-            '/fork/pingou/test3/%s' % commit.oid.hex, follow_redirects=True)
+            "/fork/pingou/test3/%s" % commit.oid.hex, follow_redirects=True
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         self.assertTrue(
         self.assertTrue(
-            'href="#commit-overview-collapse"'
-            in output.get_data(as_text=True))
-        self.assertTrue('Authored by Alice Author' in output.get_data(as_text=True))
-        self.assertTrue('Committed by Cecil Committer' in output.get_data(as_text=True))
+            'href="#commit-overview-collapse"' in output.get_data(as_text=True)
+        )
+        self.assertTrue(
+            "Authored by Alice Author" in output.get_data(as_text=True)
+        )
+        self.assertTrue(
+            "Committed by Cecil Committer" in output.get_data(as_text=True)
+        )
 
 
         # Try the old URL scheme with a short hash
         # Try the old URL scheme with a short hash
         output = self.app.get(
         output = self.app.get(
-            '/fork/pingou/test3/%s' % commit.oid.hex[:10],
-            follow_redirects=True)
+            "/fork/pingou/test3/%s" % commit.oid.hex[:10],
+            follow_redirects=True,
+        )
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
-        self.assertIn('<p>Project not found</p>', output.get_data(as_text=True))
+        self.assertIn(
+            "<p>Project not found</p>", output.get_data(as_text=True)
+        )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 51 - 55
tests/test_pagure_flask_ui_plugins.py

@@ -15,8 +15,9 @@ import sys
 import os
 import os
 import wtforms
 import wtforms
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.plugins
 import pagure.lib.plugins
 import pagure.hooks
 import pagure.hooks
@@ -24,13 +25,10 @@ import tests
 
 
 
 
 class FakeForm(wtforms.Form):
 class FakeForm(wtforms.Form):
-    ''' Form to configure the mail hook. '''
-    field1 = wtforms.StringField(
-        'Title', [pagure.hooks.RequiredIf('active')]
-    )
-    field2 = wtforms.BooleanField(
-        'Title2', [wtforms.validators.Optional()]
-    )
+    """ Form to configure the mail hook. """
+
+    field1 = wtforms.StringField("Title", [pagure.hooks.RequiredIf("active")])
+    field2 = wtforms.BooleanField("Title2", [wtforms.validators.Optional()])
 
 
 
 
 class PagureFlaskPluginstests(tests.SimplePagureTest):
 class PagureFlaskPluginstests(tests.SimplePagureTest):
@@ -42,95 +40,94 @@ class PagureFlaskPluginstests(tests.SimplePagureTest):
         self.assertEqual(
         self.assertEqual(
             sorted(names),
             sorted(names),
             [
             [
-                'Block Un-Signed commits',
-                'Block non fast-forward pushes',
-                'Fedmsg',
-                'IRC',
-                'Mail',
-                'Mirroring',
-                'Pagure',
-                'Pagure CI',
-                'Pagure requests',
-                'Pagure tickets',
-                'Prevent creating new branches by git push',
-                'Read the Doc',
-            ]
+                "Block Un-Signed commits",
+                "Block non fast-forward pushes",
+                "Fedmsg",
+                "IRC",
+                "Mail",
+                "Mirroring",
+                "Pagure",
+                "Pagure CI",
+                "Pagure requests",
+                "Pagure tickets",
+                "Prevent creating new branches by git push",
+                "Read the Doc",
+            ],
         )
         )
 
 
     def test_get_plugin(self):
     def test_get_plugin(self):
         """ Test the get_plugin function. """
         """ Test the get_plugin function. """
-        name = pagure.lib.plugins.get_plugin('Mail')
+        name = pagure.lib.plugins.get_plugin("Mail")
         self.assertEqual(str(name), "<class 'pagure.hooks.mail.Mail'>")
         self.assertEqual(str(name), "<class 'pagure.hooks.mail.Mail'>")
 
 
     def test_view_plugin_page(self):
     def test_view_plugin_page(self):
         """ Test the view_plugin_page endpoint. """
         """ Test the view_plugin_page endpoint. """
 
 
         # No Git repo
         # No Git repo
-        output = self.app.get('/foo/settings/Mail')
+        output = self.app.get("/foo/settings/Mail")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/foo/settings/Mail')
+            output = self.app.get("/foo/settings/Mail")
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
             tests.create_projects(self.session)
             tests.create_projects(self.session)
-            tests.create_projects_git(os.path.join(self.path, 'repos'))
+            tests.create_projects_git(os.path.join(self.path, "repos"))
 
 
-            output = self.app.get('/test/settings/Mail')
+            output = self.app.get("/test/settings/Mail")
             self.assertEqual(output.status_code, 403)
             self.assertEqual(output.status_code, 403)
 
 
         # User not logged in
         # User not logged in
-        output = self.app.get('/test/settings/Mail')
+        output = self.app.get("/test/settings/Mail")
         self.assertEqual(output.status_code, 302)
         self.assertEqual(output.status_code, 302)
 
 
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/settings/Mail')
+            output = self.app.get("/test/settings/Mail")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<form action="/test/settings/Mail" method="post">',
                 '<form action="/test/settings/Mail" method="post">',
-                output_text)
-            self.assertIn(
-                '<label for="mail_to">Mail to</label>',
-                output_text)
+                output_text,
+            )
+            self.assertIn('<label for="mail_to">Mail to</label>', output_text)
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             data = {
             data = {
-                'active': True,
-                'mail_to': 'pingou@fp.org',
-                'csrf_token': csrf_token,
+                "active": True,
+                "mail_to": "pingou@fp.org",
+                "csrf_token": csrf_token,
             }
             }
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Mail', data=data, follow_redirects=True)
+                "/test/settings/Mail", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Mail activated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Mail activated", output_text)
 
 
-            data = {
-                'mail_to': '',
-                'csrf_token': csrf_token,
-            }
+            data = {"mail_to": "", "csrf_token": csrf_token}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Mail', data=data, follow_redirects=True)
+                "/test/settings/Mail", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Mail deactivated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Mail deactivated", output_text)
 
 
     def test_RequiredIf(self):
     def test_RequiredIf(self):
         """ Test the behavior of the RequiredIf validator. """
         """ Test the behavior of the RequiredIf validator. """
@@ -139,9 +136,8 @@ class PagureFlaskPluginstests(tests.SimplePagureTest):
         try:
         try:
             form.validate()
             form.validate()
         except Exception as err:
         except Exception as err:
-            self.assertEqual(
-                str(err), 'no field named "active" in form')
+            self.assertEqual(str(err), 'no field named "active" in form')
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 6 - 7
tests/test_pagure_flask_ui_plugins_default_hook.py

@@ -20,8 +20,9 @@ import flask
 import pygit2
 import pygit2
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.hooks.default
 import pagure.hooks.default
 import pagure.lib.plugins
 import pagure.lib.plugins
@@ -38,14 +39,12 @@ class PagureFlaskPluginDefaultHooktests(tests.Modeltests):
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         test = pagure.lib.query.search_projects(self.session)[0]
         test = pagure.lib.query.search_projects(self.session)[0]
         self.assertIsNone(pagure.hooks.default.Default.backref)
         self.assertIsNone(pagure.hooks.default.Default.backref)
-        self.assertTrue(
-            pagure.hooks.default.Default.is_enabled_for(test)
-        )
+        self.assertTrue(pagure.hooks.default.Default.is_enabled_for(test))
         self.assertEqual(
         self.assertEqual(
             [(pagure.hooks.default.Default, None)],
             [(pagure.hooks.default.Default, None)],
-            pagure.lib.plugins.get_enabled_plugins(test)
+            pagure.lib.plugins.get_enabled_plugins(test),
         )
         )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 177 - 92
tests/test_pagure_flask_ui_plugins_fedmsg.py

@@ -16,8 +16,9 @@ import os
 
 
 from mock import patch
 from mock import patch
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import tests
 import tests
 import pagure.config
 import pagure.config
@@ -31,129 +32,182 @@ class PagureFlaskPluginFedmsgtests(tests.SimplePagureTest):
         super(PagureFlaskPluginFedmsgtests, self).setUp()
         super(PagureFlaskPluginFedmsgtests, self).setUp()
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'))
-        tests.create_projects_git(os.path.join(self.path, 'docs'))
+        tests.create_projects_git(os.path.join(self.path, "repos"))
+        tests.create_projects_git(os.path.join(self.path, "docs"))
 
 
     def tearDown(self):
     def tearDown(self):
         """ Tear Down the environment after the tests. """
         """ Tear Down the environment after the tests. """
         super(PagureFlaskPluginFedmsgtests, self).tearDown()
         super(PagureFlaskPluginFedmsgtests, self).tearDown()
-        pagure.config.config['DOCS_FOLDER'] = None
+        pagure.config.config["DOCS_FOLDER"] = None
 
 
     def test_plugin_fedmsg_defaul_page(self):
     def test_plugin_fedmsg_defaul_page(self):
         """ Test the fedmsg plugin endpoint's default page. """
         """ Test the fedmsg plugin endpoint's default page. """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/settings/Fedmsg')
+            output = self.app.get("/test/settings/Fedmsg")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Fedmsg - test - Pagure</title>', output_text)
+                "<title>Settings Fedmsg - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
             csrf_token = self.get_csrf(output=output)
             csrf_token = self.get_csrf(output=output)
 
 
             data = {}
             data = {}
 
 
-            output = self.app.post('/test/settings/Fedmsg', data=data)
+            output = self.app.post("/test/settings/Fedmsg", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Fedmsg - test - Pagure</title>', output_text)
+                "<title>Settings Fedmsg - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'post-receive.fedmsg')))
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'docs', 'test.git', 'hooks',
-                'post-receive')))
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "post-receive.fedmsg",
+                    )
+                )
+            )
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path, "docs", "test.git", "hooks", "post-receive"
+                    )
+                )
+            )
 
 
     def test_plugin_fedmsg_no_data(self):
     def test_plugin_fedmsg_no_data(self):
         """ Test the setting up the fedmsg plugin when there are no Docs
         """ Test the setting up the fedmsg plugin when there are no Docs
         folder.
         folder.
         """
         """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
-            data = {'csrf_token': csrf_token}
+            data = {"csrf_token": csrf_token}
 
 
             # With the git repo
             # With the git repo
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Fedmsg', data=data, follow_redirects=True)
+                "/test/settings/Fedmsg", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Fedmsg deactivated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Fedmsg deactivated", output_text)
 
 
-            output = self.app.get('/test/settings/Fedmsg', data=data)
+            output = self.app.get("/test/settings/Fedmsg", data=data)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Fedmsg - test - Pagure</title>', output_text)
+                "<title>Settings Fedmsg - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'post-receive.fedmsg')))
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'docs', 'test.git', 'hooks',
-                'post-receive')))
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "post-receive.fedmsg",
+                    )
+                )
+            )
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path, "docs", "test.git", "hooks", "post-receive"
+                    )
+                )
+            )
 
 
     def test_plugin_fedmsg_activate(self):
     def test_plugin_fedmsg_activate(self):
         """ Test the setting up the fedmsg plugin when there are no Docs
         """ Test the setting up the fedmsg plugin when there are no Docs
         folder.
         folder.
         """
         """
-        pagure.config.config['DOCS_FOLDER'] = os.path.join(
-            self.path, 'repos', 'docs')
+        pagure.config.config["DOCS_FOLDER"] = os.path.join(
+            self.path, "repos", "docs"
+        )
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             # Activate hook
             # Activate hook
-            data = {
-                'csrf_token': csrf_token,
-                'active': 'y',
-            }
+            data = {"csrf_token": csrf_token, "active": "y"}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Fedmsg', data=data, follow_redirects=True)
+                "/test/settings/Fedmsg", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Fedmsg activated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Fedmsg activated", output_text)
 
 
-            output = self.app.get('/test/settings/Fedmsg', data=data)
+            output = self.app.get("/test/settings/Fedmsg", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Fedmsg - test - Pagure</title>', output_text)
+                "<title>Settings Fedmsg - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'post-receive.fedmsg')))
-            self.assertTrue(os.path.exists(os.path.join(
-                self.path, 'repos', 'docs', 'test.git', 'hooks',
-                'post-receive')))
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "post-receive.fedmsg",
+                    )
+                )
+            )
+            self.assertTrue(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "docs",
+                        "test.git",
+                        "hooks",
+                        "post-receive",
+                    )
+                )
+            )
 
 
     def test_plugin_fedmsg_deactivate(self):
     def test_plugin_fedmsg_deactivate(self):
         """ Test the setting up the fedmsg plugin when there are no Docs
         """ Test the setting up the fedmsg plugin when there are no Docs
@@ -161,66 +215,97 @@ class PagureFlaskPluginFedmsgtests(tests.SimplePagureTest):
         """
         """
         self.test_plugin_fedmsg_activate()
         self.test_plugin_fedmsg_activate()
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             # De-Activate hook
             # De-Activate hook
-            data = {'csrf_token': csrf_token}
+            data = {"csrf_token": csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Fedmsg', data=data, follow_redirects=True)
+                "/test/settings/Fedmsg", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Fedmsg deactivated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Fedmsg deactivated", output_text)
 
 
-            output = self.app.get('/test/settings/Fedmsg', data=data)
+            output = self.app.get("/test/settings/Fedmsg", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Fedmsg - test - Pagure</title>', output_text)
+                "<title>Settings Fedmsg - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output.get_data(as_text=True))
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'post-receive.fedmsg')))
-            self.assertTrue(os.path.exists(os.path.join(
-                self.path, 'repos', 'docs', 'test.git', 'hooks',
-                'post-receive')))
-
-    @patch.dict('pagure.config.config', {'DOCS_FOLDER': None})
+                'type="checkbox" value="y">',
+                output.get_data(as_text=True),
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "post-receive.fedmsg",
+                    )
+                )
+            )
+            self.assertTrue(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "docs",
+                        "test.git",
+                        "hooks",
+                        "post-receive",
+                    )
+                )
+            )
+
+    @patch.dict("pagure.config.config", {"DOCS_FOLDER": None})
     def test_plugin_fedmsg_no_docs(self):
     def test_plugin_fedmsg_no_docs(self):
         """ Test the setting up the fedmsg plugin when there are no Docs
         """ Test the setting up the fedmsg plugin when there are no Docs
         folder.
         folder.
         """
         """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             # Activate hook
             # Activate hook
-            data = {
-                'csrf_token': csrf_token,
-                'active': 'y',
-            }
+            data = {"csrf_token": csrf_token, "active": "y"}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Fedmsg', data=data, follow_redirects=True)
+                "/test/settings/Fedmsg", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
 
 
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'post-receive.fedmsg')))
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'docs', 'test.git', 'hooks',
-                'post-receive')))
-
-
-if __name__ == '__main__':
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "post-receive.fedmsg",
+                    )
+                )
+            )
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path, "docs", "test.git", "hooks", "post-receive"
+                    )
+                )
+            )
+
+
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 105 - 54
tests/test_pagure_flask_ui_plugins_irc.py

@@ -14,8 +14,9 @@ import unittest
 import sys
 import sys
 import os
 import os
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import tests
 import tests
 
 
@@ -27,116 +28,166 @@ class PagureFlaskPluginIRCtests(tests.SimplePagureTest):
         """ Test the irc plugin on/off endpoint. """
         """ Test the irc plugin on/off endpoint. """
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'))
+        tests.create_projects_git(os.path.join(self.path, "repos"))
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/settings/IRC')
+            output = self.app.get("/test/settings/IRC")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings IRC - test - Pagure</title>', output_text)
+                "<title>Settings IRC - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             data = {}
             data = {}
 
 
-            output = self.app.post('/test/settings/IRC', data=data)
+            output = self.app.post("/test/settings/IRC", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings IRC - test - Pagure</title>', output_text)
+                "<title>Settings IRC - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks', 'post-receive.irc')))
-
-            data['csrf_token'] = csrf_token
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "post-receive.irc",
+                    )
+                )
+            )
+
+            data["csrf_token"] = csrf_token
 
 
             # With the git repo
             # With the git repo
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/IRC', data=data, follow_redirects=True)
+                "/test/settings/IRC", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook IRC deactivated', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook IRC deactivated", output_text)
 
 
-            output = self.app.get('/test/settings/IRC')
+            output = self.app.get("/test/settings/IRC")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings IRC - test - Pagure</title>', output_text)
+                "<title>Settings IRC - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks', 'post-receive.irc')))
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "post-receive.irc",
+                    )
+                )
+            )
 
 
             # Activate hook
             # Activate hook
             data = {
             data = {
-                'csrf_token': csrf_token,
-                'active': 'y',
-                'server': 'irc.freenode.net',
-                'port': 6667,
-                'room': '#fedora-apps',
+                "csrf_token": csrf_token,
+                "active": "y",
+                "server": "irc.freenode.net",
+                "port": 6667,
+                "room": "#fedora-apps",
             }
             }
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/IRC', data=data, follow_redirects=True)
+                "/test/settings/IRC", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook IRC activated', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook IRC activated", output_text)
 
 
-            output = self.app.get('/test/settings/IRC')
+            output = self.app.get("/test/settings/IRC")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings IRC - test - Pagure</title>', output_text)
+                "<title>Settings IRC - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
             # TODO: Fix this
             # TODO: Fix this
-            #self.assertTrue(os.path.exists(os.path.join(
-                #self.path, 'repos', 'test.git', 'hooks', 'post-receive.irc')))
+            # self.assertTrue(os.path.exists(os.path.join(
+            # self.path, 'repos', 'test.git', 'hooks', 'post-receive.irc')))
 
 
             # De-Activate hook
             # De-Activate hook
-            data = {'csrf_token': csrf_token}
-            output = self.app.post('/test/settings/IRC', data=data, follow_redirects=True)
+            data = {"csrf_token": csrf_token}
+            output = self.app.post(
+                "/test/settings/IRC", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook IRC deactivated', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook IRC deactivated", output_text)
 
 
-            output = self.app.get('/test/settings/IRC')
+            output = self.app.get("/test/settings/IRC")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings IRC - test - Pagure</title>', output_text)
+                "<title>Settings IRC - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks', 'post-receive.irc')))
-
-
-if __name__ == '__main__':
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "post-receive.irc",
+                    )
+                )
+            )
+
+
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 79 - 57
tests/test_pagure_flask_ui_plugins_mail.py

@@ -15,8 +15,9 @@ import sys
 import os
 import os
 
 
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import tests
 import tests
 
 
@@ -28,140 +29,161 @@ class PagureFlaskPluginMailtests(tests.SimplePagureTest):
         """ Test the mail plugin on/off endpoint. """
         """ Test the mail plugin on/off endpoint. """
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'))
+        tests.create_projects_git(os.path.join(self.path, "repos"))
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/settings/Mail')
+            output = self.app.get("/test/settings/Mail")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Mail - test - Pagure</title>', output_text)
-            self.assertIn(
-                '<label for="mail_to">Mail to</label>',
-                output_text)
+                "<title>Settings Mail - test - Pagure</title>", output_text
+            )
+            self.assertIn('<label for="mail_to">Mail to</label>', output_text)
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             data = {}
             data = {}
 
 
-            output = self.app.post('/test/settings/Mail', data=data)
+            output = self.app.post("/test/settings/Mail", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Mail - test - Pagure</title>', output_text)
-            self.assertIn(
-                '<label for="mail_to">Mail to</label>', output_text)
+                "<title>Settings Mail - test - Pagure</title>", output_text
+            )
+            self.assertIn('<label for="mail_to">Mail to</label>', output_text)
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
-            data['csrf_token'] = csrf_token
+            data["csrf_token"] = csrf_token
 
 
             # With the git repo
             # With the git repo
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Mail', data=data, follow_redirects=True)
+                "/test/settings/Mail", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Mail deactivated', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Mail deactivated", output_text)
 
 
-            output = self.app.get('/test/settings/Mail')
+            output = self.app.get("/test/settings/Mail")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Mail - test - Pagure</title>', output_text)
-            self.assertIn(
-                '<label for="mail_to">Mail to</label>', output_text)
+                "<title>Settings Mail - test - Pagure</title>", output_text
+            )
+            self.assertIn('<label for="mail_to">Mail to</label>', output_text)
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
             # Missing the required mail_to
             # Missing the required mail_to
-            data = {'csrf_token': csrf_token, 'active': 'y'}
+            data = {"csrf_token": csrf_token, "active": "y"}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Mail', data=data, follow_redirects=True)
+                "/test/settings/Mail", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Mail - test - Pagure</title>', output_text)
-            self.assertNotIn(
-                'Hook activated', output_text)
+                "<title>Settings Mail - test - Pagure</title>", output_text
+            )
+            self.assertNotIn("Hook activated", output_text)
             if self.get_wtforms_version() >= (2, 2):
             if self.get_wtforms_version() >= (2, 2):
                 self.assertIn(
                 self.assertIn(
                     '<div class="col-sm-10">\n        '
                     '<div class="col-sm-10">\n        '
                     '<input class="form-control pl-0" id="mail_to" name="mail_to" '
                     '<input class="form-control pl-0" id="mail_to" name="mail_to" '
                     'required type="text" value="">\n    </div>\n  </div>\n      '
                     'required type="text" value="">\n    </div>\n  </div>\n      '
                     '<div class="alert alert-danger">This field is required.</div>',
                     '<div class="alert alert-danger">This field is required.</div>',
-                    output_text)
+                    output_text,
+                )
             else:
             else:
                 self.assertIn(
                 self.assertIn(
                     '<div class="col-sm-10">\n        '
                     '<div class="col-sm-10">\n        '
                     '<input class="form-control pl-0" id="mail_to" name="mail_to" '
                     '<input class="form-control pl-0" id="mail_to" name="mail_to" '
                     'type="text" value="">\n    </div>\n  </div>\n      '
                     'type="text" value="">\n    </div>\n  </div>\n      '
                     '<div class="alert alert-danger">This field is required.</div>',
                     '<div class="alert alert-danger">This field is required.</div>',
-                    output_text)
+                    output_text,
+                )
             self.assertIn(
             self.assertIn(
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
             # Activate hook
             # Activate hook
             data = {
             data = {
-                'csrf_token': csrf_token,
-                'active': 'y',
-                'mail_to': 'foo@bar'
+                "csrf_token": csrf_token,
+                "active": "y",
+                "mail_to": "foo@bar",
             }
             }
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Mail', data=data, follow_redirects=True)
+                "/test/settings/Mail", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Mail activated', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Mail activated", output_text)
 
 
-            output = self.app.get('/test/settings/Mail')
+            output = self.app.get("/test/settings/Mail")
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Mail - test - Pagure</title>', output_text)
-            self.assertIn(
-                '<label for="mail_to">Mail to</label>', output_text)
+                "<title>Settings Mail - test - Pagure</title>", output_text
+            )
+            self.assertIn('<label for="mail_to">Mail to</label>', output_text)
             self.assertIn(
             self.assertIn(
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
             # De-Activate hook
             # De-Activate hook
-            data = {'csrf_token': csrf_token}
+            data = {"csrf_token": csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Mail', data=data, follow_redirects=True)
+                "/test/settings/Mail", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Mail deactivated', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Mail deactivated", output_text)
 
 
-            output = self.app.get('/test/settings/Mail')
+            output = self.app.get("/test/settings/Mail")
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Mail - test - Pagure</title>', output_text)
-            self.assertIn(
-                '<label for="mail_to">Mail to</label>', output_text)
+                "<title>Settings Mail - test - Pagure</title>", output_text
+            )
+            self.assertIn('<label for="mail_to">Mail to</label>', output_text)
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 150 - 92
tests/test_pagure_flask_ui_plugins_mirror.py

@@ -16,8 +16,9 @@ import os
 
 
 from mock import patch
 from mock import patch
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.utils
 import pagure.utils
 import tests
 import tests
@@ -31,217 +32,274 @@ class PagureFlaskPluginMirrortests(tests.Modeltests):
         super(PagureFlaskPluginMirrortests, self).setUp()
         super(PagureFlaskPluginMirrortests, self).setUp()
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'))
+        tests.create_projects_git(os.path.join(self.path, "repos"))
 
 
     def test_valid_ssh_url_pattern(self):
     def test_valid_ssh_url_pattern(self):
         """ Check a number of valide ssh target that the pattern should let
         """ Check a number of valide ssh target that the pattern should let
         through.
         through.
         """
         """
         entries = [
         entries = [
-            'ssh://user@host.lcl:/path/to/repo.git',
-            'git@github.com:user/project.git',
-            'ssh://user@host.org/target',
-            'git+ssh://user@host.org/target',
-            'git+ssh://user@host.lcl:/path/to/repo.git',
+            "ssh://user@host.lcl:/path/to/repo.git",
+            "git@github.com:user/project.git",
+            "ssh://user@host.org/target",
+            "git+ssh://user@host.org/target",
+            "git+ssh://user@host.lcl:/path/to/repo.git",
         ]
         ]
         for el in entries:
         for el in entries:
             print(el)
             print(el)
             self.assertIsNotNone(pagure.utils.ssh_urlpattern.match(el))
             self.assertIsNotNone(pagure.utils.ssh_urlpattern.match(el))
 
 
-
     def test_plugin_mirror_no_csrf(self):
     def test_plugin_mirror_no_csrf(self):
         """ Test setting up the mirror plugin with no csrf. """
         """ Test setting up the mirror plugin with no csrf. """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/settings/Mirroring')
+            output = self.app.get("/test/settings/Mirroring")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Mirroring - test - Pagure</title>',
-                output_text)
+                "<title>Settings Mirroring - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
             data = {}
             data = {}
 
 
-            output = self.app.post('/test/settings/Mirroring', data=data)
+            output = self.app.post("/test/settings/Mirroring", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Mirroring - test - Pagure</title>',
-                output_text)
+                "<title>Settings Mirroring - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'post-receive.mirror')))
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "post-receive.mirror",
+                    )
+                )
+            )
 
 
     def test_plugin_mirror_no_data(self):
     def test_plugin_mirror_no_data(self):
         """ Test the setting up the mirror plugin when there are no data
         """ Test the setting up the mirror plugin when there are no data
         provided in the request.
         provided in the request.
         """
         """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
-            data = {'csrf_token': csrf_token}
+            data = {"csrf_token": csrf_token}
 
 
             # With the git repo
             # With the git repo
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Mirroring', data=data, follow_redirects=True)
+                "/test/settings/Mirroring", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
-            self.assertIn(
-                '</i> Hook Mirroring deactivated</div>',
-                output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
+            self.assertIn("</i> Hook Mirroring deactivated</div>", output_text)
 
 
-            output = self.app.get('/test/settings/Mirroring', data=data)
+            output = self.app.get("/test/settings/Mirroring", data=data)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Mirroring - test - Pagure</title>',
-                output_text)
+                "<title>Settings Mirroring - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'post-receive.mirror')))
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "post-receive.mirror",
+                    )
+                )
+            )
 
 
     def test_plugin_mirror_invalid_target(self):
     def test_plugin_mirror_invalid_target(self):
         """ Test the setting up the mirror plugin when there are the target
         """ Test the setting up the mirror plugin when there are the target
         provided is invalid.
         provided is invalid.
         """
         """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             data = {
             data = {
-                'csrf_token': csrf_token,
-                'active': True,
-                'target': 'https://host.org/target',
+                "csrf_token": csrf_token,
+                "active": True,
+                "target": "https://host.org/target",
             }
             }
 
 
             # With the git repo
             # With the git repo
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Mirroring', data=data, follow_redirects=True)
+                "/test/settings/Mirroring", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Mirroring - test - Pagure</title>',
-                output_text)
+                "<title>Settings Mirroring - test - Pagure</title>",
+                output_text,
+            )
             if self.get_wtforms_version() >= (2, 2):
             if self.get_wtforms_version() >= (2, 2):
                 self.assertIn(
                 self.assertIn(
                     '<div class="col-sm-10">\n        '
                     '<div class="col-sm-10">\n        '
                     '<input class="form-control pl-0" id="target" name="target" '
                     '<input class="form-control pl-0" id="target" name="target" '
                     'required type="text" value="https://host.org/target">\n'
                     'required type="text" value="https://host.org/target">\n'
-                    '    </div>\n  '
+                    "    </div>\n  "
                     '</div>\n      <div class="alert alert-danger">Invalid '
                     '</div>\n      <div class="alert alert-danger">Invalid '
-                    'input.</div>', output_text)
+                    "input.</div>",
+                    output_text,
+                )
             else:
             else:
                 self.assertIn(
                 self.assertIn(
                     '<div class="col-sm-10">\n        '
                     '<div class="col-sm-10">\n        '
                     '<input class="form-control pl-0" id="target" name="target" '
                     '<input class="form-control pl-0" id="target" name="target" '
                     'type="text" value="https://host.org/target">\n    </div>\n  '
                     'type="text" value="https://host.org/target">\n    </div>\n  '
                     '</div>\n      <div class="alert alert-danger">Invalid '
                     '</div>\n      <div class="alert alert-danger">Invalid '
-                    'input.</div>', output_text)
+                    "input.</div>",
+                    output_text,
+                )
 
 
-            output = self.app.get('/test/settings/Mirroring', data=data)
+            output = self.app.get("/test/settings/Mirroring", data=data)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Mirroring - test - Pagure</title>',
-                output_text)
+                "<title>Settings Mirroring - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'post-receive.mirror')))
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "post-receive.mirror",
+                    )
+                )
+            )
 
 
     def test_setting_up_mirror(self):
     def test_setting_up_mirror(self):
         """ Test the setting up the mirror plugin.
         """ Test the setting up the mirror plugin.
         """
         """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             data = {
             data = {
-                'csrf_token': csrf_token,
-                'active': True,
-                'target': 'ssh://user@host.org/target',
+                "csrf_token": csrf_token,
+                "active": True,
+                "target": "ssh://user@host.org/target",
             }
             }
 
 
             # With the git repo
             # With the git repo
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Mirroring', data=data, follow_redirects=True)
+                "/test/settings/Mirroring", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>',
-                output_text)
-            self.assertIn(
-                '</i> Hook Mirroring activated</div>',
-                output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
+            self.assertIn("</i> Hook Mirroring activated</div>", output_text)
 
 
-            output = self.app.get('/test/settings/Mirroring', data=data)
+            output = self.app.get("/test/settings/Mirroring", data=data)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Mirroring - test - Pagure</title>',
-                output_text)
+                "<title>Settings Mirroring - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertTrue(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'post-receive')))
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertTrue(
+                os.path.exists(
+                    os.path.join(
+                        self.path, "repos", "test.git", "hooks", "post-receive"
+                    )
+                )
+            )
 
 
     def test_plugin_mirror_deactivate(self):
     def test_plugin_mirror_deactivate(self):
         """ Test the deactivating the mirror plugin.
         """ Test the deactivating the mirror plugin.
         """
         """
         self.test_setting_up_mirror()
         self.test_setting_up_mirror()
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             # De-Activate hook
             # De-Activate hook
-            data = {'csrf_token': csrf_token}
+            data = {"csrf_token": csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Mirroring', data=data, follow_redirects=True)
+                "/test/settings/Mirroring", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>',
-                output_text)
-            self.assertIn(
-                '</i> Hook Mirroring deactivated</div>',
-                output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
+            self.assertIn("</i> Hook Mirroring deactivated</div>", output_text)
 
 
-            output = self.app.get('/test/settings/Mirroring', data=data)
+            output = self.app.get("/test/settings/Mirroring", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Mirroring - test - Pagure</title>',
-                output_text)
+                "<title>Settings Mirroring - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output.get_data(as_text=True))
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'post-receive.mirror')))
-
-
-if __name__ == '__main__':
+                'type="checkbox" value="y">',
+                output.get_data(as_text=True),
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "post-receive.mirror",
+                    )
+                )
+            )
+
+
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 165 - 75
tests/test_pagure_flask_ui_plugins_noff.py

@@ -15,8 +15,9 @@ import sys
 import os
 import os
 
 
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import tests
 import tests
 
 
@@ -28,193 +29,282 @@ class PagureFlaskPluginNoFFtests(tests.SimplePagureTest):
         """ Test the noff plugin on/off endpoint. """
         """ Test the noff plugin on/off endpoint. """
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'))
+        tests.create_projects_git(os.path.join(self.path, "repos"))
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             output = self.app.get(
             output = self.app.get(
-                '/test/settings/Block non fast-forward pushes')
+                "/test/settings/Block non fast-forward pushes"
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Block non fast-forward pushes - test - '
-                'Pagure</title>', output_text)
+                "<title>Settings Block non fast-forward pushes - test - "
+                "Pagure</title>",
+                output_text,
+            )
             if self.get_wtforms_version() >= (2, 2):
             if self.get_wtforms_version() >= (2, 2):
                 self.assertIn(
                 self.assertIn(
                     '<input class="form-control pl-0" id="branches" name="branches" '
                     '<input class="form-control pl-0" id="branches" name="branches" '
-                    'required type="text" value="">', output_text)
+                    'required type="text" value="">',
+                    output_text,
+                )
             else:
             else:
                 self.assertIn(
                 self.assertIn(
                     '<input class="form-control pl-0" id="branches" name="branches" '
                     '<input class="form-control pl-0" id="branches" name="branches" '
-                    'type="text" value="">', output_text)
+                    'type="text" value="">',
+                    output_text,
+                )
             self.assertTrue(
             self.assertTrue(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">' in output_text)
+                'type="checkbox" value="y">' in output_text
+            )
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             data = {}
             data = {}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Block non fast-forward pushes', data=data)
+                "/test/settings/Block non fast-forward pushes", data=data
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Block non fast-forward pushes - test - '
-                'Pagure</title>', output_text)
+                "<title>Settings Block non fast-forward pushes - test - "
+                "Pagure</title>",
+                output_text,
+            )
             if self.get_wtforms_version() >= (2, 2):
             if self.get_wtforms_version() >= (2, 2):
                 self.assertIn(
                 self.assertIn(
                     '<input class="form-control pl-0" id="branches" name="branches" '
                     '<input class="form-control pl-0" id="branches" name="branches" '
-                    'required type="text" value="">', output_text)
+                    'required type="text" value="">',
+                    output_text,
+                )
             else:
             else:
                 self.assertIn(
                 self.assertIn(
                     '<input class="form-control pl-0" id="branches" name="branches" '
                     '<input class="form-control pl-0" id="branches" name="branches" '
-                    'type="text" value="">', output_text)
+                    'type="text" value="">',
+                    output_text,
+                )
             self.assertTrue(
             self.assertTrue(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">' in output_text)
+                'type="checkbox" value="y">' in output_text
+            )
 
 
-            data['csrf_token'] = csrf_token
+            data["csrf_token"] = csrf_token
 
 
             # With the git repo
             # With the git repo
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Block non fast-forward pushes',
-                data=data, follow_redirects=True)
+                "/test/settings/Block non fast-forward pushes",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             self.assertTrue(
             self.assertTrue(
-                'Hook Block non '
-                'fast-forward pushes deactivated' in output_text)
+                "Hook Block non "
+                "fast-forward pushes deactivated" in output_text
+            )
 
 
             output = self.app.get(
             output = self.app.get(
-                '/test/settings/Block non fast-forward pushes')
+                "/test/settings/Block non fast-forward pushes"
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Block non fast-forward pushes - test - '
-                'Pagure</title>', output_text)
+                "<title>Settings Block non fast-forward pushes - test - "
+                "Pagure</title>",
+                output_text,
+            )
             if self.get_wtforms_version() >= (2, 2):
             if self.get_wtforms_version() >= (2, 2):
                 self.assertIn(
                 self.assertIn(
                     '<input class="form-control pl-0" id="branches" name="branches" '
                     '<input class="form-control pl-0" id="branches" name="branches" '
-                    'required type="text" value="">', output_text)
+                    'required type="text" value="">',
+                    output_text,
+                )
             else:
             else:
                 self.assertIn(
                 self.assertIn(
                     '<input class="form-control pl-0" id="branches" name="branches" '
                     '<input class="form-control pl-0" id="branches" name="branches" '
-                    'type="text" value="">', output_text)
+                    'type="text" value="">',
+                    output_text,
+                )
             self.assertTrue(
             self.assertTrue(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">' in output_text)
+                'type="checkbox" value="y">' in output_text
+            )
 
 
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks', 'post-receive.mail')))
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "post-receive.mail",
+                    )
+                )
+            )
 
 
             # Missing the required mail_to
             # Missing the required mail_to
-            data = {'csrf_token': csrf_token, 'active': 'y'}
+            data = {"csrf_token": csrf_token, "active": "y"}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Block non fast-forward pushes',
-                data=data, follow_redirects=True)
+                "/test/settings/Block non fast-forward pushes",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Block non fast-forward pushes - test - '
-                'Pagure</title>', output_text)
-            self.assertNotIn(
-                'Hook activated',
-                output_text)
+                "<title>Settings Block non fast-forward pushes - test - "
+                "Pagure</title>",
+                output_text,
+            )
+            self.assertNotIn("Hook activated", output_text)
             if self.get_wtforms_version() >= (2, 2):
             if self.get_wtforms_version() >= (2, 2):
                 self.assertIn(
                 self.assertIn(
                     '<input class="form-control pl-0" id="branches" name="branches" '
                     '<input class="form-control pl-0" id="branches" name="branches" '
-                    'required type="text" value="">', output_text)
+                    'required type="text" value="">',
+                    output_text,
+                )
             else:
             else:
                 self.assertIn(
                 self.assertIn(
                     '<input class="form-control pl-0" id="branches" name="branches" '
                     '<input class="form-control pl-0" id="branches" name="branches" '
-                    'type="text" value="">', output_text)
+                    'type="text" value="">',
+                    output_text,
+                )
             self.assertTrue(
             self.assertTrue(
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">' in output_text)
+                'type="checkbox" value="y">' in output_text
+            )
 
 
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'pre-receive.pagureforcecommit')))
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "pre-receive.pagureforcecommit",
+                    )
+                )
+            )
 
 
             # Activate hook
             # Activate hook
             data = {
             data = {
-                'csrf_token': csrf_token,
-                'active': 'y',
-                'branches': 'master',
+                "csrf_token": csrf_token,
+                "active": "y",
+                "branches": "master",
             }
             }
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Block non fast-forward pushes',
-                data=data, follow_redirects=True)
+                "/test/settings/Block non fast-forward pushes",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                'Hook Block non '
-                'fast-forward pushes activated', output_text)
+                "Hook Block non " "fast-forward pushes activated", output_text
+            )
 
 
             output = self.app.get(
             output = self.app.get(
-                '/test/settings/Block non fast-forward pushes')
+                "/test/settings/Block non fast-forward pushes"
+            )
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Block non fast-forward pushes - test - '
-                'Pagure</title>', output_text)
+                "<title>Settings Block non fast-forward pushes - test - "
+                "Pagure</title>",
+                output_text,
+            )
             if self.get_wtforms_version() >= (2, 2):
             if self.get_wtforms_version() >= (2, 2):
                 self.assertIn(
                 self.assertIn(
                     '<input class="form-control pl-0" id="branches" name="branches" '
                     '<input class="form-control pl-0" id="branches" name="branches" '
-                    'required type="text" value="master">', output_text)
+                    'required type="text" value="master">',
+                    output_text,
+                )
             else:
             else:
                 self.assertIn(
                 self.assertIn(
                     '<input class="form-control pl-0" id="branches" name="branches" '
                     '<input class="form-control pl-0" id="branches" name="branches" '
-                    'type="text" value="master">', output_text)
+                    'type="text" value="master">',
+                    output_text,
+                )
             self.assertIn(
             self.assertIn(
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
             # De-Activate hook
             # De-Activate hook
-            data = {'csrf_token': csrf_token}
+            data = {"csrf_token": csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Block non fast-forward pushes',
-                data=data, follow_redirects=True)
+                "/test/settings/Block non fast-forward pushes",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                'Hook Block non '
-                'fast-forward pushes deactivated', output_text)
+                "Hook Block non " "fast-forward pushes deactivated",
+                output_text,
+            )
 
 
             output = self.app.get(
             output = self.app.get(
-                '/test/settings/Block non fast-forward pushes')
+                "/test/settings/Block non fast-forward pushes"
+            )
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Block non fast-forward pushes - test - '
-                'Pagure</title>', output_text)
+                "<title>Settings Block non fast-forward pushes - test - "
+                "Pagure</title>",
+                output_text,
+            )
             if self.get_wtforms_version() >= (2, 2):
             if self.get_wtforms_version() >= (2, 2):
                 self.assertIn(
                 self.assertIn(
                     '<input class="form-control pl-0" id="branches" name="branches" '
                     '<input class="form-control pl-0" id="branches" name="branches" '
-                    'required type="text" value="">', output_text)
+                    'required type="text" value="">',
+                    output_text,
+                )
             else:
             else:
                 self.assertIn(
                 self.assertIn(
                     '<input class="form-control pl-0" id="branches" name="branches" '
                     '<input class="form-control pl-0" id="branches" name="branches" '
-                    'type="text" value="">', output_text)
+                    'type="text" value="">',
+                    output_text,
+                )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'pre-receive.pagureforcecommit')))
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "pre-receive.pagureforcecommit",
+                    )
+                )
+            )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 253 - 159
tests/test_pagure_flask_ui_plugins_pagure_ci.py

@@ -8,8 +8,9 @@ import os
 
 
 import mock
 import mock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.tasks_services
 import pagure.lib.tasks_services
 import tests
 import tests
@@ -22,163 +23,205 @@ class PagureFlaskPluginPagureCItests(tests.SimplePagureTest):
         """ Test the pagure ci plugin on/off endpoint. """
         """ Test the pagure ci plugin on/off endpoint. """
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'))
+        tests.create_projects_git(os.path.join(self.path, "repos"))
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/settings/Pagure CI')
+            output = self.app.get("/test/settings/Pagure CI")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure CI - test - Pagure</title>',
-                output_text)
+                "<title>Settings Pagure CI - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<label for="ci_url">URL to the project on the CI '
                 '<label for="ci_url">URL to the project on the CI '
-                'service</label>', output_text)
+                "service</label>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                '<label for="ci_job">Name of the job to trigger'
-                '</label>', output_text)
+                '<label for="ci_job">Name of the job to trigger' "</label>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active_commit" '
                 '<input class="form-check-input mt-2" id="active_commit" '
-                'name="active_commit" type="checkbox" value="y">', output_text)
+                'name="active_commit" type="checkbox" value="y">',
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active_pr" '
                 '<input class="form-check-input mt-2" id="active_pr" '
-                'name="active_pr" type="checkbox" value="y">', output_text)
+                'name="active_pr" type="checkbox" value="y">',
+                output_text,
+            )
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             data = {}
             data = {}
 
 
-            output = self.app.post('/test/settings/Pagure CI', data=data)
+            output = self.app.post("/test/settings/Pagure CI", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure CI - test - Pagure</title>',
-                output_text)
+                "<title>Settings Pagure CI - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<label for="ci_url">URL to the project on the CI '
                 '<label for="ci_url">URL to the project on the CI '
-                'service</label>', output_text)
+                "service</label>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                '<label for="ci_job">Name of the job to trigger'
-                '</label>', output_text)
+                '<label for="ci_job">Name of the job to trigger' "</label>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active_commit" '
                 '<input class="form-check-input mt-2" id="active_commit" '
-                'name="active_commit" type="checkbox" value="y">', output_text)
+                'name="active_commit" type="checkbox" value="y">',
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active_pr" '
                 '<input class="form-check-input mt-2" id="active_pr" '
-                'name="active_pr" type="checkbox" value="y">', output_text)
+                'name="active_pr" type="checkbox" value="y">',
+                output_text,
+            )
 
 
             # Activate hook
             # Activate hook
             data = {
             data = {
-                'active_commit': 'y',
-                'ci_url': 'https://jenkins.fedoraproject.org',
-                'ci_type': 'jenkins',
-                'ci_job': 'test/job'
+                "active_commit": "y",
+                "ci_url": "https://jenkins.fedoraproject.org",
+                "ci_type": "jenkins",
+                "ci_job": "test/job",
             }
             }
             # CSRF Token missing
             # CSRF Token missing
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Pagure CI', data=data, follow_redirects=True)
+                "/test/settings/Pagure CI", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure CI - test - Pagure</title>',
-                output_text)
+                "<title>Settings Pagure CI - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<label for="ci_url">URL to the project on the CI '
                 '<label for="ci_url">URL to the project on the CI '
-                'service</label>', output_text)
+                "service</label>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                '<label for="ci_job">Name of the job to trigger'
-                '</label>', output_text)
+                '<label for="ci_job">Name of the job to trigger' "</label>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input checked class="form-check-input mt-2" id="active_commit" '
                 '<input checked class="form-check-input mt-2" id="active_commit" '
-                'name="active_commit" type="checkbox" value="y">', output_text)
+                'name="active_commit" type="checkbox" value="y">',
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active_pr" '
                 '<input class="form-check-input mt-2" id="active_pr" '
-                'name="active_pr" type="checkbox" value="y">', output_text)
+                'name="active_pr" type="checkbox" value="y">',
+                output_text,
+            )
 
 
-            data['csrf_token'] = csrf_token
+            data["csrf_token"] = csrf_token
 
 
             # Activate hook
             # Activate hook
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Pagure CI', data=data, follow_redirects=True)
+                "/test/settings/Pagure CI", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Pagure CI activated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Pagure CI activated", output_text)
 
 
-            output = self.app.get('/test/settings/Pagure CI')
+            output = self.app.get("/test/settings/Pagure CI")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure CI - test - Pagure</title>',
-                output_text)
+                "<title>Settings Pagure CI - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<label for="ci_url">URL to the project on the CI '
                 '<label for="ci_url">URL to the project on the CI '
-                'service</label>', output_text)
+                "service</label>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                '<label for="ci_job">Name of the job to trigger'
-                '</label>', output_text)
+                '<label for="ci_job">Name of the job to trigger' "</label>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input checked class="form-check-input mt-2" id="active_commit" '
                 '<input checked class="form-check-input mt-2" id="active_commit" '
-                'name="active_commit" type="checkbox" value="y">', output_text)
+                'name="active_commit" type="checkbox" value="y">',
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                '<pre>\nhttp://localhost.localdomain/api/0/ci/jenkins/test/',
-                output_text)
+                "<pre>\nhttp://localhost.localdomain/api/0/ci/jenkins/test/",
+                output_text,
+            )
 
 
             # De-activate the hook
             # De-activate the hook
-            data = {
-                'csrf_token': csrf_token,
-            }
+            data = {"csrf_token": csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Pagure CI', data=data, follow_redirects=True)
+                "/test/settings/Pagure CI", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Pagure CI deactivated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Pagure CI deactivated", output_text)
 
 
-            output = self.app.get('/test/settings/Pagure CI')
+            output = self.app.get("/test/settings/Pagure CI")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure CI - test - Pagure</title>',
-                output_text)
+                "<title>Settings Pagure CI - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<label for="ci_url">URL to the project on the CI '
                 '<label for="ci_url">URL to the project on the CI '
-                'service</label>', output_text)
+                "service</label>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                '<label for="ci_job">Name of the job to trigger'
-                '</label>', output_text)
+                '<label for="ci_job">Name of the job to trigger' "</label>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active_commit" '
                 '<input class="form-check-input mt-2" id="active_commit" '
-                'name="active_commit" type="checkbox" value="y">', output_text)
+                'name="active_commit" type="checkbox" value="y">',
+                output_text,
+            )
 
 
             # Missing the required ci_url
             # Missing the required ci_url
-            data = {'csrf_token': csrf_token, 'active_commit': 'y'}
+            data = {"csrf_token": csrf_token, "active_commit": "y"}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Pagure CI', data=data, follow_redirects=True)
+                "/test/settings/Pagure CI", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure CI - test - Pagure</title>',
-                output_text)
-            self.assertNotIn(
-                'Hook Pagure CI activated',
-                output_text)
+                "<title>Settings Pagure CI - test - Pagure</title>",
+                output_text,
+            )
+            self.assertNotIn("Hook Pagure CI activated", output_text)
 
 
             if self.get_wtforms_version() >= (2, 2):
             if self.get_wtforms_version() >= (2, 2):
                 self.assertIn(
                 self.assertIn(
@@ -186,198 +229,249 @@ class PagureFlaskPluginPagureCItests(tests.SimplePagureTest):
                     '<input class="form-control pl-0" id="ci_url" name="ci_url" '
                     '<input class="form-control pl-0" id="ci_url" name="ci_url" '
                     'required type="text" value="">\n    </div>\n  </div>\n      '
                     'required type="text" value="">\n    </div>\n  </div>\n      '
                     '<div class="alert alert-danger">This field is required.</div>',
                     '<div class="alert alert-danger">This field is required.</div>',
-                    output_text)
+                    output_text,
+                )
                 self.assertIn(
                 self.assertIn(
                     '<div class="col-sm-10">\n        '
                     '<div class="col-sm-10">\n        '
                     '<input class="form-control pl-0" id="ci_job" name="ci_job" '
                     '<input class="form-control pl-0" id="ci_job" name="ci_job" '
                     'required type="text" value="">\n    </div>\n  </div>\n      '
                     'required type="text" value="">\n    </div>\n  </div>\n      '
                     '<div class="alert alert-danger">This field is required.</div>',
                     '<div class="alert alert-danger">This field is required.</div>',
-                    output_text)
+                    output_text,
+                )
             else:
             else:
                 self.assertIn(
                 self.assertIn(
                     '<div class="col-sm-10">\n        '
                     '<div class="col-sm-10">\n        '
                     '<input class="form-control pl-0" id="ci_url" name="ci_url" '
                     '<input class="form-control pl-0" id="ci_url" name="ci_url" '
                     'type="text" value="">\n    </div>\n  </div>\n      '
                     'type="text" value="">\n    </div>\n  </div>\n      '
                     '<div class="alert alert-danger">This field is required.</div>',
                     '<div class="alert alert-danger">This field is required.</div>',
-                    output_text)
+                    output_text,
+                )
                 self.assertIn(
                 self.assertIn(
                     '<div class="col-sm-10">\n        '
                     '<div class="col-sm-10">\n        '
                     '<input class="form-control pl-0" id="ci_job" name="ci_job" '
                     '<input class="form-control pl-0" id="ci_job" name="ci_job" '
                     'type="text" value="">\n    </div>\n  </div>\n      '
                     'type="text" value="">\n    </div>\n  </div>\n      '
                     '<div class="alert alert-danger">This field is required.</div>',
                     '<div class="alert alert-danger">This field is required.</div>',
-                    output_text)
+                    output_text,
+                )
             self.assertIn(
             self.assertIn(
                 '<input checked class="form-check-input mt-2" id="active_commit" '
                 '<input checked class="form-check-input mt-2" id="active_commit" '
-                'name="active_commit" type="checkbox" value="y">', output_text)
+                'name="active_commit" type="checkbox" value="y">',
+                output_text,
+            )
 
 
     def test_plugin_pagure_ci_namespaced(self):
     def test_plugin_pagure_ci_namespaced(self):
         """ Test the pagure ci plugin on/off endpoint. """
         """ Test the pagure ci plugin on/off endpoint. """
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'))
+        tests.create_projects_git(os.path.join(self.path, "repos"))
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/somenamespace/test3/settings/Pagure CI')
+            output = self.app.get("/somenamespace/test3/settings/Pagure CI")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure CI - somenamespace/test3 - '
-                'Pagure</title>', output_text)
+                "<title>Settings Pagure CI - somenamespace/test3 - "
+                "Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<label for="ci_url">URL to the project on the CI '
                 '<label for="ci_url">URL to the project on the CI '
-                'service</label>', output_text)
+                "service</label>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                '<label for="ci_job">Name of the job to trigger'
-                '</label>', output_text)
+                '<label for="ci_job">Name of the job to trigger' "</label>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active_pr" name="active_pr" '
                 '<input class="form-check-input mt-2" id="active_pr" name="active_pr" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             # Activate hook
             # Activate hook
             data = {
             data = {
-                'active_pr': 'y',
-                'ci_url': 'https://jenkins.fedoraproject.org',
-                'ci_job': 'test/job',
-                'ci_type': 'jenkins',
-                'csrf_token': csrf_token,
+                "active_pr": "y",
+                "ci_url": "https://jenkins.fedoraproject.org",
+                "ci_job": "test/job",
+                "ci_type": "jenkins",
+                "csrf_token": csrf_token,
             }
             }
 
 
             # Activate hook
             # Activate hook
             output = self.app.post(
             output = self.app.post(
-                '/somenamespace/test3/settings/Pagure CI', data=data, follow_redirects=True)
+                "/somenamespace/test3/settings/Pagure CI",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                '<title>Settings - somenamespace/test3 - Pagure</title>',
-                output_text)
+                "<title>Settings - somenamespace/test3 - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Pagure CI activated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Pagure CI activated", output_text)
 
 
-            output = self.app.get('/somenamespace/test3/settings/Pagure CI')
+            output = self.app.get("/somenamespace/test3/settings/Pagure CI")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure CI - somenamespace/test3 - '
-                'Pagure</title>', output_text)
+                "<title>Settings Pagure CI - somenamespace/test3 - "
+                "Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<label for="ci_url">URL to the project on the CI '
                 '<label for="ci_url">URL to the project on the CI '
-                'service</label>', output_text)
+                "service</label>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                '<label for="ci_job">Name of the job to trigger'
-                '</label>', output_text)
+                '<label for="ci_job">Name of the job to trigger' "</label>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input checked class="form-check-input mt-2" id="active_pr" name="active_pr" '
                 '<input checked class="form-check-input mt-2" id="active_pr" name="active_pr" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                '<pre>\nhttp://localhost.localdomain/api/0/ci/jenkins/somenamespace/test3/',
-                output_text)
+                "<pre>\nhttp://localhost.localdomain/api/0/ci/jenkins/somenamespace/test3/",
+                output_text,
+            )
 
 
-    @mock.patch('pagure.lib.tasks_services.trigger_jenkins_build')
+    @mock.patch("pagure.lib.tasks_services.trigger_jenkins_build")
     def test_plugin_pagure_ci_namespaced_auth(self, trigger_jenk):
     def test_plugin_pagure_ci_namespaced_auth(self, trigger_jenk):
         """ Test the pagure ci plugin on/off endpoint. """
         """ Test the pagure ci plugin on/off endpoint. """
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'))
+        tests.create_projects_git(os.path.join(self.path, "repos"))
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/somenamespace/test3/settings/Pagure CI')
+            output = self.app.get("/somenamespace/test3/settings/Pagure CI")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure CI - somenamespace/test3 - '
-                'Pagure</title>', output_text)
+                "<title>Settings Pagure CI - somenamespace/test3 - "
+                "Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<label for="ci_url">URL to the project on the CI '
                 '<label for="ci_url">URL to the project on the CI '
-                'service</label>', output_text)
+                "service</label>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                '<label for="ci_job">Name of the job to trigger'
-                '</label>', output_text)
+                '<label for="ci_job">Name of the job to trigger' "</label>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active_pr" name="active_pr" '
                 '<input class="form-check-input mt-2" id="active_pr" name="active_pr" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             # Activate hook
             # Activate hook
             data = {
             data = {
-                'active_pr': 'y',
-                'ci_url': 'https://jenkins.fedoraproject.org',
-                'ci_job': 'test/job',
-                'ci_type': 'jenkins',
-                'ci_username': 'jenkins_username',
-                'ci_password': 'jenkins_password',
-                'csrf_token': csrf_token,
+                "active_pr": "y",
+                "ci_url": "https://jenkins.fedoraproject.org",
+                "ci_job": "test/job",
+                "ci_type": "jenkins",
+                "ci_username": "jenkins_username",
+                "ci_password": "jenkins_password",
+                "csrf_token": csrf_token,
             }
             }
 
 
             # Activate hook
             # Activate hook
             output = self.app.post(
             output = self.app.post(
-                '/somenamespace/test3/settings/Pagure CI', data=data, follow_redirects=True)
+                "/somenamespace/test3/settings/Pagure CI",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                '<title>Settings - somenamespace/test3 - Pagure</title>',
-                output_text)
+                "<title>Settings - somenamespace/test3 - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Pagure CI activated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Pagure CI activated", output_text)
 
 
-            output = self.app.get('/somenamespace/test3/settings/Pagure CI')
+            output = self.app.get("/somenamespace/test3/settings/Pagure CI")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure CI - somenamespace/test3 - '
-                'Pagure</title>', output_text)
+                "<title>Settings Pagure CI - somenamespace/test3 - "
+                "Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<label for="ci_url">URL to the project on the CI '
                 '<label for="ci_url">URL to the project on the CI '
-                'service</label>', output_text)
+                "service</label>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                '<label for="ci_job">Name of the job to trigger'
-                '</label>', output_text)
+                '<label for="ci_job">Name of the job to trigger' "</label>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input checked class="form-check-input mt-2" id="active_pr" name="active_pr" '
                 '<input checked class="form-check-input mt-2" id="active_pr" name="active_pr" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                '<pre>\nhttp://localhost.localdomain/api/0/ci/jenkins/somenamespace/test3/',
-                output_text)
+                "<pre>\nhttp://localhost.localdomain/api/0/ci/jenkins/somenamespace/test3/",
+                output_text,
+            )
 
 
         output = pagure.lib.tasks_services.trigger_ci_build(
         output = pagure.lib.tasks_services.trigger_ci_build(
-            project_name='somenamespace/test3',
-            cause='PR#ID',
-            branch='feature',
-            branch_to='master',
-            ci_type='jenkins')
+            project_name="somenamespace/test3",
+            cause="PR#ID",
+            branch="feature",
+            branch_to="master",
+            ci_type="jenkins",
+        )
         self.assertIsNone(output)
         self.assertIsNone(output)
         trigger_jenk.assert_called_once_with(
         trigger_jenk.assert_called_once_with(
-           branch=u'feature',
-           cause=u'PR#ID',
-           ci_password="jenkins_password",
-           ci_username="jenkins_username",
-           job=u'test/job',
-           project_path=u'somenamespace/test3.git',
-           token=mock.ANY,
-           url=u'https://jenkins.fedoraproject.org',
-           branch_to='master',
+            branch="feature",
+            cause="PR#ID",
+            ci_password="jenkins_password",
+            ci_username="jenkins_username",
+            job="test/job",
+            project_path="somenamespace/test3.git",
+            token=mock.ANY,
+            url="https://jenkins.fedoraproject.org",
+            branch_to="master",
         )
         )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 241 - 146
tests/test_pagure_flask_ui_plugins_pagure_hook.py

@@ -16,8 +16,9 @@ import os
 
 
 from mock import patch
 from mock import patch
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import tests
 import tests
 import pagure.config
 import pagure.config
@@ -31,273 +32,367 @@ class PagureFlaskPluginPagureHooktests(tests.SimplePagureTest):
         super(PagureFlaskPluginPagureHooktests, self).setUp()
         super(PagureFlaskPluginPagureHooktests, self).setUp()
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'))
-        tests.create_projects_git(os.path.join(self.path, 'repos', 'docs'))
+        tests.create_projects_git(os.path.join(self.path, "repos"))
+        tests.create_projects_git(os.path.join(self.path, "repos", "docs"))
 
 
     def tearDown(self):
     def tearDown(self):
         """ Tear Down the environment after the tests. """
         """ Tear Down the environment after the tests. """
         super(PagureFlaskPluginPagureHooktests, self).tearDown()
         super(PagureFlaskPluginPagureHooktests, self).tearDown()
-        pagure.config.config['DOCS_FOLDER'] = None
+        pagure.config.config["DOCS_FOLDER"] = None
 
 
     def test_plugin_mail_page(self):
     def test_plugin_mail_page(self):
         """ Test the default page of the pagure hook plugin. """
         """ Test the default page of the pagure hook plugin. """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/settings/Pagure')
+            output = self.app.get("/test/settings/Pagure")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure - test - Pagure</title>',
-                output_text)
+                "<title>Settings Pagure - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
     def test_plugin_mail_no_data(self):
     def test_plugin_mail_no_data(self):
         """ Test the pagure hook plugin endpoint when no data is sent. """
         """ Test the pagure hook plugin endpoint when no data is sent. """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
             data = {}
             data = {}
 
 
-            output = self.app.post('/test/settings/Pagure', data=data)
+            output = self.app.post("/test/settings/Pagure", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure - test - Pagure</title>',
-                output_text)
+                "<title>Settings Pagure - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'post-receive')))
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'docs', 'test.git', 'hooks',
-                'post-receive')))
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path, "repos", "test.git", "hooks", "post-receive"
+                    )
+                )
+            )
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path, "docs", "test.git", "hooks", "post-receive"
+                    )
+                )
+            )
 
 
     def test_plugin_mail_no_data_csrf(self):
     def test_plugin_mail_no_data_csrf(self):
         """ Test the pagure hook plugin endpoint when no data is sent but
         """ Test the pagure hook plugin endpoint when no data is sent but
         the csrf token.
         the csrf token.
         """
         """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
-            data = {'csrf_token': csrf_token}
+            data = {"csrf_token": csrf_token}
 
 
-            tests.create_projects_git(os.path.join(self.path, 'repos', 'docs'))
-            tests.create_projects_git(os.path.join(self.path, 'repos', 'requests'))
+            tests.create_projects_git(os.path.join(self.path, "repos", "docs"))
+            tests.create_projects_git(
+                os.path.join(self.path, "repos", "requests")
+            )
 
 
             # With the git repo
             # With the git repo
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Pagure', data=data, follow_redirects=True)
+                "/test/settings/Pagure", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Pagure deactivated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Pagure deactivated", output_text)
 
 
-            output = self.app.get('/test/settings/Pagure')
+            output = self.app.get("/test/settings/Pagure")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure - test - Pagure</title>',
-                output_text)
+                "<title>Settings Pagure - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'post-receive.pagure')))
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'post-receive')))
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'docs', 'test.git', 'hooks',
-                'post-receive')))
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "post-receive.pagure",
+                    )
+                )
+            )
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path, "repos", "test.git", "hooks", "post-receive"
+                    )
+                )
+            )
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path, "docs", "test.git", "hooks", "post-receive"
+                    )
+                )
+            )
 
 
     def test_plugin_mail_activate_hook(self):
     def test_plugin_mail_activate_hook(self):
         """ Test the pagure hook plugin endpoint when activating the hook.
         """ Test the pagure hook plugin endpoint when activating the hook.
         """
         """
-        pagure.config.config['DOCS_FOLDER'] = os.path.join(
-            self.path, 'repos', 'docs')
+        pagure.config.config["DOCS_FOLDER"] = os.path.join(
+            self.path, "repos", "docs"
+        )
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             # Activate hook
             # Activate hook
-            data = {
-                'csrf_token': csrf_token,
-                'active': 'y',
-            }
+            data = {"csrf_token": csrf_token, "active": "y"}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Pagure', data=data, follow_redirects=True)
+                "/test/settings/Pagure", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Pagure activated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Pagure activated", output_text)
 
 
-            output = self.app.get('/test/settings/Pagure')
+            output = self.app.get("/test/settings/Pagure")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure - test - Pagure</title>',
-                output_text)
+                "<title>Settings Pagure - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertTrue(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'post-receive')))
-            self.assertTrue(os.path.exists(os.path.join(
-                self.path, 'repos', 'docs', 'test.git', 'hooks',
-                'post-receive')))
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertTrue(
+                os.path.exists(
+                    os.path.join(
+                        self.path, "repos", "test.git", "hooks", "post-receive"
+                    )
+                )
+            )
+            self.assertTrue(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "docs",
+                        "test.git",
+                        "hooks",
+                        "post-receive",
+                    )
+                )
+            )
 
 
     def test_plugin_mail_deactivate_hook(self):
     def test_plugin_mail_deactivate_hook(self):
         """ Test the pagure hook plugin endpoint when activating the hook.
         """ Test the pagure hook plugin endpoint when activating the hook.
         """
         """
         self.test_plugin_mail_activate_hook()
         self.test_plugin_mail_activate_hook()
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             # De-Activate hook
             # De-Activate hook
-            data = {'csrf_token': csrf_token}
+            data = {"csrf_token": csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Pagure', data=data, follow_redirects=True)
+                "/test/settings/Pagure", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Pagure deactivated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Pagure deactivated", output_text)
 
 
-            output = self.app.get('/test/settings/Pagure')
+            output = self.app.get("/test/settings/Pagure")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure - test - Pagure</title>',
-                output_text)
+                "<title>Settings Pagure - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'post-receive.pagure')))
-            self.assertTrue(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'post-receive')))
-            self.assertTrue(os.path.exists(os.path.join(
-                self.path, 'repos', 'docs', 'test.git', 'hooks',
-                'post-receive')))
-
-    @patch.dict('pagure.config.config', {'DOCS_FOLDER': None})
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "post-receive.pagure",
+                    )
+                )
+            )
+            self.assertTrue(
+                os.path.exists(
+                    os.path.join(
+                        self.path, "repos", "test.git", "hooks", "post-receive"
+                    )
+                )
+            )
+            self.assertTrue(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "docs",
+                        "test.git",
+                        "hooks",
+                        "post-receive",
+                    )
+                )
+            )
+
+    @patch.dict("pagure.config.config", {"DOCS_FOLDER": None})
     def test_plugin_mail_activate_hook_no_doc(self):
     def test_plugin_mail_activate_hook_no_doc(self):
         """ Test the pagure hook plugin endpoint when activating the hook
         """ Test the pagure hook plugin endpoint when activating the hook
         on a pagure instance that de-activated the doc repos.
         on a pagure instance that de-activated the doc repos.
         """
         """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             # Activate hook
             # Activate hook
-            data = {
-                'csrf_token': csrf_token,
-                'active': 'y',
-            }
+            data = {"csrf_token": csrf_token, "active": "y"}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Pagure', data=data, follow_redirects=True)
+                "/test/settings/Pagure", data=data, follow_redirects=True
+            )
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertIn(
-                'Hook Pagure activated',
-                output_text)
-
-            self.assertTrue(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'post-receive')))
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'docs', 'test.git', 'hooks',
-                'post-receive')))
-
-    @patch.dict('pagure.config.config', {'DOCS_FOLDER': None})
+            self.assertIn("Hook Pagure activated", output_text)
+
+            self.assertTrue(
+                os.path.exists(
+                    os.path.join(
+                        self.path, "repos", "test.git", "hooks", "post-receive"
+                    )
+                )
+            )
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path, "docs", "test.git", "hooks", "post-receive"
+                    )
+                )
+            )
+
+    @patch.dict("pagure.config.config", {"DOCS_FOLDER": None})
     def test_plugin_mail_deactivate_hook_no_doc(self):
     def test_plugin_mail_deactivate_hook_no_doc(self):
         """ Test the pagure hook plugin endpoint when activating then
         """ Test the pagure hook plugin endpoint when activating then
         deactivating the hook on a pagure instance that de-activated the
         deactivating the hook on a pagure instance that de-activated the
         doc repos.
         doc repos.
         """
         """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             # Activate hook
             # Activate hook
-            data = {
-                'csrf_token': csrf_token,
-                'active': 'y',
-            }
+            data = {"csrf_token": csrf_token, "active": "y"}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Pagure', data=data, follow_redirects=True)
+                "/test/settings/Pagure", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Pagure activated',
-                output_text)
-
-            self.assertTrue(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'post-receive')))
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'docs', 'test.git', 'hooks',
-                'post-receive')))
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Pagure activated", output_text)
+
+            self.assertTrue(
+                os.path.exists(
+                    os.path.join(
+                        self.path, "repos", "test.git", "hooks", "post-receive"
+                    )
+                )
+            )
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path, "docs", "test.git", "hooks", "post-receive"
+                    )
+                )
+            )
 
 
             # Deactivate hook
             # Deactivate hook
-            data = {
-                'csrf_token': csrf_token,
-            }
+            data = {"csrf_token": csrf_token}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Pagure', data=data, follow_redirects=True)
+                "/test/settings/Pagure", data=data, follow_redirects=True
+            )
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertIn(
-                'Hook Pagure deactivated',
-                output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'post-receive.pagure')))
-            self.assertTrue(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'post-receive')))
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'docs', 'test.git', 'hooks',
-                'post-receive')))
-
-
-if __name__ == '__main__':
+            self.assertIn("Hook Pagure deactivated", output_text)
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "post-receive.pagure",
+                    )
+                )
+            )
+            self.assertTrue(
+                os.path.exists(
+                    os.path.join(
+                        self.path, "repos", "test.git", "hooks", "post-receive"
+                    )
+                )
+            )
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path, "docs", "test.git", "hooks", "post-receive"
+                    )
+                )
+            )
+
+
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 118 - 66
tests/test_pagure_flask_ui_plugins_pagure_no_new_branch.py

@@ -16,8 +16,9 @@ import sys
 import os
 import os
 
 
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import tests
 import tests
 import pagure.config
 import pagure.config
@@ -31,10 +32,9 @@ class PagureFlaskPluginPagureNoNewBranchHooktests(tests.SimplePagureTest):
         super(PagureFlaskPluginPagureNoNewBranchHooktests, self).setUp()
         super(PagureFlaskPluginPagureNoNewBranchHooktests, self).setUp()
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'))
+        tests.create_projects_git(os.path.join(self.path, "repos"))
 
 
-        pagure.config.config['GIT_FOLDER'] = os.path.join(
-            self.path, 'repos')
+        pagure.config.config["GIT_FOLDER"] = os.path.join(self.path, "repos")
 
 
         with tests.user_set(self.app.application, tests.FakeUser()):
         with tests.user_set(self.app.application, tests.FakeUser()):
             self.csrf_token = self.get_csrf()
             self.csrf_token = self.get_csrf()
@@ -42,145 +42,197 @@ class PagureFlaskPluginPagureNoNewBranchHooktests(tests.SimplePagureTest):
     def test_plugin_pagure_ticket_no_data(self):
     def test_plugin_pagure_ticket_no_data(self):
         """ Test the pagure_ticket plugin on/off endpoint. """
         """ Test the pagure_ticket plugin on/off endpoint. """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             output = self.app.get(
             output = self.app.get(
-                '/test/settings/Prevent creating new branches by git push')
+                "/test/settings/Prevent creating new branches by git push"
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Prevent creating new branches by git '
-                'push - test - Pagure</title>', output_text)
+                "<title>Settings Prevent creating new branches by git "
+                "push - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
             data = {}
             data = {}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Prevent creating new branches by git push',
-                data=data)
+                "/test/settings/Prevent creating new branches by git push",
+                data=data,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Prevent creating new branches by git push '
-                '- test - Pagure</title>', output_text)
+                "<title>Settings Prevent creating new branches by git push "
+                "- test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
     def test_plugin_pagure_ticket_deactivate(self):
     def test_plugin_pagure_ticket_deactivate(self):
         """ Test the pagure_ticket plugin on/off endpoint. """
         """ Test the pagure_ticket plugin on/off endpoint. """
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            data = {'csrf_token': self.csrf_token}
+            data = {"csrf_token": self.csrf_token}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Prevent creating new branches by git push',
-                data=data, follow_redirects=True)
+                "/test/settings/Prevent creating new branches by git push",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                'Hook Prevent creating new branches by git push deactivated',
-                output_text)
+                "Hook Prevent creating new branches by git push deactivated",
+                output_text,
+            )
 
 
             output = self.app.get(
             output = self.app.get(
-                '/test/settings/Prevent creating new branches by git push')
+                "/test/settings/Prevent creating new branches by git push"
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Prevent creating new branches by git push '
-                '- test - Pagure</title>', output_text)
+                "<title>Settings Prevent creating new branches by git push "
+                "- test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks', 'post-receive.pagure')))
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "post-receive.pagure",
+                    )
+                )
+            )
 
 
     def test_plugin_pagure_ticket_activate(self):
     def test_plugin_pagure_ticket_activate(self):
         """ Test the pagure_ticket plugin on/off endpoint. """
         """ Test the pagure_ticket plugin on/off endpoint. """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             # Activate hook
             # Activate hook
-            data = {
-                'csrf_token': self.csrf_token,
-                'active': 'y',
-            }
+            data = {"csrf_token": self.csrf_token, "active": "y"}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Prevent creating new branches by git push',
-                data=data, follow_redirects=True)
+                "/test/settings/Prevent creating new branches by git push",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                'Hook Prevent creating new branches by git push activated',
-                output_text)
+                "Hook Prevent creating new branches by git push activated",
+                output_text,
+            )
 
 
             output = self.app.get(
             output = self.app.get(
-                '/test/settings/Prevent creating new branches by git push')
+                "/test/settings/Prevent creating new branches by git push"
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Prevent creating new branches by git push '
-                '- test - Pagure</title>', output_text)
+                "<title>Settings Prevent creating new branches by git push "
+                "- test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
             # De-Activate hook
             # De-Activate hook
-            data = {'csrf_token': self.csrf_token}
+            data = {"csrf_token": self.csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Prevent creating new branches by git push',
-                data=data, follow_redirects=True)
+                "/test/settings/Prevent creating new branches by git push",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                'Hook Prevent creating new branches by git push deactivated',
-                output_text)
+                "Hook Prevent creating new branches by git push deactivated",
+                output_text,
+            )
 
 
             output = self.app.get(
             output = self.app.get(
-                '/test/settings/Prevent creating new branches by git push')
+                "/test/settings/Prevent creating new branches by git push"
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Prevent creating new branches by git push '
-                '- test - Pagure</title>', output_text)
+                "<title>Settings Prevent creating new branches by git push "
+                "- test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'pre-receive.pagure_no_new_branches')))
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "pre-receive.pagure_no_new_branches",
+                    )
+                )
+            )
 
 
     def test_plugin_pagure_ticket_activate_w_no_repo(self):
     def test_plugin_pagure_ticket_activate_w_no_repo(self):
         """ Test the pagure_ticket plugin on/off endpoint. """
         """ Test the pagure_ticket plugin on/off endpoint. """
-        shutil.rmtree(os.path.join(self.path, 'repos', 'test.git'))
+        shutil.rmtree(os.path.join(self.path, "repos", "test.git"))
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             # Try re-activate hook w/o the git repo
             # Try re-activate hook w/o the git repo
-            data = {
-                'csrf_token': self.csrf_token,
-                'active': 'y',
-            }
+            data = {"csrf_token": self.csrf_token, "active": "y"}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Prevent creating new branches by git push',
-                data=data)
+                "/test/settings/Prevent creating new branches by git push",
+                data=data,
+            )
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 102 - 62
tests/test_pagure_flask_ui_plugins_pagure_request_hook.py

@@ -15,8 +15,9 @@ import shutil
 import sys
 import sys
 import os
 import os
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import tests
 import tests
 
 
@@ -28,122 +29,161 @@ class PagureFlaskPluginPagureRequestHooktests(tests.SimplePagureTest):
         """ Test the pagure_request plugin on/off endpoint. """
         """ Test the pagure_request plugin on/off endpoint. """
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'))
+        tests.create_projects_git(os.path.join(self.path, "repos"))
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/settings/Pagure requests')
+            output = self.app.get("/test/settings/Pagure requests")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure requests - test - Pagure</title>',
-                output_text)
+                "<title>Settings Pagure requests - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
-            csrf_token = output.get_data(as_text=True).split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+            csrf_token = (
+                output.get_data(as_text=True)
+                .split('name="csrf_token" type="hidden" value="')[1]
+                .split('">')[0]
+            )
 
 
             data = {}
             data = {}
 
 
-            output = self.app.post('/test/settings/Pagure requests', data=data)
+            output = self.app.post("/test/settings/Pagure requests", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure requests - test - Pagure</title>',
-                output_text)
+                "<title>Settings Pagure requests - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
-            data['csrf_token'] = csrf_token
+            data["csrf_token"] = csrf_token
 
 
             # Create the requests repo
             # Create the requests repo
-            tests.create_projects_git(os.path.join(self.path, 'repos', 'requests'))
+            tests.create_projects_git(
+                os.path.join(self.path, "repos", "requests")
+            )
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Pagure requests', data=data,
-                follow_redirects=True)
+                "/test/settings/Pagure requests",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Pagure requests deactivated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Pagure requests deactivated", output_text)
 
 
-            output = self.app.get('/test/settings/Pagure requests')
+            output = self.app.get("/test/settings/Pagure requests")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure requests - test - Pagure</title>',
-                output_text)
+                "<title>Settings Pagure requests - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'requests', 'test.git', 'hooks',
-                'post-receive.pagure')))
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "requests",
+                        "test.git",
+                        "hooks",
+                        "post-receive.pagure",
+                    )
+                )
+            )
 
 
             # Activate hook
             # Activate hook
-            data = {
-                'csrf_token': csrf_token,
-                'active': 'y',
-            }
+            data = {"csrf_token": csrf_token, "active": "y"}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Pagure requests', data=data,
-                follow_redirects=True)
+                "/test/settings/Pagure requests",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Pagure requests activated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Pagure requests activated", output_text)
 
 
-            output = self.app.get('/test/settings/Pagure requests')
+            output = self.app.get("/test/settings/Pagure requests")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure requests - test - Pagure</title>',
-                output_text)
+                "<title>Settings Pagure requests - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
             # De-Activate hook
             # De-Activate hook
-            data = {'csrf_token': csrf_token}
+            data = {"csrf_token": csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Pagure requests', data=data,
-                follow_redirects=True)
+                "/test/settings/Pagure requests",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Pagure requests deactivated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Pagure requests deactivated", output_text)
 
 
-            output = self.app.get('/test/settings/Pagure requests')
+            output = self.app.get("/test/settings/Pagure requests")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure requests - test - Pagure</title>',
-                output_text)
+                "<title>Settings Pagure requests - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'requests', 'test.git', 'hooks',
-                'post-receive.pagure-requests')))
-
-
-if __name__ == '__main__':
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "requests",
+                        "test.git",
+                        "hooks",
+                        "post-receive.pagure-requests",
+                    )
+                )
+            )
+
+
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 109 - 72
tests/test_pagure_flask_ui_plugins_pagure_ticket_hook.py

@@ -16,8 +16,9 @@ import sys
 import os
 import os
 
 
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import tests
 import tests
 
 
@@ -29,139 +30,175 @@ class PagureFlaskPluginPagureTicketHooktests(tests.SimplePagureTest):
         """ Test the pagure_ticket plugin on/off endpoint. """
         """ Test the pagure_ticket plugin on/off endpoint. """
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'))
+        tests.create_projects_git(os.path.join(self.path, "repos"))
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/settings/Pagure tickets')
+            output = self.app.get("/test/settings/Pagure tickets")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure tickets - test - Pagure</title>',
-                output_text)
+                "<title>Settings Pagure tickets - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             data = {}
             data = {}
 
 
-            output = self.app.post('/test/settings/Pagure tickets', data=data)
+            output = self.app.post("/test/settings/Pagure tickets", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure tickets - test - Pagure</title>',
-                output_text)
+                "<title>Settings Pagure tickets - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
-            data['csrf_token'] = csrf_token
+            data["csrf_token"] = csrf_token
 
 
             # Create the tickets repo
             # Create the tickets repo
-            tests.create_projects_git(os.path.join(self.path, 'repos', 'tickets'))
+            tests.create_projects_git(
+                os.path.join(self.path, "repos", "tickets")
+            )
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Pagure tickets', data=data,
-                follow_redirects=True)
+                "/test/settings/Pagure tickets",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Pagure tickets deactivated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Pagure tickets deactivated", output_text)
 
 
-            output = self.app.get('/test/settings/Pagure tickets')
+            output = self.app.get("/test/settings/Pagure tickets")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure tickets - test - Pagure</title>',
-                output_text)
+                "<title>Settings Pagure tickets - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'tickets', 'test.git', 'hooks',
-                'post-receive.pagure')))
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "tickets",
+                        "test.git",
+                        "hooks",
+                        "post-receive.pagure",
+                    )
+                )
+            )
 
 
             # Activate hook
             # Activate hook
-            data = {
-                'csrf_token': csrf_token,
-                'active': 'y',
-            }
+            data = {"csrf_token": csrf_token, "active": "y"}
 
 
-            print('    ==== ACTIVATE ')
+            print("    ==== ACTIVATE ")
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Pagure tickets', data=data,
-                follow_redirects=True)
+                "/test/settings/Pagure tickets",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Pagure tickets activated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Pagure tickets activated", output_text)
 
 
-            print('    ==== CHECK ')
-            output = self.app.get('/test/settings/Pagure tickets')
+            print("    ==== CHECK ")
+            output = self.app.get("/test/settings/Pagure tickets")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure tickets - test - Pagure</title>',
-                output_text)
+                "<title>Settings Pagure tickets - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
             # De-Activate hook
             # De-Activate hook
-            print('    ==== DEACTIVATE ')
-            data = {'csrf_token': csrf_token}
+            print("    ==== DEACTIVATE ")
+            data = {"csrf_token": csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Pagure tickets', data=data,
-                follow_redirects=True)
+                "/test/settings/Pagure tickets",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Pagure tickets deactivated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Pagure tickets deactivated", output_text)
 
 
-            print('    ==== CHECK ')
-            output = self.app.get('/test/settings/Pagure tickets')
+            print("    ==== CHECK ")
+            output = self.app.get("/test/settings/Pagure tickets")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Pagure tickets - test - Pagure</title>',
-                output_text)
+                "<title>Settings Pagure tickets - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'tickets', 'test.git', 'hooks',
-                'post-receive.pagure-ticket')))
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "tickets",
+                        "test.git",
+                        "hooks",
+                        "post-receive.pagure-ticket",
+                    )
+                )
+            )
 
 
             # Try re-activate hook w/o the git repo
             # Try re-activate hook w/o the git repo
-            data = {
-                'csrf_token': csrf_token,
-                'active': 'y',
-            }
-            shutil.rmtree(os.path.join(self.path, 'repos', 'tickets', 'test.git'))
-
-            print('    ==== NO GIT REPO ')
-            output = self.app.post('/test/settings/Pagure tickets', data=data)
+            data = {"csrf_token": csrf_token, "active": "y"}
+            shutil.rmtree(
+                os.path.join(self.path, "repos", "tickets", "test.git")
+            )
+
+            print("    ==== NO GIT REPO ")
+            output = self.app.post("/test/settings/Pagure tickets", data=data)
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
-        print('*** DONE ***')
+        print("*** DONE ***")
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 96 - 63
tests/test_pagure_flask_ui_plugins_rtd_hook.py

@@ -16,8 +16,9 @@ import sys
 import os
 import os
 
 
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import tests
 import tests
 
 
@@ -29,134 +30,166 @@ class PagureFlaskPluginRtdHooktests(tests.SimplePagureTest):
         """ Test the pagure_request plugin on/off endpoint. """
         """ Test the pagure_request plugin on/off endpoint. """
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'))
+        tests.create_projects_git(os.path.join(self.path, "repos"))
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/settings/Read the Doc')
+            output = self.app.get("/test/settings/Read the Doc")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Read the Doc - test - Pagure</title>',
-                output_text)
+                "<title>Settings Read the Doc - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             data = {}
             data = {}
 
 
-            output = self.app.post('/test/settings/Read the Doc', data=data)
+            output = self.app.post("/test/settings/Read the Doc", data=data)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Read the Doc - test - Pagure</title>',
-                output_text)
+                "<title>Settings Read the Doc - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
-            data['csrf_token'] = csrf_token
+            data["csrf_token"] = csrf_token
 
 
             # Create the requests repo
             # Create the requests repo
-            tests.create_projects_git(os.path.join(self.path, 'requests'))
+            tests.create_projects_git(os.path.join(self.path, "requests"))
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Read the Doc', data=data,
-                follow_redirects=True)
+                "/test/settings/Read the Doc", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Read the Doc deactivated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Read the Doc deactivated", output_text)
 
 
-            output = self.app.get('/test/settings/Read the Doc')
+            output = self.app.get("/test/settings/Read the Doc")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Read the Doc - test - Pagure</title>',
-                output_text)
+                "<title>Settings Read the Doc - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'requests', 'test.git', 'hooks',
-                'post-receive.pagure')))
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "requests",
+                        "test.git",
+                        "hooks",
+                        "post-receive.pagure",
+                    )
+                )
+            )
 
 
             # Activate hook
             # Activate hook
             data = {
             data = {
-                'csrf_token': csrf_token,
-                'active': 'y',
-                'project_name': 'foo',
+                "csrf_token": csrf_token,
+                "active": "y",
+                "project_name": "foo",
             }
             }
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Read the Doc', data=data,
-                follow_redirects=True)
+                "/test/settings/Read the Doc", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Read the Doc activated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Read the Doc activated", output_text)
 
 
-            output = self.app.get('/test/settings/Read the Doc')
+            output = self.app.get("/test/settings/Read the Doc")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Read the Doc - test - Pagure</title>',
-                output_text)
+                "<title>Settings Read the Doc - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
                 '<input checked class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
+                'type="checkbox" value="y">',
+                output_text,
+            )
 
 
             # De-Activate hook
             # De-Activate hook
-            data = {'csrf_token': csrf_token}
+            data = {"csrf_token": csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Read the Doc', data=data,
-                follow_redirects=True)
+                "/test/settings/Read the Doc", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Hook Read the Doc deactivated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Hook Read the Doc deactivated", output_text)
 
 
-            output = self.app.get('/test/settings/Read the Doc')
+            output = self.app.get("/test/settings/Read the Doc")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Read the Doc - test - Pagure</title>',
-                output_text)
+                "<title>Settings Read the Doc - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'post-receive.rtd')))
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "post-receive.rtd",
+                    )
+                )
+            )
 
 
             # Try re-activate hook w/o the git repo
             # Try re-activate hook w/o the git repo
             data = {
             data = {
-                'csrf_token': csrf_token,
-                'active': 'y',
-                'project_name': 'foo',
+                "csrf_token": csrf_token,
+                "active": "y",
+                "project_name": "foo",
             }
             }
-            shutil.rmtree(os.path.join(self.path, 'repos', 'test.git'))
+            shutil.rmtree(os.path.join(self.path, "repos", "test.git"))
 
 
-            output = self.app.post('/test/settings/Read the Doc', data=data)
+            output = self.app.post("/test/settings/Read the Doc", data=data)
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 93 - 54
tests/test_pagure_flask_ui_plugins_unsigned.py

@@ -15,8 +15,9 @@ import sys
 import os
 import os
 
 
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import tests
 import tests
 
 
@@ -28,110 +29,148 @@ class PagureFlaskPluginUnsignedtests(tests.SimplePagureTest):
         """ Test the noff plugin on/off endpoint. """
         """ Test the noff plugin on/off endpoint. """
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'))
+        tests.create_projects_git(os.path.join(self.path, "repos"))
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get(
-                '/test/settings/Block Un-Signed commits')
+            output = self.app.get("/test/settings/Block Un-Signed commits")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Block Un-Signed commits - test - '
-                'Pagure</title>', output_text)
+                "<title>Settings Block Un-Signed commits - test - "
+                "Pagure</title>",
+                output_text,
+            )
             self.assertTrue(
             self.assertTrue(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">' in output_text)
+                'type="checkbox" value="y">' in output_text
+            )
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             data = {}
             data = {}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Block Un-Signed commits', data=data)
+                "/test/settings/Block Un-Signed commits", data=data
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Block Un-Signed commits - test - '
-                'Pagure</title>', output_text)
+                "<title>Settings Block Un-Signed commits - test - "
+                "Pagure</title>",
+                output_text,
+            )
             self.assertTrue(
             self.assertTrue(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">' in output_text)
+                'type="checkbox" value="y">' in output_text
+            )
 
 
-            data['csrf_token'] = csrf_token
+            data["csrf_token"] = csrf_token
 
 
             # With the git repo
             # With the git repo
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Block Un-Signed commits',
-                data=data, follow_redirects=True)
+                "/test/settings/Block Un-Signed commits",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             self.assertTrue(
             self.assertTrue(
-                'Hook Block Un-Signed '
-                'commits deactivated' in output_text)
+                "Hook Block Un-Signed " "commits deactivated" in output_text
+            )
 
 
-            output = self.app.get(
-                '/test/settings/Block Un-Signed commits')
+            output = self.app.get("/test/settings/Block Un-Signed commits")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Block Un-Signed commits - test - '
-                'Pagure</title>', output_text)
+                "<title>Settings Block Un-Signed commits - test - "
+                "Pagure</title>",
+                output_text,
+            )
             self.assertTrue(
             self.assertTrue(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">' in output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'pre-receive.pagureunsignedcommit')))
+                'type="checkbox" value="y">' in output_text
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "pre-receive.pagureunsignedcommit",
+                    )
+                )
+            )
 
 
             # Activate the hook
             # Activate the hook
-            data = {'csrf_token': csrf_token, 'active': 'y'}
+            data = {"csrf_token": csrf_token, "active": "y"}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Block Un-Signed commits',
-                data=data, follow_redirects=True)
+                "/test/settings/Block Un-Signed commits",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertNotIn(
-                'Hook activated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertNotIn("Hook activated", output_text)
 
 
             # De-Activate hook
             # De-Activate hook
-            data = {'csrf_token': csrf_token}
+            data = {"csrf_token": csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Block Un-Signed commits',
-                data=data, follow_redirects=True)
+                "/test/settings/Block Un-Signed commits",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             self.assertTrue(
             self.assertTrue(
-                'Hook Block Un-Signed '
-                'commits deactivated' in output_text)
+                "Hook Block Un-Signed " "commits deactivated" in output_text
+            )
 
 
-            output = self.app.get(
-                '/test/settings/Block Un-Signed commits')
+            output = self.app.get("/test/settings/Block Un-Signed commits")
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings Block Un-Signed commits - test - '
-                'Pagure</title>', output_text)
+                "<title>Settings Block Un-Signed commits - test - "
+                "Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<input class="form-check-input mt-2" id="active" name="active" '
                 '<input class="form-check-input mt-2" id="active" name="active" '
-                'type="checkbox" value="y">', output_text)
-
-            self.assertFalse(os.path.exists(os.path.join(
-                self.path, 'repos', 'test.git', 'hooks',
-                'pre-receive.pagureunsignedcommit')))
-
-
-if __name__ == '__main__':
+                'type="checkbox" value="y">',
+                output_text,
+            )
+
+            self.assertFalse(
+                os.path.exists(
+                    os.path.join(
+                        self.path,
+                        "repos",
+                        "test.git",
+                        "hooks",
+                        "pre-receive.pagureunsignedcommit",
+                    )
+                )
+            )
+
+
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 90 - 93
tests/test_pagure_flask_ui_pr_no_sources.py

@@ -21,8 +21,9 @@ import os
 import pygit2
 import pygit2
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import tests
 import tests
@@ -34,162 +35,158 @@ class PagureFlaskPrNoSourcestests(tests.Modeltests):
 
 
     maxDiff = None
     maxDiff = None
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
-    @patch('pagure.lib.notify.fedmsg_publish', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
+    @patch("pagure.lib.notify.fedmsg_publish", MagicMock(return_value=True))
     def setUp(self):
     def setUp(self):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(PagureFlaskPrNoSourcestests, self).setUp()
         super(PagureFlaskPrNoSourcestests, self).setUp()
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(
-            os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         # Create foo's fork of pingou's test project
         # Create foo's fork of pingou's test project
         item = pagure.lib.model.Project(
         item = pagure.lib.model.Project(
             user_id=2,  # foo
             user_id=2,  # foo
-            name='test',
-            description='test project #1',
-            hook_token='aaabbb',
+            name="test",
+            description="test project #1",
+            hook_token="aaabbb",
             is_fork=True,
             is_fork=True,
             parent_id=1,
             parent_id=1,
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
         # Create the fork's git repo
         # Create the fork's git repo
-        repo_path = os.path.join(self.path, 'repos', item.path)
+        repo_path = os.path.join(self.path, "repos", item.path)
         pygit2.init_repository(repo_path, bare=True)
         pygit2.init_repository(repo_path, bare=True)
 
 
-        project = pagure.lib.query.get_authorized_project(self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         fork = pagure.lib.query.get_authorized_project(
         fork = pagure.lib.query.get_authorized_project(
-            self.session, 'test', user='foo')
+            self.session, "test", user="foo"
+        )
 
 
         self.set_up_git_repo(repo=project, fork=fork)
         self.set_up_git_repo(repo=project, fork=fork)
 
 
         # Ensure things got setup straight
         # Ensure things got setup straight
-        project = pagure.lib.query.get_authorized_project(self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(project.requests), 1)
         self.assertEqual(len(project.requests), 1)
 
 
         # wait for the worker to process the task
         # wait for the worker to process the task
         path = os.path.join(
         path = os.path.join(
-            self.path, 'repos', 'test.git',
-            'refs', 'pull', '1', 'head')
+            self.path, "repos", "test.git", "refs", "pull", "1", "head"
+        )
         self.assertTrue(os.path.exists(path))
         self.assertTrue(os.path.exists(path))
 
 
-    def set_up_git_repo(self, repo, fork, branch_from='feature'):
+    def set_up_git_repo(self, repo, fork, branch_from="feature"):
         """ Set up the git repo and create the corresponding PullRequest
         """ Set up the git repo and create the corresponding PullRequest
         object.
         object.
         """
         """
 
 
         # Clone the main repo
         # Clone the main repo
-        gitrepo = os.path.join(self.path, 'repos', repo.path)
-        newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
-        repopath = os.path.join(newpath, 'test')
+        gitrepo = os.path.join(self.path, "repos", repo.path)
+        newpath = tempfile.mkdtemp(prefix="pagure-fork-test")
+        repopath = os.path.join(newpath, "test")
         clone_repo = pygit2.clone_repository(gitrepo, repopath)
         clone_repo = pygit2.clone_repository(gitrepo, repopath)
 
 
         # Create a file in that git repo
         # Create a file in that git repo
-        with open(os.path.join(repopath, 'sources'), 'w') as stream:
-            stream.write('foo\n bar')
-        clone_repo.index.add('sources')
+        with open(os.path.join(repopath, "sources"), "w") as stream:
+            stream.write("foo\n bar")
+        clone_repo.index.add("sources")
         clone_repo.index.write()
         clone_repo.index.write()
 
 
         # Commits the files added
         # Commits the files added
         tree = clone_repo.index.write_tree()
         tree = clone_repo.index.write_tree()
-        author = pygit2.Signature(
-            'Alice Author', 'alice@authors.tld')
-        committer = pygit2.Signature(
-            'Cecil Committer', 'cecil@committers.tld')
+        author = pygit2.Signature("Alice Author", "alice@authors.tld")
+        committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
         clone_repo.create_commit(
         clone_repo.create_commit(
-            'refs/heads/master',  # the name of the reference to update
+            "refs/heads/master",  # the name of the reference to update
             author,
             author,
             committer,
             committer,
-            'Add sources file for testing',
+            "Add sources file for testing",
             # binary string representing the tree object ID
             # binary string representing the tree object ID
             tree,
             tree,
             # list of binary strings representing parents of the new commit
             # list of binary strings representing parents of the new commit
-            []
+            [],
         )
         )
-        refname = 'refs/heads/master:refs/heads/master'
+        refname = "refs/heads/master:refs/heads/master"
         ori_remote = clone_repo.remotes[0]
         ori_remote = clone_repo.remotes[0]
         PagureRepo.push(ori_remote, refname)
         PagureRepo.push(ori_remote, refname)
 
 
-        first_commit = clone_repo.revparse_single('HEAD')
+        first_commit = clone_repo.revparse_single("HEAD")
 
 
         # Set the second repo
         # Set the second repo
-        repopath = os.path.join(self.path, 'repos', fork.path)
-        new_gitrepo = os.path.join(newpath, 'fork_test')
+        repopath = os.path.join(self.path, "repos", fork.path)
+        new_gitrepo = os.path.join(newpath, "fork_test")
         clone_repo = pygit2.clone_repository(repopath, new_gitrepo)
         clone_repo = pygit2.clone_repository(repopath, new_gitrepo)
 
 
         # Add the main project as remote repo
         # Add the main project as remote repo
-        upstream_path = os.path.join(self.path, 'repos', repo.path)
-        remote = clone_repo.create_remote('upstream', upstream_path)
+        upstream_path = os.path.join(self.path, "repos", repo.path)
+        remote = clone_repo.create_remote("upstream", upstream_path)
         remote.fetch()
         remote.fetch()
 
 
         # Edit the sources file again
         # Edit the sources file again
-        with open(os.path.join(new_gitrepo, 'sources'), 'w') as stream:
-            stream.write('foo\n bar\nbaz\n boose')
-        clone_repo.index.add('sources')
+        with open(os.path.join(new_gitrepo, "sources"), "w") as stream:
+            stream.write("foo\n bar\nbaz\n boose")
+        clone_repo.index.add("sources")
         clone_repo.index.write()
         clone_repo.index.write()
 
 
         # Commits the files added
         # Commits the files added
         tree = clone_repo.index.write_tree()
         tree = clone_repo.index.write_tree()
-        author = pygit2.Signature(
-            'Alice Author', 'alice@authors.tld')
-        committer = pygit2.Signature(
-            'Cecil Committer', 'cecil@committers.tld')
+        author = pygit2.Signature("Alice Author", "alice@authors.tld")
+        committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
         clone_repo.create_commit(
         clone_repo.create_commit(
-            'refs/heads/%s' % branch_from,
+            "refs/heads/%s" % branch_from,
             author,
             author,
             committer,
             committer,
-            'A commit on branch %s' % branch_from,
+            "A commit on branch %s" % branch_from,
             tree,
             tree,
-            [first_commit.oid.hex]
+            [first_commit.oid.hex],
         )
         )
-        refname = 'refs/heads/%s' % (branch_from)
+        refname = "refs/heads/%s" % (branch_from)
         ori_remote = clone_repo.remotes[0]
         ori_remote = clone_repo.remotes[0]
         PagureRepo.push(ori_remote, refname)
         PagureRepo.push(ori_remote, refname)
 
 
         # Create a PR for these changes
         # Create a PR for these changes
-        project = pagure.lib.query.get_authorized_project(self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         req = pagure.lib.query.new_pull_request(
         req = pagure.lib.query.new_pull_request(
             session=self.session,
             session=self.session,
             repo_from=fork,
             repo_from=fork,
             branch_from=branch_from,
             branch_from=branch_from,
             repo_to=project,
             repo_to=project,
-            branch_to='master',
-            title='PR from the %s branch' % branch_from,
-            user='pingou',
+            branch_to="master",
+            title="PR from the %s branch" % branch_from,
+            user="pingou",
         )
         )
         self.session.commit()
         self.session.commit()
         self.assertEqual(req.id, 1)
         self.assertEqual(req.id, 1)
-        self.assertEqual(req.title, 'PR from the %s branch' % branch_from)
+        self.assertEqual(req.title, "PR from the %s branch" % branch_from)
 
 
         shutil.rmtree(newpath)
         shutil.rmtree(newpath)
 
 
     def test_request_pull_reference(self):
     def test_request_pull_reference(self):
         """ Test if there is a reference created for a new PR. """
         """ Test if there is a reference created for a new PR. """
 
 
-        project = pagure.lib.query.get_authorized_project(self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(project.requests), 1)
         self.assertEqual(len(project.requests), 1)
 
 
-        gitrepo = os.path.join(self.path, 'repos', 'test.git')
+        gitrepo = os.path.join(self.path, "repos", "test.git")
         repo = pygit2.Repository(gitrepo)
         repo = pygit2.Repository(gitrepo)
         self.assertEqual(
         self.assertEqual(
             list(repo.listall_references()),
             list(repo.listall_references()),
-            ['refs/heads/master', 'refs/pull/1/head']
+            ["refs/heads/master", "refs/pull/1/head"],
         )
         )
 
 
     def test_request_pull_fork_reference(self):
     def test_request_pull_fork_reference(self):
         """ Test if there the references created on the fork. """
         """ Test if there the references created on the fork. """
 
 
         project = pagure.lib.query.get_authorized_project(
         project = pagure.lib.query.get_authorized_project(
-            self.session, 'test', user='foo')
+            self.session, "test", user="foo"
+        )
         self.assertEqual(len(project.requests), 0)
         self.assertEqual(len(project.requests), 0)
 
 
-        gitrepo = os.path.join(self.path, 'repos', project.path)
+        gitrepo = os.path.join(self.path, "repos", project.path)
         repo = pygit2.Repository(gitrepo)
         repo = pygit2.Repository(gitrepo)
         self.assertEqual(
         self.assertEqual(
-            list(repo.listall_references()),
-            ['refs/heads/feature']
+            list(repo.listall_references()), ["refs/heads/feature"]
         )
         )
 
 
     def test_accessing_pr_fork_deleted(self):
     def test_accessing_pr_fork_deleted(self):
@@ -197,8 +194,9 @@ class PagureFlaskPrNoSourcestests(tests.Modeltests):
 
 
         # Delete fork on disk
         # Delete fork on disk
         project = pagure.lib.query.get_authorized_project(
         project = pagure.lib.query.get_authorized_project(
-            self.session, 'test', user='foo')
-        repo_path = os.path.join(self.path, 'repos', project.path)
+            self.session, "test", user="foo"
+        )
+        repo_path = os.path.join(self.path, "repos", project.path)
         self.assertTrue(os.path.exists(repo_path))
         self.assertTrue(os.path.exists(repo_path))
         shutil.rmtree(repo_path)
         shutil.rmtree(repo_path)
         self.assertFalse(os.path.exists(repo_path))
         self.assertFalse(os.path.exists(repo_path))
@@ -208,7 +206,7 @@ class PagureFlaskPrNoSourcestests(tests.Modeltests):
         self.session.commit()
         self.session.commit()
 
 
         # View the pull-request
         # View the pull-request
-        output2 = self.app.get('/test/pull-request/1')
+        output2 = self.app.get("/test/pull-request/1")
         self.assertEqual(output2.status_code, 200)
         self.assertEqual(output2.status_code, 200)
 
 
     def test_accessing_pr_patch_fork_deleted(self):
     def test_accessing_pr_patch_fork_deleted(self):
@@ -216,8 +214,9 @@ class PagureFlaskPrNoSourcestests(tests.Modeltests):
 
 
         # Delete fork on disk
         # Delete fork on disk
         project = pagure.lib.query.get_authorized_project(
         project = pagure.lib.query.get_authorized_project(
-            self.session, 'test', user='foo')
-        repo_path = os.path.join(self.path, 'repos', project.path)
+            self.session, "test", user="foo"
+        )
+        repo_path = os.path.join(self.path, "repos", project.path)
         self.assertTrue(os.path.exists(repo_path))
         self.assertTrue(os.path.exists(repo_path))
         shutil.rmtree(repo_path)
         shutil.rmtree(repo_path)
         self.assertFalse(os.path.exists(repo_path))
         self.assertFalse(os.path.exists(repo_path))
@@ -227,81 +226,79 @@ class PagureFlaskPrNoSourcestests(tests.Modeltests):
         self.session.commit()
         self.session.commit()
 
 
         # View the pull-request
         # View the pull-request
-        output = self.app.get('/test/pull-request/1.patch')
+        output = self.app.get("/test/pull-request/1.patch")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         self.assertIn(
         self.assertIn(
-            '--- a/sources\n+++ b/sources\n@@ -1,2 +1,4 @@',
-            output.get_data(as_text=True))
+            "--- a/sources\n+++ b/sources\n@@ -1,2 +1,4 @@",
+            output.get_data(as_text=True),
+        )
 
 
     def test_accessing_pr_branch_deleted(self):
     def test_accessing_pr_branch_deleted(self):
         """ Test accessing the PR if branch it originates from has been
         """ Test accessing the PR if branch it originates from has been
         deleted. """
         deleted. """
         project = pagure.lib.query.get_authorized_project(
         project = pagure.lib.query.get_authorized_project(
-            self.session, 'test', user='foo')
+            self.session, "test", user="foo"
+        )
 
 
         # Check the branches before
         # Check the branches before
-        gitrepo = os.path.join(self.path, 'repos', project.path)
+        gitrepo = os.path.join(self.path, "repos", project.path)
         repo = pygit2.Repository(gitrepo)
         repo = pygit2.Repository(gitrepo)
         self.assertEqual(
         self.assertEqual(
-            list(repo.listall_references()),
-            ['refs/heads/feature']
+            list(repo.listall_references()), ["refs/heads/feature"]
         )
         )
 
 
         # Delete branch of the fork
         # Delete branch of the fork
-        user = tests.FakeUser(username='foo')
+        user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             output = self.app.post(
             output = self.app.post(
-                '/fork/foo/test/b/feature/delete', follow_redirects=True)
+                "/fork/foo/test/b/feature/delete", follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
 
 
         # Check the branches after
         # Check the branches after
-        gitrepo = os.path.join(self.path, 'repos', project.path)
+        gitrepo = os.path.join(self.path, "repos", project.path)
         repo = pygit2.Repository(gitrepo)
         repo = pygit2.Repository(gitrepo)
-        self.assertEqual(
-            list(repo.listall_references()),
-            []
-        )
+        self.assertEqual(list(repo.listall_references()), [])
 
 
         # View the pull-request
         # View the pull-request
-        output2 = self.app.get('/test/pull-request/1')
+        output2 = self.app.get("/test/pull-request/1")
         self.assertEqual(output2.status_code, 200)
         self.assertEqual(output2.status_code, 200)
 
 
     def test_accessing_pr_patch_branch_deleted(self):
     def test_accessing_pr_patch_branch_deleted(self):
         """ Test accessing the PR's patch if branch it originates from has
         """ Test accessing the PR's patch if branch it originates from has
         been deleted. """
         been deleted. """
         project = pagure.lib.query.get_authorized_project(
         project = pagure.lib.query.get_authorized_project(
-            self.session, 'test', user='foo')
+            self.session, "test", user="foo"
+        )
 
 
         # Check the branches before
         # Check the branches before
-        gitrepo = os.path.join(self.path, 'repos', project.path)
+        gitrepo = os.path.join(self.path, "repos", project.path)
         repo = pygit2.Repository(gitrepo)
         repo = pygit2.Repository(gitrepo)
         self.assertEqual(
         self.assertEqual(
-            list(repo.listall_references()),
-            ['refs/heads/feature']
+            list(repo.listall_references()), ["refs/heads/feature"]
         )
         )
 
 
         # Delete branch of the fork
         # Delete branch of the fork
-        user = tests.FakeUser(username='foo')
+        user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             output = self.app.post(
             output = self.app.post(
-                '/fork/foo/test/b/feature/delete', follow_redirects=True)
+                "/fork/foo/test/b/feature/delete", follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
 
 
         # Check the branches after
         # Check the branches after
-        gitrepo = os.path.join(self.path, 'repos', project.path)
+        gitrepo = os.path.join(self.path, "repos", project.path)
         repo = pygit2.Repository(gitrepo)
         repo = pygit2.Repository(gitrepo)
-        self.assertEqual(
-            list(repo.listall_references()),
-            []
-        )
+        self.assertEqual(list(repo.listall_references()), [])
 
 
         # View the pull-request
         # View the pull-request
-        output = self.app.get('/test/pull-request/1.patch')
+        output = self.app.get("/test/pull-request/1.patch")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         self.assertIn(
         self.assertIn(
-            '--- a/sources\n+++ b/sources\n@@ -1,2 +1,4 @@',
-            output.get_data(as_text=True))
+            "--- a/sources\n+++ b/sources\n@@ -1,2 +1,4 @@",
+            output.get_data(as_text=True),
+        )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 684 - 452
tests/test_pagure_flask_ui_priorities.py

@@ -21,8 +21,9 @@ import os
 import pygit2
 import pygit2
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import tests
 import tests
@@ -32,1228 +33,1459 @@ from pagure.lib.repo import PagureRepo
 class PagureFlaskPrioritiestests(tests.Modeltests):
 class PagureFlaskPrioritiestests(tests.Modeltests):
     """ Tests for the behavior of priorities in pagure """
     """ Tests for the behavior of priorities in pagure """
 
 
-    @patch('pagure.lib.git.update_git')
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.git.update_git")
+    @patch("pagure.lib.notify.send_email")
     def test_ticket_with_no_priority(self, p_send_email, p_ugt):
     def test_ticket_with_no_priority(self, p_send_email, p_ugt):
         """ Test creating a ticket without priority. """
         """ Test creating a ticket without priority. """
         p_send_email.return_value = True
         p_send_email.return_value = True
         p_ugt.return_value = True
         p_ugt.return_value = True
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
             # Get the CSRF token
             # Get the CSRF token
-            output = self.app.get('/test/new_issue')
+            output = self.app.get("/test/new_issue")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertTrue(
             self.assertTrue(
                 '<h4 class="font-weight-bold mb-4">New Issue</h4>\n'
                 '<h4 class="font-weight-bold mb-4">New Issue</h4>\n'
-                in output_text)
+                in output_text
+            )
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             data = {
             data = {
-                'title': 'Test issue',
-                'issue_content': 'We really should improve on this issue',
-                'status': 'Open',
-                'csrf_token': csrf_token,
+                "title": "Test issue",
+                "issue_content": "We really should improve on this issue",
+                "status": "Open",
+                "csrf_token": csrf_token,
             }
             }
 
 
             # Create the issue
             # Create the issue
             output = self.app.post(
             output = self.app.post(
-                '/test/new_issue', data=data, follow_redirects=True)
+                "/test/new_issue", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Issue #1: Test issue - test - Pagure</title>',
-                output_text)
+                "<title>Issue #1: Test issue - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 'href="/test/issue/1/edit" title="Edit this issue">',
                 'href="/test/issue/1/edit" title="Edit this issue">',
-                output_text)
-            self.assertNotIn('<div class="ml-2" id="priority_plain">', output_text)
+                output_text,
+            )
+            self.assertNotIn(
+                '<div class="ml-2" id="priority_plain">', output_text
+            )
             self.assertNotIn('<option value="1">High</option>', output_text)
             self.assertNotIn('<option value="1">High</option>', output_text)
 
 
-    @patch('pagure.lib.git.update_git')
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.git.update_git")
+    @patch("pagure.lib.notify.send_email")
     def test_ticket_with_priorities(self, p_send_email, p_ugt):
     def test_ticket_with_priorities(self, p_send_email, p_ugt):
         """ Test creating a ticket with priorities. """
         """ Test creating a ticket with priorities. """
         p_send_email.return_value = True
         p_send_email.return_value = True
         p_ugt.return_value = True
         p_ugt.return_value = True
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         # Set some priorities
         # Set some priorities
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
-        repo.priorities = {'1': 'High', '2': 'Normal'}
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
+        repo.priorities = {"1": "High", "2": "Normal"}
         self.session.add(repo)
         self.session.add(repo)
         self.session.commit()
         self.session.commit()
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
             # Get the CSRF token
             # Get the CSRF token
-            output = self.app.get('/test/new_issue')
+            output = self.app.get("/test/new_issue")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertTrue(
             self.assertTrue(
                 '<h4 class="font-weight-bold mb-4">New Issue</h4>\n'
                 '<h4 class="font-weight-bold mb-4">New Issue</h4>\n'
-                in output_text)
+                in output_text
+            )
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             data = {
             data = {
-                'title': 'Test issue',
-                'issue_content': 'We really should improve on this issue',
-                'status': 'Open',
-                'csrf_token': csrf_token,
+                "title": "Test issue",
+                "issue_content": "We really should improve on this issue",
+                "status": "Open",
+                "csrf_token": csrf_token,
             }
             }
 
 
             # Create the issue
             # Create the issue
             output = self.app.post(
             output = self.app.post(
-                '/test/new_issue', data=data, follow_redirects=True)
+                "/test/new_issue", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Issue #1: Test issue - test - Pagure</title>',
-                output_text)
+                "<title>Issue #1: Test issue - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 'href="/test/issue/1/edit" title="Edit this issue">',
                 'href="/test/issue/1/edit" title="Edit this issue">',
-                output_text)
-            self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
+                output_text,
+            )
+            self.assertIn(
+                '<div class="ml-2" id="priority_plain">', output_text
+            )
             self.assertIn('<option value="1">High</option>', output_text)
             self.assertIn('<option value="1">High</option>', output_text)
 
 
     def test_update_priorities(self):
     def test_update_priorities(self):
         """ Test updating priorities of a repo. """
         """ Test updating priorities of a repo. """
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         # Set some priorities
         # Set some priorities
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(repo.priorities, {})
         self.assertEqual(repo.priorities, {})
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
             # Get the CSRF token
             # Get the CSRF token
-            output = self.app.get('/test/settings')
+            output = self.app.get("/test/settings")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
-            data = {
-                'priority_weigth': 1,
-                'priority_title': 'High',
-            }
+            data = {"priority_weigth": 1, "priority_title": "High"}
             output = self.app.post(
             output = self.app.post(
-                '/test/update/priorities', data=data, follow_redirects=True)
+                "/test/update/priorities", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             # Check the result of the action -- None, no CSRF
             # Check the result of the action -- None, no CSRF
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
             self.assertEqual(repo.priorities, {})
             self.assertEqual(repo.priorities, {})
 
 
             data = {
             data = {
-                'priority_weigth': 1,
-                'priority_title': 'High',
-                'csrf_token': csrf_token,
+                "priority_weigth": 1,
+                "priority_title": "High",
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/priorities', data=data, follow_redirects=True)
+                "/test/update/priorities", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             # Check the result of the action -- Priority recorded
             # Check the result of the action -- Priority recorded
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
-            self.assertEqual(repo.priorities, {'': '', '1': 'High'})
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
+            self.assertEqual(repo.priorities, {"": "", "1": "High"})
 
 
             data = {
             data = {
-                'priority_weigth': [1, 2, 3],
-                'priority_title': ['High', 'Normal', 'Low'],
-                'csrf_token': csrf_token,
+                "priority_weigth": [1, 2, 3],
+                "priority_title": ["High", "Normal", "Low"],
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/priorities', data=data, follow_redirects=True)
+                "/test/update/priorities", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             # Check the ordering
             # Check the ordering
             self.assertTrue(
             self.assertTrue(
-                output_text.find('High') < output_text.find('Normal'))
+                output_text.find("High") < output_text.find("Normal")
+            )
             self.assertTrue(
             self.assertTrue(
-                output_text.find('Normal') < output_text.find('Low'))
+                output_text.find("Normal") < output_text.find("Low")
+            )
             # Check the result of the action -- Priority recorded
             # Check the result of the action -- Priority recorded
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
             self.assertEqual(
             self.assertEqual(
                 repo.priorities,
                 repo.priorities,
-                {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
+                {"": "", "1": "High", "2": "Normal", "3": "Low"},
             )
             )
 
 
             # Check error - less weigths than titles
             # Check error - less weigths than titles
             data = {
             data = {
-                'priority_weigth': [1, 2],
-                'priority_title': ['High', 'Normal', 'Low'],
-                'csrf_token': csrf_token,
+                "priority_weigth": [1, 2],
+                "priority_title": ["High", "Normal", "Low"],
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/priorities', data=data, follow_redirects=True)
+                "/test/update/priorities", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                'Priorities weights and titles are '
-                'not of the same length', output_text)
+                "Priorities weights and titles are " "not of the same length",
+                output_text,
+            )
             # Check the result of the action -- Priorities un-changed
             # Check the result of the action -- Priorities un-changed
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
             self.assertEqual(
             self.assertEqual(
                 repo.priorities,
                 repo.priorities,
-                {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
+                {"": "", "1": "High", "2": "Normal", "3": "Low"},
             )
             )
 
 
             # Check error - weigths must be integer
             # Check error - weigths must be integer
             data = {
             data = {
-                'priority_weigth': [1, 2, 'c'],
-                'priority_title': ['High', 'Normal', 'Low'],
-                'csrf_token': csrf_token,
+                "priority_weigth": [1, 2, "c"],
+                "priority_title": ["High", "Normal", "Low"],
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/priorities', data=data, follow_redirects=True)
+                "/test/update/priorities", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Priorities weights must be numbers',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Priorities weights must be numbers", output_text)
             # Check the result of the action -- Priorities un-changed
             # Check the result of the action -- Priorities un-changed
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
             self.assertEqual(
             self.assertEqual(
                 repo.priorities,
                 repo.priorities,
-                {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
+                {"": "", "1": "High", "2": "Normal", "3": "Low"},
             )
             )
 
 
             # Check error - Twice the same priority weigth
             # Check error - Twice the same priority weigth
             data = {
             data = {
-                'priority_weigth': [1, 2, 2],
-                'priority_title': ['High', 'Normal', 'Low'],
-                'csrf_token': csrf_token,
+                "priority_weigth": [1, 2, 2],
+                "priority_title": ["High", "Normal", "Low"],
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/priorities', data=data, follow_redirects=True)
+                "/test/update/priorities", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Priority weight 2 is present 2 times',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Priority weight 2 is present 2 times", output_text)
             # Check the result of the action -- Priorities un-changed
             # Check the result of the action -- Priorities un-changed
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
             self.assertEqual(
             self.assertEqual(
                 repo.priorities,
                 repo.priorities,
-                {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
+                {"": "", "1": "High", "2": "Normal", "3": "Low"},
             )
             )
 
 
             # Check error - Twice the same priority title
             # Check error - Twice the same priority title
             data = {
             data = {
-                'priority_weigth': [1, 2, 3],
-                'priority_title': ['High', 'Normal', 'Normal'],
-                'csrf_token': csrf_token,
+                "priority_weigth": [1, 2, 3],
+                "priority_title": ["High", "Normal", "Normal"],
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/priorities', data=data, follow_redirects=True)
+                "/test/update/priorities", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Priority Normal is present 2 times',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Priority Normal is present 2 times", output_text)
             # Check the result of the action -- Priorities un-changed
             # Check the result of the action -- Priorities un-changed
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
             self.assertEqual(
             self.assertEqual(
                 repo.priorities,
                 repo.priorities,
-                {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
+                {"": "", "1": "High", "2": "Normal", "3": "Low"},
             )
             )
 
 
             # Check the behavior if the project disabled the issue tracker
             # Check the behavior if the project disabled the issue tracker
             settings = repo.settings
             settings = repo.settings
-            settings['issue_tracker'] = False
+            settings["issue_tracker"] = False
             repo.settings = settings
             repo.settings = settings
             self.session.add(repo)
             self.session.add(repo)
             self.session.commit()
             self.session.commit()
 
 
-            output = self.app.post(
-                '/test/update/priorities', data=data)
+            output = self.app.post("/test/update/priorities", data=data)
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
             # Check for an invalid project
             # Check for an invalid project
-            output = self.app.post(
-                '/foo/update/priorities', data=data)
+            output = self.app.post("/foo/update/priorities", data=data)
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
         # Check for a non-admin user
         # Check for a non-admin user
         settings = repo.settings
         settings = repo.settings
-        settings['issue_tracker'] = True
+        settings["issue_tracker"] = True
         repo.settings = settings
         repo.settings = settings
         self.session.add(repo)
         self.session.add(repo)
         self.session.commit()
         self.session.commit()
 
 
-        user.username = 'ralph'
+        user.username = "ralph"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post(
-                '/test/update/priorities', data=data)
+            output = self.app.post("/test/update/priorities", data=data)
             self.assertEqual(output.status_code, 403)
             self.assertEqual(output.status_code, 403)
 
 
-    @patch('pagure.lib.git.update_git')
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.git.update_git")
+    @patch("pagure.lib.notify.send_email")
     def test_reset_priorities(self, p_send_email, p_ugt):
     def test_reset_priorities(self, p_send_email, p_ugt):
         """ Test resetting the priorities of a repo. """
         """ Test resetting the priorities of a repo. """
         p_send_email.return_value = True
         p_send_email.return_value = True
         p_ugt.return_value = True
         p_ugt.return_value = True
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         # Start from scrach on priorities
         # Start from scrach on priorities
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
         self.assertEqual(repo.priorities, {})
         self.assertEqual(repo.priorities, {})
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
             # Get the CSRF token
             # Get the CSRF token
-            output = self.app.get('/test/settings')
+            output = self.app.get("/test/settings")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             # Set some priorities
             # Set some priorities
             data = {
             data = {
-                'priority_weigth': [1, 2, 3],
-                'priority_title': ['High', 'Normal', 'Low'],
-                'csrf_token': csrf_token,
+                "priority_weigth": [1, 2, 3],
+                "priority_title": ["High", "Normal", "Low"],
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/priorities', data=data, follow_redirects=True)
+                "/test/update/priorities", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
 
 
             # Check the result of the action -- Priority recorded
             # Check the result of the action -- Priority recorded
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query._get_project(self.session, 'test')
+            repo = pagure.lib.query._get_project(self.session, "test")
             self.assertEqual(
             self.assertEqual(
                 repo.priorities,
                 repo.priorities,
-                {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
+                {"": "", "1": "High", "2": "Normal", "3": "Low"},
             )
             )
 
 
             # Create an issue
             # Create an issue
             data = {
             data = {
-                'title': 'Test issue',
-                'issue_content': 'We really should improve on this issue',
-                'status': 'Open',
-                'csrf_token': csrf_token,
+                "title": "Test issue",
+                "issue_content": "We really should improve on this issue",
+                "status": "Open",
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/new_issue', data=data, follow_redirects=True)
+                "/test/new_issue", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Issue #1: Test issue - test - Pagure</title>',
-                output_text)
+                "<title>Issue #1: Test issue - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 'href="/test/issue/1/edit" title="Edit this issue">',
                 'href="/test/issue/1/edit" title="Edit this issue">',
-                output_text)
-            self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
+                output_text,
+            )
+            self.assertIn(
+                '<div class="ml-2" id="priority_plain">', output_text
+            )
             self.assertIn('<option value="1">High</option>', output_text)
             self.assertIn('<option value="1">High</option>', output_text)
 
 
             # Check that the ticket *does* have priorities
             # Check that the ticket *does* have priorities
-            output = self.app.get('/test/issue/1')
+            output = self.app.get("/test/issue/1")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
+            self.assertIn(
+                '<div class="ml-2" id="priority_plain">', output_text
+            )
             self.assertIn('<option value="1">High</option>', output_text)
             self.assertIn('<option value="1">High</option>', output_text)
 
 
             # Reset the priorities
             # Reset the priorities
-            data = {
-                'csrf_token': csrf_token,
-            }
+            data = {"csrf_token": csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/test/update/priorities', data=data, follow_redirects=True)
+                "/test/update/priorities", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
 
 
             # Check that the issue list renders fine
             # Check that the issue list renders fine
-            output = self.app.get('/test/issues')
+            output = self.app.get("/test/issues")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
 
 
             # Check that the ticket *does not* have priorities
             # Check that the ticket *does not* have priorities
-            output = self.app.get('/test/issue/1')
+            output = self.app.get("/test/issue/1")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertNotIn('<div class="ml-2" id="priority_plain">', output_text)
+            self.assertNotIn(
+                '<div class="ml-2" id="priority_plain">', output_text
+            )
             self.assertNotIn('<option value="1">High</option>', output_text)
             self.assertNotIn('<option value="1">High</option>', output_text)
 
 
             # Check the result of the action -- Priority reset
             # Check the result of the action -- Priority reset
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query._get_project(self.session, 'test')
+            repo = pagure.lib.query._get_project(self.session, "test")
             self.assertEqual(repo.priorities, {})
             self.assertEqual(repo.priorities, {})
 
 
-    @patch('pagure.lib.git.update_git')
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.git.update_git")
+    @patch("pagure.lib.notify.send_email")
     def test_reset_priorities_None(self, p_send_email, p_ugt):
     def test_reset_priorities_None(self, p_send_email, p_ugt):
         """ Test resetting the priorities of a repo. """
         """ Test resetting the priorities of a repo. """
         p_send_email.return_value = True
         p_send_email.return_value = True
         p_ugt.return_value = True
         p_ugt.return_value = True
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         # Start from scrach on priorities
         # Start from scrach on priorities
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
         self.assertEqual(repo.priorities, {})
         self.assertEqual(repo.priorities, {})
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
             # Get the CSRF token
             # Get the CSRF token
-            output = self.app.get('/test/settings')
+            output = self.app.get("/test/settings")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             # Set some priorities
             # Set some priorities
             data = {
             data = {
-                'priority_weigth': [1, 2, 3],
-                'priority_title': ['High', 'Normal', 'Low'],
-                'csrf_token': csrf_token,
+                "priority_weigth": [1, 2, 3],
+                "priority_title": ["High", "Normal", "Low"],
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/priorities', data=data, follow_redirects=True)
+                "/test/update/priorities", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
 
 
             # Check the result of the action -- Priority recorded
             # Check the result of the action -- Priority recorded
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query._get_project(self.session, 'test')
+            repo = pagure.lib.query._get_project(self.session, "test")
             self.assertEqual(
             self.assertEqual(
                 repo.priorities,
                 repo.priorities,
-                {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
+                {"": "", "1": "High", "2": "Normal", "3": "Low"},
             )
             )
 
 
             # Create an issue
             # Create an issue
             data = {
             data = {
-                'title': 'Test issue',
-                'issue_content': 'We really should improve on this issue',
-                'status': 'Open',
-                'csrf_token': csrf_token,
+                "title": "Test issue",
+                "issue_content": "We really should improve on this issue",
+                "status": "Open",
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/new_issue', data=data, follow_redirects=True)
+                "/test/new_issue", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Issue #1: Test issue - test - Pagure</title>',
-                output_text)
+                "<title>Issue #1: Test issue - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 'href="/test/issue/1/edit" title="Edit this issue">',
                 'href="/test/issue/1/edit" title="Edit this issue">',
-                output_text)
-            self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
+                output_text,
+            )
+            self.assertIn(
+                '<div class="ml-2" id="priority_plain">', output_text
+            )
             self.assertIn('<option value="1">High</option>', output_text)
             self.assertIn('<option value="1">High</option>', output_text)
 
 
             # Check that the ticket *does* have priorities
             # Check that the ticket *does* have priorities
-            output = self.app.get('/test/issue/1')
+            output = self.app.get("/test/issue/1")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
+            self.assertIn(
+                '<div class="ml-2" id="priority_plain">', output_text
+            )
             self.assertIn('<option value="1">High</option>', output_text)
             self.assertIn('<option value="1">High</option>', output_text)
 
 
             # Reset the priorities
             # Reset the priorities
-            data = {
-                'priority': None,
-                'csrf_token': csrf_token,
-            }
+            data = {"priority": None, "csrf_token": csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/test/update/priorities', data=data, follow_redirects=True)
+                "/test/update/priorities", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
 
 
             # Check that the issue list renders fine
             # Check that the issue list renders fine
-            output = self.app.get('/test/issues')
+            output = self.app.get("/test/issues")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
 
 
             # Check that the ticket *does not* have priorities
             # Check that the ticket *does not* have priorities
-            output = self.app.get('/test/issue/1')
+            output = self.app.get("/test/issue/1")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertNotIn('<div class="ml-2" id="priority_plain">', output_text)
+            self.assertNotIn(
+                '<div class="ml-2" id="priority_plain">', output_text
+            )
             self.assertNotIn('<option value="1">High</option>', output_text)
             self.assertNotIn('<option value="1">High</option>', output_text)
 
 
             # Check the result of the action -- Priority recorded
             # Check the result of the action -- Priority recorded
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query._get_project(self.session, 'test')
+            repo = pagure.lib.query._get_project(self.session, "test")
             self.assertEqual(repo.priorities, {})
             self.assertEqual(repo.priorities, {})
 
 
-    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.git.update_git", MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_set_priority_1_and_back(self):
     def test_set_priority_1_and_back(self):
         """ Test setting the priority of a ticket to 1. """
         """ Test setting the priority of a ticket to 1. """
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         # Start from scrach on priorities
         # Start from scrach on priorities
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
         self.assertEqual(repo.priorities, {})
         self.assertEqual(repo.priorities, {})
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
             # Get the CSRF token
             # Get the CSRF token
-            output = self.app.get('/test/settings')
+            output = self.app.get("/test/settings")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             # Set some priorities
             # Set some priorities
             data = {
             data = {
-                'priority_weigth': [-1, 0, 1, 2, 3],
-                'priority_title': [
-                    'Sky Falling', 'Urgent', 'High', 'Normal', 'Low'],
-                'csrf_token': csrf_token,
+                "priority_weigth": [-1, 0, 1, 2, 3],
+                "priority_title": [
+                    "Sky Falling",
+                    "Urgent",
+                    "High",
+                    "Normal",
+                    "Low",
+                ],
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/priorities', data=data, follow_redirects=True)
+                "/test/update/priorities", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
 
 
             # Check the result of the action -- Priority recorded
             # Check the result of the action -- Priority recorded
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query._get_project(self.session, 'test')
+            repo = pagure.lib.query._get_project(self.session, "test")
             self.assertEqual(
             self.assertEqual(
                 repo.priorities,
                 repo.priorities,
-                {'': '', '-1': 'Sky Falling', '0': 'Urgent',
-                 '1': 'High', '2': 'Normal', '3': 'Low'}
+                {
+                    "": "",
+                    "-1": "Sky Falling",
+                    "0": "Urgent",
+                    "1": "High",
+                    "2": "Normal",
+                    "3": "Low",
+                },
             )
             )
 
 
             # Create an issue
             # Create an issue
             data = {
             data = {
-                'title': 'Test issue',
-                'issue_content': 'We really should improve on this issue',
-                'status': 'Open',
-                'csrf_token': csrf_token,
+                "title": "Test issue",
+                "issue_content": "We really should improve on this issue",
+                "status": "Open",
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/new_issue', data=data, follow_redirects=True)
+                "/test/new_issue", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Issue #1: Test issue - test - Pagure</title>',
-                output_text)
+                "<title>Issue #1: Test issue - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 'href="/test/issue/1/edit" title="Edit this issue">',
                 'href="/test/issue/1/edit" title="Edit this issue">',
-                output_text)
-            self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
+                output_text,
+            )
+            self.assertIn(
+                '<div class="ml-2" id="priority_plain">', output_text
+            )
             self.assertIn('<option value="1">High</option>', output_text)
             self.assertIn('<option value="1">High</option>', output_text)
 
 
             # Check that the ticket *does* have priorities
             # Check that the ticket *does* have priorities
-            output = self.app.get('/test/issue/1')
+            output = self.app.get("/test/issue/1")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
             self.assertIn(
             self.assertIn(
-                '<option value="-1">Sky Falling</option>', output_text)
+                '<div class="ml-2" id="priority_plain">', output_text
+            )
+            self.assertIn(
+                '<option value="-1">Sky Falling</option>', output_text
+            )
             self.assertIn('<option value="0">Urgent</option>', output_text)
             self.assertIn('<option value="0">Urgent</option>', output_text)
             self.assertIn('<option value="1">High</option>', output_text)
             self.assertIn('<option value="1">High</option>', output_text)
 
 
             # Set the priority to High
             # Set the priority to High
 
 
-            data = {
-                'priority': '1',
-                'csrf_token': csrf_token,
-            }
+            data = {"priority": "1", "csrf_token": csrf_token}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/issue/1/update', data=data, follow_redirects=True)
+                "/test/issue/1/update", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Issue #1: Test issue - test - Pagure</title>',
-                output_text)
+                "<title>Issue #1: Test issue - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 'href="/test/issue/1/edit" title="Edit this issue">',
                 'href="/test/issue/1/edit" title="Edit this issue">',
-                output_text)
-            self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
+                output_text,
+            )
+            self.assertIn(
+                '<div class="ml-2" id="priority_plain">', output_text
+            )
             self.assertIn(
             self.assertIn(
-                '<option value="-1">Sky Falling</option>', output_text)
+                '<option value="-1">Sky Falling</option>', output_text
+            )
             self.assertIn('<option value="0">Urgent</option>', output_text)
             self.assertIn('<option value="0">Urgent</option>', output_text)
             self.assertIn(
             self.assertIn(
-                '<option selected value="1">High</option>', output_text)
+                '<option selected value="1">High</option>', output_text
+            )
 
 
             # Reset the priority
             # Reset the priority
-            data = {
-                'priority': '',
-                'csrf_token': csrf_token,
-            }
+            data = {"priority": "", "csrf_token": csrf_token}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/issue/1/update', data=data, follow_redirects=True)
+                "/test/issue/1/update", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Issue #1: Test issue - test - Pagure</title>',
-                output_text)
+                "<title>Issue #1: Test issue - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 'href="/test/issue/1/edit" title="Edit this issue">',
                 'href="/test/issue/1/edit" title="Edit this issue">',
-                output_text)
-            self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                '<option value="-1">Sky Falling</option>', output_text)
+                '<div class="ml-2" id="priority_plain">', output_text
+            )
+            self.assertIn(
+                '<option value="-1">Sky Falling</option>', output_text
+            )
             self.assertIn('<option value="0">Urgent</option>', output_text)
             self.assertIn('<option value="0">Urgent</option>', output_text)
             self.assertIn('<option value="1">High</option>', output_text)
             self.assertIn('<option value="1">High</option>', output_text)
 
 
-    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.git.update_git", MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_set_priority_0(self):
     def test_set_priority_0(self):
         """ Test setting the priority of a ticket to 0. """
         """ Test setting the priority of a ticket to 0. """
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         # Start from scrach on priorities
         # Start from scrach on priorities
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
         self.assertEqual(repo.priorities, {})
         self.assertEqual(repo.priorities, {})
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
             # Get the CSRF token
             # Get the CSRF token
-            output = self.app.get('/test/settings')
+            output = self.app.get("/test/settings")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             # Set some priorities
             # Set some priorities
             data = {
             data = {
-                'priority_weigth': [-1, 0, 1, 2, 3],
-                'priority_title': [
-                    'Sky Falling', 'Urgent', 'High', 'Normal', 'Low'],
-                'csrf_token': csrf_token,
+                "priority_weigth": [-1, 0, 1, 2, 3],
+                "priority_title": [
+                    "Sky Falling",
+                    "Urgent",
+                    "High",
+                    "Normal",
+                    "Low",
+                ],
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/priorities', data=data, follow_redirects=True)
+                "/test/update/priorities", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
 
 
             # Check the result of the action -- Priority recorded
             # Check the result of the action -- Priority recorded
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query._get_project(self.session, 'test')
+            repo = pagure.lib.query._get_project(self.session, "test")
             self.assertEqual(
             self.assertEqual(
                 repo.priorities,
                 repo.priorities,
-                {'': '', '-1': 'Sky Falling', '0': 'Urgent',
-                 '1': 'High', '2': 'Normal', '3': 'Low'}
+                {
+                    "": "",
+                    "-1": "Sky Falling",
+                    "0": "Urgent",
+                    "1": "High",
+                    "2": "Normal",
+                    "3": "Low",
+                },
             )
             )
 
 
             # Create an issue
             # Create an issue
             data = {
             data = {
-                'title': 'Test issue',
-                'issue_content': 'We really should improve on this issue',
-                'status': 'Open',
-                'csrf_token': csrf_token,
+                "title": "Test issue",
+                "issue_content": "We really should improve on this issue",
+                "status": "Open",
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/new_issue', data=data, follow_redirects=True)
+                "/test/new_issue", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Issue #1: Test issue - test - Pagure</title>',
-                output_text)
+                "<title>Issue #1: Test issue - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 'href="/test/issue/1/edit" title="Edit this issue">',
                 'href="/test/issue/1/edit" title="Edit this issue">',
-                output_text)
-            self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
+                output_text,
+            )
+            self.assertIn(
+                '<div class="ml-2" id="priority_plain">', output_text
+            )
             self.assertIn('<option value="1">High</option>', output_text)
             self.assertIn('<option value="1">High</option>', output_text)
 
 
             # Check that the ticket *does* have priorities
             # Check that the ticket *does* have priorities
-            output = self.app.get('/test/issue/1')
+            output = self.app.get("/test/issue/1")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
             self.assertIn(
             self.assertIn(
-                '<option value="-1">Sky Falling</option>', output_text)
+                '<div class="ml-2" id="priority_plain">', output_text
+            )
+            self.assertIn(
+                '<option value="-1">Sky Falling</option>', output_text
+            )
             self.assertIn('<option value="0">Urgent</option>', output_text)
             self.assertIn('<option value="0">Urgent</option>', output_text)
             self.assertIn('<option value="1">High</option>', output_text)
             self.assertIn('<option value="1">High</option>', output_text)
 
 
             # Set the priority to Urgent
             # Set the priority to Urgent
 
 
-            data = {
-                'priority': '0',
-                'csrf_token': csrf_token,
-            }
+            data = {"priority": "0", "csrf_token": csrf_token}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/issue/1/update', data=data, follow_redirects=True)
+                "/test/issue/1/update", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Issue #1: Test issue - test - Pagure</title>',
-                output_text)
+                "<title>Issue #1: Test issue - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 'href="/test/issue/1/edit" title="Edit this issue">',
                 'href="/test/issue/1/edit" title="Edit this issue">',
-                output_text)
-            self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                '<option value="-1">Sky Falling</option>', output_text)
+                '<div class="ml-2" id="priority_plain">', output_text
+            )
+            self.assertIn(
+                '<option value="-1">Sky Falling</option>', output_text
+            )
             self.assertIn(
             self.assertIn(
-                '<option selected value="0">Urgent</option>',
-                output_text)
+                '<option selected value="0">Urgent</option>', output_text
+            )
             self.assertIn('<option value="1">High</option>', output_text)
             self.assertIn('<option value="1">High</option>', output_text)
 
 
-    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.git.update_git", MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_set_priority_minus1(self):
     def test_set_priority_minus1(self):
         """ Test setting the priority of a ticket to -1. """
         """ Test setting the priority of a ticket to -1. """
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         # Start from scrach on priorities
         # Start from scrach on priorities
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
         self.assertEqual(repo.priorities, {})
         self.assertEqual(repo.priorities, {})
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
             # Get the CSRF token
             # Get the CSRF token
-            output = self.app.get('/test/settings')
+            output = self.app.get("/test/settings")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             # Set some priorities
             # Set some priorities
             data = {
             data = {
-                'priority_weigth': [-1, 0, 1, 2, 3],
-                'priority_title': [
-                    'Sky Falling', 'Urgent', 'High', 'Normal', 'Low'],
-                'csrf_token': csrf_token,
+                "priority_weigth": [-1, 0, 1, 2, 3],
+                "priority_title": [
+                    "Sky Falling",
+                    "Urgent",
+                    "High",
+                    "Normal",
+                    "Low",
+                ],
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/priorities', data=data, follow_redirects=True)
+                "/test/update/priorities", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
 
 
             # Check the result of the action -- Priority recorded
             # Check the result of the action -- Priority recorded
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query._get_project(self.session, 'test')
+            repo = pagure.lib.query._get_project(self.session, "test")
             self.assertEqual(
             self.assertEqual(
                 repo.priorities,
                 repo.priorities,
-                {'': '', '-1': 'Sky Falling', '0': 'Urgent',
-                 '1': 'High', '2': 'Normal', '3': 'Low'}
+                {
+                    "": "",
+                    "-1": "Sky Falling",
+                    "0": "Urgent",
+                    "1": "High",
+                    "2": "Normal",
+                    "3": "Low",
+                },
             )
             )
 
 
             # Create an issue
             # Create an issue
             data = {
             data = {
-                'title': 'Test issue',
-                'issue_content': 'We really should improve on this issue',
-                'status': 'Open',
-                'csrf_token': csrf_token,
+                "title": "Test issue",
+                "issue_content": "We really should improve on this issue",
+                "status": "Open",
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/new_issue', data=data, follow_redirects=True)
+                "/test/new_issue", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Issue #1: Test issue - test - Pagure</title>',
-                output_text)
+                "<title>Issue #1: Test issue - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 'href="/test/issue/1/edit" title="Edit this issue">',
                 'href="/test/issue/1/edit" title="Edit this issue">',
-                output_text)
-            self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
+                output_text,
+            )
+            self.assertIn(
+                '<div class="ml-2" id="priority_plain">', output_text
+            )
             self.assertIn('<option value="1">High</option>', output_text)
             self.assertIn('<option value="1">High</option>', output_text)
 
 
             # Check that the ticket *does* have priorities
             # Check that the ticket *does* have priorities
-            output = self.app.get('/test/issue/1')
+            output = self.app.get("/test/issue/1")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
             self.assertIn(
             self.assertIn(
-                '<option value="-1">Sky Falling</option>', output_text)
+                '<div class="ml-2" id="priority_plain">', output_text
+            )
+            self.assertIn(
+                '<option value="-1">Sky Falling</option>', output_text
+            )
             self.assertIn('<option value="0">Urgent</option>', output_text)
             self.assertIn('<option value="0">Urgent</option>', output_text)
             self.assertIn('<option value="1">High</option>', output_text)
             self.assertIn('<option value="1">High</option>', output_text)
 
 
             # Set the priority to Sky Falling
             # Set the priority to Sky Falling
 
 
-            data = {
-                'priority': '-1',
-                'csrf_token': csrf_token,
-            }
+            data = {"priority": "-1", "csrf_token": csrf_token}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/issue/1/update', data=data, follow_redirects=True)
+                "/test/issue/1/update", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Issue #1: Test issue - test - Pagure</title>',
-                output_text)
+                "<title>Issue #1: Test issue - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 'href="/test/issue/1/edit" title="Edit this issue">',
                 'href="/test/issue/1/edit" title="Edit this issue">',
-                output_text)
-            self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                '<option selected value="-1">Sky Falling</option>',
-                output_text)
+                '<div class="ml-2" id="priority_plain">', output_text
+            )
+            self.assertIn(
+                '<option selected value="-1">Sky Falling</option>', output_text
+            )
             self.assertIn('<option value="0">Urgent</option>', output_text)
             self.assertIn('<option value="0">Urgent</option>', output_text)
             self.assertIn('<option value="1">High</option>', output_text)
             self.assertIn('<option value="1">High</option>', output_text)
 
 
-    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.git.update_git", MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_default_priority(self):
     def test_default_priority(self):
         """ Test updating the default priority of a repo. """
         """ Test updating the default priority of a repo. """
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         # Check the default priorities
         # Check the default priorities
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(repo.priorities, {})
         self.assertEqual(repo.priorities, {})
         self.assertEqual(repo.default_priority, None)
         self.assertEqual(repo.default_priority, None)
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             # Set some priorities
             # Set some priorities
             data = {
             data = {
-                'priority_weigth': [1, 2, 3],
-                'priority_title': ['High', 'Normal', 'Low'],
-                'csrf_token': csrf_token,
+                "priority_weigth": [1, 2, 3],
+                "priority_title": ["High", "Normal", "Low"],
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/priorities', data=data, follow_redirects=True)
+                "/test/update/priorities", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             # Check the ordering
             # Check the ordering
             self.assertTrue(
             self.assertTrue(
-                output_text.find('High') < output_text.find('Normal'))
+                output_text.find("High") < output_text.find("Normal")
+            )
             self.assertTrue(
             self.assertTrue(
-                output_text.find('Normal') < output_text.find('Low'))
+                output_text.find("Normal") < output_text.find("Low")
+            )
             # Check the result of the action -- Priority recorded
             # Check the result of the action -- Priority recorded
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
             self.assertEqual(
             self.assertEqual(
                 repo.priorities,
                 repo.priorities,
-                {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
+                {"": "", "1": "High", "2": "Normal", "3": "Low"},
             )
             )
 
 
             # Try setting the default priority  --  no csrf
             # Try setting the default priority  --  no csrf
-            data = {'priority': 'High'}
+            data = {"priority": "High"}
             output = self.app.post(
             output = self.app.post(
-                '/test/update/default_priority', data=data,
-                follow_redirects=True)
+                "/test/update/default_priority",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             # Check the result of the action -- default_priority no change
             # Check the result of the action -- default_priority no change
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
             self.assertEqual(repo.default_priority, None)
             self.assertEqual(repo.default_priority, None)
 
 
             # Try setting the default priority
             # Try setting the default priority
-            data = {'priority': 'High', 'csrf_token': csrf_token}
+            data = {"priority": "High", "csrf_token": csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/test/update/default_priority', data=data,
-                follow_redirects=True)
+                "/test/update/default_priority",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Default priority set '
-                'to High', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Default priority set " "to High", output_text)
             # Check the result of the action -- default_priority no change
             # Check the result of the action -- default_priority no change
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
-            self.assertEqual(repo.default_priority, 'High')
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
+            self.assertEqual(repo.default_priority, "High")
 
 
             # Try setting a wrong default priority
             # Try setting a wrong default priority
-            data = {'priority': 'Smooth', 'csrf_token': csrf_token}
+            data = {"priority": "Smooth", "csrf_token": csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/test/update/default_priority', data=data,
-                follow_redirects=True)
+                "/test/update/default_priority",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             # Check the result of the action -- default_priority no change
             # Check the result of the action -- default_priority no change
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
-            self.assertEqual(repo.default_priority, 'High')
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
+            self.assertEqual(repo.default_priority, "High")
 
 
             # reset the default priority
             # reset the default priority
-            data = {'csrf_token': csrf_token, 'priority': ''}
+            data = {"csrf_token": csrf_token, "priority": ""}
             output = self.app.post(
             output = self.app.post(
-                '/test/update/default_priority', data=data,
-                follow_redirects=True)
+                "/test/update/default_priority",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Default priority reset',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Default priority reset", output_text)
             # Check the result of the action -- default_priority no change
             # Check the result of the action -- default_priority no change
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
             self.assertEqual(repo.default_priority, None)
             self.assertEqual(repo.default_priority, None)
 
 
             # Check the behavior if the project disabled the issue tracker
             # Check the behavior if the project disabled the issue tracker
             settings = repo.settings
             settings = repo.settings
-            settings['issue_tracker'] = False
+            settings["issue_tracker"] = False
             repo.settings = settings
             repo.settings = settings
             self.session.add(repo)
             self.session.add(repo)
             self.session.commit()
             self.session.commit()
 
 
-            output = self.app.post(
-                '/test/update/default_priority', data=data)
+            output = self.app.post("/test/update/default_priority", data=data)
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
             # Check for an invalid project
             # Check for an invalid project
-            output = self.app.post(
-                '/foo/update/default_priority', data=data)
+            output = self.app.post("/foo/update/default_priority", data=data)
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
         # Check for a non-admin user
         # Check for a non-admin user
         settings = repo.settings
         settings = repo.settings
-        settings['issue_tracker'] = True
+        settings["issue_tracker"] = True
         repo.settings = settings
         repo.settings = settings
         self.session.add(repo)
         self.session.add(repo)
         self.session.commit()
         self.session.commit()
 
 
-        user.username = 'ralph'
+        user.username = "ralph"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post(
-                '/test/update/default_priority', data=data)
+            output = self.app.post("/test/update/default_priority", data=data)
             self.assertEqual(output.status_code, 403)
             self.assertEqual(output.status_code, 403)
 
 
-    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.git.update_git", MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_default_priority_reset_when_updating_priorities(self):
     def test_default_priority_reset_when_updating_priorities(self):
         """ Test updating the default priority of a repo when updating the
         """ Test updating the default priority of a repo when updating the
         priorities.
         priorities.
         """
         """
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         # Check the default priorities
         # Check the default priorities
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(repo.priorities, {})
         self.assertEqual(repo.priorities, {})
         self.assertEqual(repo.default_priority, None)
         self.assertEqual(repo.default_priority, None)
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             # Set some priorities
             # Set some priorities
             data = {
             data = {
-                'priority_weigth': [1, 2, 3],
-                'priority_title': ['High', 'Normal', 'Low'],
-                'csrf_token': csrf_token,
+                "priority_weigth": [1, 2, 3],
+                "priority_title": ["High", "Normal", "Low"],
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/priorities', data=data, follow_redirects=True)
+                "/test/update/priorities", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             # Check the ordering
             # Check the ordering
             self.assertTrue(
             self.assertTrue(
-                output_text.find('High') < output_text.find('Normal'))
+                output_text.find("High") < output_text.find("Normal")
+            )
             self.assertTrue(
             self.assertTrue(
-                output_text.find('Normal') < output_text.find('Low'))
+                output_text.find("Normal") < output_text.find("Low")
+            )
             # Check the result of the action -- Priority recorded
             # Check the result of the action -- Priority recorded
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
             self.assertEqual(
             self.assertEqual(
                 repo.priorities,
                 repo.priorities,
-                {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
+                {"": "", "1": "High", "2": "Normal", "3": "Low"},
             )
             )
 
 
             # Try setting the default priority
             # Try setting the default priority
-            data = {'priority': 'High', 'csrf_token': csrf_token}
+            data = {"priority": "High", "csrf_token": csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/test/update/default_priority', data=data,
-                follow_redirects=True)
+                "/test/update/default_priority",
+                data=data,
+                follow_redirects=True,
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Default priority set '
-                'to High', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Default priority set " "to High", output_text)
             # Check the result of the action -- default_priority no change
             # Check the result of the action -- default_priority no change
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
-            self.assertEqual(repo.default_priority, 'High')
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
+            self.assertEqual(repo.default_priority, "High")
 
 
             # Remove the Hight priority
             # Remove the Hight priority
             data = {
             data = {
-                'priority_weigth': [1, 2],
-                'priority_title': ['Normal', 'Low'],
-                'csrf_token': csrf_token,
+                "priority_weigth": [1, 2],
+                "priority_title": ["Normal", "Low"],
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/priorities', data=data, follow_redirects=True)
+                "/test/update/priorities", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Priorities updated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Priorities updated", output_text)
             self.assertIn(
             self.assertIn(
-                'Default priority reset '
-                'as it is no longer one of set priorities.',
-                output_text)
+                "Default priority reset "
+                "as it is no longer one of set priorities.",
+                output_text,
+            )
             # Check the ordering
             # Check the ordering
             self.assertTrue(
             self.assertTrue(
-                output_text.find('Normal') < output_text.find('Low'))
+                output_text.find("Normal") < output_text.find("Low")
+            )
             # Check the result of the action -- Priority recorded
             # Check the result of the action -- Priority recorded
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
             self.assertEqual(
             self.assertEqual(
-                repo.priorities,
-                {'': '', '1': 'Normal', '2': 'Low'}
+                repo.priorities, {"": "", "1": "Normal", "2": "Low"}
             )
             )
             # Default priority is now None
             # Default priority is now None
             self.assertIsNone(repo.default_priority)
             self.assertIsNone(repo.default_priority)
 
 
-    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.git.update_git", MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_default_priority_on_new_ticket(self):
     def test_default_priority_on_new_ticket(self):
         """ Test updating the default priority of a repo. """
         """ Test updating the default priority of a repo. """
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         # Set some priority and the default one
         # Set some priority and the default one
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
-        repo.priorities = {'1': 'High', '2': 'Normal'}
-        repo.default_priority = 'Normal'
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
+        repo.priorities = {"1": "High", "2": "Normal"}
+        repo.default_priority = "Normal"
         self.session.add(repo)
         self.session.add(repo)
         self.session.commit()
         self.session.commit()
 
 
         # Check the default priorities
         # Check the default priorities
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
-        self.assertEqual(repo.priorities, {'1': 'High', '2': 'Normal'})
-        self.assertEqual(repo.default_priority, 'Normal')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
+        self.assertEqual(repo.priorities, {"1": "High", "2": "Normal"})
+        self.assertEqual(repo.default_priority, "Normal")
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             data = {
             data = {
-                'title': 'Test issue',
-                'issue_content': 'We really should improve on this issue',
-                'status': 'Open',
-                'csrf_token': csrf_token,
+                "title": "Test issue",
+                "issue_content": "We really should improve on this issue",
+                "status": "Open",
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/new_issue', data=data, follow_redirects=True)
+                "/test/new_issue", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Issue #1: Test issue - test - Pagure</title>',
-                output_text)
+                "<title>Issue #1: Test issue - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 'href="/test/issue/1/edit" title="Edit this issue">',
                 'href="/test/issue/1/edit" title="Edit this issue">',
-                output_text)
+                output_text,
+            )
 
 
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(repo.issues), 1)
         self.assertEqual(len(repo.issues), 1)
         self.assertEqual(repo.issues[0].priority, 2)
         self.assertEqual(repo.issues[0].priority, 2)
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 83 - 82
tests/test_pagure_flask_ui_quick_reply.py

@@ -17,8 +17,9 @@ import unittest
 
 
 import six
 import six
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.model
 import pagure.lib.model
 import pagure.lib.plugins
 import pagure.lib.plugins
@@ -35,19 +36,19 @@ class PagureFlaskQuickReplytest(tests.Modeltests):
         super(PagureFlaskQuickReplytest, self).setUp()
         super(PagureFlaskQuickReplytest, self).setUp()
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
-        self.admin = tests.FakeUser(username='pingou')
-        self.user = tests.FakeUser(username='ralph')
-        self.repo = pagure.lib.query._get_project(self.session, 'test')
+        self.admin = tests.FakeUser(username="pingou")
+        self.user = tests.FakeUser(username="ralph")
+        self.repo = pagure.lib.query._get_project(self.session, "test")
 
 
     def disable_issues_and_pull_requests(self):
     def disable_issues_and_pull_requests(self):
         """Disable both issues and pull requests."""
         """Disable both issues and pull requests."""
         # This can not use direct access as repo.settings is a property that
         # This can not use direct access as repo.settings is a property that
         # serializes data into JSON. Direct modification is not preserved.
         # serializes data into JSON. Direct modification is not preserved.
         settings = self.repo.settings
         settings = self.repo.settings
-        settings['issue_tracker'] = False
-        settings['pull_requests'] = False
+        settings["issue_tracker"] = False
+        settings["pull_requests"] = False
         self.repo.settings = settings
         self.repo.settings = settings
         self.session.add(self.repo)
         self.session.add(self.repo)
         self.session.commit()
         self.session.commit()
@@ -58,17 +59,19 @@ class PagureFlaskQuickReplytest(tests.Modeltests):
         The full replies are stored as r1 and r2 attributes, with shortened
         The full replies are stored as r1 and r2 attributes, with shortened
         versions in sr1 and sr2.
         versions in sr1 and sr2.
         """
         """
-        self.r1 = 'Ship it!'
-        self.r2 = ('Nah. I would prefer if you did not submit this, as there '
-                   'are problems.')
+        self.r1 = "Ship it!"
+        self.r2 = (
+            "Nah. I would prefer if you did not submit this, as there "
+            "are problems."
+        )
         self.sr1 = self.r1
         self.sr1 = self.r1
-        self.sr2 = 'Nah. I would prefer if you did not submit this, as...'
+        self.sr2 = "Nah. I would prefer if you did not submit this, as..."
 
 
         # Set some quick replies
         # Set some quick replies
         self.repo.quick_replies = [self.r1, self.r2]
         self.repo.quick_replies = [self.r1, self.r2]
         self.session.add(self.repo)
         self.session.add(self.repo)
 
 
-    def assertRedirectToSettings(self, output, project='test', notice=None):
+    def assertRedirectToSettings(self, output, project="test", notice=None):
         """
         """
         Check that user was redirected to settings page of a given project
         Check that user was redirected to settings page of a given project
         and that a given notice was printed.
         and that a given notice was printed.
@@ -76,15 +79,17 @@ class PagureFlaskQuickReplytest(tests.Modeltests):
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
-            '<title>Settings - %s - Pagure</title>' % project,
-            output_text)
+            "<title>Settings - %s - Pagure</title>" % project, output_text
+        )
         self.assertIn(
         self.assertIn(
-                '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+            '<h5 class="pl-2 font-weight-bold text-muted">'
+            "Project Settings</h5>\n",
+            output_text,
+        )
         if notice:
         if notice:
             self.assertIn(notice, output_text)
             self.assertIn(notice, output_text)
 
 
-    def assertQuickReplies(self, quick_replies, project='test'):
+    def assertQuickReplies(self, quick_replies, project="test"):
         self.session.commit()
         self.session.commit()
         repo = pagure.lib.query._get_project(self.session, project)
         repo = pagure.lib.query._get_project(self.session, project)
         self.assertEqual(repo.quick_replies, quick_replies)
         self.assertEqual(repo.quick_replies, quick_replies)
@@ -93,84 +98,83 @@ class PagureFlaskQuickReplytest(tests.Modeltests):
         """Assert reply links created by setup_quick_replies are present."""
         """Assert reply links created by setup_quick_replies are present."""
         link = r'data-qr="%s">\s*%s\s*</a>'
         link = r'data-qr="%s">\s*%s\s*</a>'
         six.assertRegex(
         six.assertRegex(
-            self,
-            output.get_data(as_text=True),
-            link % (self.r1, self.sr1))
+            self, output.get_data(as_text=True), link % (self.r1, self.sr1)
+        )
         six.assertRegex(
         six.assertRegex(
-            self,
-            output.get_data(as_text=True),
-            link % (self.r2, self.sr2))
+            self, output.get_data(as_text=True), link % (self.r2, self.sr2)
+        )
 
 
     def test_new_project_has_none(self):
     def test_new_project_has_none(self):
         self.assertQuickReplies([])
         self.assertQuickReplies([])
 
 
     def test_update_quick_reply_without_csrf(self):
     def test_update_quick_reply_without_csrf(self):
         with tests.user_set(self.app.application, self.admin):
         with tests.user_set(self.app.application, self.admin):
-            output = self.app.get('/test/settings')
+            output = self.app.get("/test/settings")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
 
 
-            data = {
-                'quick_reply': 'Ship it!',
-            }
+            data = {"quick_reply": "Ship it!"}
             output = self.app.post(
             output = self.app.post(
-                '/test/update/quick_replies', data=data, follow_redirects=True)
+                "/test/update/quick_replies", data=data, follow_redirects=True
+            )
             self.assertRedirectToSettings(output)
             self.assertRedirectToSettings(output)
             self.assertQuickReplies([])
             self.assertQuickReplies([])
 
 
     def test_update_quick_replies_single(self):
     def test_update_quick_replies_single(self):
         with tests.user_set(self.app.application, self.admin):
         with tests.user_set(self.app.application, self.admin):
-            data = {
-                'quick_reply': 'Ship it!',
-                'csrf_token': self.get_csrf(),
-            }
+            data = {"quick_reply": "Ship it!", "csrf_token": self.get_csrf()}
             output = self.app.post(
             output = self.app.post(
-                '/test/update/quick_replies', data=data, follow_redirects=True)
+                "/test/update/quick_replies", data=data, follow_redirects=True
+            )
             self.assertRedirectToSettings(
             self.assertRedirectToSettings(
-                output, notice='quick replies updated')
-            self.assertQuickReplies(['Ship it!'])
-            self.assertIn('>Ship it!</textarea>', output.get_data(as_text=True))
+                output, notice="quick replies updated"
+            )
+            self.assertQuickReplies(["Ship it!"])
+            self.assertIn(
+                ">Ship it!</textarea>", output.get_data(as_text=True)
+            )
 
 
     def test_update_quick_replies_multiple(self):
     def test_update_quick_replies_multiple(self):
         with tests.user_set(self.app.application, self.admin):
         with tests.user_set(self.app.application, self.admin):
             data = {
             data = {
-                'quick_reply': ['Ship it!', 'Nah.'],
-                'csrf_token': self.get_csrf(),
+                "quick_reply": ["Ship it!", "Nah."],
+                "csrf_token": self.get_csrf(),
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/quick_replies', data=data, follow_redirects=True)
+                "/test/update/quick_replies", data=data, follow_redirects=True
+            )
             self.assertRedirectToSettings(
             self.assertRedirectToSettings(
-                output, notice='quick replies updated')
-            self.assertQuickReplies(['Ship it!', 'Nah.'])
+                output, notice="quick replies updated"
+            )
+            self.assertQuickReplies(["Ship it!", "Nah."])
             # Check page has filled in textarea.
             # Check page has filled in textarea.
-            self.assertIn('>Ship it!</textarea>', output.get_data(as_text=True))
-            self.assertIn('>Nah.</textarea>', output.get_data(as_text=True))
+            self.assertIn(
+                ">Ship it!</textarea>", output.get_data(as_text=True)
+            )
+            self.assertIn(">Nah.</textarea>", output.get_data(as_text=True))
 
 
     def test_update_quick_replies_empty_to_reset(self):
     def test_update_quick_replies_empty_to_reset(self):
         # Set some quick replies
         # Set some quick replies
-        repo = pagure.lib.query._get_project(self.session, 'test')
-        repo.quick_replies = ['Ship it!', 'Nah.']
+        repo = pagure.lib.query._get_project(self.session, "test")
+        repo.quick_replies = ["Ship it!", "Nah."]
         self.session.add(repo)
         self.session.add(repo)
         self.session.commit()
         self.session.commit()
 
 
         with tests.user_set(self.app.application, self.admin):
         with tests.user_set(self.app.application, self.admin):
-            data = {
-                'quick_reply': [],
-                'csrf_token': self.get_csrf(),
-            }
+            data = {"quick_reply": [], "csrf_token": self.get_csrf()}
             output = self.app.post(
             output = self.app.post(
-                '/test/update/quick_replies', data=data, follow_redirects=True)
+                "/test/update/quick_replies", data=data, follow_redirects=True
+            )
             self.assertRedirectToSettings(
             self.assertRedirectToSettings(
-                output, notice='quick replies updated')
+                output, notice="quick replies updated"
+            )
             self.assertQuickReplies([])
             self.assertQuickReplies([])
 
 
     def test_update_quick_replies_unprivileged(self):
     def test_update_quick_replies_unprivileged(self):
         with tests.user_set(self.app.application, self.user):
         with tests.user_set(self.app.application, self.user):
-            data = {
-                'quick_reply': 'Ship it!',
-                'csrf_token': 'a guess',
-            }
+            data = {"quick_reply": "Ship it!", "csrf_token": "a guess"}
             output = self.app.post(
             output = self.app.post(
-                '/test/update/quick_replies', data=data, follow_redirects=True)
+                "/test/update/quick_replies", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 403)
             self.assertEqual(output.status_code, 403)
             self.assertQuickReplies([])
             self.assertQuickReplies([])
 
 
@@ -178,53 +182,49 @@ class PagureFlaskQuickReplytest(tests.Modeltests):
         self.disable_issues_and_pull_requests()
         self.disable_issues_and_pull_requests()
 
 
         with tests.user_set(self.app.application, self.admin):
         with tests.user_set(self.app.application, self.admin):
-            output = self.app.get('/test/settings')
-            self.assertNotIn('Quick replies', output.get_data(as_text=True))
+            output = self.app.get("/test/settings")
+            self.assertNotIn("Quick replies", output.get_data(as_text=True))
 
 
     def test_no_submit_with_disabled_issues_and_pull_requests(self):
     def test_no_submit_with_disabled_issues_and_pull_requests(self):
         self.disable_issues_and_pull_requests()
         self.disable_issues_and_pull_requests()
 
 
         with tests.user_set(self.app.application, self.admin):
         with tests.user_set(self.app.application, self.admin):
-            data = {
-                'quick_reply': 'Ship it!',
-                'csrf_token': 'a guess',
-            }
+            data = {"quick_reply": "Ship it!", "csrf_token": "a guess"}
             output = self.app.post(
             output = self.app.post(
-                '/test/update/quick_replies', data=data, follow_redirects=True)
+                "/test/update/quick_replies", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
             self.assertQuickReplies([])
             self.assertQuickReplies([])
 
 
     def test_submit_for_bad_project(self):
     def test_submit_for_bad_project(self):
         with tests.user_set(self.app.application, self.admin):
         with tests.user_set(self.app.application, self.admin):
-            data = {
-                'quick_reply': 'Ship it!',
-                'csrf_token': 'a guess',
-            }
+            data = {"quick_reply": "Ship it!", "csrf_token": "a guess"}
             output = self.app.post(
             output = self.app.post(
-                '/boom/update/quick_replies', data=data, follow_redirects=True)
+                "/boom/update/quick_replies", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
-    @mock.patch('pagure.lib.git.update_git')
+    @mock.patch("pagure.lib.git.update_git")
     def test_issue_page_has_quick_replies(self, p_ugt):
     def test_issue_page_has_quick_replies(self, p_ugt):
         self.setup_quick_replies()
         self.setup_quick_replies()
 
 
         issue = pagure.lib.query.new_issue(
         issue = pagure.lib.query.new_issue(
             self.session,
             self.session,
             self.repo,
             self.repo,
-            'Dummy issue',
-            'Just a lonely issue.',
-            'pingou',
+            "Dummy issue",
+            "Just a lonely issue.",
+            "pingou",
             None,
             None,
-            notify=False
+            notify=False,
         )
         )
 
 
         with tests.user_set(self.app.application, self.user):
         with tests.user_set(self.app.application, self.user):
-            output = self.app.get('/test/issue/%s' % issue.id)
+            output = self.app.get("/test/issue/%s" % issue.id)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertQuickReplyLinks(output)
             self.assertQuickReplyLinks(output)
 
 
-    @mock.patch('pagure.lib.git.update_git')
-    @mock.patch('pagure.lib.git.diff_pull_request')
+    @mock.patch("pagure.lib.git.update_git")
+    @mock.patch("pagure.lib.git.diff_pull_request")
     def test_pull_request_page_has_quick_replies(self, diff, p_ugt):
     def test_pull_request_page_has_quick_replies(self, diff, p_ugt):
         diff.return_value = ([], [])
         diff.return_value = ([], [])
 
 
@@ -232,20 +232,21 @@ class PagureFlaskQuickReplytest(tests.Modeltests):
 
 
         pr = pagure.lib.query.new_pull_request(
         pr = pagure.lib.query.new_pull_request(
             self.session,
             self.session,
-            'pr',
+            "pr",
             self.repo,
             self.repo,
-            'master',
-            'Dummy PR', 'pingou',
+            "master",
+            "Dummy PR",
+            "pingou",
             None,
             None,
             repo_from=self.repo,
             repo_from=self.repo,
             notify=False,
             notify=False,
         )
         )
 
 
         with tests.user_set(self.app.application, self.user):
         with tests.user_set(self.app.application, self.user):
-            output = self.app.get('/test/pull-request/%s' % pr.id)
+            output = self.app.get("/test/pull-request/%s" % pr.id)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertQuickReplyLinks(output)
             self.assertQuickReplyLinks(output)
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 275 - 235
tests/test_pagure_flask_ui_remote_pr.py

@@ -24,8 +24,9 @@ import wtforms
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 from bs4 import BeautifulSoup
 from bs4 import BeautifulSoup
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import tests
 import tests
@@ -40,87 +41,84 @@ class PagureRemotePRtests(tests.Modeltests):
         """ Set up the environment. """
         """ Set up the environment. """
         super(PagureRemotePRtests, self).setUp()
         super(PagureRemotePRtests, self).setUp()
 
 
-        self.newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
-        self.old_value = pagure.config.config['REMOTE_GIT_FOLDER']
-        pagure.config.config['REMOTE_GIT_FOLDER'] = os.path.join(
-            self.path, 'remotes')
+        self.newpath = tempfile.mkdtemp(prefix="pagure-fork-test")
+        self.old_value = pagure.config.config["REMOTE_GIT_FOLDER"]
+        pagure.config.config["REMOTE_GIT_FOLDER"] = os.path.join(
+            self.path, "remotes"
+        )
 
 
     def tearDown(self):
     def tearDown(self):
         """ Clear things up. """
         """ Clear things up. """
         super(PagureRemotePRtests, self).tearDown()
         super(PagureRemotePRtests, self).tearDown()
 
 
-        pagure.config.config['REMOTE_GIT_FOLDER'] = self.old_value
+        pagure.config.config["REMOTE_GIT_FOLDER"] = self.old_value
         shutil.rmtree(self.newpath)
         shutil.rmtree(self.newpath)
 
 
-    def set_up_git_repo(self, new_project=None, branch_from='feature'):
+    def set_up_git_repo(self, new_project=None, branch_from="feature"):
         """ Set up the git repo and create the corresponding PullRequest
         """ Set up the git repo and create the corresponding PullRequest
         object.
         object.
         """
         """
 
 
         # Create a git repo to play with
         # Create a git repo to play with
-        gitrepo = os.path.join(self.path, 'repos', 'test.git')
+        gitrepo = os.path.join(self.path, "repos", "test.git")
         repo = pygit2.init_repository(gitrepo, bare=True)
         repo = pygit2.init_repository(gitrepo, bare=True)
 
 
-        repopath = os.path.join(self.newpath, 'test')
+        repopath = os.path.join(self.newpath, "test")
         clone_repo = pygit2.clone_repository(gitrepo, repopath)
         clone_repo = pygit2.clone_repository(gitrepo, repopath)
 
 
         # Create a file in that git repo
         # Create a file in that git repo
-        with open(os.path.join(repopath, 'sources'), 'w') as stream:
-            stream.write('foo\n bar')
-        clone_repo.index.add('sources')
+        with open(os.path.join(repopath, "sources"), "w") as stream:
+            stream.write("foo\n bar")
+        clone_repo.index.add("sources")
         clone_repo.index.write()
         clone_repo.index.write()
 
 
         try:
         try:
-            com = repo.revparse_single('HEAD')
+            com = repo.revparse_single("HEAD")
             prev_commit = [com.oid.hex]
             prev_commit = [com.oid.hex]
         except:
         except:
             prev_commit = []
             prev_commit = []
 
 
         # Commits the files added
         # Commits the files added
         tree = clone_repo.index.write_tree()
         tree = clone_repo.index.write_tree()
-        author = _make_signature(
-            'Alice Author', 'alice@authors.tld')
-        committer = _make_signature(
-            'Cecil Committer', 'cecil@committers.tld')
+        author = _make_signature("Alice Author", "alice@authors.tld")
+        committer = _make_signature("Cecil Committer", "cecil@committers.tld")
         clone_repo.create_commit(
         clone_repo.create_commit(
-            'refs/heads/master',  # the name of the reference to update
+            "refs/heads/master",  # the name of the reference to update
             author,
             author,
             committer,
             committer,
-            'Add sources file for testing',
+            "Add sources file for testing",
             # binary string representing the tree object ID
             # binary string representing the tree object ID
             tree,
             tree,
             # list of binary strings representing parents of the new commit
             # list of binary strings representing parents of the new commit
-            prev_commit
+            prev_commit,
         )
         )
         # time.sleep(1)
         # time.sleep(1)
-        refname = 'refs/heads/master:refs/heads/master'
+        refname = "refs/heads/master:refs/heads/master"
         ori_remote = clone_repo.remotes[0]
         ori_remote = clone_repo.remotes[0]
         PagureRepo.push(ori_remote, refname)
         PagureRepo.push(ori_remote, refname)
 
 
-        first_commit = repo.revparse_single('HEAD')
+        first_commit = repo.revparse_single("HEAD")
 
 
-        with open(os.path.join(repopath, '.gitignore'), 'w') as stream:
-            stream.write('*~')
-        clone_repo.index.add('.gitignore')
+        with open(os.path.join(repopath, ".gitignore"), "w") as stream:
+            stream.write("*~")
+        clone_repo.index.add(".gitignore")
         clone_repo.index.write()
         clone_repo.index.write()
 
 
         # Commits the files added
         # Commits the files added
         tree = clone_repo.index.write_tree()
         tree = clone_repo.index.write_tree()
-        author = _make_signature(
-            'Alice Äuthòr', 'alice@äuthòrs.tld')
-        committer = _make_signature(
-            'Cecil Cõmmîttër', 'cecil@cõmmîttërs.tld')
+        author = _make_signature("Alice Äuthòr", "alice@äuthòrs.tld")
+        committer = _make_signature("Cecil Cõmmîttër", "cecil@cõmmîttërs.tld")
         clone_repo.create_commit(
         clone_repo.create_commit(
-            'refs/heads/master',
+            "refs/heads/master",
             author,
             author,
             committer,
             committer,
-            'Add .gitignore file for testing',
+            "Add .gitignore file for testing",
             # binary string representing the tree object ID
             # binary string representing the tree object ID
             tree,
             tree,
             # list of binary strings representing parents of the new commit
             # list of binary strings representing parents of the new commit
-            [first_commit.oid.hex]
+            [first_commit.oid.hex],
         )
         )
-        refname = 'refs/heads/master:refs/heads/master'
+        refname = "refs/heads/master:refs/heads/master"
         ori_remote = clone_repo.remotes[0]
         ori_remote = clone_repo.remotes[0]
         PagureRepo.push(ori_remote, refname)
         PagureRepo.push(ori_remote, refname)
 
 
@@ -137,312 +135,340 @@ class PagureRemotePRtests(tests.Modeltests):
         repo = pygit2.Repository(new_gitrepo)
         repo = pygit2.Repository(new_gitrepo)
 
 
         # Edit the sources file again
         # Edit the sources file again
-        with open(os.path.join(new_gitrepo, 'sources'), 'w') as stream:
-            stream.write('foo\n bar\nbaz\n boose')
-        repo.index.add('sources')
+        with open(os.path.join(new_gitrepo, "sources"), "w") as stream:
+            stream.write("foo\n bar\nbaz\n boose")
+        repo.index.add("sources")
         repo.index.write()
         repo.index.write()
 
 
         # Commits the files added
         # Commits the files added
         tree = repo.index.write_tree()
         tree = repo.index.write_tree()
-        author = _make_signature(
-            'Alice Author', 'alice@authors.tld')
-        committer = _make_signature(
-            'Cecil Committer', 'cecil@committers.tld')
+        author = _make_signature("Alice Author", "alice@authors.tld")
+        committer = _make_signature("Cecil Committer", "cecil@committers.tld")
         repo.create_commit(
         repo.create_commit(
-            'refs/heads/%s' % branch_from,
+            "refs/heads/%s" % branch_from,
             author,
             author,
             committer,
             committer,
-            'A commit on branch %s' % branch_from,
+            "A commit on branch %s" % branch_from,
             tree,
             tree,
-            [first_commit.oid.hex]
+            [first_commit.oid.hex],
         )
         )
-        refname = 'refs/heads/%s' % (branch_from)
+        refname = "refs/heads/%s" % (branch_from)
         ori_remote = repo.remotes[0]
         ori_remote = repo.remotes[0]
         PagureRepo.push(ori_remote, refname)
         PagureRepo.push(ori_remote, refname)
 
 
-    @patch('pagure.lib.notify.send_email',  MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_new_remote_pr_unauth(self):
     def test_new_remote_pr_unauth(self):
         """ Test creating a new remote PR un-authenticated. """
         """ Test creating a new remote PR un-authenticated. """
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         tests.create_projects_git(
         tests.create_projects_git(
-            os.path.join(self.path, 'requests'), bare=True)
+            os.path.join(self.path, "requests"), bare=True
+        )
         self.set_up_git_repo()
         self.set_up_git_repo()
 
 
         # Before
         # Before
-        project = pagure.lib.query.get_authorized_project(self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(project.requests), 0)
         self.assertEqual(len(project.requests), 0)
 
 
         # Try creating a remote PR
         # Try creating a remote PR
-        output = self.app.get('/test/diff/remote')
+        output = self.app.get("/test/diff/remote")
         self.assertEqual(output.status_code, 302)
         self.assertEqual(output.status_code, 302)
         self.assertIn(
         self.assertIn(
-            'You should be redirected automatically to target URL: '
-            '<a href="/login/?', output.get_data(as_text=True))
+            "You should be redirected automatically to target URL: "
+            '<a href="/login/?',
+            output.get_data(as_text=True),
+        )
 
 
-    @patch('pagure.lib.notify.send_email',  MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_new_remote_pr_auth(self):
     def test_new_remote_pr_auth(self):
         """ Test creating a new remote PR authenticated. """
         """ Test creating a new remote PR authenticated. """
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         tests.create_projects_git(
         tests.create_projects_git(
-            os.path.join(self.path, 'requests'), bare=True)
+            os.path.join(self.path, "requests"), bare=True
+        )
         self.set_up_git_repo()
         self.set_up_git_repo()
 
 
         # Before
         # Before
         self.session = pagure.lib.query.create_session(self.dbpath)
         self.session = pagure.lib.query.create_session(self.dbpath)
-        project = pagure.lib.query.get_authorized_project(self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(project.requests), 0)
         self.assertEqual(len(project.requests), 0)
 
 
         # Try creating a remote PR
         # Try creating a remote PR
-        user = tests.FakeUser(username='foo')
+        user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/diff/remote')
+            output = self.app.get("/test/diff/remote")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                '<h2>New remote pull-request</h2>',
-                output.get_data(as_text=True))
+                "<h2>New remote pull-request</h2>",
+                output.get_data(as_text=True),
+            )
 
 
             csrf_token = self.get_csrf(output=output)
             csrf_token = self.get_csrf(output=output)
             with patch(
             with patch(
-                    'pagure.forms.RemoteRequestPullForm.git_repo.args',
-                    MagicMock(return_value=(
-                        u'Git Repo address',
-                        [wtforms.validators.DataRequired()]))):
+                "pagure.forms.RemoteRequestPullForm.git_repo.args",
+                MagicMock(
+                    return_value=(
+                        "Git Repo address",
+                        [wtforms.validators.DataRequired()],
+                    )
+                ),
+            ):
                 data = {
                 data = {
-                    'csrf_token': csrf_token,
-                    'title': 'Remote PR title',
-                    'branch_from': 'feature',
-                    'branch_to': 'master',
-                    'git_repo': os.path.join(self.newpath, 'test'),
+                    "csrf_token": csrf_token,
+                    "title": "Remote PR title",
+                    "branch_from": "feature",
+                    "branch_to": "master",
+                    "git_repo": os.path.join(self.newpath, "test"),
                 }
                 }
-                output = self.app.post('/test/diff/remote', data=data)
+                output = self.app.post("/test/diff/remote", data=data)
                 self.assertEqual(output.status_code, 200)
                 self.assertEqual(output.status_code, 200)
                 output_text = output.get_data(as_text=True)
                 output_text = output.get_data(as_text=True)
-                self.assertIn('Create Pull Request\n    </div>\n', output_text)
-                self.assertIn(
-                    '<div class="card mb-3" id="_1">\n', output_text)
-                self.assertIn(
-                    '<div class="card mb-3" id="_2">\n', output_text)
+                self.assertIn("Create Pull Request\n    </div>\n", output_text)
+                self.assertIn('<div class="card mb-3" id="_1">\n', output_text)
+                self.assertIn('<div class="card mb-3" id="_2">\n', output_text)
                 self.assertNotIn(
                 self.assertNotIn(
-                    '<div class="card mb-3" id="_3">\n', output_text)
+                    '<div class="card mb-3" id="_3">\n', output_text
+                )
 
 
                 # Not saved yet
                 # Not saved yet
                 self.session = pagure.lib.query.create_session(self.dbpath)
                 self.session = pagure.lib.query.create_session(self.dbpath)
-                project = pagure.lib.query.get_authorized_project(self.session, 'test')
+                project = pagure.lib.query.get_authorized_project(
+                    self.session, "test"
+                )
                 self.assertEqual(len(project.requests), 0)
                 self.assertEqual(len(project.requests), 0)
 
 
                 data = {
                 data = {
-                    'csrf_token': csrf_token,
-                    'title': 'Remote PR title',
-                    'branch_from': 'feature',
-                    'branch_to': 'master',
-                    'git_repo': os.path.join(self.newpath, 'test'),
-                    'confirm': 1,
+                    "csrf_token": csrf_token,
+                    "title": "Remote PR title",
+                    "branch_from": "feature",
+                    "branch_to": "master",
+                    "git_repo": os.path.join(self.newpath, "test"),
+                    "confirm": 1,
                 }
                 }
-                self.old_value = pagure.config.config['DISABLE_REMOTE_PR']
-                pagure.config.config['DISABLE_REMOTE_PR'] = True
+                self.old_value = pagure.config.config["DISABLE_REMOTE_PR"]
+                pagure.config.config["DISABLE_REMOTE_PR"] = True
                 output = self.app.post(
                 output = self.app.post(
-                    '/test/diff/remote', data=data, follow_redirects=True)
+                    "/test/diff/remote", data=data, follow_redirects=True
+                )
                 self.assertEqual(output.status_code, 404)
                 self.assertEqual(output.status_code, 404)
-                pagure.config.config['DISABLE_REMOTE_PR'] = self.old_value
+                pagure.config.config["DISABLE_REMOTE_PR"] = self.old_value
                 output = self.app.post(
                 output = self.app.post(
-                    '/test/diff/remote', data=data, follow_redirects=True)
+                    "/test/diff/remote", data=data, follow_redirects=True
+                )
                 self.assertEqual(output.status_code, 200)
                 self.assertEqual(output.status_code, 200)
                 output_text = output.get_data(as_text=True)
                 output_text = output.get_data(as_text=True)
                 self.assertIn(
                 self.assertIn(
                     '<span class="text-success font-weight-bold">#1',
                     '<span class="text-success font-weight-bold">#1',
-                    output_text)
-                self.assertIn(
-                    '<div class="card mb-3" id="_1">\n', output_text)
-                self.assertIn(
-                    '<div class="card mb-3" id="_2">\n', output_text)
+                    output_text,
+                )
+                self.assertIn('<div class="card mb-3" id="_1">\n', output_text)
+                self.assertIn('<div class="card mb-3" id="_2">\n', output_text)
                 self.assertNotIn(
                 self.assertNotIn(
-                    '<div class="card mb-3" id="_3">\n', output_text)
+                    '<div class="card mb-3" id="_3">\n', output_text
+                )
 
 
                 # Show the filename in the Changes summary
                 # Show the filename in the Changes summary
                 self.assertIn(
                 self.assertIn(
-                    '<a href="#_1" class="list-group-item', output_text)
+                    '<a href="#_1" class="list-group-item', output_text
+                )
                 self.assertIn(
                 self.assertIn(
                     '<div class="ellipsis pr-changes-description">'
                     '<div class="ellipsis pr-changes-description">'
-                    '\n          <small>.gitignore</small>', output_text)
+                    "\n          <small>.gitignore</small>",
+                    output_text,
+                )
                 self.assertIn(
                 self.assertIn(
-                    '<a href="#_2" class="list-group-item', output_text)
+                    '<a href="#_2" class="list-group-item', output_text
+                )
                 self.assertIn(
                 self.assertIn(
                     '<div class="ellipsis pr-changes-description">'
                     '<div class="ellipsis pr-changes-description">'
-                    '\n          <small>sources</small>', output_text)
+                    "\n          <small>sources</small>",
+                    output_text,
+                )
 
 
         # Remote PR Created
         # Remote PR Created
         self.session = pagure.lib.query.create_session(self.dbpath)
         self.session = pagure.lib.query.create_session(self.dbpath)
-        project = pagure.lib.query.get_authorized_project(self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(project.requests), 1)
         self.assertEqual(len(project.requests), 1)
 
 
-    @patch('pagure.lib.notify.send_email',  MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_new_remote_no_title(self):
     def test_new_remote_no_title(self):
         """ Test creating a new remote PR authenticated when no title is
         """ Test creating a new remote PR authenticated when no title is
         specified. """
         specified. """
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         tests.create_projects_git(
         tests.create_projects_git(
-            os.path.join(self.path, 'requests'), bare=True)
+            os.path.join(self.path, "requests"), bare=True
+        )
         self.set_up_git_repo()
         self.set_up_git_repo()
 
 
         # Before
         # Before
         self.session = pagure.lib.query.create_session(self.dbpath)
         self.session = pagure.lib.query.create_session(self.dbpath)
-        project = pagure.lib.query.get_authorized_project(self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(project.requests), 0)
         self.assertEqual(len(project.requests), 0)
 
 
         # Try creating a remote PR
         # Try creating a remote PR
-        user = tests.FakeUser(username='foo')
+        user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/diff/remote')
+            output = self.app.get("/test/diff/remote")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                '<h2>New remote pull-request</h2>',
-                output.get_data(as_text=True))
+                "<h2>New remote pull-request</h2>",
+                output.get_data(as_text=True),
+            )
 
 
             csrf_token = self.get_csrf(output=output)
             csrf_token = self.get_csrf(output=output)
             with patch(
             with patch(
-                    'pagure.forms.RemoteRequestPullForm.git_repo.args',
-                    MagicMock(return_value=(
-                        u'Git Repo address',
-                        [wtforms.validators.DataRequired()]))):
+                "pagure.forms.RemoteRequestPullForm.git_repo.args",
+                MagicMock(
+                    return_value=(
+                        "Git Repo address",
+                        [wtforms.validators.DataRequired()],
+                    )
+                ),
+            ):
                 data = {
                 data = {
-                    'csrf_token': csrf_token,
-                    'branch_from': 'master',
-                    'branch_to': 'feature',
-                    'git_repo': os.path.join(self.newpath, 'test'),
+                    "csrf_token": csrf_token,
+                    "branch_from": "master",
+                    "branch_to": "feature",
+                    "git_repo": os.path.join(self.newpath, "test"),
                 }
                 }
-                output = self.app.post('/test/diff/remote', data=data)
+                output = self.app.post("/test/diff/remote", data=data)
                 self.assertEqual(output.status_code, 200)
                 self.assertEqual(output.status_code, 200)
                 output_text = output.get_data(as_text=True)
                 output_text = output.get_data(as_text=True)
-                self.assertIn(
-                    '<h2>New remote pull-request</h2>', output_text)
-                self.assertIn(
-                    '<option selected>feature</option>', output_text)
+                self.assertIn("<h2>New remote pull-request</h2>", output_text)
+                self.assertIn("<option selected>feature</option>", output_text)
 
 
-    @patch('pagure.lib.notify.send_email',  MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_new_remote_pr_empty_target(self):
     def test_new_remote_pr_empty_target(self):
         """ Test creating a new remote PR authenticated against an empty
         """ Test creating a new remote PR authenticated against an empty
         git repo. """
         git repo. """
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         tests.create_projects_git(
         tests.create_projects_git(
-            os.path.join(self.path, 'requests'), bare=True)
+            os.path.join(self.path, "requests"), bare=True
+        )
 
 
         # Create empty target git repo
         # Create empty target git repo
-        gitrepo = os.path.join(self.path, 'repos', 'test.git')
+        gitrepo = os.path.join(self.path, "repos", "test.git")
         pygit2.init_repository(gitrepo, bare=True)
         pygit2.init_repository(gitrepo, bare=True)
 
 
         # Create git repo we'll pull from
         # Create git repo we'll pull from
-        gitrepo = os.path.join(self.path, 'repos', 'test_origin.git')
+        gitrepo = os.path.join(self.path, "repos", "test_origin.git")
         repo = pygit2.init_repository(gitrepo)
         repo = pygit2.init_repository(gitrepo)
 
 
         # Create a file in that git repo
         # Create a file in that git repo
-        with open(os.path.join(gitrepo, 'sources'), 'w') as stream:
-            stream.write('foo\n bar')
-        repo.index.add('sources')
+        with open(os.path.join(gitrepo, "sources"), "w") as stream:
+            stream.write("foo\n bar")
+        repo.index.add("sources")
         repo.index.write()
         repo.index.write()
 
 
         prev_commit = []
         prev_commit = []
 
 
         # Commits the files added
         # Commits the files added
         tree = repo.index.write_tree()
         tree = repo.index.write_tree()
-        author = _make_signature(
-            'Alice Author', 'alice@authors.tld')
-        committer = _make_signature(
-            'Cecil Committer', 'cecil@committers.tld')
+        author = _make_signature("Alice Author", "alice@authors.tld")
+        committer = _make_signature("Cecil Committer", "cecil@committers.tld")
         repo.create_commit(
         repo.create_commit(
-            'refs/heads/feature',  # the name of the reference to update
+            "refs/heads/feature",  # the name of the reference to update
             author,
             author,
             committer,
             committer,
-            'Add sources file for testing',
+            "Add sources file for testing",
             # binary string representing the tree object ID
             # binary string representing the tree object ID
             tree,
             tree,
             # list of binary strings representing parents of the new commit
             # list of binary strings representing parents of the new commit
-            prev_commit
+            prev_commit,
         )
         )
 
 
         # Before
         # Before
         self.session = pagure.lib.query.create_session(self.dbpath)
         self.session = pagure.lib.query.create_session(self.dbpath)
-        project = pagure.lib.query.get_authorized_project(self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(project.requests), 0)
         self.assertEqual(len(project.requests), 0)
 
 
         # Try creating a remote PR
         # Try creating a remote PR
-        user = tests.FakeUser(username='foo')
+        user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/diff/remote')
+            output = self.app.get("/test/diff/remote")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                '<h2>New remote pull-request</h2>',
-                output.get_data(as_text=True))
+                "<h2>New remote pull-request</h2>",
+                output.get_data(as_text=True),
+            )
 
 
             csrf_token = self.get_csrf(output=output)
             csrf_token = self.get_csrf(output=output)
 
 
             with patch(
             with patch(
-                    'pagure.forms.RemoteRequestPullForm.git_repo.args',
-                    MagicMock(return_value=(
-                        u'Git Repo address',
-                        [wtforms.validators.DataRequired()]))):
+                "pagure.forms.RemoteRequestPullForm.git_repo.args",
+                MagicMock(
+                    return_value=(
+                        "Git Repo address",
+                        [wtforms.validators.DataRequired()],
+                    )
+                ),
+            ):
                 data = {
                 data = {
-                    'csrf_token': csrf_token,
-                    'title': 'Remote PR title',
-                    'branch_from': 'feature',
-                    'branch_to': 'master',
-                    'git_repo': gitrepo,
+                    "csrf_token": csrf_token,
+                    "title": "Remote PR title",
+                    "branch_from": "feature",
+                    "branch_to": "master",
+                    "git_repo": gitrepo,
                 }
                 }
-                output = self.app.post('/test/diff/remote', data=data)
+                output = self.app.post("/test/diff/remote", data=data)
                 self.assertEqual(output.status_code, 200)
                 self.assertEqual(output.status_code, 200)
                 output_text = output.get_data(as_text=True)
                 output_text = output.get_data(as_text=True)
-                self.assertIn('Create Pull Request\n    </div>\n', output_text)
-                self.assertIn(
-                    '<div class="card mb-3" id="_1">\n', output_text)
+                self.assertIn("Create Pull Request\n    </div>\n", output_text)
+                self.assertIn('<div class="card mb-3" id="_1">\n', output_text)
                 self.assertNotIn(
                 self.assertNotIn(
-                    '<div class="card mb-3" id="_2">\n', output_text)
+                    '<div class="card mb-3" id="_2">\n', output_text
+                )
 
 
                 # Not saved yet
                 # Not saved yet
                 self.session = pagure.lib.query.create_session(self.dbpath)
                 self.session = pagure.lib.query.create_session(self.dbpath)
-                project = pagure.lib.query.get_authorized_project(self.session, 'test')
+                project = pagure.lib.query.get_authorized_project(
+                    self.session, "test"
+                )
                 self.assertEqual(len(project.requests), 0)
                 self.assertEqual(len(project.requests), 0)
 
 
                 data = {
                 data = {
-                    'csrf_token': csrf_token,
-                    'title': 'Remote PR title',
-                    'branch_from': 'feature',
-                    'branch_to': 'master',
-                    'git_repo': gitrepo,
-                    'confirm': 1,
+                    "csrf_token": csrf_token,
+                    "title": "Remote PR title",
+                    "branch_from": "feature",
+                    "branch_to": "master",
+                    "git_repo": gitrepo,
+                    "confirm": 1,
                 }
                 }
                 output = self.app.post(
                 output = self.app.post(
-                    '/test/diff/remote', data=data, follow_redirects=True)
+                    "/test/diff/remote", data=data, follow_redirects=True
+                )
                 self.assertEqual(output.status_code, 200)
                 self.assertEqual(output.status_code, 200)
                 output_text = output.get_data(as_text=True)
                 output_text = output.get_data(as_text=True)
                 self.assertIn(
                 self.assertIn(
-                    '<title>PR#1: Remote PR title - test\n - Pagure</title>',
-                    output_text)
-                self.assertIn(
-                    '<div class="card mb-3" id="_1">\n', output_text)
+                    "<title>PR#1: Remote PR title - test\n - Pagure</title>",
+                    output_text,
+                )
+                self.assertIn('<div class="card mb-3" id="_1">\n', output_text)
                 self.assertNotIn(
                 self.assertNotIn(
-                    '<div class="card mb-3" id="_2">\n', output_text)
+                    '<div class="card mb-3" id="_2">\n', output_text
+                )
 
 
                 # Show the filename in the Changes summary
                 # Show the filename in the Changes summary
                 self.assertIn(
                 self.assertIn(
-                    '<a href="#_1" class="list-group-item', output_text)
+                    '<a href="#_1" class="list-group-item', output_text
+                )
                 self.assertIn(
                 self.assertIn(
                     '<div class="ellipsis pr-changes-description">'
                     '<div class="ellipsis pr-changes-description">'
-                    '\n          <small>sources</small>', output_text)
+                    "\n          <small>sources</small>",
+                    output_text,
+                )
 
 
         # Remote PR Created
         # Remote PR Created
         self.session = pagure.lib.query.create_session(self.dbpath)
         self.session = pagure.lib.query.create_session(self.dbpath)
-        project = pagure.lib.query.get_authorized_project(self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(project.requests), 1)
         self.assertEqual(len(project.requests), 1)
 
 
         # Check the merge state of the PR
         # Check the merge state of the PR
-        data = {
-            'csrf_token': csrf_token,
-            'requestid': project.requests[0].uid,
-        }
-        output = self.app.post('/pv/pull-request/merge', data=data)
+        data = {"csrf_token": csrf_token, "requestid": project.requests[0].uid}
+        output = self.app.post("/pv/pull-request/merge", data=data)
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         data = json.loads(output_text)
         data = json.loads(output_text)
@@ -451,157 +477,171 @@ class PagureRemotePRtests(tests.Modeltests):
             {
             {
                 "code": "FFORWARD",
                 "code": "FFORWARD",
                 "message": "The pull-request can be merged and fast-forwarded",
                 "message": "The pull-request can be merged and fast-forwarded",
-                "short_code": "Ok"
-            }
+                "short_code": "Ok",
+            },
         )
         )
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             # Merge the PR
             # Merge the PR
-            data = {
-                'csrf_token': csrf_token,
-            }
+            data = {"csrf_token": csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/test/pull-request/1/merge', data=data, follow_redirects=True)
+                "/test/pull-request/1/merge", data=data, follow_redirects=True
+            )
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                '<title>Overview - test - Pagure</title>', output_text
+                "<title>Overview - test - Pagure</title>", output_text
             )
             )
 
 
-    @patch('pagure.lib.notify.send_email',  MagicMock(return_value=True))
-    @patch('pagure.lib.tasks_services.trigger_ci_build')
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
+    @patch("pagure.lib.tasks_services.trigger_ci_build")
     def test_new_remote_pr_ci_off(self, trigger_ci):
     def test_new_remote_pr_ci_off(self, trigger_ci):
         """ Test creating a new remote PR when CI is not configured. """
         """ Test creating a new remote PR when CI is not configured. """
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         tests.create_projects_git(
         tests.create_projects_git(
-            os.path.join(self.path, 'requests'), bare=True)
+            os.path.join(self.path, "requests"), bare=True
+        )
         self.set_up_git_repo()
         self.set_up_git_repo()
 
 
         # Before
         # Before
         self.session = pagure.lib.query.create_session(self.dbpath)
         self.session = pagure.lib.query.create_session(self.dbpath)
-        project = pagure.lib.query.get_authorized_project(self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(project.requests), 0)
         self.assertEqual(len(project.requests), 0)
 
 
         # Create a remote PR
         # Create a remote PR
-        user = tests.FakeUser(username='foo')
+        user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
             data = {
             data = {
-                'csrf_token': csrf_token,
-                'title': 'Remote PR title',
-                'branch_from': 'feature',
-                'branch_to': 'master',
-                'git_repo': os.path.join(self.newpath, 'test'),
+                "csrf_token": csrf_token,
+                "title": "Remote PR title",
+                "branch_from": "feature",
+                "branch_to": "master",
+                "git_repo": os.path.join(self.newpath, "test"),
             }
             }
             with patch(
             with patch(
-                    'pagure.forms.RemoteRequestPullForm.git_repo.args',
-                    MagicMock(return_value=(
-                        u'Git Repo address',
-                        [wtforms.validators.DataRequired()]))):
+                "pagure.forms.RemoteRequestPullForm.git_repo.args",
+                MagicMock(
+                    return_value=(
+                        "Git Repo address",
+                        [wtforms.validators.DataRequired()],
+                    )
+                ),
+            ):
 
 
                 output = self.app.post(
                 output = self.app.post(
-                    '/test/diff/remote', data=data, follow_redirects=True)
+                    "/test/diff/remote", data=data, follow_redirects=True
+                )
                 self.assertEqual(output.status_code, 200)
                 self.assertEqual(output.status_code, 200)
 
 
-                data['confirm'] = 1
+                data["confirm"] = 1
                 output = self.app.post(
                 output = self.app.post(
-                    '/test/diff/remote', data=data, follow_redirects=True)
+                    "/test/diff/remote", data=data, follow_redirects=True
+                )
                 self.assertEqual(output.status_code, 200)
                 self.assertEqual(output.status_code, 200)
                 output_text = output.get_data(as_text=True)
                 output_text = output.get_data(as_text=True)
                 self.assertIn(
                 self.assertIn(
                     '<span class="text-success font-weight-bold">#1',
                     '<span class="text-success font-weight-bold">#1',
-                    output_text)
-                self.assertIn(
-                    '<div class="card mb-3" id="_1">\n', output_text)
-                self.assertIn(
-                    '<div class="card mb-3" id="_2">\n', output_text)
+                    output_text,
+                )
+                self.assertIn('<div class="card mb-3" id="_1">\n', output_text)
+                self.assertIn('<div class="card mb-3" id="_2">\n', output_text)
                 self.assertNotIn(
                 self.assertNotIn(
-                    '<div class="card mb-3" id="_3">\n', output_text)
+                    '<div class="card mb-3" id="_3">\n', output_text
+                )
 
 
         # Remote PR Created
         # Remote PR Created
         self.session = pagure.lib.query.create_session(self.dbpath)
         self.session = pagure.lib.query.create_session(self.dbpath)
-        project = pagure.lib.query.get_authorized_project(self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(project.requests), 1)
         self.assertEqual(len(project.requests), 1)
         trigger_ci.assert_not_called()
         trigger_ci.assert_not_called()
 
 
-    @patch('pagure.lib.notify.send_email',  MagicMock(return_value=True))
-    @patch('pagure.lib.tasks_services.trigger_ci_build')
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
+    @patch("pagure.lib.tasks_services.trigger_ci_build")
     def test_new_remote_pr_ci_on(self, trigger_ci):
     def test_new_remote_pr_ci_on(self, trigger_ci):
         """ Test creating a new remote PR when CI is configured. """
         """ Test creating a new remote PR when CI is configured. """
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         tests.create_projects_git(
         tests.create_projects_git(
-            os.path.join(self.path, 'requests'), bare=True)
+            os.path.join(self.path, "requests"), bare=True
+        )
         self.set_up_git_repo()
         self.set_up_git_repo()
 
 
         # Before
         # Before
         self.session = pagure.lib.query.create_session(self.dbpath)
         self.session = pagure.lib.query.create_session(self.dbpath)
-        project = pagure.lib.query.get_authorized_project(self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(project.requests), 0)
         self.assertEqual(len(project.requests), 0)
 
 
         # Create a remote PR
         # Create a remote PR
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
 
 
             # Activate CI hook
             # Activate CI hook
             data = {
             data = {
-                'active_pr': 'y',
-                'ci_url': 'https://jenkins.fedoraproject.org',
-                'ci_job': 'test/job',
-                'ci_type': 'jenkins',
-                'csrf_token': csrf_token,
+                "active_pr": "y",
+                "ci_url": "https://jenkins.fedoraproject.org",
+                "ci_job": "test/job",
+                "ci_type": "jenkins",
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/settings/Pagure CI', data=data, follow_redirects=True)
+                "/test/settings/Pagure CI", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
 
 
-        user = tests.FakeUser(username='foo')
+        user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             data = {
             data = {
-                'csrf_token': csrf_token,
-                'title': 'Remote PR title',
-                'branch_from': 'feature',
-                'branch_to': 'master',
-                'git_repo': os.path.join(self.newpath, 'test'),
+                "csrf_token": csrf_token,
+                "title": "Remote PR title",
+                "branch_from": "feature",
+                "branch_to": "master",
+                "git_repo": os.path.join(self.newpath, "test"),
             }
             }
             # Disables checking the URL pattern for git_repo
             # Disables checking the URL pattern for git_repo
             with patch(
             with patch(
-                    'pagure.forms.RemoteRequestPullForm.git_repo.args',
-                    MagicMock(return_value=(
-                        u'Git Repo address',
-                        [wtforms.validators.DataRequired()]))):
+                "pagure.forms.RemoteRequestPullForm.git_repo.args",
+                MagicMock(
+                    return_value=(
+                        "Git Repo address",
+                        [wtforms.validators.DataRequired()],
+                    )
+                ),
+            ):
 
 
                 # Do the preview, triggers the cache & all
                 # Do the preview, triggers the cache & all
                 output = self.app.post(
                 output = self.app.post(
-                    '/test/diff/remote', data=data, follow_redirects=True)
+                    "/test/diff/remote", data=data, follow_redirects=True
+                )
                 self.assertEqual(output.status_code, 200)
                 self.assertEqual(output.status_code, 200)
 
 
                 # Confirm the PR creation
                 # Confirm the PR creation
-                data['confirm'] = 1
+                data["confirm"] = 1
                 output = self.app.post(
                 output = self.app.post(
-                    '/test/diff/remote', data=data, follow_redirects=True)
+                    "/test/diff/remote", data=data, follow_redirects=True
+                )
                 self.assertEqual(output.status_code, 200)
                 self.assertEqual(output.status_code, 200)
                 output_text = output.get_data(as_text=True)
                 output_text = output.get_data(as_text=True)
                 self.assertIn(
                 self.assertIn(
                     '<span class="text-success font-weight-bold">#1',
                     '<span class="text-success font-weight-bold">#1',
-                    output_text)
-                self.assertIn(
-                    '<div class="card mb-3" id="_1">\n', output_text)
-                self.assertIn(
-                    '<div class="card mb-3" id="_2">\n', output_text)
+                    output_text,
+                )
+                self.assertIn('<div class="card mb-3" id="_1">\n', output_text)
+                self.assertIn('<div class="card mb-3" id="_2">\n', output_text)
                 self.assertNotIn(
                 self.assertNotIn(
-                    '<div class="card mb-3" id="_3">\n', output_text)
+                    '<div class="card mb-3" id="_3">\n', output_text
+                )
 
 
         # Remote PR Created
         # Remote PR Created
         self.session = pagure.lib.query.create_session(self.dbpath)
         self.session = pagure.lib.query.create_session(self.dbpath)
-        project = pagure.lib.query.get_authorized_project(self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(project.requests), 1)
         self.assertEqual(len(project.requests), 1)
         trigger_ci.assert_not_called()
         trigger_ci.assert_not_called()
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

File diff suppressed because it is too large
+ 491 - 402
tests/test_pagure_flask_ui_repo.py


+ 141 - 90
tests/test_pagure_flask_ui_repo_delete_project.py

@@ -15,8 +15,9 @@ import os
 
 
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import tests
 import tests
@@ -31,19 +32,22 @@ class PagureFlaskDeleteRepotests(tests.Modeltests):
 
 
         # Create some projects
         # Create some projects
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'))
+        tests.create_projects_git(os.path.join(self.path, "repos"))
         self.session.commit()
         self.session.commit()
 
 
         # Create all the git repos
         # Create all the git repos
-        tests.create_projects_git(os.path.join(self.path, 'repos'))
-        tests.create_projects_git(os.path.join(self.path, 'repos', 'docs'))
+        tests.create_projects_git(os.path.join(self.path, "repos"))
+        tests.create_projects_git(os.path.join(self.path, "repos", "docs"))
         tests.create_projects_git(
         tests.create_projects_git(
-            os.path.join(self.path, 'repos', 'tickets'), bare=True)
+            os.path.join(self.path, "repos", "tickets"), bare=True
+        )
         tests.create_projects_git(
         tests.create_projects_git(
-            os.path.join(self.path, 'repos', 'requests'), bare=True)
+            os.path.join(self.path, "repos", "requests"), bare=True
+        )
 
 
         project = pagure.lib.query.get_authorized_project(
         project = pagure.lib.query.get_authorized_project(
-            self.session, project_name='test')
+            self.session, project_name="test"
+        )
         self.assertIsNotNone(project)
         self.assertIsNotNone(project)
         # Ensure the project isn't read-only
         # Ensure the project isn't read-only
         project.read_only = False
         project.read_only = False
@@ -52,9 +56,7 @@ class PagureFlaskDeleteRepotests(tests.Modeltests):
 
 
         # Create a fork
         # Create a fork
         task = pagure.lib.query.fork_project(
         task = pagure.lib.query.fork_project(
-            session=self.session,
-            user='pingou',
-            repo=project,
+            session=self.session, user="pingou", repo=project
         )
         )
         task.get()
         task.get()
 
 
@@ -62,193 +64,235 @@ class PagureFlaskDeleteRepotests(tests.Modeltests):
         projects = pagure.lib.query.search_projects(self.session)
         projects = pagure.lib.query.search_projects(self.session)
         self.assertEqual(len(projects), 4)
         self.assertEqual(len(projects), 4)
 
 
-    @patch.dict('pagure.config.config', {'ENABLE_DEL_PROJECTS': False})
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
-    @patch('pagure.decorators.admin_session_timedout',
-           MagicMock(return_value=False))
+    @patch.dict("pagure.config.config", {"ENABLE_DEL_PROJECTS": False})
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
+    @patch(
+        "pagure.decorators.admin_session_timedout",
+        MagicMock(return_value=False),
+    )
     def test_delete_repo_when_turned_off(self):
     def test_delete_repo_when_turned_off(self):
         """ Test the delete_repo endpoint for a fork when only deleting main
         """ Test the delete_repo endpoint for a fork when only deleting main
         project is forbidden.
         project is forbidden.
         """
         """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post('/test/delete', follow_redirects=True)
+            output = self.app.post("/test/delete", follow_redirects=True)
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
         projects = pagure.lib.query.search_projects(self.session)
         projects = pagure.lib.query.search_projects(self.session)
         self.assertEqual(len(projects), 4)
         self.assertEqual(len(projects), 4)
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
-    @patch('pagure.decorators.admin_session_timedout',
-           MagicMock(return_value=False))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
+    @patch(
+        "pagure.decorators.admin_session_timedout",
+        MagicMock(return_value=False),
+    )
     def test_delete_button_present(self):
     def test_delete_button_present(self):
         """ Test that the delete button is present when deletions are
         """ Test that the delete button is present when deletions are
         allowed.
         allowed.
         """
         """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/settings')
+            output = self.app.get("/test/settings")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
-            self.assertIn('<form action="/test/delete"', output.get_data(as_text=True))
-            self.assertIn('&nbsp; Delete the test project', output.get_data(as_text=True))
+            self.assertIn(
+                '<form action="/test/delete"', output.get_data(as_text=True)
+            )
+            self.assertIn(
+                "&nbsp; Delete the test project", output.get_data(as_text=True)
+            )
 
 
         projects = pagure.lib.query.search_projects(self.session)
         projects = pagure.lib.query.search_projects(self.session)
         self.assertEqual(len(projects), 4)
         self.assertEqual(len(projects), 4)
 
 
-    @patch.dict('pagure.config.config', {'ENABLE_DEL_PROJECTS': False})
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
-    @patch('pagure.decorators.admin_session_timedout',
-           MagicMock(return_value=False))
+    @patch.dict("pagure.config.config", {"ENABLE_DEL_PROJECTS": False})
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
+    @patch(
+        "pagure.decorators.admin_session_timedout",
+        MagicMock(return_value=False),
+    )
     def test_delete_button_absent(self):
     def test_delete_button_absent(self):
         """ Test that the delete button is absent when deletions are not
         """ Test that the delete button is absent when deletions are not
         allowed.
         allowed.
         """
         """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/settings')
+            output = self.app.get("/test/settings")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
-            self.assertNotIn('<form action="/test/delete"', output.get_data(as_text=True))
-            self.assertNotIn('&nbsp; Delete the test project', output.get_data(as_text=True))
+            self.assertNotIn(
+                '<form action="/test/delete"', output.get_data(as_text=True)
+            )
+            self.assertNotIn(
+                "&nbsp; Delete the test project", output.get_data(as_text=True)
+            )
 
 
         projects = pagure.lib.query.search_projects(self.session)
         projects = pagure.lib.query.search_projects(self.session)
         self.assertEqual(len(projects), 4)
         self.assertEqual(len(projects), 4)
 
 
-    @patch.dict('pagure.config.config', {'ENABLE_DEL_PROJECTS': False})
-    @patch.dict('pagure.config.config', {'ENABLE_DEL_FORKS': True})
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
-    @patch('pagure.decorators.admin_session_timedout',
-           MagicMock(return_value=False))
+    @patch.dict("pagure.config.config", {"ENABLE_DEL_PROJECTS": False})
+    @patch.dict("pagure.config.config", {"ENABLE_DEL_FORKS": True})
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
+    @patch(
+        "pagure.decorators.admin_session_timedout",
+        MagicMock(return_value=False),
+    )
     def test_delete_fork_when_project_off_refreshing(self):
     def test_delete_fork_when_project_off_refreshing(self):
         """ Test the delete_repo endpoint for a fork when only deleting main
         """ Test the delete_repo endpoint for a fork when only deleting main
         project is forbidden but the fork is being refreshed in the backend
         project is forbidden but the fork is being refreshed in the backend
         """
         """
         project = pagure.lib.query.get_authorized_project(
         project = pagure.lib.query.get_authorized_project(
-            self.session, project_name='test', user='pingou')
+            self.session, project_name="test", user="pingou"
+        )
         self.assertIsNotNone(project)
         self.assertIsNotNone(project)
         # Ensure the project isn't read-only
         # Ensure the project isn't read-only
         project.read_only = True
         project.read_only = True
         self.session.add(project)
         self.session.add(project)
         self.session.commit()
         self.session.commit()
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             output = self.app.post(
             output = self.app.post(
-                '/fork/pingou/test/delete', follow_redirects=True)
+                "/fork/pingou/test/delete", follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                'The ACLs of this project '
-                'are being refreshed in the backend this prevents the '
-                'project from being deleted. Please wait for this task to '
-                'finish before trying again. Thanks!', output.get_data(as_text=True))
+                "The ACLs of this project "
+                "are being refreshed in the backend this prevents the "
+                "project from being deleted. Please wait for this task to "
+                "finish before trying again. Thanks!",
+                output.get_data(as_text=True),
+            )
 
 
         projects = pagure.lib.query.search_projects(self.session)
         projects = pagure.lib.query.search_projects(self.session)
         self.assertEqual(len(projects), 4)
         self.assertEqual(len(projects), 4)
 
 
-    @patch.dict('pagure.config.config', {'ENABLE_DEL_PROJECTS': False})
-    @patch.dict('pagure.config.config', {'ENABLE_DEL_FORKS': True})
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
-    @patch('pagure.decorators.admin_session_timedout',
-           MagicMock(return_value=False))
+    @patch.dict("pagure.config.config", {"ENABLE_DEL_PROJECTS": False})
+    @patch.dict("pagure.config.config", {"ENABLE_DEL_FORKS": True})
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
+    @patch(
+        "pagure.decorators.admin_session_timedout",
+        MagicMock(return_value=False),
+    )
     def test_delete_fork_when_project_off(self):
     def test_delete_fork_when_project_off(self):
         """ Test the delete_repo endpoint for a fork when only deleting main
         """ Test the delete_repo endpoint for a fork when only deleting main
         project is forbidden.
         project is forbidden.
         """
         """
         project = pagure.lib.query.get_authorized_project(
         project = pagure.lib.query.get_authorized_project(
-            self.session, project_name='test', user='pingou')
+            self.session, project_name="test", user="pingou"
+        )
         self.assertIsNotNone(project)
         self.assertIsNotNone(project)
         # Ensure the project isn't read-only
         # Ensure the project isn't read-only
         project.read_only = False
         project.read_only = False
         self.session.add(project)
         self.session.add(project)
         self.session.commit()
         self.session.commit()
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             output = self.app.post(
             output = self.app.post(
-                '/fork/pingou/test/delete', follow_redirects=True)
+                "/fork/pingou/test/delete", follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
 
 
         projects = pagure.lib.query.search_projects(self.session)
         projects = pagure.lib.query.search_projects(self.session)
         self.assertEqual(len(projects), 3)
         self.assertEqual(len(projects), 3)
 
 
-    @patch.dict('pagure.config.config', {'ENABLE_DEL_PROJECTS': False})
-    @patch.dict('pagure.config.config', {'ENABLE_DEL_FORKS': False})
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
-    @patch('pagure.decorators.admin_session_timedout',
-           MagicMock(return_value=False))
+    @patch.dict("pagure.config.config", {"ENABLE_DEL_PROJECTS": False})
+    @patch.dict("pagure.config.config", {"ENABLE_DEL_FORKS": False})
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
+    @patch(
+        "pagure.decorators.admin_session_timedout",
+        MagicMock(return_value=False),
+    )
     def test_delete_fork_when_fork_and_project_off(self):
     def test_delete_fork_when_fork_and_project_off(self):
         """ Test the delete_repo endpoint for a fork when deleting fork and
         """ Test the delete_repo endpoint for a fork when deleting fork and
         project is forbidden.
         project is forbidden.
         """
         """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             output = self.app.post(
             output = self.app.post(
-                '/fork/pingou/test/delete', follow_redirects=True)
+                "/fork/pingou/test/delete", follow_redirects=True
+            )
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
         projects = pagure.lib.query.search_projects(self.session)
         projects = pagure.lib.query.search_projects(self.session)
         self.assertEqual(len(projects), 4)
         self.assertEqual(len(projects), 4)
 
 
-    @patch.dict('pagure.config.config', {'ENABLE_DEL_PROJECTS': False})
-    @patch.dict('pagure.config.config', {'ENABLE_DEL_FORKS': False})
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
-    @patch('pagure.decorators.admin_session_timedout',
-           MagicMock(return_value=False))
+    @patch.dict("pagure.config.config", {"ENABLE_DEL_PROJECTS": False})
+    @patch.dict("pagure.config.config", {"ENABLE_DEL_FORKS": False})
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
+    @patch(
+        "pagure.decorators.admin_session_timedout",
+        MagicMock(return_value=False),
+    )
     def test_delete_fork_button_absent(self):
     def test_delete_fork_button_absent(self):
         """ Test that the delete button is absent when deletions are not
         """ Test that the delete button is absent when deletions are not
         allowed.
         allowed.
         """
         """
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/fork/pingou/test/settings')
+            output = self.app.get("/fork/pingou/test/settings")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertNotIn(
             self.assertNotIn(
-                '<form action="/fork/pingou/test/delete"', output.get_data(as_text=True))
+                '<form action="/fork/pingou/test/delete"',
+                output.get_data(as_text=True),
+            )
             self.assertNotIn(
             self.assertNotIn(
-                '&nbsp; Delete the forks/pingou/test project', output.get_data(as_text=True))
+                "&nbsp; Delete the forks/pingou/test project",
+                output.get_data(as_text=True),
+            )
 
 
         projects = pagure.lib.query.search_projects(self.session)
         projects = pagure.lib.query.search_projects(self.session)
         self.assertEqual(len(projects), 4)
         self.assertEqual(len(projects), 4)
 
 
-    @patch.dict('pagure.config.config', {'ENABLE_DEL_PROJECTS': False})
-    @patch.dict('pagure.config.config', {'ENABLE_DEL_FORKS': True})
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
-    @patch('pagure.decorators.admin_session_timedout',
-           MagicMock(return_value=False))
+    @patch.dict("pagure.config.config", {"ENABLE_DEL_PROJECTS": False})
+    @patch.dict("pagure.config.config", {"ENABLE_DEL_FORKS": True})
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
+    @patch(
+        "pagure.decorators.admin_session_timedout",
+        MagicMock(return_value=False),
+    )
     def test_delete_fork_button_fork_del_allowed(self):
     def test_delete_fork_button_fork_del_allowed(self):
         """ Test that the delete button is present when deletions of projects
         """ Test that the delete button is present when deletions of projects
         is not allowed but deletions of forks is.
         is not allowed but deletions of forks is.
         """
         """
 
 
         project = pagure.lib.query.get_authorized_project(
         project = pagure.lib.query.get_authorized_project(
-            self.session, project_name='test', user='pingou')
+            self.session, project_name="test", user="pingou"
+        )
         self.assertIsNotNone(project)
         self.assertIsNotNone(project)
         # Ensure the project isn't read-only
         # Ensure the project isn't read-only
         project.read_only = False
         project.read_only = False
         self.session.add(project)
         self.session.add(project)
         self.session.commit()
         self.session.commit()
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/fork/pingou/test/settings')
+            output = self.app.get("/fork/pingou/test/settings")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                '<form action="/fork/pingou/test/delete"', output.get_data(as_text=True))
+                '<form action="/fork/pingou/test/delete"',
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
-                '&nbsp; Delete the forks/pingou/test project', output.get_data(as_text=True))
+                "&nbsp; Delete the forks/pingou/test project",
+                output.get_data(as_text=True),
+            )
 
 
         projects = pagure.lib.query.search_projects(self.session)
         projects = pagure.lib.query.search_projects(self.session)
         self.assertEqual(len(projects), 4)
         self.assertEqual(len(projects), 4)
 
 
-    @patch.dict('pagure.config.config', {'ENABLE_DEL_PROJECTS': False})
-    @patch.dict('pagure.config.config', {'ENABLE_DEL_FORKS': True})
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
-    @patch('pagure.decorators.admin_session_timedout',
-           MagicMock(return_value=False))
+    @patch.dict("pagure.config.config", {"ENABLE_DEL_PROJECTS": False})
+    @patch.dict("pagure.config.config", {"ENABLE_DEL_FORKS": True})
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
+    @patch(
+        "pagure.decorators.admin_session_timedout",
+        MagicMock(return_value=False),
+    )
     def test_delete_fork_button_fork_del_allowed_read_only(self):
     def test_delete_fork_button_fork_del_allowed_read_only(self):
         """ Test that the delete button is absent when deletions of projects
         """ Test that the delete button is absent when deletions of projects
         is not allowed but deletions of forks is but fork is still being
         is not allowed but deletions of forks is but fork is still being
@@ -256,21 +300,28 @@ class PagureFlaskDeleteRepotests(tests.Modeltests):
         """
         """
 
 
         project = pagure.lib.query.get_authorized_project(
         project = pagure.lib.query.get_authorized_project(
-            self.session, project_name='test', user='pingou')
+            self.session, project_name="test", user="pingou"
+        )
         self.assertIsNotNone(project)
         self.assertIsNotNone(project)
         # Ensure the project is read-only
         # Ensure the project is read-only
         project.read_only = True
         project.read_only = True
         self.session.add(project)
         self.session.add(project)
         self.session.commit()
         self.session.commit()
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/fork/pingou/test/settings')
+            output = self.app.get("/fork/pingou/test/settings")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertNotIn(
             self.assertNotIn(
-                '<form action="/fork/pingou/test/delete"', output.get_data(as_text=True))
+                '<form action="/fork/pingou/test/delete"',
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
-                'title="Action disabled while project\'s ACLs are being '
-                'refreshed">', output.get_data(as_text=True))
+                "title=\"Action disabled while project's ACLs are being "
+                'refreshed">',
+                output.get_data(as_text=True),
+            )
             self.assertIn(
             self.assertIn(
-                '&nbsp; Delete the forks/pingou/test project', output.get_data(as_text=True))
+                "&nbsp; Delete the forks/pingou/test project",
+                output.get_data(as_text=True),
+            )

+ 168 - 151
tests/test_pagure_flask_ui_repo_flag_commit.py

@@ -17,8 +17,9 @@ import os
 from mock import patch
 from mock import patch
 import pygit2
 import pygit2
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import tests
 import tests
@@ -35,288 +36,304 @@ class ViewCommitFlagtests(tests.SimplePagureTest):
         tests.create_tokens(self.session)
         tests.create_tokens(self.session)
 
 
         # Add a README to the git repo - First commit
         # Add a README to the git repo - First commit
-        tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
-        repo = pygit2.Repository(os.path.join(self.path, 'repos', 'test.git'))
-        self.commit = repo.revparse_single('HEAD')
+        tests.add_readme_git_repo(os.path.join(self.path, "repos", "test.git"))
+        repo = pygit2.Repository(os.path.join(self.path, "repos", "test.git"))
+        self.commit = repo.revparse_single("HEAD")
 
 
     def test_view_commit_no_flag(self):
     def test_view_commit_no_flag(self):
         """ Test the view_commit endpoint. """
         """ Test the view_commit endpoint. """
 
 
         # View first commit
         # View first commit
-        output = self.app.get('/test/c/%s' % self.commit.oid.hex)
+        output = self.app.get("/test/c/%s" % self.commit.oid.hex)
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         self.assertIn(
         self.assertIn(
-            '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
-            output.get_data(as_text=True))
+            "<title>Commit - test - %s - Pagure</title>" % self.commit.oid.hex,
+            output.get_data(as_text=True),
+        )
+        self.assertIn(
+            "#commit-overview-collapse", output.get_data(as_text=True)
+        )
+        self.assertIn("Merged by Alice Author", output.get_data(as_text=True))
         self.assertIn(
         self.assertIn(
-            '#commit-overview-collapse',
-            output.get_data(as_text=True))
-        self.assertIn('Merged by Alice Author', output.get_data(as_text=True))
-        self.assertIn('Committed by Cecil Committer', output.get_data(as_text=True))
+            "Committed by Cecil Committer", output.get_data(as_text=True)
+        )
 
 
     def test_view_commit_pending_flag(self):
     def test_view_commit_pending_flag(self):
         """ Test the view_commit endpoint with a pending flag. """
         """ Test the view_commit endpoint with a pending flag. """
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
 
 
         msg = pagure.lib.query.add_commit_flag(
         msg = pagure.lib.query.add_commit_flag(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
             commit_hash=self.commit.oid.hex,
             commit_hash=self.commit.oid.hex,
-            username='simple-koji-ci',
-            status='pending',
+            username="simple-koji-ci",
+            status="pending",
             percent=None,
             percent=None,
-            comment='Build is running',
-            url='https://koji.fp.o/koji...',
-            uid='uid',
-            user='foo',
-            token='aaabbbcccddd'
+            comment="Build is running",
+            url="https://koji.fp.o/koji...",
+            uid="uid",
+            user="foo",
+            token="aaabbbcccddd",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, ('Flag added', 'uid'))
+        self.assertEqual(msg, ("Flag added", "uid"))
 
 
         # View first commit
         # View first commit
-        output = self.app.get('/test/c/%s' % self.commit.oid.hex)
+        output = self.app.get("/test/c/%s" % self.commit.oid.hex)
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
-            '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
-            output_text)
-        self.assertIn(
-            '#commit-overview-collapse',
-            output_text)
-        self.assertIn('Merged by Alice Author', output_text)
-        self.assertIn('Committed by Cecil Committer', output_text)
+            "<title>Commit - test - %s - Pagure</title>" % self.commit.oid.hex,
+            output_text,
+        )
+        self.assertIn("#commit-overview-collapse", output_text)
+        self.assertIn("Merged by Alice Author", output_text)
+        self.assertIn("Committed by Cecil Committer", output_text)
         self.assertIn(
         self.assertIn(
-            '<span>\n                    <a '
+            "<span>\n                    <a "
             'href="https://koji.fp.o/koji...">simple-koji-ci</a>'
             'href="https://koji.fp.o/koji...">simple-koji-ci</a>'
-            '\n                  </span>', output_text)
+            "\n                  </span>",
+            output_text,
+        )
         self.assertIn(
         self.assertIn(
             '<div class="pull-xs-right">\n                    '
             '<div class="pull-xs-right">\n                    '
             '<span class="badge badge-info">pending</span>'
             '<span class="badge badge-info">pending</span>'
-            '\n                  </div>', output_text)
-        self.assertIn(
-            '<span>Build is running</span>', output_text)
+            "\n                  </div>",
+            output_text,
+        )
+        self.assertIn("<span>Build is running</span>", output_text)
 
 
     def test_view_commit_success_flag(self):
     def test_view_commit_success_flag(self):
         """ Test the view_commit endpoint with a successful flag. """
         """ Test the view_commit endpoint with a successful flag. """
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
 
 
         msg = pagure.lib.query.add_commit_flag(
         msg = pagure.lib.query.add_commit_flag(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
             commit_hash=self.commit.oid.hex,
             commit_hash=self.commit.oid.hex,
-            username='simple-koji-ci',
-            status='success',
+            username="simple-koji-ci",
+            status="success",
             percent=100,
             percent=100,
-            comment='Build passed',
-            url='https://koji.fp.o/koji...',
-            uid='uid',
-            user='foo',
-            token='aaabbbcccddd'
+            comment="Build passed",
+            url="https://koji.fp.o/koji...",
+            uid="uid",
+            user="foo",
+            token="aaabbbcccddd",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, ('Flag added', 'uid'))
+        self.assertEqual(msg, ("Flag added", "uid"))
 
 
         # View first commit
         # View first commit
-        output = self.app.get('/test/c/%s' % self.commit.oid.hex)
+        output = self.app.get("/test/c/%s" % self.commit.oid.hex)
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
-            '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
-            output_text)
-        self.assertIn(
-            '#commit-overview-collapse',
-            output_text)
-        self.assertIn('Merged by Alice Author', output_text)
-        self.assertIn('Committed by Cecil Committer', output_text)
+            "<title>Commit - test - %s - Pagure</title>" % self.commit.oid.hex,
+            output_text,
+        )
+        self.assertIn("#commit-overview-collapse", output_text)
+        self.assertIn("Merged by Alice Author", output_text)
+        self.assertIn("Committed by Cecil Committer", output_text)
         self.assertIn(
         self.assertIn(
-            '<span>\n                    <a '
+            "<span>\n                    <a "
             'href="https://koji.fp.o/koji...">simple-koji-ci</a>'
             'href="https://koji.fp.o/koji...">simple-koji-ci</a>'
-            '\n                  </span>', output_text)
+            "\n                  </span>",
+            output_text,
+        )
         self.assertIn(
         self.assertIn(
             '<div class="pull-xs-right">\n                    '
             '<div class="pull-xs-right">\n                    '
             '<span class="badge badge-success">success (100%)</span>'
             '<span class="badge badge-success">success (100%)</span>'
-            '\n                  </div>', output_text)
-        self.assertIn(
-            '<span>Build passed</span>', output_text)
+            "\n                  </div>",
+            output_text,
+        )
+        self.assertIn("<span>Build passed</span>", output_text)
 
 
     def test_view_commit_error_flag(self):
     def test_view_commit_error_flag(self):
         """ Test the view_commit endpoint with a error flag. """
         """ Test the view_commit endpoint with a error flag. """
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
 
 
         msg = pagure.lib.query.add_commit_flag(
         msg = pagure.lib.query.add_commit_flag(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
             commit_hash=self.commit.oid.hex,
             commit_hash=self.commit.oid.hex,
-            username='simple-koji-ci',
-            status='error',
+            username="simple-koji-ci",
+            status="error",
             percent=None,
             percent=None,
-            comment='Build errored',
-            url='https://koji.fp.o/koji...',
-            uid='uid',
-            user='foo',
-            token='aaabbbcccddd'
+            comment="Build errored",
+            url="https://koji.fp.o/koji...",
+            uid="uid",
+            user="foo",
+            token="aaabbbcccddd",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, ('Flag added', 'uid'))
+        self.assertEqual(msg, ("Flag added", "uid"))
 
 
         # View first commit
         # View first commit
-        output = self.app.get('/test/c/%s' % self.commit.oid.hex)
+        output = self.app.get("/test/c/%s" % self.commit.oid.hex)
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
-            '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
-            output_text)
-        self.assertIn(
-            '#commit-overview-collapse',
-            output_text)
-        self.assertIn('Merged by Alice Author', output_text)
-        self.assertIn('Committed by Cecil Committer', output_text)
+            "<title>Commit - test - %s - Pagure</title>" % self.commit.oid.hex,
+            output_text,
+        )
+        self.assertIn("#commit-overview-collapse", output_text)
+        self.assertIn("Merged by Alice Author", output_text)
+        self.assertIn("Committed by Cecil Committer", output_text)
         self.assertIn(
         self.assertIn(
-            '<span>\n                    <a '
+            "<span>\n                    <a "
             'href="https://koji.fp.o/koji...">simple-koji-ci</a>'
             'href="https://koji.fp.o/koji...">simple-koji-ci</a>'
-            '\n                  </span>', output_text)
+            "\n                  </span>",
+            output_text,
+        )
         self.assertIn(
         self.assertIn(
             '<div class="pull-xs-right">\n                    '
             '<div class="pull-xs-right">\n                    '
             '<span class="badge badge-danger">error</span>'
             '<span class="badge badge-danger">error</span>'
-            '\n                  </div>', output_text)
-        self.assertIn(
-            '<span>Build errored</span>', output_text)
+            "\n                  </div>",
+            output_text,
+        )
+        self.assertIn("<span>Build errored</span>", output_text)
 
 
     def test_view_commit_failure_flag(self):
     def test_view_commit_failure_flag(self):
         """ Test the view_commit endpoint with a failure flag. """
         """ Test the view_commit endpoint with a failure flag. """
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
 
 
         msg = pagure.lib.query.add_commit_flag(
         msg = pagure.lib.query.add_commit_flag(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
             commit_hash=self.commit.oid.hex,
             commit_hash=self.commit.oid.hex,
-            username='simple-koji-ci',
-            status='failure',
+            username="simple-koji-ci",
+            status="failure",
             percent=None,
             percent=None,
-            comment='Build failed',
-            url='https://koji.fp.o/koji...',
-            uid='uid',
-            user='foo',
-            token='aaabbbcccddd'
+            comment="Build failed",
+            url="https://koji.fp.o/koji...",
+            uid="uid",
+            user="foo",
+            token="aaabbbcccddd",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, ('Flag added', 'uid'))
+        self.assertEqual(msg, ("Flag added", "uid"))
 
 
         # View first commit
         # View first commit
-        output = self.app.get('/test/c/%s' % self.commit.oid.hex)
+        output = self.app.get("/test/c/%s" % self.commit.oid.hex)
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
-            '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
-            output_text)
-        self.assertIn(
-            '#commit-overview-collapse',
-            output_text)
-        self.assertIn('Merged by Alice Author', output_text)
-        self.assertIn('Committed by Cecil Committer', output_text)
+            "<title>Commit - test - %s - Pagure</title>" % self.commit.oid.hex,
+            output_text,
+        )
+        self.assertIn("#commit-overview-collapse", output_text)
+        self.assertIn("Merged by Alice Author", output_text)
+        self.assertIn("Committed by Cecil Committer", output_text)
         self.assertIn(
         self.assertIn(
             '<span>\n                    <a href="https://koji.fp.o/koji...">'
             '<span>\n                    <a href="https://koji.fp.o/koji...">'
-            'simple-koji-ci</a>\n                  </span>', output_text)
+            "simple-koji-ci</a>\n                  </span>",
+            output_text,
+        )
         self.assertIn(
         self.assertIn(
             '<div class="pull-xs-right">\n                    '
             '<div class="pull-xs-right">\n                    '
             '<span class="badge badge-danger">failure</span>'
             '<span class="badge badge-danger">failure</span>'
-            '\n                  </div>', output_text)
-        self.assertIn(
-            '<span>Build failed</span>', output_text)
+            "\n                  </div>",
+            output_text,
+        )
+        self.assertIn("<span>Build failed</span>", output_text)
 
 
     def test_view_commit_canceled_flag(self):
     def test_view_commit_canceled_flag(self):
         """ Test the view_commit endpoint with a canceled flag. """
         """ Test the view_commit endpoint with a canceled flag. """
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
 
 
         msg = pagure.lib.query.add_commit_flag(
         msg = pagure.lib.query.add_commit_flag(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
             commit_hash=self.commit.oid.hex,
             commit_hash=self.commit.oid.hex,
-            username='simple-koji-ci',
-            status='canceled',
+            username="simple-koji-ci",
+            status="canceled",
             percent=None,
             percent=None,
-            comment='Build canceled',
-            url='https://koji.fp.o/koji...',
-            uid='uid',
-            user='foo',
-            token='aaabbbcccddd'
+            comment="Build canceled",
+            url="https://koji.fp.o/koji...",
+            uid="uid",
+            user="foo",
+            token="aaabbbcccddd",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, ('Flag added', 'uid'))
+        self.assertEqual(msg, ("Flag added", "uid"))
 
 
         # View first commit
         # View first commit
-        output = self.app.get('/test/c/%s' % self.commit.oid.hex)
+        output = self.app.get("/test/c/%s" % self.commit.oid.hex)
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
-            '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
-            output_text)
-        self.assertIn(
-            '#commit-overview-collapse',
-            output_text)
-        self.assertIn('Merged by Alice Author', output_text)
-        self.assertIn('Committed by Cecil Committer', output_text)
+            "<title>Commit - test - %s - Pagure</title>" % self.commit.oid.hex,
+            output_text,
+        )
+        self.assertIn("#commit-overview-collapse", output_text)
+        self.assertIn("Merged by Alice Author", output_text)
+        self.assertIn("Committed by Cecil Committer", output_text)
         self.assertIn(
         self.assertIn(
             '<span>\n                    <a href="https://koji.fp.o/koji...">'
             '<span>\n                    <a href="https://koji.fp.o/koji...">'
-            'simple-koji-ci</a>\n                  </span>', output_text)
+            "simple-koji-ci</a>\n                  </span>",
+            output_text,
+        )
         self.assertIn(
         self.assertIn(
             '<div class="pull-xs-right">\n                    '
             '<div class="pull-xs-right">\n                    '
             '<span class="badge badge-warning">canceled</span>'
             '<span class="badge badge-warning">canceled</span>'
-            '\n                  </div>', output_text)
-        self.assertIn(
-            '<span>Build canceled</span>', output_text)
-
-    @patch.dict('pagure.config.config',
-                {
-                    'FLAG_STATUSES_LABELS':
-                        {
-                            'status1': 'badge-warning',
-                            'otherstatus': 'badge-success',
-                        },
-                })
+            "\n                  </div>",
+            output_text,
+        )
+        self.assertIn("<span>Build canceled</span>", output_text)
+
+    @patch.dict(
+        "pagure.config.config",
+        {
+            "FLAG_STATUSES_LABELS": {
+                "status1": "badge-warning",
+                "otherstatus": "badge-success",
+            }
+        },
+    )
     def test_view_commit_with_custom_flags(self):
     def test_view_commit_with_custom_flags(self):
         """ Test the view_commit endpoint while having custom flags. """
         """ Test the view_commit endpoint while having custom flags. """
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
 
 
         msg = pagure.lib.query.add_commit_flag(
         msg = pagure.lib.query.add_commit_flag(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
             commit_hash=self.commit.oid.hex,
             commit_hash=self.commit.oid.hex,
-            username='simple-koji-ci',
-            status='status1',
+            username="simple-koji-ci",
+            status="status1",
             percent=None,
             percent=None,
-            comment='Build canceled',
-            url='https://koji.fp.o/koji...',
-            uid='uid',
-            user='foo',
-            token='aaabbbcccddd'
+            comment="Build canceled",
+            url="https://koji.fp.o/koji...",
+            uid="uid",
+            user="foo",
+            token="aaabbbcccddd",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, ('Flag added', 'uid'))
+        self.assertEqual(msg, ("Flag added", "uid"))
 
 
         # View first commit
         # View first commit
-        output = self.app.get('/test/c/%s' % self.commit.oid.hex)
+        output = self.app.get("/test/c/%s" % self.commit.oid.hex)
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
-            '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
-            output_text)
-        self.assertIn(
-            '#commit-overview-collapse',
-            output_text)
-        self.assertIn('Merged by Alice Author', output_text)
-        self.assertIn('Committed by Cecil Committer', output_text)
+            "<title>Commit - test - %s - Pagure</title>" % self.commit.oid.hex,
+            output_text,
+        )
+        self.assertIn("#commit-overview-collapse", output_text)
+        self.assertIn("Merged by Alice Author", output_text)
+        self.assertIn("Committed by Cecil Committer", output_text)
         self.assertIn(
         self.assertIn(
             '<span>\n                    <a href="https://koji.fp.o/koji...">'
             '<span>\n                    <a href="https://koji.fp.o/koji...">'
-            'simple-koji-ci</a>\n                  </span>', output_text)
+            "simple-koji-ci</a>\n                  </span>",
+            output_text,
+        )
         self.assertIn(
         self.assertIn(
             '<div class="pull-xs-right">\n                    '
             '<div class="pull-xs-right">\n                    '
             '<span class="badge badge-warning">status1</span>'
             '<span class="badge badge-warning">status1</span>'
-            '\n                  </div>', output_text)
-        self.assertIn(
-            '<span>Build canceled</span>', output_text)
+            "\n                  </div>",
+            output_text,
+        )
+        self.assertIn("<span>Build canceled</span>", output_text)
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 69 - 58
tests/test_pagure_flask_ui_repo_milestones.py

@@ -16,8 +16,9 @@ import os
 
 
 from mock import ANY, patch, MagicMock
 from mock import ANY, patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import tests
 import tests
@@ -26,43 +27,47 @@ import tests
 class PagureFlaskRepoMilestonestests(tests.Modeltests):
 class PagureFlaskRepoMilestonestests(tests.Modeltests):
     """ Tests for milestones in pagure """
     """ Tests for milestones in pagure """
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def setUp(self):
     def setUp(self):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(PagureFlaskRepoMilestonestests, self).setUp()
         super(PagureFlaskRepoMilestonestests, self).setUp()
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'))
+        tests.create_projects_git(os.path.join(self.path, "repos"))
 
 
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
-            title='Test issue #1',
-            content='We should work on this for the second time',
-            user='foo',
-            status='Open',
+            title="Test issue #1",
+            content="We should work on this for the second time",
+            user="foo",
+            status="Open",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg.title, 'Test issue #1')
+        self.assertEqual(msg.title, "Test issue #1")
 
 
-    @patch('pagure.decorators.admin_session_timedout',
-           MagicMock(return_value=False))
+    @patch(
+        "pagure.decorators.admin_session_timedout",
+        MagicMock(return_value=False),
+    )
     def test_milestones_settings_empty(self):
     def test_milestones_settings_empty(self):
         """ Test the settings page when no milestones are set. """
         """ Test the settings page when no milestones are set. """
 
 
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(repo.milestones, {})
         self.assertEqual(repo.milestones, {})
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/settings')
+            output = self.app.get("/test/settings")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output.get_data(as_text=True))
+                "<title>Settings - test - Pagure</title>",
+                output.get_data(as_text=True),
+            )
             # Check that the milestones have their empty fields
             # Check that the milestones have their empty fields
             self.assertIn(
             self.assertIn(
-            '''<div id="milestones">
+                """<div id="milestones">
       <div class="row p-t-1 milestone" id="milestone_1">
       <div class="row p-t-1 milestone" id="milestone_1">
         <input type="hidden" name="milestones" value="1">
         <input type="hidden" name="milestones" value="1">
         <div class="col-sm-4 p-r-0">
         <div class="col-sm-4 p-r-0">
@@ -82,22 +87,26 @@ class PagureFlaskRepoMilestonestests(tests.Modeltests):
         <div class="col-sm-1 p-r-0" >
         <div class="col-sm-1 p-r-0" >
             <input type="checkbox" name="milestone_1_active" />
             <input type="checkbox" name="milestone_1_active" />
         </div>
         </div>
-      </div>''', output.get_data(as_text=True))
+      </div>""",
+                output.get_data(as_text=True),
+            )
 
 
-    @patch('pagure.decorators.admin_session_timedout',
-           MagicMock(return_value=False))
+    @patch(
+        "pagure.decorators.admin_session_timedout",
+        MagicMock(return_value=False),
+    )
     def test_setting_retrieving_milestones(self):
     def test_setting_retrieving_milestones(self):
         """ Test setting and retrieving milestones off a project. """
         """ Test setting and retrieving milestones off a project. """
 
 
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
 
 
         milestones = {
         milestones = {
-            '1.0': None,
-            '1.1': None,
-            '1.2': '2018-12-31',
-            '2.0': '2019',
-            '3.0': 'future',
-            '4.0': None,
+            "1.0": None,
+            "1.1": None,
+            "1.2": "2018-12-31",
+            "2.0": "2019",
+            "3.0": "future",
+            "4.0": None,
         }
         }
         repo.milestones = milestones
         repo.milestones = milestones
         self.session.add(repo)
         self.session.add(repo)
@@ -106,37 +115,35 @@ class PagureFlaskRepoMilestonestests(tests.Modeltests):
         self.assertEqual(
         self.assertEqual(
             repo.milestones,
             repo.milestones,
             {
             {
-                '1.0': {'active': True, 'date': None},
-                '1.1': {'active': True, 'date': None},
-                '1.2': {'active': True, 'date': '2018-12-31'},
-                '2.0': {'active': True, 'date': '2019'},
-                '3.0': {'active': True, 'date': 'future'},
-                '4.0': {'active': True, 'date': None},
-            }
+                "1.0": {"active": True, "date": None},
+                "1.1": {"active": True, "date": None},
+                "1.2": {"active": True, "date": "2018-12-31"},
+                "2.0": {"active": True, "date": "2019"},
+                "3.0": {"active": True, "date": "future"},
+                "4.0": {"active": True, "date": None},
+            },
         )
         )
 
 
-    @patch('pagure.decorators.admin_session_timedout',
-           MagicMock(return_value=False))
+    @patch(
+        "pagure.decorators.admin_session_timedout",
+        MagicMock(return_value=False),
+    )
     def test_issue_page_milestone_actives(self):
     def test_issue_page_milestone_actives(self):
         """ Test viewing tickets on a project having milestones, all active.
         """ Test viewing tickets on a project having milestones, all active.
         """
         """
 
 
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
 
 
-        milestones = {
-            '1.0': None,
-            '2.0': '2019',
-            '3.0': 'future',
-        }
-        milestones_keys = ['1.0', '3.0', '2.0']
+        milestones = {"1.0": None, "2.0": "2019", "3.0": "future"}
+        milestones_keys = ["1.0", "3.0", "2.0"]
         repo.milestones = milestones
         repo.milestones = milestones
         repo.milestones_keys = milestones_keys
         repo.milestones_keys = milestones_keys
         self.session.add(repo)
         self.session.add(repo)
         self.session.commit()
         self.session.commit()
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/issue/1')
+            output = self.app.get("/test/issue/1")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
                 '<select class="form-control c-select" id="milestone" name="milestone">'
                 '<select class="form-control c-select" id="milestone" name="milestone">'
@@ -144,42 +151,46 @@ class PagureFlaskRepoMilestonestests(tests.Modeltests):
                 '<option value="1.0">1.0</option>'
                 '<option value="1.0">1.0</option>'
                 '<option value="3.0">3.0</option>'
                 '<option value="3.0">3.0</option>'
                 '<option value="2.0">2.0</option>'
                 '<option value="2.0">2.0</option>'
-                '</select>', output.get_data(as_text=True)
+                "</select>",
+                output.get_data(as_text=True),
             )
             )
 
 
-    @patch('pagure.decorators.admin_session_timedout',
-           MagicMock(return_value=False))
+    @patch(
+        "pagure.decorators.admin_session_timedout",
+        MagicMock(return_value=False),
+    )
     def test_issue_page_milestone_not_allactives(self):
     def test_issue_page_milestone_not_allactives(self):
         """ Test viewing tickets on a project having milestones, not all
         """ Test viewing tickets on a project having milestones, not all
         being active.
         being active.
         """
         """
 
 
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
 
 
         milestones = {
         milestones = {
-            '1.0': {'date': None, 'active': False},
-            '2.0': {'date': '2018-01-01', 'active': False},
-            '3.0': {'date': '2025-01-01', 'active': True},
-            '4.0': {'date': 'future', 'active': True},
+            "1.0": {"date": None, "active": False},
+            "2.0": {"date": "2018-01-01", "active": False},
+            "3.0": {"date": "2025-01-01", "active": True},
+            "4.0": {"date": "future", "active": True},
         }
         }
-        milestones_keys = ['1.0', '2.0', '3.0', '4.0']
+        milestones_keys = ["1.0", "2.0", "3.0", "4.0"]
         repo.milestones = milestones
         repo.milestones = milestones
         repo.milestones_keys = milestones_keys
         repo.milestones_keys = milestones_keys
         self.session.add(repo)
         self.session.add(repo)
         self.session.commit()
         self.session.commit()
 
 
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/issue/1')
+            output = self.app.get("/test/issue/1")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
                 '<select class="form-control c-select" id="milestone" name="milestone">'
                 '<select class="form-control c-select" id="milestone" name="milestone">'
                 '<option selected value=""></option>'
                 '<option selected value=""></option>'
                 '<option value="3.0">3.0</option>'
                 '<option value="3.0">3.0</option>'
                 '<option value="4.0">4.0</option>'
                 '<option value="4.0">4.0</option>'
-                '</select>', output.get_data(as_text=True)
+                "</select>",
+                output.get_data(as_text=True),
             )
             )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 85 - 74
tests/test_pagure_flask_ui_repo_slash_name.py

@@ -20,8 +20,9 @@ import os
 import pygit2
 import pygit2
 from mock import patch
 from mock import patch
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import tests
 import tests
@@ -36,44 +37,42 @@ class PagureFlaskSlashInNametests(tests.SimplePagureTest):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(PagureFlaskSlashInNametests, self).setUp()
         super(PagureFlaskSlashInNametests, self).setUp()
 
 
-    def set_up_git_repo(self, name='test'):
+    def set_up_git_repo(self, name="test"):
         """ Set up the git repo to play with. """
         """ Set up the git repo to play with. """
 
 
         # Create a git repo to play with
         # Create a git repo to play with
-        gitrepo = os.path.join(self.path, 'repos', '%s.git' % name)
+        gitrepo = os.path.join(self.path, "repos", "%s.git" % name)
         repo = pygit2.init_repository(gitrepo, bare=True)
         repo = pygit2.init_repository(gitrepo, bare=True)
 
 
-        newpath = tempfile.mkdtemp(prefix='pagure-other-test')
-        repopath = os.path.join(newpath, 'test')
+        newpath = tempfile.mkdtemp(prefix="pagure-other-test")
+        repopath = os.path.join(newpath, "test")
         clone_repo = pygit2.clone_repository(gitrepo, repopath)
         clone_repo = pygit2.clone_repository(gitrepo, repopath)
 
 
         # Create a file in that git repo
         # Create a file in that git repo
-        with open(os.path.join(repopath, 'sources'), 'w') as stream:
-            stream.write('foo\n bar')
-        clone_repo.index.add('sources')
+        with open(os.path.join(repopath, "sources"), "w") as stream:
+            stream.write("foo\n bar")
+        clone_repo.index.add("sources")
         clone_repo.index.write()
         clone_repo.index.write()
 
 
         # Commits the files added
         # Commits the files added
         tree = clone_repo.index.write_tree()
         tree = clone_repo.index.write_tree()
-        author = pygit2.Signature(
-            'Alice Author', 'alice@authors.tld')
-        committer = pygit2.Signature(
-            'Cecil Committer', 'cecil@committers.tld')
+        author = pygit2.Signature("Alice Author", "alice@authors.tld")
+        committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
         clone_repo.create_commit(
         clone_repo.create_commit(
-            'refs/heads/master',  # the name of the reference to update
+            "refs/heads/master",  # the name of the reference to update
             author,
             author,
             committer,
             committer,
-            'Add sources file for testing',
+            "Add sources file for testing",
             # binary string representing the tree object ID
             # binary string representing the tree object ID
             tree,
             tree,
             # list of binary strings representing parents of the new commit
             # list of binary strings representing parents of the new commit
-            []
+            [],
         )
         )
-        refname = 'refs/heads/master'
+        refname = "refs/heads/master"
         ori_remote = clone_repo.remotes[0]
         ori_remote = clone_repo.remotes[0]
         PagureRepo.push(ori_remote, refname)
         PagureRepo.push(ori_remote, refname)
 
 
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.notify.send_email")
     def test_view_repo_empty(self, send_email):
     def test_view_repo_empty(self, send_email):
         """ Test the view_repo endpoint when the project has a slash in its
         """ Test the view_repo endpoint when the project has a slash in its
         name.
         name.
@@ -82,77 +81,83 @@ class PagureFlaskSlashInNametests(tests.SimplePagureTest):
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         # Non-existant git repo
         # Non-existant git repo
-        output = self.app.get('/test')
+        output = self.app.get("/test")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
         # Create a git repo to play with
         # Create a git repo to play with
-        gitrepo = os.path.join(self.path, 'repos', 'test.git')
+        gitrepo = os.path.join(self.path, "repos", "test.git")
         repo = pygit2.init_repository(gitrepo, bare=True)
         repo = pygit2.init_repository(gitrepo, bare=True)
 
 
         # With git repo
         # With git repo
-        output = self.app.get('/test')
+        output = self.app.get("/test")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
             '<input class="form-control bg-white" type="text" '
             '<input class="form-control bg-white" type="text" '
             'value="git://localhost.localdomain/test.git" readonly>',
             'value="git://localhost.localdomain/test.git" readonly>',
-            output_text)
+            output_text,
+        )
         self.assertIn(
         self.assertIn(
-            '<p>The Project Creator has not pushed any code yet</p>',
-            output_text)
+            "<p>The Project Creator has not pushed any code yet</p>",
+            output_text,
+        )
 
 
         # We can't create the project `forks/test` the normal way
         # We can't create the project `forks/test` the normal way
         self.assertRaises(
         self.assertRaises(
             pagure.exceptions.PagureException,
             pagure.exceptions.PagureException,
             pagure.lib.query.new_project,
             pagure.lib.query.new_project,
             self.session,
             self.session,
-            name='test',
-            namespace='forks',
+            name="test",
+            namespace="forks",
             repospanner_region=None,
             repospanner_region=None,
-            description='test project forks/test',
-            url='',
-            avatar_email='',
-            user='pingou',
-            blacklist=pagure.config.config['BLACKLISTED_PROJECTS'],
-            allowed_prefix=pagure.config.config['ALLOWED_PREFIX'],
+            description="test project forks/test",
+            url="",
+            avatar_email="",
+            user="pingou",
+            blacklist=pagure.config.config["BLACKLISTED_PROJECTS"],
+            allowed_prefix=pagure.config.config["ALLOWED_PREFIX"],
         )
         )
 
 
         # So just put it in the DB
         # So just put it in the DB
         item = pagure.lib.model.Project(
         item = pagure.lib.model.Project(
             user_id=1,  # pingou
             user_id=1,  # pingou
-            name='test',
-            namespace='forks',
-            description='test project forks/test',
-            hook_token='aaabbbcccddd',
+            name="test",
+            namespace="forks",
+            description="test project forks/test",
+            hook_token="aaabbbcccddd",
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
 
 
         # Create a git repo to play with
         # Create a git repo to play with
-        gitrepo = os.path.join(self.path, 'repos', 'forks/test.git')
+        gitrepo = os.path.join(self.path, "repos", "forks/test.git")
         repo = pygit2.init_repository(gitrepo, bare=True)
         repo = pygit2.init_repository(gitrepo, bare=True)
 
 
-        output = self.app.get('/forks/test')
+        output = self.app.get("/forks/test")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
             '<input class="form-control bg-white" type="text" '
             '<input class="form-control bg-white" type="text" '
             'value="git://localhost.localdomain/forks/test.git" readonly>',
             'value="git://localhost.localdomain/forks/test.git" readonly>',
-            output_text)
+            output_text,
+        )
         self.assertIn(
         self.assertIn(
-            '<p>The Project Creator has not pushed any code yet</p>',
-            output_text)
+            "<p>The Project Creator has not pushed any code yet</p>",
+            output_text,
+        )
 
 
-        output = self.app.get('/forks/test/issues')
+        output = self.app.get("/forks/test/issues")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
-            '<title>Issues - forks/test - Pagure</title>', output_text)
+            "<title>Issues - forks/test - Pagure</title>", output_text
+        )
         self.assertIn(
         self.assertIn(
             '<span class="font-weight-bold">no open issues found</span>\n',
             '<span class="font-weight-bold">no open issues found</span>\n',
-            output_text)
+            output_text,
+        )
 
 
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.notify.send_email")
     def test_view_repo(self, send_email):
     def test_view_repo(self, send_email):
         """ Test the view_repo endpoint when the project has a slash in its
         """ Test the view_repo endpoint when the project has a slash in its
         name.
         name.
@@ -161,89 +166,95 @@ class PagureFlaskSlashInNametests(tests.SimplePagureTest):
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         # Non-existant git repo
         # Non-existant git repo
-        output = self.app.get('/test')
+        output = self.app.get("/test")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
         self.set_up_git_repo()
         self.set_up_git_repo()
 
 
         # With git repo
         # With git repo
-        output = self.app.get('/test')
+        output = self.app.get("/test")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
             '<input class="form-control bg-white" type="text" '
             '<input class="form-control bg-white" type="text" '
             'value="git://localhost.localdomain/test.git" readonly>',
             'value="git://localhost.localdomain/test.git" readonly>',
-            output_text)
+            output_text,
+        )
 
 
         # We can't create the project `forks/test` the normal way
         # We can't create the project `forks/test` the normal way
         self.assertRaises(
         self.assertRaises(
             pagure.exceptions.PagureException,
             pagure.exceptions.PagureException,
             pagure.lib.query.new_project,
             pagure.lib.query.new_project,
             self.session,
             self.session,
-            name='test',
-            namespace='forks',
+            name="test",
+            namespace="forks",
             repospanner_region=None,
             repospanner_region=None,
-            description='test project forks/test',
-            url='',
-            avatar_email='',
-            user='pingou',
-            blacklist=pagure.config.config['BLACKLISTED_PROJECTS'],
-            allowed_prefix=pagure.config.config['ALLOWED_PREFIX'],
+            description="test project forks/test",
+            url="",
+            avatar_email="",
+            user="pingou",
+            blacklist=pagure.config.config["BLACKLISTED_PROJECTS"],
+            allowed_prefix=pagure.config.config["ALLOWED_PREFIX"],
         )
         )
 
 
         # So just put it in the DB
         # So just put it in the DB
         item = pagure.lib.model.Project(
         item = pagure.lib.model.Project(
             user_id=1,  # pingou
             user_id=1,  # pingou
-            name='test',
-            namespace='forks',
-            description='test project forks/test',
-            hook_token='aaabbbcccddd',
+            name="test",
+            namespace="forks",
+            description="test project forks/test",
+            hook_token="aaabbbcccddd",
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
 
 
-        self.set_up_git_repo(name='forks/test')
+        self.set_up_git_repo(name="forks/test")
 
 
         # Front page shows fine
         # Front page shows fine
-        output = self.app.get('/forks/test')
+        output = self.app.get("/forks/test")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
             '<input class="form-control bg-white" type="text" '
             '<input class="form-control bg-white" type="text" '
             'value="git://localhost.localdomain/forks/test.git" readonly>',
             'value="git://localhost.localdomain/forks/test.git" readonly>',
-            output_text)
+            output_text,
+        )
         self.assertIn(
         self.assertIn(
-            '<title>Overview - forks/test - Pagure</title>', output_text)
+            "<title>Overview - forks/test - Pagure</title>", output_text
+        )
 
 
         # Issues list shows fine
         # Issues list shows fine
-        output = self.app.get('/forks/test/issues')
+        output = self.app.get("/forks/test/issues")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
-            '<title>Issues - forks/test - Pagure</title>', output_text)
+            "<title>Issues - forks/test - Pagure</title>", output_text
+        )
         self.assertIn(
         self.assertIn(
             '<span class="font-weight-bold">no open issues found</span>\n',
             '<span class="font-weight-bold">no open issues found</span>\n',
-            output_text)
+            output_text,
+        )
 
 
         # Try accessing the commit
         # Try accessing the commit
-        gitrepo = os.path.join(self.path, 'repos', 'forks/test.git')
+        gitrepo = os.path.join(self.path, "repos", "forks/test.git")
         repo = pygit2.Repository(gitrepo)
         repo = pygit2.Repository(gitrepo)
-        master_branch = repo.lookup_branch('master')
+        master_branch = repo.lookup_branch("master")
         first_commit = master_branch.peel().hex
         first_commit = master_branch.peel().hex
 
 
-        output = self.app.get('/forks/test/commits')
+        output = self.app.get("/forks/test/commits")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(first_commit, output_text)
         self.assertIn(first_commit, output_text)
         self.assertIn(
         self.assertIn(
             '<a href="/forks/test/c/%s?branch=master"' % first_commit,
             '<a href="/forks/test/c/%s?branch=master"' % first_commit,
-            output_text)
+            output_text,
+        )
 
 
-        output = self.app.get('/forks/test/c/%s' % first_commit)
+        output = self.app.get("/forks/test/c/%s" % first_commit)
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
-        self.assertIn('<title>Commit - forks/test ', output_text)
+        self.assertIn("<title>Commit - forks/test ", output_text)
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 141 - 101
tests/test_pagure_flask_ui_repo_view_file.py

@@ -16,8 +16,9 @@ import os
 
 
 import pygit2
 import pygit2
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.model  # noqa
 import pagure.lib.model  # noqa
 import tests  # noqa
 import tests  # noqa
@@ -31,10 +32,11 @@ class LocalBasetests(tests.Modeltests):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(LocalBasetests, self).setUp()
         super(LocalBasetests, self).setUp()
 
 
-        pagure.config.config['VIRUS_SCAN_ATTACHMENTS'] = False
-        pagure.config.config['UPLOAD_FOLDER_URL'] = '/releases/'
-        pagure.config.config['UPLOAD_FOLDER_PATH'] = os.path.join(
-            self.path, 'releases')
+        pagure.config.config["VIRUS_SCAN_ATTACHMENTS"] = False
+        pagure.config.config["UPLOAD_FOLDER_URL"] = "/releases/"
+        pagure.config.config["UPLOAD_FOLDER_PATH"] = os.path.join(
+            self.path, "releases"
+        )
 
 
 
 
 class PagureFlaskRepoViewFileSimpletests(LocalBasetests):
 class PagureFlaskRepoViewFileSimpletests(LocalBasetests):
@@ -42,7 +44,7 @@ class PagureFlaskRepoViewFileSimpletests(LocalBasetests):
 
 
     def test_view_file_no_project(self):
     def test_view_file_no_project(self):
         """ Test the view_file when the project is unknown. """
         """ Test the view_file when the project is unknown. """
-        output = self.app.get('/foo/blob/foo/f/sources')
+        output = self.app.get("/foo/blob/foo/f/sources")
         # No project registered in the DB
         # No project registered in the DB
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
@@ -50,16 +52,16 @@ class PagureFlaskRepoViewFileSimpletests(LocalBasetests):
         """ Test the view_file when the project has no git repo. """
         """ Test the view_file when the project has no git repo. """
         tests.create_projects(self.session)
         tests.create_projects(self.session)
 
 
-        output = self.app.get('/test/blob/foo/f/sources')
+        output = self.app.get("/test/blob/foo/f/sources")
         # No git repo associated
         # No git repo associated
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
     def test_view_file_no_git_content(self):
     def test_view_file_no_git_content(self):
         """ Test the view_file when the file doesn't exist. """
         """ Test the view_file when the file doesn't exist. """
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
-        output = self.app.get('/test/blob/foo/f/sources')
+        output = self.app.get("/test/blob/foo/f/sources")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
 
 
@@ -70,38 +72,39 @@ class PagureFlaskRepoViewFiletests(LocalBasetests):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(PagureFlaskRepoViewFiletests, self).setUp()
         super(PagureFlaskRepoViewFiletests, self).setUp()
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(
-            os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         # Add some content to the git repo
         # Add some content to the git repo
         tests.add_content_git_repo(
         tests.add_content_git_repo(
-            os.path.join(self.path, 'repos', 'test.git'))
-        tests.add_readme_git_repo(
-            os.path.join(self.path, 'repos', 'test.git'))
+            os.path.join(self.path, "repos", "test.git")
+        )
+        tests.add_readme_git_repo(os.path.join(self.path, "repos", "test.git"))
         tests.add_binary_git_repo(
         tests.add_binary_git_repo(
-            os.path.join(self.path, 'repos', 'test.git'), 'test.jpg')
+            os.path.join(self.path, "repos", "test.git"), "test.jpg"
+        )
         tests.add_binary_git_repo(
         tests.add_binary_git_repo(
-            os.path.join(self.path, 'repos', 'test.git'), 'test_binary')
+            os.path.join(self.path, "repos", "test.git"), "test_binary"
+        )
 
 
     def test_view_file_invalid_file(self):
     def test_view_file_invalid_file(self):
         """ Test the view_file when the file doesn't exist. """
         """ Test the view_file when the file doesn't exist. """
 
 
-        output = self.app.get('/test/blob/master/foofile')
+        output = self.app.get("/test/blob/master/foofile")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
-        output = self.app.get('/test/blob/sources/f/testfoo.jpg')
+        output = self.app.get("/test/blob/sources/f/testfoo.jpg")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
-        output = self.app.get('/test/blob/master/f/folder1/testfoo.jpg')
+        output = self.app.get("/test/blob/master/f/folder1/testfoo.jpg")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
     def test_view_file_basic_text(self):
     def test_view_file_basic_text(self):
         """ Test the view_file with a basic text file. """
         """ Test the view_file with a basic text file. """
-        output = self.app.get('/test/blob/master/f/sources')
+        output = self.app.get("/test/blob/master/f/sources")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
             '<pre class="syntaxhighlightblock">'
             '<pre class="syntaxhighlightblock">'
             '<code class="lang-plaintext">foo\n bar</code></pre>',
             '<code class="lang-plaintext">foo\n bar</code></pre>',
-            output_text
+            output_text,
         )
         )
 
 
     def test_view_file_empty_file(self):
     def test_view_file_empty_file(self):
@@ -109,114 +112,119 @@ class PagureFlaskRepoViewFiletests(LocalBasetests):
 
 
         # Empty files should also be displayed
         # Empty files should also be displayed
         tests.add_content_to_git(
         tests.add_content_to_git(
-            os.path.join(self.path, 'repos', 'test.git'),
+            os.path.join(self.path, "repos", "test.git"),
             filename="emptyfile.md",
             filename="emptyfile.md",
-            content="")
-        output = self.app.get('/test/blob/master/f/emptyfile.md')
+            content="",
+        )
+        output = self.app.get("/test/blob/master/f/emptyfile.md")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
             '<a class="btn btn-secondary btn-sm" '
             '<a class="btn btn-secondary btn-sm" '
             'href="/test/raw/master/f/emptyfile.md" '
             'href="/test/raw/master/f/emptyfile.md" '
-            'title="View as raw">Raw</a>', output_text)
+            'title="View as raw">Raw</a>',
+            output_text,
+        )
         self.assertIn(
         self.assertIn(
-            '<div class="m-2">\n'
-            '        \n      </div>', output_text)
+            '<div class="m-2">\n' "        \n      </div>", output_text
+        )
 
 
     def test_view_file_binary_file(self):
     def test_view_file_binary_file(self):
         """ Test the view_file with a binary file. """
         """ Test the view_file with a binary file. """
 
 
         # View what's supposed to be an image
         # View what's supposed to be an image
-        output = self.app.get('/test/blob/master/f/test.jpg')
+        output = self.app.get("/test/blob/master/f/test.jpg")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
-        self.assertIn(
-            'Binary files cannot be rendered.<br/>', output_text)
+        self.assertIn("Binary files cannot be rendered.<br/>", output_text)
         self.assertIn(
         self.assertIn(
             '<a href="/test/raw/master/f/test.jpg">view the raw version',
             '<a href="/test/raw/master/f/test.jpg">view the raw version',
-            output_text)
+            output_text,
+        )
 
 
     def test_view_file_by_commit(self):
     def test_view_file_by_commit(self):
         """ Test the view_file in a specific commit. """
         """ Test the view_file in a specific commit. """
 
 
         # View by commit id
         # View by commit id
-        repo = pygit2.Repository(os.path.join(self.path, 'repos', 'test.git'))
-        commit = repo.revparse_single('HEAD')
+        repo = pygit2.Repository(os.path.join(self.path, "repos", "test.git"))
+        commit = repo.revparse_single("HEAD")
 
 
-        output = self.app.get('/test/blob/%s/f/test.jpg' % commit.oid.hex)
+        output = self.app.get("/test/blob/%s/f/test.jpg" % commit.oid.hex)
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
-        self.assertIn(
-            'Binary files cannot be rendered.<br/>', output_text)
+        self.assertIn("Binary files cannot be rendered.<br/>", output_text)
         self.assertIn('/f/test.jpg">view the raw version', output_text)
         self.assertIn('/f/test.jpg">view the raw version', output_text)
 
 
     def test_view_file_by_name(self):
     def test_view_file_by_name(self):
         """ Test the view_file via a image name. """
         """ Test the view_file via a image name. """
 
 
         # View by image name -- somehow we support this
         # View by image name -- somehow we support this
-        output = self.app.get('/test/blob/sources/f/test.jpg')
+        output = self.app.get("/test/blob/sources/f/test.jpg")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
-        self.assertIn(
-            'Binary files cannot be rendered.<br/>', output_text)
+        self.assertIn("Binary files cannot be rendered.<br/>", output_text)
         self.assertIn('/f/test.jpg">view the raw version', output_text)
         self.assertIn('/f/test.jpg">view the raw version', output_text)
 
 
     def test_view_file_binary_file2(self):
     def test_view_file_binary_file2(self):
         """ Test the view_file with a binary file (2). """
         """ Test the view_file with a binary file (2). """
 
 
         # View binary file
         # View binary file
-        output = self.app.get('/test/blob/sources/f/test_binary')
+        output = self.app.get("/test/blob/sources/f/test_binary")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn('/f/test_binary">view the raw version', output_text)
         self.assertIn('/f/test_binary">view the raw version', output_text)
-        self.assertTrue(
-            'Binary files cannot be rendered.<br/>'
-            in output_text)
+        self.assertTrue("Binary files cannot be rendered.<br/>" in output_text)
 
 
     def test_view_file_for_folder(self):
     def test_view_file_for_folder(self):
         """ Test the view_file with a folder. """
         """ Test the view_file with a folder. """
 
 
         # View folder
         # View folder
-        output = self.app.get('/test/blob/master/f/folder1')
+        output = self.app.get("/test/blob/master/f/folder1")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
-            '<span class="fa fa-folder text-muted"></span>',
-            output_text)
-        self.assertIn('<title>Tree - test - Pagure</title>', output_text)
+            '<span class="fa fa-folder text-muted"></span>', output_text
+        )
+        self.assertIn("<title>Tree - test - Pagure</title>", output_text)
         self.assertIn(
         self.assertIn(
-            '<a href="/test/blob/master/f/folder1/folder2">', output_text)
+            '<a href="/test/blob/master/f/folder1/folder2">', output_text
+        )
 
 
     def test_view_file_nested_file(self):
     def test_view_file_nested_file(self):
         """ Test the view_file with a nested file. """
         """ Test the view_file with a nested file. """
 
 
         # Verify the nav links correctly when viewing a nested folder/file.
         # Verify the nav links correctly when viewing a nested folder/file.
-        output = self.app.get('/test/blob/master/f/folder1/folder2/file')
+        output = self.app.get("/test/blob/master/f/folder1/folder2/file")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
             '<li class="breadcrumb-item"><a '
             '<li class="breadcrumb-item"><a '
             'href="/test/blob/master/f/folder1/folder2">\n            '
             'href="/test/blob/master/f/folder1/folder2">\n            '
             '<span class="fa fa-folder"></span>&nbsp; folder2</a>'
             '<span class="fa fa-folder"></span>&nbsp; folder2</a>'
-            '\n          </li>', output_text)
+            "\n          </li>",
+            output_text,
+        )
 
 
     def test_view_file_non_ascii_file(self):
     def test_view_file_non_ascii_file(self):
         """ Test the view_file with a non-ascii file name. """
         """ Test the view_file with a non-ascii file name. """
 
 
         # View file with a non-ascii name
         # View file with a non-ascii name
         tests.add_commit_git_repo(
         tests.add_commit_git_repo(
-            os.path.join(self.path, 'repos', 'test.git'),
-            ncommits=1, filename='Šource')
-        output = self.app.get('/test/blob/master/f/Šource')
+            os.path.join(self.path, "repos", "test.git"),
+            ncommits=1,
+            filename="Šource",
+        )
+        output = self.app.get("/test/blob/master/f/Šource")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
-        self.assertEqual(output.headers['Content-Type'].lower(),
-                         'text/html; charset=utf-8')
-        self.assertIn('</span>&nbsp; Šource', output_text)
+        self.assertEqual(
+            output.headers["Content-Type"].lower(), "text/html; charset=utf-8"
+        )
+        self.assertIn("</span>&nbsp; Šource", output_text)
         self.assertIn(
         self.assertIn(
             '<pre class="syntaxhighlightblock">'
             '<pre class="syntaxhighlightblock">'
             '<code class="lang-plaintext">Row 0\n</code></pre>',
             '<code class="lang-plaintext">Row 0\n</code></pre>',
-            output_text
+            output_text,
         )
         )
 
 
     def test_view_file_fork_and_edit_logged_out(self):
     def test_view_file_fork_and_edit_logged_out(self):
@@ -225,16 +233,20 @@ class PagureFlaskRepoViewFiletests(LocalBasetests):
         """
         """
 
 
         # not logged in, no edit button but fork & edit is there
         # not logged in, no edit button but fork & edit is there
-        output = self.app.get('/test/blob/master/f/sources')
+        output = self.app.get("/test/blob/master/f/sources")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertNotIn(
         self.assertNotIn(
             '<a class="btn btn-sm btn-secondary" '
             '<a class="btn btn-sm btn-secondary" '
             'href="/test/edit/master/f/sources" title="Edit file">'
             'href="/test/edit/master/f/sources" title="Edit file">'
-            'Edit</a>', output_text)
+            "Edit</a>",
+            output_text,
+        )
         self.assertIn(
         self.assertIn(
             'onclick="fork_project.submit();">\n                    '
             'onclick="fork_project.submit();">\n                    '
-            '        Fork and Edit', output_text)
+            "        Fork and Edit",
+            output_text,
+        )
 
 
     def test_view_file_fork_and_edit_logged_in(self):
     def test_view_file_fork_and_edit_logged_in(self):
         """ Test the view_file fork and edit button presence when logged
         """ Test the view_file fork and edit button presence when logged
@@ -242,18 +254,22 @@ class PagureFlaskRepoViewFiletests(LocalBasetests):
         """
         """
 
 
         # logged in, both buttons are there
         # logged in, both buttons are there
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/blob/master/f/sources')
+            output = self.app.get("/test/blob/master/f/sources")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<a class="btn btn-sm btn-secondary" '
                 '<a class="btn btn-sm btn-secondary" '
                 'href="/test/edit/master/f/sources" title="Edit file">'
                 'href="/test/edit/master/f/sources" title="Edit file">'
-                'Edit</a>', output_text)
+                "Edit</a>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 'onclick="fork_project.submit();">\n                    '
                 'onclick="fork_project.submit();">\n                    '
-                '        Fork and Edit', output_text)
+                "        Fork and Edit",
+                output_text,
+            )
 
 
 
 
 class PagureFlaskRepoViewFileForktests(LocalBasetests):
 class PagureFlaskRepoViewFileForktests(LocalBasetests):
@@ -264,95 +280,111 @@ class PagureFlaskRepoViewFileForktests(LocalBasetests):
         super(PagureFlaskRepoViewFileForktests, self).setUp()
         super(PagureFlaskRepoViewFileForktests, self).setUp()
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(
-            os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         # Add some content to the git repo
         # Add some content to the git repo
         tests.add_content_git_repo(
         tests.add_content_git_repo(
-            os.path.join(self.path, 'repos', 'test.git'))
-        tests.add_readme_git_repo(
-            os.path.join(self.path, 'repos', 'test.git'))
+            os.path.join(self.path, "repos", "test.git")
+        )
+        tests.add_readme_git_repo(os.path.join(self.path, "repos", "test.git"))
         tests.add_binary_git_repo(
         tests.add_binary_git_repo(
-            os.path.join(self.path, 'repos', 'test.git'), 'test.jpg')
+            os.path.join(self.path, "repos", "test.git"), "test.jpg"
+        )
         tests.add_binary_git_repo(
         tests.add_binary_git_repo(
-            os.path.join(self.path, 'repos', 'test.git'), 'test_binary')
+            os.path.join(self.path, "repos", "test.git"), "test_binary"
+        )
 
 
         # Add a fork of a fork
         # Add a fork of a fork
         item = pagure.lib.model.Project(
         item = pagure.lib.model.Project(
             user_id=1,  # pingou
             user_id=1,  # pingou
-            name='test',
-            description='test project #3',
+            name="test",
+            description="test project #3",
             is_fork=True,
             is_fork=True,
             parent_id=1,
             parent_id=1,
-            hook_token='aaabbbppp',
+            hook_token="aaabbbppp",
         )
         )
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
 
 
         tests.add_content_git_repo(
         tests.add_content_git_repo(
-            os.path.join(self.path, 'repos', 'forks', 'pingou', 'test.git'))
+            os.path.join(self.path, "repos", "forks", "pingou", "test.git")
+        )
         tests.add_readme_git_repo(
         tests.add_readme_git_repo(
-            os.path.join(self.path, 'repos', 'forks', 'pingou', 'test.git'))
+            os.path.join(self.path, "repos", "forks", "pingou", "test.git")
+        )
         tests.add_commit_git_repo(
         tests.add_commit_git_repo(
-            os.path.join(self.path, 'repos', 'forks', 'pingou', 'test.git'),
-            ncommits=10)
+            os.path.join(self.path, "repos", "forks", "pingou", "test.git"),
+            ncommits=10,
+        )
 
 
     def test_view_file_nested_file_in_fork(self):
     def test_view_file_nested_file_in_fork(self):
         """ Test the view_file with a nested file in fork. """
         """ Test the view_file with a nested file in fork. """
         # Verify the nav links correctly when viewing a file/folder in a fork.
         # Verify the nav links correctly when viewing a file/folder in a fork.
         output = self.app.get(
         output = self.app.get(
-            '/fork/pingou/test/blob/master/f/folder1/folder2/file')
+            "/fork/pingou/test/blob/master/f/folder1/folder2/file"
+        )
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         self.assertIn(
         self.assertIn(
             '<li class="breadcrumb-item"><a '
             '<li class="breadcrumb-item"><a '
             'href="/fork/pingou/test/blob/master/f/folder1/folder2">'
             'href="/fork/pingou/test/blob/master/f/folder1/folder2">'
             '\n            <span class="fa fa-folder"></span>&nbsp; folder2'
             '\n            <span class="fa fa-folder"></span>&nbsp; folder2'
-            '</a>\n          </li>', output.get_data(as_text=True))
+            "</a>\n          </li>",
+            output.get_data(as_text=True),
+        )
 
 
     def test_view_file_in_branch_in_fork(self):
     def test_view_file_in_branch_in_fork(self):
         """ Test the view_file in a specific branch of a fork. """
         """ Test the view_file in a specific branch of a fork. """
-        output = self.app.get('/fork/pingou/test/blob/master/f/sources')
+        output = self.app.get("/fork/pingou/test/blob/master/f/sources")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
             '<pre class="syntaxhighlightblock"><code class="lang-plaintext">'
             '<pre class="syntaxhighlightblock"><code class="lang-plaintext">'
-            'foo\n barRow 0\n'
-            'Row 1\nRow 2\nRow 3\nRow 4\nRow 5\nRow 6\nRow 7\nRow 8\n'
-            'Row 9\n</code></pre>', output_text
+            "foo\n barRow 0\n"
+            "Row 1\nRow 2\nRow 3\nRow 4\nRow 5\nRow 6\nRow 7\nRow 8\n"
+            "Row 9\n</code></pre>",
+            output_text,
         )
         )
 
 
     def test_view_file_fork_and_edit_on_fork_logged_out(self):
     def test_view_file_fork_and_edit_on_fork_logged_out(self):
         """ Test the view_file on a text file on a fork when logged out. """
         """ Test the view_file on a text file on a fork when logged out. """
 
 
         # not logged in, no edit button but fork & edit is there
         # not logged in, no edit button but fork & edit is there
-        output = self.app.get('/fork/pingou/test/blob/master/f/sources')
+        output = self.app.get("/fork/pingou/test/blob/master/f/sources")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertNotIn(
         self.assertNotIn(
             '<a class="btn btn-sm btn-secondary" '
             '<a class="btn btn-sm btn-secondary" '
             'href="/test/edit/master/f/sources" title="Edit file">'
             'href="/test/edit/master/f/sources" title="Edit file">'
-            'Edit</a>', output_text)
+            "Edit</a>",
+            output_text,
+        )
         self.assertIn(
         self.assertIn(
             'onclick="fork_project.submit();">\n                    '
             'onclick="fork_project.submit();">\n                    '
-            '        Fork and Edit', output_text)
+            "        Fork and Edit",
+            output_text,
+        )
 
 
     def test_view_file_fork_and_edit_on_your_fork(self):
     def test_view_file_fork_and_edit_on_your_fork(self):
         """ Test the view_file on a text file on your fork when logged in.
         """ Test the view_file on a text file on your fork when logged in.
         """
         """
 
 
         # logged in, but it's your own fork, so just edit button is there
         # logged in, but it's your own fork, so just edit button is there
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/fork/pingou/test/blob/master/f/sources')
+            output = self.app.get("/fork/pingou/test/blob/master/f/sources")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<a class="btn btn-sm btn-secondary" '
                 '<a class="btn btn-sm btn-secondary" '
                 'href="/fork/pingou/test/edit/master/f/sources" title="Edit file">'
                 'href="/fork/pingou/test/edit/master/f/sources" title="Edit file">'
-                'Edit</a>', output_text)
+                "Edit</a>",
+                output_text,
+            )
             self.assertNotIn(
             self.assertNotIn(
                 'onclick="fork_project.submit();">\n                    '
                 'onclick="fork_project.submit();">\n                    '
-                '        Fork and Edit', output_text)
+                "        Fork and Edit",
+                output_text,
+            )
 
 
     def test_view_file_fork_and_edit_on_a_fork(self):
     def test_view_file_fork_and_edit_on_a_fork(self):
         """ Test the view_file on a text file on somone else's fork when
         """ Test the view_file on a text file on somone else's fork when
@@ -361,18 +393,22 @@ class PagureFlaskRepoViewFileForktests(LocalBasetests):
 
 
         # logged in, but it's not your fork, so only fork and edit button
         # logged in, but it's not your fork, so only fork and edit button
         # is there
         # is there
-        user = tests.FakeUser(username='foo')
+        user = tests.FakeUser(username="foo")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/fork/pingou/test/blob/master/f/sources')
+            output = self.app.get("/fork/pingou/test/blob/master/f/sources")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertNotIn(
             self.assertNotIn(
                 '<a class="btn btn-sm btn-secondary" '
                 '<a class="btn btn-sm btn-secondary" '
                 'href="/fork/pingou/test/edit/master/f/sources" title="Edit file">'
                 'href="/fork/pingou/test/edit/master/f/sources" title="Edit file">'
-                'Edit</a>', output_text)
+                "Edit</a>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 'onclick="fork_project.submit();">\n                    '
                 'onclick="fork_project.submit();">\n                    '
-                '        Fork and Edit', output_text)
+                "        Fork and Edit",
+                output_text,
+            )
 
 
     def test_view_file_fork_and_edit_on_project(self):
     def test_view_file_fork_and_edit_on_project(self):
         """ Test the view_file on a text file on somone else's fork when
         """ Test the view_file on a text file on somone else's fork when
@@ -380,19 +416,23 @@ class PagureFlaskRepoViewFileForktests(LocalBasetests):
         """
         """
 
 
         # logged in and seeing the project you forked
         # logged in and seeing the project you forked
-        user = tests.FakeUser(username='pingou')
+        user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/blob/master/f/sources')
+            output = self.app.get("/test/blob/master/f/sources")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
                 '<a class="btn btn-sm btn-secondary" '
                 '<a class="btn btn-sm btn-secondary" '
                 'href="/test/edit/master/f/sources" title="Edit file">'
                 'href="/test/edit/master/f/sources" title="Edit file">'
-                'Edit</a>', output_text)
+                "Edit</a>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 'onclick="fork_project.submit();">\n                    '
                 'onclick="fork_project.submit();">\n                    '
-                '        Edit in your fork', output_text)
+                "        Edit in your fork",
+                output_text,
+            )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 312 - 238
tests/test_pagure_flask_ui_roadmap.py

@@ -21,8 +21,9 @@ import os
 import pygit2
 import pygit2
 from mock import patch
 from mock import patch
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import tests
 import tests
@@ -32,397 +33,452 @@ from pagure.lib.repo import PagureRepo
 class PagureFlaskRoadmaptests(tests.Modeltests):
 class PagureFlaskRoadmaptests(tests.Modeltests):
     """ Tests for the pagure's roadmap """
     """ Tests for the pagure's roadmap """
 
 
-    @patch('pagure.lib.git.update_git')
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.git.update_git")
+    @patch("pagure.lib.notify.send_email")
     def test_ticket_with_no_roadmap(self, p_send_email, p_ugt):
     def test_ticket_with_no_roadmap(self, p_send_email, p_ugt):
         """ Test creating a ticket without roadmap. """
         """ Test creating a ticket without roadmap. """
         p_send_email.return_value = True
         p_send_email.return_value = True
         p_ugt.return_value = True
         p_ugt.return_value = True
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
             # Get the CSRF token
             # Get the CSRF token
-            output = self.app.get('/test/new_issue')
+            output = self.app.get("/test/new_issue")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertTrue(
             self.assertTrue(
                 '<h4 class="font-weight-bold mb-4">New Issue</h4>\n'
                 '<h4 class="font-weight-bold mb-4">New Issue</h4>\n'
-                in output_text)
+                in output_text
+            )
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             data = {
             data = {
-                'title': 'Test issue',
-                'issue_content': 'We really should improve on this issue',
-                'status': 'Open',
-                'csrf_token': csrf_token,
+                "title": "Test issue",
+                "issue_content": "We really should improve on this issue",
+                "status": "Open",
+                "csrf_token": csrf_token,
             }
             }
 
 
             # Create the issue
             # Create the issue
             output = self.app.post(
             output = self.app.post(
-                '/test/new_issue', data=data, follow_redirects=True)
+                "/test/new_issue", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Issue #1: Test issue - test - Pagure</title>',
-                output_text)
+                "<title>Issue #1: Test issue - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 'href="/test/issue/1/edit" title="Edit this issue">',
                 'href="/test/issue/1/edit" title="Edit this issue">',
-                output_text)
+                output_text,
+            )
 
 
-    @patch('pagure.lib.git.update_git')
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.git.update_git")
+    @patch("pagure.lib.notify.send_email")
     def test_ticket_with_roadmap(self, p_send_email, p_ugt):
     def test_ticket_with_roadmap(self, p_send_email, p_ugt):
         """ Test creating a ticket with roadmap. """
         """ Test creating a ticket with roadmap. """
         p_send_email.return_value = True
         p_send_email.return_value = True
         p_ugt.return_value = True
         p_ugt.return_value = True
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         # Set some milestone
         # Set some milestone
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
-        repo.milestone = {'v1.0': '', 'v2.0': 'Tomorrow!'}
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
+        repo.milestone = {"v1.0": "", "v2.0": "Tomorrow!"}
         self.session.add(repo)
         self.session.add(repo)
         self.session.commit()
         self.session.commit()
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
             # Get the CSRF token
             # Get the CSRF token
-            output = self.app.get('/test/new_issue')
+            output = self.app.get("/test/new_issue")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertTrue(
             self.assertTrue(
                 '<h4 class="font-weight-bold mb-4">New Issue</h4>\n'
                 '<h4 class="font-weight-bold mb-4">New Issue</h4>\n'
-                in output_text)
+                in output_text
+            )
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             data = {
             data = {
-                'title': 'Test issue',
-                'issue_content': 'We really should improve on this issue',
-                'status': 'Open',
-                'csrf_token': csrf_token,
+                "title": "Test issue",
+                "issue_content": "We really should improve on this issue",
+                "status": "Open",
+                "csrf_token": csrf_token,
             }
             }
 
 
             # Create the issue
             # Create the issue
             output = self.app.post(
             output = self.app.post(
-                '/test/new_issue', data=data, follow_redirects=True)
+                "/test/new_issue", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Issue #1: Test issue - test - Pagure</title>',
-                output_text)
+                "<title>Issue #1: Test issue - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 'href="/test/issue/1/edit" title="Edit this issue">',
                 'href="/test/issue/1/edit" title="Edit this issue">',
-                output_text)
+                output_text,
+            )
 
 
             # Mark the ticket for the roadmap
             # Mark the ticket for the roadmap
-            data = {
-                'tag': 'roadmap',
-                'csrf_token': csrf_token,
-            }
+            data = {"tag": "roadmap", "csrf_token": csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/test/issue/1/update', data=data, follow_redirects=True)
+                "/test/issue/1/update", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Issue #1: Test issue - test - Pagure</title>',
-                output_text)
+                "<title>Issue #1: Test issue - test - Pagure</title>",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 '<a class="btn btn-outline-secondary btn-sm border-0" '
                 'href="/test/issue/1/edit" title="Edit this issue">',
                 'href="/test/issue/1/edit" title="Edit this issue">',
-                output_text)
+                output_text,
+            )
 
 
     def test_update_milestones(self):
     def test_update_milestones(self):
         """ Test updating milestones of a repo. """
         """ Test updating milestones of a repo. """
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         # Set some milestones
         # Set some milestones
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(repo.milestones, {})
         self.assertEqual(repo.milestones, {})
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
             # Get the CSRF token
             # Get the CSRF token
-            output = self.app.get('/test/settings')
+            output = self.app.get("/test/settings")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             data = {
             data = {
-                'milestones': 1,
-                'milestone_1_name': '1',
-                'milestone_1_date': 'Tomorrow',
+                "milestones": 1,
+                "milestone_1_name": "1",
+                "milestone_1_date": "Tomorrow",
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/milestones', data=data, follow_redirects=True)
+                "/test/update/milestones", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             # Check the result of the action -- None, no CSRF
             # Check the result of the action -- None, no CSRF
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
             self.assertEqual(repo.milestones, {})
             self.assertEqual(repo.milestones, {})
 
 
             data = {
             data = {
-                'milestones': 1,
-                'milestone_1_name': '1',
-                'milestone_date': '',
-                'csrf_token': csrf_token,
+                "milestones": 1,
+                "milestone_1_name": "1",
+                "milestone_date": "",
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/milestones', data=data, follow_redirects=True)
+                "/test/update/milestones", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn('Milestones updated', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Milestones updated", output_text)
 
 
             # Check the result of the action -- Milestones recorded
             # Check the result of the action -- Milestones recorded
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
-            self.assertEqual(repo.milestones, {'1': {'active': False, 'date': None}})
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
+            self.assertEqual(
+                repo.milestones, {"1": {"active": False, "date": None}}
+            )
 
 
             data = {
             data = {
-                'milestones': [1, 2],
-                'milestone_1_name': 'v1.0',
-                'milestone_2_name': 'v2.0',
-                'milestone_1_date': 'Tomorrow',
-                'milestone_2_date': '',
-                'csrf_token': csrf_token,
+                "milestones": [1, 2],
+                "milestone_1_name": "v1.0",
+                "milestone_2_name": "v2.0",
+                "milestone_1_date": "Tomorrow",
+                "milestone_2_date": "",
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/milestones', data=data, follow_redirects=True)
+                "/test/update/milestones", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn('Milestones updated', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Milestones updated", output_text)
             # Check the result of the action -- Milestones recorded
             # Check the result of the action -- Milestones recorded
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
             self.assertEqual(
             self.assertEqual(
                 repo.milestones,
                 repo.milestones,
                 {
                 {
-                    'v1.0': {'active': False, 'date': 'Tomorrow'},
-                    'v2.0': {'active': False, 'date': None}
-                }
+                    "v1.0": {"active": False, "date": "Tomorrow"},
+                    "v2.0": {"active": False, "date": None},
+                },
             )
             )
 
 
             # Check error - less milestones than dates
             # Check error - less milestones than dates
             data = {
             data = {
-                'milestones': [1, 2],
-                'milestone_1_name': 'v1.0',
-                'milestone_2_name': 'v2.0',
-                'milestone_1_date': 'Tomorrow',
-                'milestone_2_date': 'Next week',
-                'milestone_3_date': 'Next Year',
-                'csrf_token': csrf_token,
+                "milestones": [1, 2],
+                "milestone_1_name": "v1.0",
+                "milestone_2_name": "v2.0",
+                "milestone_1_date": "Tomorrow",
+                "milestone_2_date": "Next week",
+                "milestone_3_date": "Next Year",
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/milestones', data=data, follow_redirects=True)
+                "/test/update/milestones", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             # Check the result of the action -- Milestones un-changed
             # Check the result of the action -- Milestones un-changed
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
             self.assertEqual(
             self.assertEqual(
                 repo.milestones,
                 repo.milestones,
                 {
                 {
-                    'v1.0': {'active': False, 'date': 'Tomorrow'},
-                    'v2.0': {'active': False, 'date': 'Next week'}
-                }
+                    "v1.0": {"active": False, "date": "Tomorrow"},
+                    "v2.0": {"active": False, "date": "Next week"},
+                },
             )
             )
 
 
             # Check error - Twice the same milestone
             # Check error - Twice the same milestone
             data = {
             data = {
-                'milestones': [1, 2, 3],
-                'milestone_1_name': 'v1.0',
-                'milestone_2_name': 'v2.0',
-                'milestone_3_name': 'v2.0',
-                'milestone_1_date': 'Tomorrow',
-                'milestone_2_date': 'Next week',
-                'milestone_3_date': 'Next Year',
-                'csrf_token': csrf_token,
+                "milestones": [1, 2, 3],
+                "milestone_1_name": "v1.0",
+                "milestone_2_name": "v2.0",
+                "milestone_3_name": "v2.0",
+                "milestone_1_date": "Tomorrow",
+                "milestone_2_date": "Next week",
+                "milestone_3_date": "Next Year",
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/milestones', data=data, follow_redirects=True)
+                "/test/update/milestones", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
-                'Milestone v2.0 is present multiple times',
-                'Milestone v2.0 is present multiple times',
-                output_text)
+                "Milestone v2.0 is present multiple times",
+                "Milestone v2.0 is present multiple times",
+                output_text,
+            )
             # Check the result of the action -- Milestones un-changed
             # Check the result of the action -- Milestones un-changed
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
             self.assertEqual(
             self.assertEqual(
                 repo.milestones,
                 repo.milestones,
                 {
                 {
-                    'v1.0': {'active': False, 'date': 'Tomorrow'},
-                    'v2.0': {'active': False, 'date': 'Next week'}
-                }
+                    "v1.0": {"active": False, "date": "Tomorrow"},
+                    "v2.0": {"active": False, "date": "Next week"},
+                },
             )
             )
 
 
             # Check error - Twice the same date
             # Check error - Twice the same date
             data = {
             data = {
-                'milestones': [1, 2, 3],
-                'milestone_1_name': 'v1.0',
-                'milestone_2_name': 'v2.0',
-                'milestone_3_name': 'v3.0',
-                'milestone_1_date': 'Tomorrow',
-                'milestone_2_date': 'Next week',
-                'milestone_3_date': 'Next week',
-                'csrf_token': csrf_token,
+                "milestones": [1, 2, 3],
+                "milestone_1_name": "v1.0",
+                "milestone_2_name": "v2.0",
+                "milestone_3_name": "v3.0",
+                "milestone_1_date": "Tomorrow",
+                "milestone_2_date": "Next week",
+                "milestone_3_date": "Next week",
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/milestones', data=data, follow_redirects=True)
+                "/test/update/milestones", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn(
-                'Milestones updated',
-                output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Milestones updated", output_text)
             # Check the result of the action -- Milestones updated
             # Check the result of the action -- Milestones updated
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
             self.assertEqual(
             self.assertEqual(
                 repo.milestones,
                 repo.milestones,
                 {
                 {
-                    'v1.0': {'active': False, 'date': 'Tomorrow'},
-                    'v2.0': {'active': False, 'date': 'Next week'},
-                    'v3.0': {'active': False, 'date': 'Next week'},
-                }
+                    "v1.0": {"active": False, "date": "Tomorrow"},
+                    "v2.0": {"active": False, "date": "Next week"},
+                    "v3.0": {"active": False, "date": "Next week"},
+                },
             )
             )
 
 
             # Check for an invalid project
             # Check for an invalid project
-            output = self.app.post(
-                '/foo/update/milestones', data=data)
+            output = self.app.post("/foo/update/milestones", data=data)
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
             # Check the behavior if the project disabled the issue tracker
             # Check the behavior if the project disabled the issue tracker
             settings = repo.settings
             settings = repo.settings
-            settings['issue_tracker'] = False
+            settings["issue_tracker"] = False
             repo.settings = settings
             repo.settings = settings
             self.session.add(repo)
             self.session.add(repo)
             self.session.commit()
             self.session.commit()
 
 
-            output = self.app.post(
-                '/test/update/milestones', data=data)
+            output = self.app.post("/test/update/milestones", data=data)
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
         # Check for a non-admin user
         # Check for a non-admin user
         settings = repo.settings
         settings = repo.settings
-        settings['issue_tracker'] = True
+        settings["issue_tracker"] = True
         repo.settings = settings
         repo.settings = settings
         self.session.add(repo)
         self.session.add(repo)
         self.session.commit()
         self.session.commit()
 
 
-        user.username = 'ralph'
+        user.username = "ralph"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.post(
-                '/test/update/milestones', data=data)
+            output = self.app.post("/test/update/milestones", data=data)
             self.assertEqual(output.status_code, 403)
             self.assertEqual(output.status_code, 403)
 
 
-    @patch('pagure.lib.git.update_git')
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.git.update_git")
+    @patch("pagure.lib.notify.send_email")
     def test_milestones_without_dates(self, p_send_email, p_ugt):
     def test_milestones_without_dates(self, p_send_email, p_ugt):
         """ Test creating two milestones with no dates. """
         """ Test creating two milestones with no dates. """
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             # Get the CSRF token
             # Get the CSRF token
-            output = self.app.get('/test/settings')
+            output = self.app.get("/test/settings")
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             data = {
             data = {
-                'milestones': [1, 2],
-                'milestone_1_name': 'v1.0',
-                'milestone_2_name': 'v2.0',
-                'milestone_1_date': '',
-                'milestone_2_date': '',
-                'csrf_token': csrf_token,
+                "milestones": [1, 2],
+                "milestone_1_name": "v1.0",
+                "milestone_2_name": "v2.0",
+                "milestone_1_date": "",
+                "milestone_2_date": "",
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/milestones', data=data, follow_redirects=True)
+                "/test/update/milestones", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn('Milestones updated', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Milestones updated", output_text)
             # Check the result of the action -- Milestones recorded
             # Check the result of the action -- Milestones recorded
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+            repo = pagure.lib.query.get_authorized_project(
+                self.session, "test"
+            )
             self.assertEqual(
             self.assertEqual(
                 repo.milestones,
                 repo.milestones,
                 {
                 {
-                    'v1.0': {'active': False, 'date': None},
-                    'v2.0': {'active': False, 'date': None}
-                }
+                    "v1.0": {"active": False, "date": None},
+                    "v2.0": {"active": False, "date": None},
+                },
             )
             )
 
 
-    @patch('pagure.lib.git.update_git')
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.git.update_git")
+    @patch("pagure.lib.notify.send_email")
     def test_roadmap_ui(self, p_send_email, p_ugt):
     def test_roadmap_ui(self, p_send_email, p_ugt):
         """ Test viewing the roadmap of a repo. """
         """ Test viewing the roadmap of a repo. """
         p_send_email.return_value = True
         p_send_email.return_value = True
@@ -431,181 +487,199 @@ class PagureFlaskRoadmaptests(tests.Modeltests):
         self.test_update_milestones()
         self.test_update_milestones()
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
             # Get the CSRF token
             # Get the CSRF token
-            output = self.app.get('/test/new_issue')
+            output = self.app.get("/test/new_issue")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             self.assertTrue(
             self.assertTrue(
                 '<h4 class="font-weight-bold mb-4">New Issue</h4>\n'
                 '<h4 class="font-weight-bold mb-4">New Issue</h4>\n'
-                in output_text)
+                in output_text
+            )
 
 
             csrf_token = output_text.split(
             csrf_token = output_text.split(
-                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
+                'name="csrf_token" type="hidden" value="'
+            )[1].split('">')[0]
 
 
             # Create an unplanned milestone
             # Create an unplanned milestone
             data = {
             data = {
-                'milestones': [1, 2, 3],
-                'milestone_1_name': 'v1.0',
-                'milestone_2_name': 'v2.0',
-                'milestone_3_name': 'unplanned',
-                'milestone_1_date': 'Tomorrow',
-                'milestone_2_date': '',
-                'milestone_3_date': '',
-                'milestone_1_active': True,
-                'milestone_2_active': True,
-                'milestone_3_active': True,
-                'csrf_token': csrf_token,
+                "milestones": [1, 2, 3],
+                "milestone_1_name": "v1.0",
+                "milestone_2_name": "v2.0",
+                "milestone_3_name": "unplanned",
+                "milestone_1_date": "Tomorrow",
+                "milestone_2_date": "",
+                "milestone_3_date": "",
+                "milestone_1_active": True,
+                "milestone_2_active": True,
+                "milestone_3_active": True,
+                "csrf_token": csrf_token,
             }
             }
             output = self.app.post(
             output = self.app.post(
-                '/test/update/milestones', data=data, follow_redirects=True)
+                "/test/update/milestones", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
             # Check the redirect
             # Check the redirect
             self.assertIn(
             self.assertIn(
-                '<title>Settings - test - Pagure</title>', output_text)
+                "<title>Settings - test - Pagure</title>", output_text
+            )
             self.assertIn(
             self.assertIn(
                 '<h5 class="pl-2 font-weight-bold text-muted">'
                 '<h5 class="pl-2 font-weight-bold text-muted">'
-                'Project Settings</h5>\n', output_text)
-            self.assertIn('Milestones updated', output_text)
+                "Project Settings</h5>\n",
+                output_text,
+            )
+            self.assertIn("Milestones updated", output_text)
 
 
             # Check the result of the action -- Milestones recorded
             # Check the result of the action -- Milestones recorded
             self.session.commit()
             self.session.commit()
-            repo = pagure.lib.query._get_project(self.session, 'test')
+            repo = pagure.lib.query._get_project(self.session, "test")
             self.assertEqual(
             self.assertEqual(
                 repo.milestones,
                 repo.milestones,
                 {
                 {
-                    'unplanned': {'active': True, 'date': None},
-                    'v1.0': {'active': True, 'date': 'Tomorrow'},
-                    'v2.0': {'active': True, 'date': None}
-                }
+                    "unplanned": {"active": True, "date": None},
+                    "v1.0": {"active": True, "date": "Tomorrow"},
+                    "v2.0": {"active": True, "date": None},
+                },
             )
             )
 
 
             # Create the issues
             # Create the issues
             for cnt in range(6):
             for cnt in range(6):
                 cnt += 1
                 cnt += 1
                 data = {
                 data = {
-                    'title': 'Test issue %s' % cnt,
-                    'issue_content': 'We really should improve on this '
-                    'issue %s' % cnt,
-                    'csrf_token': csrf_token,
+                    "title": "Test issue %s" % cnt,
+                    "issue_content": "We really should improve on this "
+                    "issue %s" % cnt,
+                    "csrf_token": csrf_token,
                 }
                 }
 
 
                 output = self.app.post(
                 output = self.app.post(
-                    '/test/new_issue', data=data, follow_redirects=True)
+                    "/test/new_issue", data=data, follow_redirects=True
+                )
                 self.assertEqual(output.status_code, 200)
                 self.assertEqual(output.status_code, 200)
                 output_text = output.get_data(as_text=True)
                 output_text = output.get_data(as_text=True)
                 self.assertIn(
                 self.assertIn(
-                    '<title>Issue #{0}: Test issue {0} - test - '
-                    'Pagure</title>'.format(cnt),
-                    output_text)
+                    "<title>Issue #{0}: Test issue {0} - test - "
+                    "Pagure</title>".format(cnt),
+                    output_text,
+                )
                 self.assertIn(
                 self.assertIn(
                     '<a class="btn btn-outline-secondary btn-sm border-0" '
                     '<a class="btn btn-outline-secondary btn-sm border-0" '
-                    'href="/test/issue/%s/edit" title="Edit this issue">' % cnt,
-                    output_text)
+                    'href="/test/issue/%s/edit" title="Edit this issue">'
+                    % cnt,
+                    output_text,
+                )
 
 
                 # Mark the ticket for the roadmap
                 # Mark the ticket for the roadmap
-                mstone = 'v%s.0' % cnt
+                mstone = "v%s.0" % cnt
                 if cnt >= 3:
                 if cnt >= 3:
                     if (cnt % 3) == 0:
                     if (cnt % 3) == 0:
-                        mstone = 'unplanned'
+                        mstone = "unplanned"
                     else:
                     else:
-                        mstone = 'v%s.0' % (cnt % 3)
-                data = {
-                    'milestone': mstone,
-                    'csrf_token': csrf_token,
-                }
+                        mstone = "v%s.0" % (cnt % 3)
+                data = {"milestone": mstone, "csrf_token": csrf_token}
                 output = self.app.post(
                 output = self.app.post(
-                    '/test/issue/%s/update' % cnt, data=data,
-                    follow_redirects=True)
+                    "/test/issue/%s/update" % cnt,
+                    data=data,
+                    follow_redirects=True,
+                )
                 self.assertEqual(output.status_code, 200)
                 self.assertEqual(output.status_code, 200)
                 output_text = output.get_data(as_text=True)
                 output_text = output.get_data(as_text=True)
                 self.assertIn(
                 self.assertIn(
-                    '<title>Issue #{0}: Test issue {0} - test - '
-                    'Pagure</title>'.format(cnt),
-                    output_text)
+                    "<title>Issue #{0}: Test issue {0} - test - "
+                    "Pagure</title>".format(cnt),
+                    output_text,
+                )
                 self.assertIn(
                 self.assertIn(
                     '<a class="btn btn-outline-secondary btn-sm border-0" '
                     '<a class="btn btn-outline-secondary btn-sm border-0" '
-                    'href="/test/issue/%s/edit" title="Edit this issue">' % cnt,
-                    output_text)
+                    'href="/test/issue/%s/edit" title="Edit this issue">'
+                    % cnt,
+                    output_text,
+                )
                 self.assertIn(
                 self.assertIn(
-                    'Issue set to the milestone: %s' % mstone,
-                    output_text)
+                    "Issue set to the milestone: %s" % mstone, output_text
+                )
                 self.assertIn(
                 self.assertIn(
-                    '<div class="ml-2" id="milestone_plain">', output_text)
+                    '<div class="ml-2" id="milestone_plain">', output_text
+                )
                 self.assertIn(
                 self.assertIn(
-                    '<a href="/test/roadmap/%s/">' % mstone, output_text)
+                    '<a href="/test/roadmap/%s/">' % mstone, output_text
+                )
 
 
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
 
 
         # Mark ticket #1 as Fixed
         # Mark ticket #1 as Fixed
         for iid in [1, 4]:
         for iid in [1, 4]:
             ticket = pagure.lib.query.search_issues(
             ticket = pagure.lib.query.search_issues(
-                self.session,
-                repo,
-                issueid=iid
+                self.session, repo, issueid=iid
             )
             )
-            ticket.status = 'Closed'
-            ticket.close_status = 'Fixed'
+            ticket.status = "Closed"
+            ticket.close_status = "Fixed"
             self.session.add(ticket)
             self.session.add(ticket)
             self.session.commit()
             self.session.commit()
 
 
         # test the roadmap view
         # test the roadmap view
-        output = self.app.get('/test/roadmap')
+        output = self.app.get("/test/roadmap")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
             '<span class="fa fa-fw fa-map-signs"></span>\n'
             '<span class="fa fa-fw fa-map-signs"></span>\n'
             '                            <span class="font'
             '                            <span class="font'
             '-weight-bold">v1.0</span>',
             '-weight-bold">v1.0</span>',
-            output_text)
+            output_text,
+        )
         self.assertIn(
         self.assertIn(
             '<span class="fa fa-fw fa-map-signs"></span>\n'
             '<span class="fa fa-fw fa-map-signs"></span>\n'
             '                            <span class="font'
             '                            <span class="font'
             '-weight-bold">unplanned</span>',
             '-weight-bold">unplanned</span>',
-            output_text)
+            output_text,
+        )
         self.assertIn(
         self.assertIn(
             'title="100% Completed | 2 Closed Issues | 0 Open Issues"\n',
             'title="100% Completed | 2 Closed Issues | 0 Open Issues"\n',
-            output_text)
+            output_text,
+        )
         self.assertIn(
         self.assertIn(
             'title="0% Completed | 0 Closed Issues | 2 Open Issues"\n',
             'title="0% Completed | 0 Closed Issues | 2 Open Issues"\n',
-            output_text)
+            output_text,
+        )
         self.assertIn(
         self.assertIn(
             'title="0% Completed | 0 Closed Issues | 2 Open Issues"\n',
             'title="0% Completed | 0 Closed Issues | 2 Open Issues"\n',
-            output_text)
+            output_text,
+        )
 
 
         # test the roadmap view for a specific milestone
         # test the roadmap view for a specific milestone
-        output = self.app.get('/test/roadmap/v2.0/')
+        output = self.app.get("/test/roadmap/v2.0/")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
             '<span class="fa fa-fw fa-exclamation-circle"></span> 2 Open\n',
             '<span class="fa fa-fw fa-exclamation-circle"></span> 2 Open\n',
-            output_text)
+            output_text,
+        )
         self.assertIn(
         self.assertIn(
             '<span class="fa fa-fw fa-exclamation-circle"></span> 0 Closed\n',
             '<span class="fa fa-fw fa-exclamation-circle"></span> 0 Closed\n',
-            output_text)
-        self.assertIn(
-            '<a class="notblue" href="/test/issue/2">', output_text)
+            output_text,
+        )
+        self.assertIn('<a class="notblue" href="/test/issue/2">', output_text)
         self.assertEquals(
         self.assertEquals(
-            output_text.count('<a class="notblue" href="/test/issue/2">'),
-            1)
+            output_text.count('<a class="notblue" href="/test/issue/2">'), 1
+        )
 
 
         # test the roadmap view for errors
         # test the roadmap view for errors
-        output = self.app.get('/foo/roadmap')
+        output = self.app.get("/foo/roadmap")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         settings = repo.settings
         settings = repo.settings
-        settings['issue_tracker'] = False
+        settings["issue_tracker"] = False
         repo.settings = settings
         repo.settings = settings
         self.session.add(repo)
         self.session.add(repo)
         self.session.commit()
         self.session.commit()
 
 
-        output = self.app.get('/test/roadmap', data=data)
+        output = self.app.get("/test/roadmap", data=data)
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 97 - 88
tests/test_pagure_flask_ui_slash_branch_name.py

@@ -20,8 +20,9 @@ import os
 import pygit2
 import pygit2
 from mock import patch
 from mock import patch
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import tests
 import tests
@@ -36,71 +37,67 @@ class PagureFlaskSlashInBranchtests(tests.SimplePagureTest):
         """ Set up the git repo to play with. """
         """ Set up the git repo to play with. """
 
 
         # Create a git repo to play with
         # Create a git repo to play with
-        gitrepo = os.path.join(self.path, 'repos', 'test.git')
+        gitrepo = os.path.join(self.path, "repos", "test.git")
         repo = pygit2.init_repository(gitrepo, bare=True)
         repo = pygit2.init_repository(gitrepo, bare=True)
 
 
-        newpath = tempfile.mkdtemp(prefix='pagure-other-test')
-        repopath = os.path.join(newpath, 'test')
+        newpath = tempfile.mkdtemp(prefix="pagure-other-test")
+        repopath = os.path.join(newpath, "test")
         clone_repo = pygit2.clone_repository(gitrepo, repopath)
         clone_repo = pygit2.clone_repository(gitrepo, repopath)
 
 
         # Create a file in that git repo
         # Create a file in that git repo
-        with open(os.path.join(repopath, 'sources'), 'w') as stream:
-            stream.write('foo\n bar')
-        clone_repo.index.add('sources')
+        with open(os.path.join(repopath, "sources"), "w") as stream:
+            stream.write("foo\n bar")
+        clone_repo.index.add("sources")
         clone_repo.index.write()
         clone_repo.index.write()
 
 
         # Commits the files added
         # Commits the files added
         tree = clone_repo.index.write_tree()
         tree = clone_repo.index.write_tree()
-        author = pygit2.Signature(
-            'Alice Author', 'alice@authors.tld')
-        committer = pygit2.Signature(
-            'Cecil Committer', 'cecil@committers.tld')
+        author = pygit2.Signature("Alice Author", "alice@authors.tld")
+        committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
         clone_repo.create_commit(
         clone_repo.create_commit(
-            'refs/heads/master',  # the name of the reference to update
+            "refs/heads/master",  # the name of the reference to update
             author,
             author,
             committer,
             committer,
-            'Add sources file for testing',
+            "Add sources file for testing",
             # binary string representing the tree object ID
             # binary string representing the tree object ID
             tree,
             tree,
             # list of binary strings representing parents of the new commit
             # list of binary strings representing parents of the new commit
-            []
+            [],
         )
         )
-        refname = 'refs/heads/master'
+        refname = "refs/heads/master"
         ori_remote = clone_repo.remotes[0]
         ori_remote = clone_repo.remotes[0]
         PagureRepo.push(ori_remote, refname)
         PagureRepo.push(ori_remote, refname)
 
 
-        master_branch = clone_repo.lookup_branch('master')
+        master_branch = clone_repo.lookup_branch("master")
         first_commit = master_branch.peel().hex
         first_commit = master_branch.peel().hex
 
 
         # Second commit
         # Second commit
-        with open(os.path.join(repopath, '.gitignore'), 'w') as stream:
-            stream.write('*~')
-        clone_repo.index.add('.gitignore')
+        with open(os.path.join(repopath, ".gitignore"), "w") as stream:
+            stream.write("*~")
+        clone_repo.index.add(".gitignore")
         clone_repo.index.write()
         clone_repo.index.write()
 
 
         tree = clone_repo.index.write_tree()
         tree = clone_repo.index.write_tree()
-        author = pygit2.Signature(
-            'Alice Author', 'alice@authors.tld')
-        committer = pygit2.Signature(
-            'Cecil Committer', 'cecil@committers.tld')
+        author = pygit2.Signature("Alice Author", "alice@authors.tld")
+        committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
         clone_repo.create_commit(
         clone_repo.create_commit(
-            'refs/heads/maxamilion/feature',
+            "refs/heads/maxamilion/feature",
             author,
             author,
             committer,
             committer,
-            'Add .gitignore file for testing',
+            "Add .gitignore file for testing",
             # binary string representing the tree object ID
             # binary string representing the tree object ID
             tree,
             tree,
             # list of binary strings representing parents of the new commit
             # list of binary strings representing parents of the new commit
-            [first_commit]
+            [first_commit],
         )
         )
 
 
-        refname = 'refs/heads/maxamilion/feature'
+        refname = "refs/heads/maxamilion/feature"
         ori_remote = clone_repo.remotes[0]
         ori_remote = clone_repo.remotes[0]
         PagureRepo.push(ori_remote, refname)
         PagureRepo.push(ori_remote, refname)
 
 
         shutil.rmtree(newpath)
         shutil.rmtree(newpath)
 
 
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.notify.send_email")
     def test_view_repo(self, send_email):
     def test_view_repo(self, send_email):
         """ Test the view_repo endpoint when the git repo has no master
         """ Test the view_repo endpoint when the git repo has no master
         branch.
         branch.
@@ -109,19 +106,20 @@ class PagureFlaskSlashInBranchtests(tests.SimplePagureTest):
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         # Non-existant git repo
         # Non-existant git repo
-        output = self.app.get('/test')
+        output = self.app.get("/test")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
         self.set_up_git_repo()
         self.set_up_git_repo()
 
 
         # With git repo
         # With git repo
-        output = self.app.get('/test')
+        output = self.app.get("/test")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
             '<input class="form-control bg-white" type="text" '
             '<input class="form-control bg-white" type="text" '
             'value="git://localhost.localdomain/test.git" readonly>',
             'value="git://localhost.localdomain/test.git" readonly>',
-            output_text)
+            output_text,
+        )
 
 
     '''
     '''
     @patch('pagure.lib.notify.send_email')
     @patch('pagure.lib.notify.send_email')
@@ -147,7 +145,7 @@ class PagureFlaskSlashInBranchtests(tests.SimplePagureTest):
             'value="git://localhost.localdomain/test.git" readonly>', output_text)
             'value="git://localhost.localdomain/test.git" readonly>', output_text)
     '''
     '''
 
 
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.notify.send_email")
     def test_view_commits(self, send_email):
     def test_view_commits(self, send_email):
         """ Test the view_commits endpoint when the git repo has no
         """ Test the view_commits endpoint when the git repo has no
         master branch.
         master branch.
@@ -156,25 +154,27 @@ class PagureFlaskSlashInBranchtests(tests.SimplePagureTest):
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         # Non-existant git repo
         # Non-existant git repo
-        output = self.app.get('/test/commits')
+        output = self.app.get("/test/commits")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
         self.set_up_git_repo()
         self.set_up_git_repo()
 
 
         # With git repo
         # With git repo
-        output = self.app.get('/test/commits')
+        output = self.app.get("/test/commits")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
-        self.assertEqual(output.get_data(as_text=True).count('<span class="commitdate"'), 1)
+        self.assertEqual(
+            output.get_data(as_text=True).count('<span class="commitdate"'), 1
+        )
 
 
-        output = self.app.get('/test/commits/maxamilion/feature')
+        output = self.app.get("/test/commits/maxamilion/feature")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
-        self.assertIn('<title>Commits - test - Pagure</title>', output_text)
-        self.assertIn('Add sources file for testing', output_text)
-        self.assertIn('Add .gitignore file for testing', output_text)
+        self.assertIn("<title>Commits - test - Pagure</title>", output_text)
+        self.assertIn("Add sources file for testing", output_text)
+        self.assertIn("Add .gitignore file for testing", output_text)
         self.assertEqual(output_text.count('<span class="commitdate"'), 3)
         self.assertEqual(output_text.count('<span class="commitdate"'), 3)
 
 
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.notify.send_email")
     def test_view_file(self, send_email):
     def test_view_file(self, send_email):
         """ Test the view_file endpoint when the git repo has no
         """ Test the view_file endpoint when the git repo has no
         master branch.
         master branch.
@@ -183,16 +183,16 @@ class PagureFlaskSlashInBranchtests(tests.SimplePagureTest):
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         # Non-existant git repo
         # Non-existant git repo
-        output = self.app.get('/test/blob/master/f/sources')
+        output = self.app.get("/test/blob/master/f/sources")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
         self.set_up_git_repo()
         self.set_up_git_repo()
 
 
         # With git repo
         # With git repo
-        output = self.app.get('/test/blob/master/f/sources')
+        output = self.app.get("/test/blob/master/f/sources")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         self.assertIn(
         self.assertIn(
-            '''<ol class="breadcrumb p-0 bg-transparent mb-0">
+            """<ol class="breadcrumb p-0 bg-transparent mb-0">
           <li class="breadcrumb-item">
           <li class="breadcrumb-item">
             <a href="/test/tree/master">
             <a href="/test/tree/master">
               <span class="fa fa-random">
               <span class="fa fa-random">
@@ -203,16 +203,18 @@ class PagureFlaskSlashInBranchtests(tests.SimplePagureTest):
             <span class="fa fa-file" data-glyph="">
             <span class="fa fa-file" data-glyph="">
             </span>&nbsp; sources
             </span>&nbsp; sources
           </li>
           </li>
-        </ol>''', output.get_data(as_text=True))
+        </ol>""",
+            output.get_data(as_text=True),
+        )
 
 
-        output = self.app.get('/test/blob/master/f/.gitignore')
+        output = self.app.get("/test/blob/master/f/.gitignore")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
-        output = self.app.get('/test/blob/maxamilion/feature/f/.gitignore')
+        output = self.app.get("/test/blob/maxamilion/feature/f/.gitignore")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
-            '''<ol class="breadcrumb p-0 bg-transparent mb-0">
+            """<ol class="breadcrumb p-0 bg-transparent mb-0">
           <li class="breadcrumb-item">
           <li class="breadcrumb-item">
             <a href="/test/tree/maxamilion/feature">
             <a href="/test/tree/maxamilion/feature">
               <span class="fa fa-random">
               <span class="fa fa-random">
@@ -223,14 +225,16 @@ class PagureFlaskSlashInBranchtests(tests.SimplePagureTest):
             <span class="fa fa-file" data-glyph="">
             <span class="fa fa-file" data-glyph="">
             </span>&nbsp; .gitignore
             </span>&nbsp; .gitignore
           </li>
           </li>
-        </ol>''', output_text)
+        </ol>""",
+            output_text,
+        )
         self.assertIn(
         self.assertIn(
             '<pre class="syntaxhighlightblock">'
             '<pre class="syntaxhighlightblock">'
             '<code class="lang-plaintext">*~</code></pre>',
             '<code class="lang-plaintext">*~</code></pre>',
-            output_text
+            output_text,
         )
         )
 
 
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.notify.send_email")
     def test_view_raw_file(self, send_email):
     def test_view_raw_file(self, send_email):
         """ Test the view_raw_file endpoint when the git repo has no
         """ Test the view_raw_file endpoint when the git repo has no
         master branch.
         master branch.
@@ -239,34 +243,34 @@ class PagureFlaskSlashInBranchtests(tests.SimplePagureTest):
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         # Non-existant git repo
         # Non-existant git repo
-        output = self.app.get('/test/raw/master')
+        output = self.app.get("/test/raw/master")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
-        output = self.app.get('/test/raw/master/f/sources')
+        output = self.app.get("/test/raw/master/f/sources")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
         self.set_up_git_repo()
         self.set_up_git_repo()
 
 
         # With git repo
         # With git repo
-        output = self.app.get('/test/raw/master')
+        output = self.app.get("/test/raw/master")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
-        self.assertIn('diff --git a/sources b/sources', output_text)
-        self.assertIn('+foo\n+ bar', output_text)
-        output = self.app.get('/test/raw/master/f/sources')
+        self.assertIn("diff --git a/sources b/sources", output_text)
+        self.assertIn("+foo\n+ bar", output_text)
+        output = self.app.get("/test/raw/master/f/sources")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
-        self.assertEqual(output.get_data(as_text=True), 'foo\n bar')
+        self.assertEqual(output.get_data(as_text=True), "foo\n bar")
 
 
-        output = self.app.get('/test/raw/maxamilion/feature')
+        output = self.app.get("/test/raw/maxamilion/feature")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
-        self.assertIn('diff --git a/.gitignore b/.gitignore', output_text)
-        self.assertIn('+*~', output_text)
+        self.assertIn("diff --git a/.gitignore b/.gitignore", output_text)
+        self.assertIn("+*~", output_text)
 
 
-        output = self.app.get('/test/raw/maxamilion/feature/f/sources')
+        output = self.app.get("/test/raw/maxamilion/feature/f/sources")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
-        self.assertEqual('foo\n bar', output.get_data(as_text=True))
+        self.assertEqual("foo\n bar", output.get_data(as_text=True))
 
 
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.notify.send_email")
     def test_view_tree(self, send_email):
     def test_view_tree(self, send_email):
         """ Test the view_tree endpoint when the git repo has no
         """ Test the view_tree endpoint when the git repo has no
         master branch.
         master branch.
@@ -275,44 +279,43 @@ class PagureFlaskSlashInBranchtests(tests.SimplePagureTest):
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         # Non-existant git repo
         # Non-existant git repo
-        output = self.app.get('/test/tree/')
+        output = self.app.get("/test/tree/")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
-        output = self.app.get('/test/tree/master')
+        output = self.app.get("/test/tree/master")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
         self.set_up_git_repo()
         self.set_up_git_repo()
 
 
         # With git repo
         # With git repo
-        output = self.app.get('/test/tree/master')
+        output = self.app.get("/test/tree/master")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn('<a href="/test/blob/master/f/sources">', output_text)
         self.assertIn('<a href="/test/blob/master/f/sources">', output_text)
 
 
-        output = self.app.get('/test/tree/master/sources')
+        output = self.app.get("/test/tree/master/sources")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn('<a href="/test/blob/master/f/sources">', output_text)
         self.assertIn('<a href="/test/blob/master/f/sources">', output_text)
 
 
-        output = self.app.get('/test/tree/feature')
+        output = self.app.get("/test/tree/feature")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn('<a href="/test/blob/master/f/sources">', output_text)
         self.assertIn('<a href="/test/blob/master/f/sources">', output_text)
 
 
-        output = self.app.get('/test/tree/maxamilion/feature')
+        output = self.app.get("/test/tree/maxamilion/feature")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn(
         self.assertIn(
-            '<a href="/test/blob/maxamilion/feature/f/sources">',
-            output_text)
+            '<a href="/test/blob/maxamilion/feature/f/sources">', output_text
+        )
 
 
         # Wrong identifier, back onto master
         # Wrong identifier, back onto master
-        output = self.app.get('/test/tree/maxamilion/feature/f/.gitignore')
+        output = self.app.get("/test/tree/maxamilion/feature/f/.gitignore")
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
         self.assertIn('<a href="/test/blob/master/f/sources">', output_text)
         self.assertIn('<a href="/test/blob/master/f/sources">', output_text)
 
 
-
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.notify.send_email")
     def test_new_request_pull(self, send_email):
     def test_new_request_pull(self, send_email):
         """ Test the new_request_pull endpoint when the git repo has no
         """ Test the new_request_pull endpoint when the git repo has no
         master branch.
         master branch.
@@ -321,44 +324,50 @@ class PagureFlaskSlashInBranchtests(tests.SimplePagureTest):
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
         # Non-existant git repo
         # Non-existant git repo
-        output = self.app.get('/test/diff/master..maxamilion/feature')
+        output = self.app.get("/test/diff/master..maxamilion/feature")
         # (used to be 302 but seeing a diff is allowed even logged out)
         # (used to be 302 but seeing a diff is allowed even logged out)
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/diff/master..maxamilion/feature')
+            output = self.app.get("/test/diff/master..maxamilion/feature")
             self.assertEqual(output.status_code, 404)
             self.assertEqual(output.status_code, 404)
 
 
         self.set_up_git_repo()
         self.set_up_git_repo()
 
 
-        output = self.app.get('/test/diff/master..maxamilion/feature')
+        output = self.app.get("/test/diff/master..maxamilion/feature")
         # (used to be 302 but seeing a diff is allowed even logged out)
         # (used to be 302 but seeing a diff is allowed even logged out)
         self.assertEqual(output.status_code, 200)
         self.assertEqual(output.status_code, 200)
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
-        self.assertEqual(
-            output_text.count('<span class="commitdate"'), 1)
+        self.assertEqual(output_text.count('<span class="commitdate"'), 1)
         self.assertIn(
         self.assertIn(
             '<span class="font-weight-bold btn btn-sm btn-success disabled opacity-100">'
             '<span class="font-weight-bold btn btn-sm btn-success disabled opacity-100">'
-            '+1</span>\n', output_text)
+            "+1</span>\n",
+            output_text,
+        )
         self.assertIn(
         self.assertIn(
             '<div class="btn btn-outline-success disabled opacity-100 border-0 font-weight-bold">\n'
             '<div class="btn btn-outline-success disabled opacity-100 border-0 font-weight-bold">\n'
-            '    file added\n', output_text)
+            "    file added\n",
+            output_text,
+        )
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
-            output = self.app.get('/test/diff/master..maxamilion/feature')
+            output = self.app.get("/test/diff/master..maxamilion/feature")
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             output_text = output.get_data(as_text=True)
             output_text = output.get_data(as_text=True)
-            self.assertEqual(
-                output_text.count('<span class="commitdate"'), 1)
+            self.assertEqual(output_text.count('<span class="commitdate"'), 1)
             self.assertIn(
             self.assertIn(
                 '<span class="font-weight-bold btn btn-sm btn-success disabled opacity-100">'
                 '<span class="font-weight-bold btn btn-sm btn-success disabled opacity-100">'
-                '+1</span>\n', output_text)
+                "+1</span>\n",
+                output_text,
+            )
             self.assertIn(
             self.assertIn(
                 '<div class="btn btn-outline-success disabled opacity-100 border-0 font-weight-bold">\n'
                 '<div class="btn btn-outline-success disabled opacity-100 border-0 font-weight-bold">\n'
-                '    file added\n', output_text)
+                "    file added\n",
+                output_text,
+            )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 72 - 89
tests/test_pagure_flask_ui_star_project.py

@@ -15,8 +15,9 @@ import unittest
 import sys
 import sys
 import os
 import os
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.config
 import pagure.config
 import pagure.lib.query
 import pagure.lib.query
@@ -29,30 +30,29 @@ class TestStarProjectUI(tests.SimplePagureTest):
         super(TestStarProjectUI, self).setUp()
         super(TestStarProjectUI, self).setUp()
 
 
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
     def _check_star_count(self, data, stars=1):
     def _check_star_count(self, data, stars=1):
         """ Check if the star count is correct or not """
         """ Check if the star count is correct or not """
-        output = self.app.get(
-            '/test/', data=data, follow_redirects=True)
+        output = self.app.get("/test/", data=data, follow_redirects=True)
         if stars == 1:
         if stars == 1:
             self.assertIn(
             self.assertIn(
                 '<a href="/test/stargazers/" class="btn btn-sm '
                 '<a href="/test/stargazers/" class="btn btn-sm '
                 'btn-primary font-weight-bold">1</a>\n',
                 'btn-primary font-weight-bold">1</a>\n',
-                output.get_data(as_text=True)
+                output.get_data(as_text=True),
             )
             )
         elif stars == 0:
         elif stars == 0:
             self.assertIn(
             self.assertIn(
                 '<a href="/test/stargazers/" class="btn btn-sm '
                 '<a href="/test/stargazers/" class="btn btn-sm '
                 'btn-primary font-weight-bold">0</a>\n',
                 'btn-primary font-weight-bold">0</a>\n',
-                output.get_data(as_text=True)
+                output.get_data(as_text=True),
             )
             )
 
 
     def test_star_project_no_project(self):
     def test_star_project_no_project(self):
         """ Test the star_project endpoint. """
         """ Test the star_project endpoint. """
 
 
         # No such project
         # No such project
-        output = self.app.post('/test42/star/1')
+        output = self.app.post("/test42/star/1")
         self.assertEqual(output.status_code, 404)
         self.assertEqual(output.status_code, 404)
 
 
     def test_star_project_no_csrf(self):
     def test_star_project_no_csrf(self):
@@ -60,26 +60,26 @@ class TestStarProjectUI(tests.SimplePagureTest):
         is no CSRF token given """
         is no CSRF token given """
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
 
 
             data = {}
             data = {}
             output = self.app.post(
             output = self.app.post(
-                '/test/star/1', data=data, follow_redirects=True)
+                "/test/star/1", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 400)
             self.assertEqual(output.status_code, 400)
 
 
     def test_star_project_invalid_star(self):
     def test_star_project_invalid_star(self):
         """ Test the star_project endpoint for invalid star """
         """ Test the star_project endpoint for invalid star """
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
-            data = {
-                'csrf_token': csrf_token,
-            }
+            data = {"csrf_token": csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/test/star/2', data=data, follow_redirects=True)
+                "/test/star/2", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 400)
             self.assertEqual(output.status_code, 400)
             self._check_star_count(data=data, stars=0)
             self._check_star_count(data=data, stars=0)
 
 
@@ -87,20 +87,18 @@ class TestStarProjectUI(tests.SimplePagureTest):
         """ Test the star_project endpoint for correct star """
         """ Test the star_project endpoint for correct star """
 
 
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
-            data = {
-                'csrf_token': csrf_token,
-            }
+            data = {"csrf_token": csrf_token}
 
 
             # try starring the project for pingou
             # try starring the project for pingou
             output = self.app.post(
             output = self.app.post(
-                '/test/star/1', data=data, follow_redirects=True)
+                "/test/star/1", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                'You starred this project',
-                output.get_data(as_text=True)
+                "You starred this project", output.get_data(as_text=True)
             )
             )
 
 
             # check home page of project for star count
             # check home page of project for star count
@@ -108,11 +106,11 @@ class TestStarProjectUI(tests.SimplePagureTest):
 
 
             # try unstarring the project for pingou
             # try unstarring the project for pingou
             output = self.app.post(
             output = self.app.post(
-                '/test/star/0', data=data, follow_redirects=True)
+                "/test/star/0", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                'You unstarred this project',
-                output.get_data(as_text=True)
+                "You unstarred this project", output.get_data(as_text=True)
             )
             )
             self._check_star_count(data=data, stars=0)
             self._check_star_count(data=data, stars=0)
 
 
@@ -122,155 +120,140 @@ class TestStarProjectUI(tests.SimplePagureTest):
         # make pingou star the project
         # make pingou star the project
         # first create pingou
         # first create pingou
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
-            data = {
-                'csrf_token': csrf_token,
-            }
+            data = {"csrf_token": csrf_token}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/star/1', data=data, follow_redirects=True)
+                "/test/star/1", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                'You starred this project',
-                output.get_data(as_text=True)
+                "You starred this project", output.get_data(as_text=True)
             )
             )
             self._check_star_count(data=data, stars=1)
             self._check_star_count(data=data, stars=1)
 
 
         # now, test if pingou's name comes in repo stargazers
         # now, test if pingou's name comes in repo stargazers
-        output = self.app.get(
-            '/test/stargazers/'
-        )
+        output = self.app.get("/test/stargazers/")
         self.assertIn(
         self.assertIn(
-            '<title>Stargazers of test  - Pagure</title>',
-            output.get_data(as_text=True)
+            "<title>Stargazers of test  - Pagure</title>",
+            output.get_data(as_text=True),
         )
         )
         self.assertIn(
         self.assertIn(
             '<a class="font-weight-bold" href="/user/pingou">pingou</a>',
             '<a class="font-weight-bold" href="/user/pingou">pingou</a>',
-            output.get_data(as_text=True)
+            output.get_data(as_text=True),
         )
         )
 
 
         # make pingou unstar the project
         # make pingou unstar the project
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
-            data = {
-                'csrf_token': csrf_token,
-            }
+            data = {"csrf_token": csrf_token}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/star/0', data=data, follow_redirects=True)
+                "/test/star/0", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                'You unstarred this project',
-                output.get_data(as_text=True)
+                "You unstarred this project", output.get_data(as_text=True)
             )
             )
             self._check_star_count(data=data, stars=0)
             self._check_star_count(data=data, stars=0)
 
 
         # now, test if pingou's name comes in repo stargazers
         # now, test if pingou's name comes in repo stargazers
         # it shouldn't because, he just unstarred
         # it shouldn't because, he just unstarred
-        output = self.app.get(
-            '/test/stargazers/'
-        )
+        output = self.app.get("/test/stargazers/")
         self.assertIn(
         self.assertIn(
-            '<title>Stargazers of test  - Pagure</title>',
-            output.get_data(as_text=True)
+            "<title>Stargazers of test  - Pagure</title>",
+            output.get_data(as_text=True),
         )
         )
         self.assertNotIn(
         self.assertNotIn(
             '<a class="font-weight-bold" href="/user/pingou">pingou</a>',
             '<a class="font-weight-bold" href="/user/pingou">pingou</a>',
-            output.get_data(as_text=True)
+            output.get_data(as_text=True),
         )
         )
 
 
     def test_user_stars(self):
     def test_user_stars(self):
         """ Test the user_stars endpoint of pagure.ui.app """
         """ Test the user_stars endpoint of pagure.ui.app """
 
 
         # Check pingou's stars before
         # Check pingou's stars before
-        output = self.app.get('/user/pingou/stars/')
+        output = self.app.get("/user/pingou/stars/")
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
-        self.assertIn(
-            "<title>pingou - starred - Pagure</title>", output_text
-        )
+        self.assertIn("<title>pingou - starred - Pagure</title>", output_text)
         self.assertIn(
         self.assertIn(
             '<span class="btn btn-outline-secondary disabled opacity-100 '
             '<span class="btn btn-outline-secondary disabled opacity-100 '
             'border-0 ml-auto font-weight-bold">0 Project</span>',
             'border-0 ml-auto font-weight-bold">0 Project</span>',
-            output_text)
+            output_text,
+        )
 
 
         # make pingou star the project
         # make pingou star the project
         # first create pingou
         # first create pingou
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
-            data = {
-                'csrf_token': csrf_token,
-            }
+            data = {"csrf_token": csrf_token}
 
 
             output = self.app.post(
             output = self.app.post(
-                '/test/star/1', data=data, follow_redirects=True)
+                "/test/star/1", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                'You starred this project',
-                output.get_data(as_text=True)
+                "You starred this project", output.get_data(as_text=True)
             )
             )
             self._check_star_count(data=data, stars=1)
             self._check_star_count(data=data, stars=1)
 
 
         # now, test if the project 'test' comes in pingou's stars
         # now, test if the project 'test' comes in pingou's stars
-        output = self.app.get('/user/pingou/stars/')
+        output = self.app.get("/user/pingou/stars/")
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
-        self.assertIn(
-            "<title>pingou - starred - Pagure</title>", output_text
-        )
+        self.assertIn("<title>pingou - starred - Pagure</title>", output_text)
         self.assertIn(
         self.assertIn(
             '<span class="btn btn-outline-secondary disabled opacity-100 '
             '<span class="btn btn-outline-secondary disabled opacity-100 '
             'border-0 ml-auto font-weight-bold">1 Project</span>',
             'border-0 ml-auto font-weight-bold">1 Project</span>',
-            output_text)
-        self.assertEqual(
-            output_text.count('class="list-group-item"'), 1)
+            output_text,
+        )
+        self.assertEqual(output_text.count('class="list-group-item"'), 1)
         self.assertEqual(
         self.assertEqual(
-            output_text.count('<div class="media-body align-self-center">'), 2)
+            output_text.count('<div class="media-body align-self-center">'), 2
+        )
 
 
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(repo.stargazers), 1)
         self.assertEqual(len(repo.stargazers), 1)
 
 
         # make pingou unstar the project
         # make pingou unstar the project
         user = tests.FakeUser()
         user = tests.FakeUser()
-        user.username = 'pingou'
+        user.username = "pingou"
         with tests.user_set(self.app.application, user):
         with tests.user_set(self.app.application, user):
             csrf_token = self.get_csrf()
             csrf_token = self.get_csrf()
-            data = {
-                'csrf_token': csrf_token,
-            }
+            data = {"csrf_token": csrf_token}
             output = self.app.post(
             output = self.app.post(
-                '/test/star/0', data=data, follow_redirects=True)
+                "/test/star/0", data=data, follow_redirects=True
+            )
             self.assertEqual(output.status_code, 200)
             self.assertEqual(output.status_code, 200)
             self.assertIn(
             self.assertIn(
-                'You unstarred this project',
-                output.get_data(as_text=True)
+                "You unstarred this project", output.get_data(as_text=True)
             )
             )
             self._check_star_count(data=data, stars=0)
             self._check_star_count(data=data, stars=0)
 
 
         self.session = pagure.lib.query.create_session(self.dbpath)
         self.session = pagure.lib.query.create_session(self.dbpath)
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(repo.stargazers), 0)
         self.assertEqual(len(repo.stargazers), 0)
 
 
         # now, test if test's name comes in pingou's stars
         # now, test if test's name comes in pingou's stars
         # it shouldn't because, he just unstarred
         # it shouldn't because, he just unstarred
-        output = self.app.get('/user/pingou/stars/')
+        output = self.app.get("/user/pingou/stars/")
         output_text = output.get_data(as_text=True)
         output_text = output.get_data(as_text=True)
-        self.assertIn(
-            "<title>pingou - starred - Pagure</title>", output_text
-        )
+        self.assertIn("<title>pingou - starred - Pagure</title>", output_text)
         self.assertIn(
         self.assertIn(
             '<span class="btn btn-outline-secondary disabled opacity-100 '
             '<span class="btn btn-outline-secondary disabled opacity-100 '
             'border-0 ml-auto font-weight-bold">0 Project</span>',
             'border-0 ml-auto font-weight-bold">0 Project</span>',
-            output_text)
-        self.assertEqual(
-            output_text.count('class="list-group-item"'), 0)
+            output_text,
+        )
+        self.assertEqual(output_text.count('class="list-group-item"'), 0)
         self.assertEqual(
         self.assertEqual(
-            output_text.count('<div class="media-body align-self-center">'), 1)
+            output_text.count('<div class="media-body align-self-center">'), 1
+        )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 23 - 23
tests/test_pagure_flask_util.py

@@ -16,8 +16,9 @@ import os
 
 
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 from pagure.utils import ssh_urlpattern
 from pagure.utils import ssh_urlpattern
 import tests
 import tests
@@ -29,39 +30,38 @@ class PagureUtilSSHPatterntests(tests.Modeltests):
     def test_ssh_pattern_valid(self):
     def test_ssh_pattern_valid(self):
         """ Test the ssh_urlpattern with valid patterns. """
         """ Test the ssh_urlpattern with valid patterns. """
         patterns = [
         patterns = [
-            'ssh://user@host.com/repo.git',
-            'git+ssh://user@host.com/repo.git',
-            'ssh://user@host.lcl:/path/to/repo.git',
-            'git@github.com:user/project.git',
-            'ssh://user@host.org/target',
-            'git+ssh://user@host.org/target',
-            'git+ssh://user@host.lcl:/path/to/repo.git',
+            "ssh://user@host.com/repo.git",
+            "git+ssh://user@host.com/repo.git",
+            "ssh://user@host.lcl:/path/to/repo.git",
+            "git@github.com:user/project.git",
+            "ssh://user@host.org/target",
+            "git+ssh://user@host.org/target",
+            "git+ssh://user@host.lcl:/path/to/repo.git",
         ]
         ]
         for pattern in patterns:
         for pattern in patterns:
             print(pattern)
             print(pattern)
             self.assertIsNotNone(ssh_urlpattern.match(pattern))
             self.assertIsNotNone(ssh_urlpattern.match(pattern))
 
 
-
     def test_ssh_pattern_invalid(self):
     def test_ssh_pattern_invalid(self):
         """ Test the ssh_urlpattern with invalid patterns. """
         """ Test the ssh_urlpattern with invalid patterns. """
         patterns = [
         patterns = [
-            'http://user@host.com/repo.git',
-            'git+http://user@host.com/repo.git',
-            'https://user@host.com/repo.git',
-            'git+https://user@host.com/repo.git',
-            'ssh://localhost/repo.git',
-            'ssh://host.com/repo.git',
-            'git+ssh://localhost/repo.git',
-            'ssh://0.0.0.0/repo.git',
-            'git+ssh://0.0.0.0/repo.git',
-            'git+ssh://host.com/repo.git',
-            'ssh://127.0.0.1/repo.git',
-            'git+ssh://127.0.0.1/repo.git',
+            "http://user@host.com/repo.git",
+            "git+http://user@host.com/repo.git",
+            "https://user@host.com/repo.git",
+            "git+https://user@host.com/repo.git",
+            "ssh://localhost/repo.git",
+            "ssh://host.com/repo.git",
+            "git+ssh://localhost/repo.git",
+            "ssh://0.0.0.0/repo.git",
+            "git+ssh://0.0.0.0/repo.git",
+            "git+ssh://host.com/repo.git",
+            "ssh://127.0.0.1/repo.git",
+            "git+ssh://127.0.0.1/repo.git",
         ]
         ]
         for pattern in patterns:
         for pattern in patterns:
             print(pattern)
             print(pattern)
             self.assertIsNone(ssh_urlpattern.match(pattern))
             self.assertIsNone(ssh_urlpattern.match(pattern))
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 76 - 48
tests/test_pagure_hooks_pagure_hook.py

@@ -16,8 +16,9 @@ import os
 
 
 import mock
 import mock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.hooks.pagure_hook
 import pagure.hooks.pagure_hook
 import tests
 import tests
@@ -30,58 +31,64 @@ class PagureHooksPagureHooktests(tests.SimplePagureTest):
         """ Set up the environnment, ran before every tests. """
         """ Set up the environnment, ran before every tests. """
         super(PagureHooksPagureHooktests, self).setUp()
         super(PagureHooksPagureHooktests, self).setUp()
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
+        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
 
 
         # Add one issue to each projects otherwise we won't be able to find
         # Add one issue to each projects otherwise we won't be able to find
-        project = pagure.lib.query.get_authorized_project(self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=project,
             repo=project,
-            title='Test issue',
-            content='We should work on this',
-            user='pingou',
+            title="Test issue",
+            content="We should work on this",
+            user="pingou",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg.title, 'Test issue')
+        self.assertEqual(msg.title, "Test issue")
 
 
         project = pagure.lib.query.get_authorized_project(
         project = pagure.lib.query.get_authorized_project(
-            self.session, 'test2')
+            self.session, "test2"
+        )
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=project,
             repo=project,
-            title='Test issue on test2',
-            content='We should work on this, really',
-            user='foo',
+            title="Test issue on test2",
+            content="We should work on this, really",
+            user="foo",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg.title, 'Test issue on test2')
+        self.assertEqual(msg.title, "Test issue on test2")
 
 
         # Create a fork of test for foo with its own ticket
         # Create a fork of test for foo with its own ticket
         item = pagure.lib.model.Project(
         item = pagure.lib.model.Project(
             user_id=2,  # foo
             user_id=2,  # foo
-            name='test',
+            name="test",
             is_fork=True,
             is_fork=True,
             parent_id=1,
             parent_id=1,
-            description='test project #1',
-            hook_token='aaabbbccc_foo',
+            description="test project #1",
+            hook_token="aaabbbccc_foo",
         )
         )
         item.close_status = [
         item.close_status = [
-            'Invalid', 'Insufficient data', 'Fixed', 'Duplicate']
+            "Invalid",
+            "Insufficient data",
+            "Fixed",
+            "Duplicate",
+        ]
         self.session.add(item)
         self.session.add(item)
         self.session.commit()
         self.session.commit()
         project = pagure.lib.query.get_authorized_project(
         project = pagure.lib.query.get_authorized_project(
-            self.session, 'test', user="foo")
+            self.session, "test", user="foo"
+        )
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=project,
             repo=project,
-            title='Test issue on fork/foo/test',
-            content='We should work on this, really',
-            user='foo',
+            title="Test issue on fork/foo/test",
+            content="We should work on this, really",
+            user="foo",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg.title, 'Test issue on fork/foo/test')
+        self.assertEqual(msg.title, "Test issue on fork/foo/test")
 
 
-        self.folder = os.path.join(self.path, 'repos', 'test.git')
+        self.folder = os.path.join(self.path, "repos", "test.git")
 
 
         # Add a README to the git repo - First commit
         # Add a README to the git repo - First commit
         tests.add_readme_git_repo(self.folder)
         tests.add_readme_git_repo(self.folder)
@@ -94,22 +101,29 @@ class PagureHooksPagureHooktests(tests.SimplePagureTest):
 
 
         # Add a commit with an url in the commit message
         # Add a commit with an url in the commit message
         tests.add_content_to_git(
         tests.add_content_to_git(
-            self.folder, branch='master', filename='sources', content='foo',
-            message='Test commit message\n\nFixes #1'
+            self.folder,
+            branch="master",
+            filename="sources",
+            content="foo",
+            message="Test commit message\n\nFixes #1",
         )
         )
 
 
-        project = pagure.lib.query.get_authorized_project(self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
 
 
         pagure.hooks.pagure_hook.generate_revision_change_log(
         pagure.hooks.pagure_hook.generate_revision_change_log(
             session=self.session,
             session=self.session,
             project=project,
             project=project,
             username=None,
             username=None,
             repodir=self.folder,
             repodir=self.folder,
-            new_commits_list=['HEAD']
+            new_commits_list=["HEAD"],
         )
         )
         fixes_relation.assert_called_once_with(
         fixes_relation.assert_called_once_with(
-            mock.ANY, None, mock.ANY, project.issues[0],
-            'http://localhost.localdomain/')
+            mock.ANY,
+            None,
+            mock.ANY,
+            project.issues[0],
+            "http://localhost.localdomain/",
+        )
 
 
     @mock.patch("pagure.hooks.pagure_hook.fixes_relation")
     @mock.patch("pagure.hooks.pagure_hook.fixes_relation")
     def test_generate_revision_change_log_full_url(self, fixes_relation):
     def test_generate_revision_change_log_full_url(self, fixes_relation):
@@ -119,26 +133,33 @@ class PagureHooksPagureHooktests(tests.SimplePagureTest):
 
 
         # Add a commit with an url in the commit message
         # Add a commit with an url in the commit message
         tests.add_content_to_git(
         tests.add_content_to_git(
-            self.folder, branch='master', filename='sources', content='foo',
-            message='Test commit message\n\n'
-            'Fixes http://localhost.localdomain/test2/issue/1'
+            self.folder,
+            branch="master",
+            filename="sources",
+            content="foo",
+            message="Test commit message\n\n"
+            "Fixes http://localhost.localdomain/test2/issue/1",
         )
         )
 
 
-        project = pagure.lib.query.get_authorized_project(
-            self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         project2 = pagure.lib.query.get_authorized_project(
         project2 = pagure.lib.query.get_authorized_project(
-            self.session, 'test2')
+            self.session, "test2"
+        )
 
 
         pagure.hooks.pagure_hook.generate_revision_change_log(
         pagure.hooks.pagure_hook.generate_revision_change_log(
             session=self.session,
             session=self.session,
             project=project,
             project=project,
             username=None,
             username=None,
             repodir=self.folder,
             repodir=self.folder,
-            new_commits_list=['HEAD']
+            new_commits_list=["HEAD"],
         )
         )
         fixes_relation.assert_called_once_with(
         fixes_relation.assert_called_once_with(
-            mock.ANY, None, mock.ANY, project2.issues[0],
-            'http://localhost.localdomain/')
+            mock.ANY,
+            None,
+            mock.ANY,
+            project2.issues[0],
+            "http://localhost.localdomain/",
+        )
 
 
     @mock.patch("pagure.hooks.pagure_hook.fixes_relation")
     @mock.patch("pagure.hooks.pagure_hook.fixes_relation")
     def test_generate_revision_change_log_full_url_fork(self, fixes_relation):
     def test_generate_revision_change_log_full_url_fork(self, fixes_relation):
@@ -148,27 +169,34 @@ class PagureHooksPagureHooktests(tests.SimplePagureTest):
 
 
         # Add a commit with an url in the commit message
         # Add a commit with an url in the commit message
         tests.add_content_to_git(
         tests.add_content_to_git(
-            self.folder, branch='master', filename='sources', content='foo',
-            message='Test commit message\n\n'
-            'Fixes http://localhost.localdomain/fork/foo/test/issue/1'
+            self.folder,
+            branch="master",
+            filename="sources",
+            content="foo",
+            message="Test commit message\n\n"
+            "Fixes http://localhost.localdomain/fork/foo/test/issue/1",
         )
         )
 
 
-        project = pagure.lib.query.get_authorized_project(
-            self.session, 'test')
+        project = pagure.lib.query.get_authorized_project(self.session, "test")
         project_fork = pagure.lib.query.get_authorized_project(
         project_fork = pagure.lib.query.get_authorized_project(
-            self.session, 'test', user="foo")
+            self.session, "test", user="foo"
+        )
 
 
         pagure.hooks.pagure_hook.generate_revision_change_log(
         pagure.hooks.pagure_hook.generate_revision_change_log(
             session=self.session,
             session=self.session,
             project=project,
             project=project,
             username=None,
             username=None,
             repodir=self.folder,
             repodir=self.folder,
-            new_commits_list=['HEAD']
+            new_commits_list=["HEAD"],
         )
         )
         fixes_relation.assert_called_once_with(
         fixes_relation.assert_called_once_with(
-            mock.ANY, None, mock.ANY, project_fork.issues[0],
-            'http://localhost.localdomain/')
+            mock.ANY,
+            None,
+            mock.ANY,
+            project_fork.issues[0],
+            "http://localhost.localdomain/",
+        )
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

File diff suppressed because it is too large
+ 262 - 272
tests/test_pagure_lib.py


+ 115 - 129
tests/test_pagure_lib_add_user_to_project.py

@@ -16,8 +16,9 @@ import os
 
 
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import tests
 import tests
@@ -33,42 +34,37 @@ class PagureLibAddUserToProjecttests(tests.Modeltests):
         tests.create_projects(self.session)
         tests.create_projects(self.session)
 
 
         item = pagure.lib.model.User(
         item = pagure.lib.model.User(
-            user='bar',
-            fullname='bar baz',
-            password='foo',
-            default_email='bar@bar.com',
+            user="bar",
+            fullname="bar baz",
+            password="foo",
+            default_email="bar@bar.com",
         )
         )
         self.session.add(item)
         self.session.add(item)
-        item = pagure.lib.model.UserEmail(
-            user_id=3,
-            email='bar@bar.com')
+        item = pagure.lib.model.UserEmail(user_id=3, email="bar@bar.com")
         self.session.add(item)
         self.session.add(item)
 
 
         self.session.commit()
         self.session.commit()
 
 
         # Before
         # Before
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
         self.assertEqual(len(repo.users), 0)
         self.assertEqual(len(repo.users), 0)
 
 
         msg = pagure.lib.query.add_user_to_project(
         msg = pagure.lib.query.add_user_to_project(
-            session=self.session,
-            project=repo,
-            new_user='foo',
-            user='pingou',
+            session=self.session, project=repo, new_user="foo", user="pingou"
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'User added')
+        self.assertEqual(msg, "User added")
 
 
         # After
         # After
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
         self.assertEqual(len(repo.users), 1)
         self.assertEqual(len(repo.users), 1)
-        self.assertEqual(repo.users[0].user, 'foo')
-        self.assertEqual(repo.admins[0].user, 'foo')
+        self.assertEqual(repo.users[0].user, "foo")
+        self.assertEqual(repo.admins[0].user, "foo")
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_re_add_user_to_project_default(self):
     def test_re_add_user_to_project_default(self):
         """ Update an existing user but to the same access level. """
         """ Update an existing user but to the same access level. """
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
 
 
         # Try adding the same user with the same access
         # Try adding the same user with the same access
         self.assertRaises(
         self.assertRaises(
@@ -76,41 +72,39 @@ class PagureLibAddUserToProjecttests(tests.Modeltests):
             pagure.lib.query.add_user_to_project,
             pagure.lib.query.add_user_to_project,
             session=self.session,
             session=self.session,
             project=repo,
             project=repo,
-            new_user='foo',
-            user='pingou',
-            access='admin'
+            new_user="foo",
+            user="pingou",
+            access="admin",
         )
         )
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_update_user_to_project_default(self):
     def test_update_user_to_project_default(self):
         """ Update an existing user without any required group membership.
         """ Update an existing user without any required group membership.
         """
         """
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
 
 
         # Update the access of the user
         # Update the access of the user
         msg = pagure.lib.query.add_user_to_project(
         msg = pagure.lib.query.add_user_to_project(
             session=self.session,
             session=self.session,
             project=repo,
             project=repo,
-            new_user='foo',
-            user='pingou',
-            access='commit'
+            new_user="foo",
+            user="pingou",
+            access="commit",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'User access updated')
+        self.assertEqual(msg, "User access updated")
         self.assertEqual(len(repo.users), 1)
         self.assertEqual(len(repo.users), 1)
-        self.assertEqual(repo.users[0].user, 'foo')
-        self.assertEqual(repo.committers[0].user, 'foo')
+        self.assertEqual(repo.users[0].user, "foo")
+        self.assertEqual(repo.committers[0].user, "foo")
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_update_user_to_project_require_packager_on_all(self):
     def test_update_user_to_project_require_packager_on_all(self):
         """
         """
         Update an existing user but required group membership on all
         Update an existing user but required group membership on all
         projects.
         projects.
         """
         """
-        repo = pagure.lib.query._get_project(self.session, 'test')
-        config = {
-            '*': ['packager']
-        }
+        repo = pagure.lib.query._get_project(self.session, "test")
+        config = {"*": ["packager"]}
 
 
         # Update the access of the user
         # Update the access of the user
         self.assertRaises(
         self.assertRaises(
@@ -118,26 +112,24 @@ class PagureLibAddUserToProjecttests(tests.Modeltests):
             pagure.lib.query.add_user_to_project,
             pagure.lib.query.add_user_to_project,
             session=self.session,
             session=self.session,
             project=repo,
             project=repo,
-            new_user='foo',
-            user='pingou',
-            access='admin',
-            required_groups=config
+            new_user="foo",
+            user="pingou",
+            access="admin",
+            required_groups=config,
         )
         )
         self.session.commit()
         self.session.commit()
         self.assertEqual(len(repo.users), 1)
         self.assertEqual(len(repo.users), 1)
-        self.assertEqual(repo.users[0].user, 'foo')
-        self.assertEqual(repo.committers[0].user, 'foo')
+        self.assertEqual(repo.users[0].user, "foo")
+        self.assertEqual(repo.committers[0].user, "foo")
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_update_user_to_project_require_packager_on_st(self):
     def test_update_user_to_project_require_packager_on_st(self):
         """
         """
         Update an existing user but required group membership on all
         Update an existing user but required group membership on all
         projects match *st.
         projects match *st.
         """
         """
-        repo = pagure.lib.query._get_project(self.session, 'test')
-        config = {
-            '*st': ['packager']
-        }
+        repo = pagure.lib.query._get_project(self.session, "test")
+        config = {"*st": ["packager"]}
 
 
         # Update the access of the user
         # Update the access of the user
         self.assertRaises(
         self.assertRaises(
@@ -145,26 +137,24 @@ class PagureLibAddUserToProjecttests(tests.Modeltests):
             pagure.lib.query.add_user_to_project,
             pagure.lib.query.add_user_to_project,
             session=self.session,
             session=self.session,
             project=repo,
             project=repo,
-            new_user='foo',
-            user='pingou',
-            access='admin',
-            required_groups=config
+            new_user="foo",
+            user="pingou",
+            access="admin",
+            required_groups=config,
         )
         )
         self.session.commit()
         self.session.commit()
         self.assertEqual(len(repo.users), 1)
         self.assertEqual(len(repo.users), 1)
-        self.assertEqual(repo.users[0].user, 'foo')
-        self.assertEqual(repo.committers[0].user, 'foo')
+        self.assertEqual(repo.users[0].user, "foo")
+        self.assertEqual(repo.committers[0].user, "foo")
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_update_user_to_project_require_packager_on_te(self):
     def test_update_user_to_project_require_packager_on_te(self):
         """
         """
         Update an existing user but required group membership on all
         Update an existing user but required group membership on all
         projects match te*.
         projects match te*.
         """
         """
-        repo = pagure.lib.query._get_project(self.session, 'test')
-        config = {
-            'te*': ['packager']
-        }
+        repo = pagure.lib.query._get_project(self.session, "test")
+        config = {"te*": ["packager"]}
 
 
         # Update the access of the user
         # Update the access of the user
         self.assertRaises(
         self.assertRaises(
@@ -172,26 +162,24 @@ class PagureLibAddUserToProjecttests(tests.Modeltests):
             pagure.lib.query.add_user_to_project,
             pagure.lib.query.add_user_to_project,
             session=self.session,
             session=self.session,
             project=repo,
             project=repo,
-            new_user='foo',
-            user='pingou',
-            access='admin',
-            required_groups=config
+            new_user="foo",
+            user="pingou",
+            access="admin",
+            required_groups=config,
         )
         )
         self.session.commit()
         self.session.commit()
         self.assertEqual(len(repo.users), 1)
         self.assertEqual(len(repo.users), 1)
-        self.assertEqual(repo.users[0].user, 'foo')
-        self.assertEqual(repo.committers[0].user, 'foo')
+        self.assertEqual(repo.users[0].user, "foo")
+        self.assertEqual(repo.committers[0].user, "foo")
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_update_user_to_project_require_packager_on_test(self):
     def test_update_user_to_project_require_packager_on_test(self):
         """
         """
         Update an existing user but required group membership on a specific
         Update an existing user but required group membership on a specific
         project: test.
         project: test.
         """
         """
-        repo = pagure.lib.query._get_project(self.session, 'test')
-        config = {
-            'test': ['packager']
-        }
+        repo = pagure.lib.query._get_project(self.session, "test")
+        config = {"test": ["packager"]}
 
 
         # Update the access of the user
         # Update the access of the user
         self.assertRaises(
         self.assertRaises(
@@ -199,45 +187,43 @@ class PagureLibAddUserToProjecttests(tests.Modeltests):
             pagure.lib.query.add_user_to_project,
             pagure.lib.query.add_user_to_project,
             session=self.session,
             session=self.session,
             project=repo,
             project=repo,
-            new_user='foo',
-            user='pingou',
-            access='admin',
-            required_groups=config
+            new_user="foo",
+            user="pingou",
+            access="admin",
+            required_groups=config,
         )
         )
         self.session.commit()
         self.session.commit()
         self.assertEqual(len(repo.users), 1)
         self.assertEqual(len(repo.users), 1)
-        self.assertEqual(repo.users[0].user, 'foo')
-        self.assertEqual(repo.committers[0].user, 'foo')
+        self.assertEqual(repo.users[0].user, "foo")
+        self.assertEqual(repo.committers[0].user, "foo")
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_add_user_to_test2_require_packager_on_test(self):
     def test_add_user_to_test2_require_packager_on_test(self):
         """
         """
         Add user to project test2 while the configuration requires group
         Add user to project test2 while the configuration requires group
         membership on the project test.
         membership on the project test.
         """
         """
-        repo = pagure.lib.query._get_project(self.session, 'test2')
+        repo = pagure.lib.query._get_project(self.session, "test2")
         self.assertEqual(len(repo.users), 0)
         self.assertEqual(len(repo.users), 0)
 
 
-        config = {
-            'test': ['packager']
-        }
+        config = {"test": ["packager"]}
 
 
         # Add the user
         # Add the user
         pagure.lib.query.add_user_to_project(
         pagure.lib.query.add_user_to_project(
             session=self.session,
             session=self.session,
             project=repo,
             project=repo,
-            new_user='foo',
-            user='pingou',
-            access='admin',
-            required_groups=config
+            new_user="foo",
+            user="pingou",
+            access="admin",
+            required_groups=config,
         )
         )
         self.session.commit()
         self.session.commit()
         self.assertEqual(len(repo.users), 1)
         self.assertEqual(len(repo.users), 1)
-        self.assertEqual(repo.users[0].user, 'foo')
-        self.assertEqual(repo.committers[0].user, 'foo')
+        self.assertEqual(repo.users[0].user, "foo")
+        self.assertEqual(repo.committers[0].user, "foo")
+
 
 
-class PagureLibAddUserToProjectWithGrouptests(
-        PagureLibAddUserToProjecttests):
+class PagureLibAddUserToProjectWithGrouptests(PagureLibAddUserToProjecttests):
     """ Tests for pagure.lib.query.add_user_to_project """
     """ Tests for pagure.lib.query.add_user_to_project """
 
 
     def setUp(self):
     def setUp(self):
@@ -247,89 +233,89 @@ class PagureLibAddUserToProjectWithGrouptests(
         # Create group
         # Create group
         msg = pagure.lib.query.add_group(
         msg = pagure.lib.query.add_group(
             self.session,
             self.session,
-            group_name='packager',
-            display_name='packager',
-            description='The Fedora packager groups',
-            group_type='user',
-            user='pingou',
+            group_name="packager",
+            display_name="packager",
+            description="The Fedora packager groups",
+            group_type="user",
+            user="pingou",
             is_admin=False,
             is_admin=False,
-            blacklist=[])
+            blacklist=[],
+        )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'User `pingou` added to the group `packager`.')
+        self.assertEqual(msg, "User `pingou` added to the group `packager`.")
 
 
         # Add user to group
         # Add user to group
-        group = pagure.lib.query.search_groups(self.session, group_name='packager')
+        group = pagure.lib.query.search_groups(
+            self.session, group_name="packager"
+        )
         msg = pagure.lib.query.add_user_to_group(
         msg = pagure.lib.query.add_user_to_group(
             self.session,
             self.session,
-            username='bar',
+            username="bar",
             group=group,
             group=group,
-            user='pingou',
-            is_admin=True)
+            user="pingou",
+            is_admin=True,
+        )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg, 'User `bar` added to the group `packager`.')
+        self.assertEqual(msg, "User `bar` added to the group `packager`.")
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_add_user_to_test_require_packager_on_test(self):
     def test_add_user_to_test_require_packager_on_test(self):
         """
         """
         Add user to project test while the configuration requires group
         Add user to project test while the configuration requires group
         membership on the project test.
         membership on the project test.
         """
         """
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
         self.assertEqual(len(repo.users), 1)
         self.assertEqual(len(repo.users), 1)
 
 
-        config = {
-            'test': ['packager']
-        }
+        config = {"test": ["packager"]}
 
 
         # Add the user to the project
         # Add the user to the project
         pagure.lib.query.add_user_to_project(
         pagure.lib.query.add_user_to_project(
             session=self.session,
             session=self.session,
             project=repo,
             project=repo,
-            new_user='bar',
-            user='pingou',
-            access='commit',
-            required_groups=config
+            new_user="bar",
+            user="pingou",
+            access="commit",
+            required_groups=config,
         )
         )
         self.session.commit()
         self.session.commit()
 
 
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
         self.assertEqual(len(repo.users), 2)
         self.assertEqual(len(repo.users), 2)
-        self.assertEqual(repo.users[0].user, 'foo')
-        self.assertEqual(repo.committers[0].user, 'foo')
-        self.assertEqual(repo.users[1].user, 'bar')
-        self.assertEqual(repo.committers[1].user, 'bar')
+        self.assertEqual(repo.users[0].user, "foo")
+        self.assertEqual(repo.committers[0].user, "foo")
+        self.assertEqual(repo.users[1].user, "bar")
+        self.assertEqual(repo.committers[1].user, "bar")
 
 
-    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
+    @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
     def test_add_user_to_test_require_packager(self):
     def test_add_user_to_test_require_packager(self):
         """
         """
         Add user to project test while the configuration requires group
         Add user to project test while the configuration requires group
         membership on all the projects.
         membership on all the projects.
         """
         """
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
         self.assertEqual(len(repo.users), 1)
         self.assertEqual(len(repo.users), 1)
 
 
-        config = {
-            '*': ['packager']
-        }
+        config = {"*": ["packager"]}
 
 
         # Add the user to the project
         # Add the user to the project
         pagure.lib.query.add_user_to_project(
         pagure.lib.query.add_user_to_project(
             session=self.session,
             session=self.session,
             project=repo,
             project=repo,
-            new_user='bar',
-            user='pingou',
-            access='commit',
-            required_groups=config
+            new_user="bar",
+            user="pingou",
+            access="commit",
+            required_groups=config,
         )
         )
         self.session.commit()
         self.session.commit()
 
 
-        repo = pagure.lib.query._get_project(self.session, 'test')
+        repo = pagure.lib.query._get_project(self.session, "test")
         self.assertEqual(len(repo.users), 2)
         self.assertEqual(len(repo.users), 2)
-        self.assertEqual(repo.users[0].user, 'foo')
-        self.assertEqual(repo.committers[0].user, 'foo')
-        self.assertEqual(repo.users[1].user, 'bar')
-        self.assertEqual(repo.committers[1].user, 'bar')
+        self.assertEqual(repo.users[0].user, "foo")
+        self.assertEqual(repo.committers[0].user, "foo")
+        self.assertEqual(repo.users[1].user, "bar")
+        self.assertEqual(repo.committers[1].user, "bar")
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 43 - 58
tests/test_pagure_lib_drop_issue.py

@@ -17,8 +17,9 @@ import os
 
 
 from mock import patch, MagicMock
 from mock import patch, MagicMock
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 import pagure.lib.query
 import pagure.lib.query
 import pagure.lib.model
 import pagure.lib.model
@@ -28,8 +29,8 @@ import tests
 class PagureLibDropIssuetests(tests.Modeltests):
 class PagureLibDropIssuetests(tests.Modeltests):
     """ Tests for pagure.lib.query.drop_issue """
     """ Tests for pagure.lib.query.drop_issue """
 
 
-    @patch('pagure.lib.git.update_git')
-    @patch('pagure.lib.notify.send_email')
+    @patch("pagure.lib.git.update_git")
+    @patch("pagure.lib.notify.send_email")
     def setUp(self, p_send_email, p_ugt):
     def setUp(self, p_send_email, p_ugt):
         """ Create a couple of tickets and add tag to the project so we can
         """ Create a couple of tickets and add tag to the project so we can
         play with them later.
         play with them later.
@@ -39,9 +40,8 @@ class PagureLibDropIssuetests(tests.Modeltests):
         p_send_email.return_value = True
         p_send_email.return_value = True
         p_ugt.return_value = True
         p_ugt.return_value = True
 
 
-
         tests.create_projects(self.session)
         tests.create_projects(self.session)
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
 
 
         # Before
         # Before
         issues = pagure.lib.query.search_issues(self.session, repo)
         issues = pagure.lib.query.search_issues(self.session, repo)
@@ -53,25 +53,25 @@ class PagureLibDropIssuetests(tests.Modeltests):
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
-            title='Test issue',
-            content='We should work on this',
-            user='pingou',
+            title="Test issue",
+            content="We should work on this",
+            user="pingou",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg.title, 'Test issue')
+        self.assertEqual(msg.title, "Test issue")
         self.assertEqual(repo.open_tickets, 1)
         self.assertEqual(repo.open_tickets, 1)
         self.assertEqual(repo.open_tickets_public, 1)
         self.assertEqual(repo.open_tickets_public, 1)
 
 
         msg = pagure.lib.query.new_issue(
         msg = pagure.lib.query.new_issue(
             session=self.session,
             session=self.session,
             repo=repo,
             repo=repo,
-            title='Test issue #2',
-            content='We should work on this for the second time',
-            user='foo',
-            status='Open',
+            title="Test issue #2",
+            content="We should work on this for the second time",
+            user="foo",
+            status="Open",
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msg.title, 'Test issue #2')
+        self.assertEqual(msg.title, "Test issue #2")
         self.assertEqual(repo.open_tickets, 2)
         self.assertEqual(repo.open_tickets, 2)
         self.assertEqual(repo.open_tickets_public, 2)
         self.assertEqual(repo.open_tickets_public, 2)
 
 
@@ -81,23 +81,19 @@ class PagureLibDropIssuetests(tests.Modeltests):
 
 
         # Add tag to the project
         # Add tag to the project
         pagure.lib.query.new_tag(
         pagure.lib.query.new_tag(
-            self.session,
-            'red',
-            'red tag',
-            '#ff0000',
-            repo.id
+            self.session, "red", "red tag", "#ff0000", repo.id
         )
         )
         self.session.commit()
         self.session.commit()
 
 
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(
         self.assertEqual(
             str(repo.tags_colored),
             str(repo.tags_colored),
-            '[TagColored(id: 1, tag:red, tag_description:red tag, color:#ff0000)]'
+            "[TagColored(id: 1, tag:red, tag_description:red tag, color:#ff0000)]",
         )
         )
 
 
-    @patch('pagure.lib.git.update_git')
-    @patch('pagure.lib.notify.send_email')
-    @patch('pagure.lib.git._maybe_wait', tests.definitely_wait)
+    @patch("pagure.lib.git.update_git")
+    @patch("pagure.lib.notify.send_email")
+    @patch("pagure.lib.git._maybe_wait", tests.definitely_wait)
     def test_drop_issue(self, p_send_email, p_ugt):
     def test_drop_issue(self, p_send_email, p_ugt):
         """ Test the drop_issue of pagure.lib.query.
         """ Test the drop_issue of pagure.lib.query.
 
 
@@ -108,40 +104,36 @@ class PagureLibDropIssuetests(tests.Modeltests):
         p_send_email.return_value = True
         p_send_email.return_value = True
         p_ugt.return_value = True
         p_ugt.return_value = True
 
 
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
 
 
         # Add tag to the second issue
         # Add tag to the second issue
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
         msgs = pagure.lib.query.update_tags(
         msgs = pagure.lib.query.update_tags(
-            self.session,
-            issue,
-            tags=['red'],
-            username='pingou',
+            self.session, issue, tags=["red"], username="pingou"
         )
         )
         self.session.commit()
         self.session.commit()
 
 
-        self.assertEqual(msgs, ['Issue tagged with: red'])
+        self.assertEqual(msgs, ["Issue tagged with: red"])
 
 
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(repo.issues), 2)
         self.assertEqual(len(repo.issues), 2)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
         self.assertEqual(
         self.assertEqual(
             str(issue.tags),
             str(issue.tags),
-            '[TagColored(id: 1, tag:red, tag_description:red tag, color:#ff0000)]'
+            "[TagColored(id: 1, tag:red, tag_description:red tag, color:#ff0000)]",
         )
         )
 
 
         # Drop the issue #2
         # Drop the issue #2
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
-        pagure.lib.query.drop_issue(
-            self.session, issue, user='pingou')
+        pagure.lib.query.drop_issue(self.session, issue, user="pingou")
         self.session.commit()
         self.session.commit()
 
 
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(repo.issues), 1)
         self.assertEqual(len(repo.issues), 1)
 
 
-    @patch('pagure.lib.git.update_git')
-    @patch('pagure.lib.notify.send_email')
-    @patch('pagure.lib.git._maybe_wait', tests.definitely_wait)
+    @patch("pagure.lib.git.update_git")
+    @patch("pagure.lib.notify.send_email")
+    @patch("pagure.lib.git._maybe_wait", tests.definitely_wait)
     def test_drop_issue_two_issues_one_tag(self, p_send_email, p_ugt):
     def test_drop_issue_two_issues_one_tag(self, p_send_email, p_ugt):
         """ Test the drop_issue of pagure.lib.query.
         """ Test the drop_issue of pagure.lib.query.
 
 
@@ -152,59 +144,52 @@ class PagureLibDropIssuetests(tests.Modeltests):
         p_send_email.return_value = True
         p_send_email.return_value = True
         p_ugt.return_value = True
         p_ugt.return_value = True
 
 
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
 
 
         # Add the tag to both issues
         # Add the tag to both issues
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         msgs = pagure.lib.query.update_tags(
         msgs = pagure.lib.query.update_tags(
-            self.session,
-            issue,
-            tags=['red'],
-            username='pingou',
+            self.session, issue, tags=["red"], username="pingou"
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msgs, ['Issue tagged with: red'])
+        self.assertEqual(msgs, ["Issue tagged with: red"])
 
 
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
         msgs = pagure.lib.query.update_tags(
         msgs = pagure.lib.query.update_tags(
-            self.session,
-            issue,
-            tags=['red'],
-            username='pingou',
+            self.session, issue, tags=["red"], username="pingou"
         )
         )
         self.session.commit()
         self.session.commit()
-        self.assertEqual(msgs, ['Issue tagged with: red'])
+        self.assertEqual(msgs, ["Issue tagged with: red"])
 
 
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(repo.issues), 2)
         self.assertEqual(len(repo.issues), 2)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         self.assertEqual(
         self.assertEqual(
             str(issue.tags),
             str(issue.tags),
-            '[TagColored(id: 1, tag:red, tag_description:red tag, color:#ff0000)]'
+            "[TagColored(id: 1, tag:red, tag_description:red tag, color:#ff0000)]",
         )
         )
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
         self.assertEqual(
         self.assertEqual(
             str(issue.tags),
             str(issue.tags),
-            '[TagColored(id: 1, tag:red, tag_description:red tag, color:#ff0000)]'
+            "[TagColored(id: 1, tag:red, tag_description:red tag, color:#ff0000)]",
         )
         )
 
 
         # Drop the issue #2
         # Drop the issue #2
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
-        pagure.lib.query.drop_issue(
-            self.session, issue, user='pingou')
+        pagure.lib.query.drop_issue(self.session, issue, user="pingou")
         self.session.commit()
         self.session.commit()
 
 
-        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        repo = pagure.lib.query.get_authorized_project(self.session, "test")
         self.assertEqual(len(repo.issues), 1)
         self.assertEqual(len(repo.issues), 1)
 
 
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
         self.assertEqual(
         self.assertEqual(
             str(issue.tags),
             str(issue.tags),
-            '[TagColored(id: 1, tag:red, tag_description:red tag, color:#ff0000)]'
+            "[TagColored(id: 1, tag:red, tag_description:red tag, color:#ff0000)]",
         )
         )
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
         issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
         self.assertIsNone(issue)
         self.assertIsNone(issue)
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

+ 51 - 34
tests/test_pagure_lib_encoding_utils.py

@@ -10,21 +10,21 @@ import os
 import unittest
 import unittest
 import sys
 import sys
 
 
-sys.path.insert(0, os.path.join(os.path.dirname(
-    os.path.abspath(__file__)), '..'))
+sys.path.insert(
+    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+)
 
 
 from pagure.lib import encoding_utils
 from pagure.lib import encoding_utils
 
 
 
 
 class TestGuessEncoding(unittest.TestCase):
 class TestGuessEncoding(unittest.TestCase):
-
     def test_guess_encoding_ascii(self):
     def test_guess_encoding_ascii(self):
         """
         """
         Assert when ascii-only data is provided ascii is the guessed encoding.
         Assert when ascii-only data is provided ascii is the guessed encoding.
         """
         """
-        data = 'Twas bryllyg, and the slythy toves did gyre and gymble'
-        result = encoding_utils.guess_encoding(data.encode('ascii'))
-        self.assertEqual(result, 'ascii')
+        data = "Twas bryllyg, and the slythy toves did gyre and gymble"
+        result = encoding_utils.guess_encoding(data.encode("ascii"))
+        self.assertEqual(result, "ascii")
 
 
     def test_guess_encoding_favor_utf_8(self):
     def test_guess_encoding_favor_utf_8(self):
         """
         """
@@ -33,67 +33,84 @@ class TestGuessEncoding(unittest.TestCase):
         python-chardet-3.0.4-2.fc27.noarch detects it as ISO-8859-9
         python-chardet-3.0.4-2.fc27.noarch detects it as ISO-8859-9
         python-chardet-2.2.1-1.el7_1.noarch detects it as ISO-8859-2
         python-chardet-2.2.1-1.el7_1.noarch detects it as ISO-8859-2
         """
         """
-        data = 'Šabata'.encode('utf-8')
+        data = "Šabata".encode("utf-8")
         result = encoding_utils.guess_encoding(data)
         result = encoding_utils.guess_encoding(data)
         chardet_result = chardet.detect(data)
         chardet_result = chardet.detect(data)
-        self.assertEqual(result, 'utf-8')
-        if chardet.__version__[0] == '3':
-            self.assertEqual(chardet_result['encoding'], 'ISO-8859-9')
+        self.assertEqual(result, "utf-8")
+        if chardet.__version__[0] == "3":
+            self.assertEqual(chardet_result["encoding"], "ISO-8859-9")
         else:
         else:
-            self.assertEqual(chardet_result['encoding'], 'ISO-8859-2')
+            self.assertEqual(chardet_result["encoding"], "ISO-8859-2")
 
 
     def test_guess_encoding_no_data(self):
     def test_guess_encoding_no_data(self):
         """ Test encoding_utils.guess_encoding() with an empty string """
         """ Test encoding_utils.guess_encoding() with an empty string """
-        result = encoding_utils.guess_encoding(''.encode('utf-8'))
-        self.assertEqual(result, 'ascii')
+        result = encoding_utils.guess_encoding("".encode("utf-8"))
+        self.assertEqual(result, "ascii")
 
 
 
 
 class TestGuessEncodings(unittest.TestCase):
 class TestGuessEncodings(unittest.TestCase):
-
     def test_guess_encodings(self):
     def test_guess_encodings(self):
         """ Test the encoding_utils.guess_encodings() method. """
         """ Test the encoding_utils.guess_encodings() method. """
-        data = 'Šabata'.encode('utf-8')
+        data = "Šabata".encode("utf-8")
         result = encoding_utils.guess_encodings(data)
         result = encoding_utils.guess_encodings(data)
         chardet_result = chardet.detect(data)
         chardet_result = chardet.detect(data)
-        if chardet.__version__[0] == '3':
+        if chardet.__version__[0] == "3":
             # The first three have different confidence values
             # The first three have different confidence values
             self.assertListEqual(
             self.assertListEqual(
                 [encoding.encoding for encoding in result][:3],
                 [encoding.encoding for encoding in result][:3],
-                ['utf-8', 'ISO-8859-9', 'ISO-8859-1']
+                ["utf-8", "ISO-8859-9", "ISO-8859-1"],
             )
             )
             # This is the one with the least confidence
             # This is the one with the least confidence
-            self.assertEqual(result[-1].encoding, 'windows-1255')
+            self.assertEqual(result[-1].encoding, "windows-1255")
             # The values in the middle of the list all have the same confidence
             # The values in the middle of the list all have the same confidence
             # value and can't be sorted reliably: use sets.
             # value and can't be sorted reliably: use sets.
             self.assertEqual(
             self.assertEqual(
                 set([encoding.encoding for encoding in result]),
                 set([encoding.encoding for encoding in result]),
-                set(['utf-8', 'ISO-8859-9', 'ISO-8859-1', 'MacCyrillic',
-                     'IBM866', 'TIS-620', 'EUC-JP', 'EUC-KR', 'GB2312',
-                     'KOI8-R', 'Big5', 'IBM855', 'ISO-8859-7', 'SHIFT_JIS',
-                     'windows-1253', 'CP949', 'EUC-TW', 'ISO-8859-5',
-                     'windows-1251', 'windows-1255'])
+                set(
+                    [
+                        "utf-8",
+                        "ISO-8859-9",
+                        "ISO-8859-1",
+                        "MacCyrillic",
+                        "IBM866",
+                        "TIS-620",
+                        "EUC-JP",
+                        "EUC-KR",
+                        "GB2312",
+                        "KOI8-R",
+                        "Big5",
+                        "IBM855",
+                        "ISO-8859-7",
+                        "SHIFT_JIS",
+                        "windows-1253",
+                        "CP949",
+                        "EUC-TW",
+                        "ISO-8859-5",
+                        "windows-1251",
+                        "windows-1255",
+                    ]
+                ),
             )
             )
-            self.assertEqual(chardet_result['encoding'], 'ISO-8859-9')
+            self.assertEqual(chardet_result["encoding"], "ISO-8859-9")
         else:
         else:
             self.assertListEqual(
             self.assertListEqual(
                 [encoding.encoding for encoding in result],
                 [encoding.encoding for encoding in result],
-                ['utf-8', 'ISO-8859-2', 'windows-1252'])
-            self.assertEqual(chardet_result['encoding'], 'ISO-8859-2')
+                ["utf-8", "ISO-8859-2", "windows-1252"],
+            )
+            self.assertEqual(chardet_result["encoding"], "ISO-8859-2")
 
 
     def test_guess_encodings_no_data(self):
     def test_guess_encodings_no_data(self):
         """ Test encoding_utils.guess_encodings() with an emtpy string """
         """ Test encoding_utils.guess_encodings() with an emtpy string """
-        result = encoding_utils.guess_encodings(''.encode('utf-8'))
-        self.assertEqual(
-            [encoding.encoding for encoding in result],
-            ['ascii'])
+        result = encoding_utils.guess_encodings("".encode("utf-8"))
+        self.assertEqual([encoding.encoding for encoding in result], ["ascii"])
 
 
-class TestDecode(unittest.TestCase):
 
 
+class TestDecode(unittest.TestCase):
     def test_decode(self):
     def test_decode(self):
         """ Test encoding_utils.decode() """
         """ Test encoding_utils.decode() """
-        data = 'Šabata'
-        self.assertEqual(data, encoding_utils.decode(data.encode('utf-8')))
+        data = "Šabata"
+        self.assertEqual(data, encoding_utils.decode(data.encode("utf-8")))
 
 
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)
     unittest.main(verbosity=2)

File diff suppressed because it is too large
+ 253 - 275
tests/test_pagure_lib_git.py


Some files were not shown because too many files changed in this diff