From 392277c0ef648063eddb3452ffd70d25871a0d7b Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 05 2018 14:37:12 +0000 Subject: Fix running the unit-tests In de8a0a0635b722ae1f824b66b5674e58935617c5 we changed is_admin() to rely on flask.g.authenticated instead of calling the function one more time. Except that this broke a few unit-tests and the API login which didn't have this attribute on flask.g. This commit fixes this. Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/api/__init__.py b/pagure/api/__init__.py index 64dbbde..a5fb764 100644 --- a/pagure/api/__init__.py +++ b/pagure/api/__init__.py @@ -130,6 +130,7 @@ def check_api_acls(acls, optional=False): if token_str: token = pagure.lib.get_api_token(flask.g.session, token_str) if token and not token.expired: + flask.g.authenticated = True if acls and set(token.acls_list).intersection(set(acls)): token_auth = True flask.g.fas_user = token.user @@ -137,6 +138,7 @@ def check_api_acls(acls, optional=False): # the CLA, so just set it to True flask.g.fas_user.cla_done = True flask.g.token = token + flask.g.authenticated = True elif not acls and optional: token_auth = True flask.g.fas_user = token.user @@ -144,6 +146,7 @@ def check_api_acls(acls, optional=False): # the CLA, so just set it to True flask.g.fas_user.cla_done = True flask.g.token = token + flask.g.authenticated = True elif optional: return diff --git a/tests/__init__.py b/tests/__init__.py index f285490..3941413 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -137,6 +137,7 @@ def user_set(APP, user): def handler(sender, **kwargs): g.fas_user = user g.fas_session_id = b'123' + g.authenticated = True with appcontext_pushed.connected_to(handler, APP): yield diff --git a/tests/test_pagure_flask.py b/tests/test_pagure_flask.py index a2c0edb..f2412a0 100644 --- a/tests/test_pagure_flask.py +++ b/tests/test_pagure_flask.py @@ -66,6 +66,7 @@ class PagureGetRemoteRepoPath(tests.SimplePagureTest): g = munch.Munch() g.fas_user = tests.FakeUser(username='pingou') + g.authenticated = True with mock.patch('pagure.flask_app.flask.g', g): output = pagure.utils.is_repo_committer(repo) self.assertTrue(output) @@ -77,6 +78,7 @@ class PagureGetRemoteRepoPath(tests.SimplePagureTest): g = munch.Munch() g.fas_user = tests.FakeUser() + g.authenticated = True with mock.patch('pagure.flask_app.flask.g', g): output = pagure.utils.is_repo_committer(repo) self.assertFalse(output) @@ -97,6 +99,7 @@ class PagureGetRemoteRepoPath(tests.SimplePagureTest): user = tests.FakeUser() g = munch.Munch() g.fas_user = user + g.authenticated = True with mock.patch('pagure.flask_app.flask.g', g): output = pagure.utils.is_repo_committer(repo) self.assertFalse(output) @@ -112,6 +115,7 @@ class PagureGetRemoteRepoPath(tests.SimplePagureTest): g = munch.Munch() g.fas_user = tests.FakeUser() g.fas_user.groups.append('provenpackager') + g.authenticated = True with mock.patch('pagure.flask_app.flask.g', g): output = pagure.utils.is_repo_committer(repo) self.assertTrue(output) @@ -133,6 +137,7 @@ class PagureGetRemoteRepoPath(tests.SimplePagureTest): g = munch.Munch() g.fas_user = tests.FakeUser() g.fas_user.groups.append('provenpackager') + g.authenticated = True with mock.patch('pagure.flask_app.flask.g', g): output = pagure.utils.is_repo_committer(repo) self.assertFalse(output) @@ -152,6 +157,7 @@ class PagureGetRemoteRepoPath(tests.SimplePagureTest): g = munch.Munch() g.fas_user = tests.FakeUser() + g.authenticated = True with mock.patch('pagure.flask_app.flask.g', g): output = pagure.utils.is_repo_committer(repo) self.assertFalse(output) @@ -165,6 +171,7 @@ class PagureGetRemoteRepoPath(tests.SimplePagureTest): g = munch.Munch() g.fas_user = tests.FakeUser() + g.authenticated = True g.fas_user.groups.append('provenpackager') with mock.patch('pagure.flask_app.flask.g', g): output = pagure.utils.is_repo_committer(repo) @@ -180,6 +187,7 @@ class PagureGetRemoteRepoPath(tests.SimplePagureTest): g = munch.Munch() g.fas_user = tests.FakeUser() + g.authenticated = True g.fas_user.groups.append('provenpackager') with mock.patch('pagure.flask_app.flask.g', g): output = pagure.utils.is_repo_committer(repo)