From 0b26ba89287e705f70fe74c3cf1bf5da88e95c3e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 03 2017 16:50:46 +0000 Subject: [PATCH 1/4] Fix unit-tests Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/default_config.py b/pagure/default_config.py index 0528217..f9365df 100644 --- a/pagure/default_config.py +++ b/pagure/default_config.py @@ -257,7 +257,8 @@ ACLS = { 'pull_request_comment': 'Comment on a pull-request', 'pull_request_flag': 'Flag a pull-request', 'pull_request_merge': 'Merge a pull-request', - 'pull_request_subscribe': 'Subscribe the user with this token to a pull-request', + 'pull_request_subscribe': + 'Subscribe the user with this token to a pull-request', 'issue_subscribe': 'Subscribe the user with this token to an issue', 'issue_update': 'Update an issue, status, comments, custom fields...', 'issue_update_custom_fields': 'Update the custom fields of an issue', diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 62b657a..0045487 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -1492,7 +1492,9 @@ def delete_repo(repo, username=None, namespace=None): namespace=namespace)) task = pagure.lib.tasks.delete_project.delay( - repo.namespace, repo.name, repo.user.user if repo.is_fork else None, flask.g.fas_user.username) + repo.namespace, repo.name, + repo.user.user if repo.is_fork else None, + flask.g.fas_user.username) return pagure.wait_for_task(task.id) From 8ac14cf0076396c0809034f0f8f0d0c731fdad39 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 03 2017 16:50:46 +0000 Subject: [PATCH 2/4] Make pagure compatible with newer python chardet Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/lib/encoding_utils.py b/pagure/lib/encoding_utils.py index 00c47bb..60c1493 100644 --- a/pagure/lib/encoding_utils.py +++ b/pagure/lib/encoding_utils.py @@ -15,7 +15,7 @@ from __future__ import unicode_literals, division, absolute_import from collections import namedtuple import logging -from chardet import universaldetector +from chardet import universaldetector, __version__ as ch_version from pagure.exceptions import PagureEncodingException @@ -51,9 +51,17 @@ def detect_encodings(data): if not result: return {'utf-8': 1.0} encodings = {result['encoding']: result['confidence']} - for prober in detector._mCharSetProbers: - if prober: - encodings[prober.get_charset_name()] = prober.get_confidence() + if ch_version[0] == '3': + for prober in detector._charset_probers: + if hasattr(prober, 'probers'): + for prober in prober.probers: + encodings[prober.charset_name] = prober.get_confidence() + else: + encodings[prober.charset_name] = prober.get_confidence() + else: + for prober in detector._mCharSetProbers: + if prober: + encodings[prober.get_charset_name()] = prober.get_confidence() return encodings diff --git a/requirements.txt b/requirements.txt index 217112b..551256f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ binaryornot < 0.4.3 bleach blinker celery -chardet < 3.0.0 +chardet docutils enum34 flask diff --git a/tests/test_pagure_lib_encoding_utils.py b/tests/test_pagure_lib_encoding_utils.py index 67fdb68..5c3d07d 100644 --- a/tests/test_pagure_lib_encoding_utils.py +++ b/tests/test_pagure_lib_encoding_utils.py @@ -26,13 +26,19 @@ class TestGuessEncoding(unittest.TestCase): def test_guess_encoding_favor_utf_8(self): """ - Test that strings that could be UTF-8 or ISO-8859-2 result in UTF-8. + Test that strings that could be UTF-8 or ISO-8859-* result in UTF-8. + + 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 """ data = u'Šabata'.encode('utf-8') result = encoding_utils.guess_encoding(data) chardet_result = chardet.detect(data) self.assertEqual(result, 'utf-8') - self.assertEqual(chardet_result['encoding'], 'ISO-8859-2') + if chardet.__version__[0] == '3': + self.assertEqual(chardet_result['encoding'], 'ISO-8859-9') + else: + self.assertEqual(chardet_result['encoding'], 'ISO-8859-2') def test_guess_encoding_no_data(self): """ Test encoding_utils.guess_encoding() with an empty string """ @@ -47,10 +53,20 @@ class TestGuessEncodings(unittest.TestCase): data = u'Šabata'.encode('utf-8') result = encoding_utils.guess_encodings(data) chardet_result = chardet.detect(data) - self.assertEqual( - [encoding.encoding for encoding in result], - ['utf-8', 'ISO-8859-2', 'windows-1252']) - self.assertEqual(chardet_result['encoding'], 'ISO-8859-2') + if chardet.__version__[0] == '3': + self.assertEqual( + [encoding.encoding for encoding in result], + ['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') + else: + self.assertEqual( + [encoding.encoding for encoding in result], + ['utf-8', 'ISO-8859-2', 'windows-1252']) + self.assertEqual(chardet_result['encoding'], 'ISO-8859-2') def test_guess_encodings_no_data(self): """ Test encoding_utils.guess_encodings() with an emtpy string """ From 626d33f07c28d2ca46fd5568ea643602836b0404 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 03 2017 16:50:46 +0000 Subject: [PATCH 3/4] Drop the restriction on requests 2.16.0+ Signed-off-by: Pierre-Yves Chibon --- diff --git a/requirements.txt b/requirements.txt index 551256f..6da7995 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,7 +23,7 @@ python-openid python-openid-cla python-openid-teams redis -requests < 2.16.0 +requests six sqlalchemy >= 0.8 straight.plugin >= 1.4.0-post-1 From 9a775c266e4b3e948bc7913fc3fbb29e0807b41e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 03 2017 16:50:46 +0000 Subject: [PATCH 4/4] Drop check on calling fedmsg fedmsg is called by the workers not the main process so using mock here will simply not work. This fixes running the tests. Signed-off-by: Pierre-Yves Chibon --- diff --git a/tests/test_pagure_flask_ui_repo.py b/tests/test_pagure_flask_ui_repo.py index 77b8c52..ea20d0e 100644 --- a/tests/test_pagure_flask_ui_repo.py +++ b/tests/test_pagure_flask_ui_repo.py @@ -2996,8 +2996,7 @@ index 0000000..fb7093d @patch('pagure.lib.notify.send_email') @patch('pagure.ui.repo.admin_session_timedout') - @patch('pagure.lib.notify.log') - def test_delete_repo(self, mock_log, ast, send_email): + def test_delete_repo(self, ast, send_email): """ Test the delete_repo endpoint. """ ast.return_value = False send_email.return_value = True @@ -3264,8 +3263,6 @@ index 0000000..fb7093d 'Forks 0', output.data) - mock_log.assert_called_with(ANY, topic='project.deleted', msg=ANY) - @patch.dict('pagure.APP.config', {'TICKETS_FOLDER': None}) @patch('pagure.lib.notify.send_email', MagicMock(return_value=True)) @patch('pagure.ui.repo.admin_session_timedout', MagicMock(return_value=False))