From cd0a93b266275db70cccc8b43e3cbcc303877be1 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 23 2020 18:26:07 +0000 Subject: Fix running the tests on py 3.8 Increase the timestamp specified so it remains an invalid timestamp. Stop patching flask.g directly and use application and request context instead. Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/api/issue.py b/pagure/api/issue.py index 3f9af2a..17987e3 100644 --- a/pagure/api/issue.py +++ b/pagure/api/issue.py @@ -459,7 +459,7 @@ def api_view_issues(repo, username=None, namespace=None): # We assume its a timestamp, so convert it to datetime try: updated_after = arrow.get(int(since)).datetime - except ValueError: + except (ValueError, OverflowError): raise pagure.exceptions.APIError( 400, error_code=APIERROR.ETIMESTAMP ) diff --git a/tests/test_pagure_flask_api_issue.py b/tests/test_pagure_flask_api_issue.py index e590cd5..5b04265 100644 --- a/tests/test_pagure_flask_api_issue.py +++ b/tests/test_pagure_flask_api_issue.py @@ -1752,7 +1752,9 @@ class PagureFlaskApiIssuetests(tests.SimplePagureTest): self.test_api_new_issue() # Invalid repo - output = self.app.get("/api/0/test/issues?since=100000000000000") + output = self.app.get( + "/api/0/test/issues?since=10000000000000000000000" + ) self.assertEqual(output.status_code, 400) data = json.loads(output.get_data(as_text=True)) self.assertDictEqual( diff --git a/tests/test_pagure_flask_ui_login.py b/tests/test_pagure_flask_ui_login.py index 4fb3bb9..f11a2b2 100644 --- a/tests/test_pagure_flask_ui_login.py +++ b/tests/test_pagure_flask_ui_login.py @@ -1068,9 +1068,7 @@ class PagureFlaskLogintests(tests.SimplePagureTest): self.assertEqual(output.status_code, 200) @patch("flask.flash") - @patch("flask.g") - @patch("flask.session") - def test_admin_session_timedout(self, session, g, flash): + def test_admin_session_timedout(self, flash): """ Test the call to admin_session_timedout. """ lifetime = pagure.config.config.get( "ADMIN_SESSION_LIFETIME", datetime.timedelta(minutes=15) @@ -1079,12 +1077,17 @@ class PagureFlaskLogintests(tests.SimplePagureTest): # session already expired user = tests.FakeUser(username="foo") user.login_time = datetime.datetime.utcnow() - lifetime - td1 - g.fas_user = user - self.assertTrue(pagure.flask_app.admin_session_timedout()) + with self.app.application.app_context() as ctx: + ctx.g.session = self.session + ctx.g.fas_user = user + self.assertTrue(pagure.flask_app.admin_session_timedout()) + # session did not expire user.login_time = datetime.datetime.utcnow() - lifetime + td1 - g.fas_user = user - self.assertFalse(pagure.flask_app.admin_session_timedout()) + with self.app.application.app_context() as ctx: + ctx.g.session = self.session + ctx.g.fas_user = user + self.assertFalse(pagure.flask_app.admin_session_timedout()) @patch.dict("pagure.config.config", {"PAGURE_AUTH": "local"}) def test_force_logout(self): diff --git a/tests/test_pagure_lib.py b/tests/test_pagure_lib.py index a922128..e88a8bb 100644 --- a/tests/test_pagure_lib.py +++ b/tests/test_pagure_lib.py @@ -18,7 +18,7 @@ import os import pygit2 import markdown -from mock import patch, MagicMock +from mock import patch, MagicMock, Mock sys.path.insert( 0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..") @@ -2506,6 +2506,7 @@ class PagureLibtests(tests.Modeltests): mockemail.return_value = True tests.create_projects(self.session) + tests.create_projects_git(os.path.join(self.path, "repos"), bare=True) # Create a forked repo item = pagure.lib.model.Project( @@ -4068,13 +4069,11 @@ class PagureLibtests(tests.Modeltests): watch_list = [obj.name for obj in watch_list_objs] self.assertEqual(watch_list, []) - @patch("flask.request.url", "http://localhost.localdomain/test/issue/69") - @patch("flask.request.url_root", "http://localhost.localdomain/") - @patch("flask.request.args.get", return_value=None) - @patch("flask.request") - @patch("flask.g") + @patch("pagure.lib.tasks.update_git", MagicMock(return_value=True)) + @patch("pagure.lib.tasks.sync_pull_ref", MagicMock(return_value=True)) @patch("pagure.lib.notify.send_email", MagicMock(return_value=True)) - def test_text2markdown(self, g, req, reqget): + @patch("pagure.pfmarkdown._commit_exists", MagicMock(return_value=True)) + def test_text2markdown(self): """ Test the text2markdown method in pagure.lib.query. """ pagure.config.config["TESTING"] = True pagure.config.config["SERVER_NAME"] = "localhost.localdomain" @@ -4246,52 +4245,51 @@ class PagureLibtests(tests.Modeltests): ] expected = [ # 'foo bar test#1 see?', - '

foo bar

foo bar test#1 see?

', # 'foo bar pingou/test#2 I mean, really', -- unknown namespace '

foo bar pingou/test#2 I mean, really

', # 'foo bar fork/pingou/test#2 bouza!', - '", # 'foo bar forks/pingou/test#2 bouza!', -- the 's' doesn't matter - '", # 'foo bar ns/test3#4 bouza!', - '

foo bar

foo bar ns/test3#4 bouza!

', # 'foo bar fork/user/ns/test#5 bouza!', -- unknown fork '

foo bar user/ns/test#5 bouza!

', # 'foo bar fork/pingou/ns/test#7 bouza!', - '

foo bar ' + '

", # 'test#1 bazinga!', - '

test#1 bazinga!

', # 'pingou opened the PR forks/pingou/test#2' - '', # 'fork/pingou/ns/test#8 is private', - '

pingou/ns/test#8 is private

', # 'implicit link to #1', - '

implicit link to #1

', + '

implicit link to #1

', # 'implicit link .#1. with non-whitespace, non-word characters', - '

implicit link .#1. with non-whitespace, non-word characters

', + '

implicit link .#1. with non-whitespace, non-word characters

', # '#2 - implicit link at start of line', - '

#2 - implicit link at start of line

', + '

#2 - implicit link at start of line

', # '#2. implicit link at start of line with no whitespace after', - '

#2. implicit link at start of line with no whitespace after

', + '

#2. implicit link at start of line with no whitespace after

', # '#regular header', '

regular header

', # '#34 looks like an implicit link, but no issue 34', '

34 looks like an implicit link, but no issue 34

', # 'pingou committed on test#9364354a4555ba17aa60f0dc844d70b74eb1aecd', - '", # 'irc://pagure.io' @@ -4378,11 +4376,19 @@ class PagureLibtests(tests.Modeltests): "

" ) - with self.app.application.app_context(): - g.session = self.session - for idx, text in enumerate(texts): - html = pagure.lib.query.text2markdown(text) - self.assertEqual(html, expected[idx]) + with self.app.application.app_context() as ctx: + ctx.g.session = self.session + with ctx.app.test_request_context() as reqctx: + reqctx.request.url_root = "http://localhost.localdomain/" + reqctx.request.url = ( + "http://localhost.localdomain/test/issue/69" + ) + reqctx.request.args = Mock() + reqctx.request.args.get = Mock(return_value=None) + for idx, text in enumerate(texts): + print(text) + html = pagure.lib.query.text2markdown(text) + self.assertEqual(html, expected[idx]) def test_text2markdown_exception(self): """ Test the text2markdown method in pagure.lib.query. """ @@ -4390,8 +4396,9 @@ class PagureLibtests(tests.Modeltests): text = "test#1 bazinga!" expected_html = "test#1 bazinga!" - html = pagure.lib.query.text2markdown(text) - self.assertEqual(html, expected_html) + with self.app.application.app_context() as ctx: + html = pagure.lib.query.text2markdown(text) + self.assertEqual(html, expected_html) def test_text2markdown_empty_string(self): """ Test the text2markdown method in pagure.lib.query. """