From cda3055bd6d1810b17a83cde991c7e059ef76657 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Thu, 7 Aug 2014 13:08:42 +0300 Subject: [PATCH] Fix another tests. (forgot to commit earlier) --- mediagoblin/media_types/pdf/processing.py | 1 + mediagoblin/submit/lib.py | 2 +- mediagoblin/tests/test_api.py | 6 +++--- mediagoblin/tests/test_auth.py | 4 ++-- mediagoblin/tests/test_edit.py | 3 +-- mediagoblin/tests/test_exif.py | 6 +++--- mediagoblin/tests/test_http_callback.py | 2 +- mediagoblin/tests/test_notifications.py | 4 ++-- mediagoblin/tests/test_oauth2.py | 6 +++--- mediagoblin/tests/test_pdf.py | 5 +++-- mediagoblin/tests/test_piwigo.py | 17 ++++++----------- mediagoblin/tests/test_pluginapi.py | 3 +-- mediagoblin/tools/crypto.py | 2 +- 13 files changed, 28 insertions(+), 33 deletions(-) diff --git a/mediagoblin/media_types/pdf/processing.py b/mediagoblin/media_types/pdf/processing.py index 0a173cf7..e02fd577 100644 --- a/mediagoblin/media_types/pdf/processing.py +++ b/mediagoblin/media_types/pdf/processing.py @@ -207,6 +207,7 @@ def pdf_info(original): _log.debug('pdfinfo could not read the pdf file.') raise BadMediaFail() + lines = [l.decode() for l in lines] info_dict = dict([[part.strip() for part in l.strip().split(':', 1)] for l in lines if ':' in l]) diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py index 7d3ea8df..61d5067f 100644 --- a/mediagoblin/submit/lib.py +++ b/mediagoblin/submit/lib.py @@ -59,7 +59,7 @@ def get_upload_file_limits(user): """ Get the upload_limit and max_file_size for this user """ - if user.upload_limit >= 0: + if user.upload_limit is not None and user.upload_limit >= 0: # TODO: debug this upload_limit = user.upload_limit else: upload_limit = mg_globals.app_config.get('upload_limit', None) diff --git a/mediagoblin/tests/test_api.py b/mediagoblin/tests/test_api.py index e19313e4..c8a254d4 100644 --- a/mediagoblin/tests/test_api.py +++ b/mediagoblin/tests/test_api.py @@ -48,10 +48,10 @@ class TestAPI(object): return template.TEMPLATE_TEST_CONTEXT[template_name] def http_auth_headers(self): - return {'Authorization': 'Basic {0}'.format( - base64.b64encode(':'.join([ + return {'Authorization': ('Basic {0}'.format( + base64.b64encode((':'.join([ self.user.username, - self.user_password])))} + self.user_password])).encode('ascii')).decode()))} def do_post(self, data, test_app, **kwargs): url = kwargs.pop('url', '/api/submit') diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index 9b7f9825..7980953f 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -119,7 +119,7 @@ def test_register_views(test_app): assert message['To'] == 'angrygrrl@example.org' email_context = template.TEMPLATE_TEST_CONTEXT[ 'mediagoblin/auth/verification_email.txt'] - assert email_context['verification_url'] in message.get_payload(decode=True) + assert email_context['verification_url'].encode('ascii') in message.get_payload(decode=True) path = urlparse.urlsplit(email_context['verification_url'])[2] get_params = urlparse.urlsplit(email_context['verification_url'])[3] @@ -190,7 +190,7 @@ def test_register_views(test_app): email_context = template.TEMPLATE_TEST_CONTEXT[ 'mediagoblin/plugins/basic_auth/fp_verification_email.txt'] #TODO - change the name of verification_url to something forgot-password-ish - assert email_context['verification_url'] in message.get_payload(decode=True) + assert email_context['verification_url'].encode('ascii') in message.get_payload(decode=True) path = urlparse.urlsplit(email_context['verification_url'])[2] get_params = urlparse.urlsplit(email_context['verification_url'])[3] diff --git a/mediagoblin/tests/test_edit.py b/mediagoblin/tests/test_edit.py index b60d4c74..cf72f308 100644 --- a/mediagoblin/tests/test_edit.py +++ b/mediagoblin/tests/test_edit.py @@ -142,8 +142,7 @@ class TestUserEdit(object): assert message['To'] == 'new@example.com' email_context = template.TEMPLATE_TEST_CONTEXT[ 'mediagoblin/edit/verification.txt'] - assert email_context['verification_url'] in \ - message.get_payload(decode=True) + assert email_context['verification_url'].encode('ascii') in message.get_payload(decode=True) path = urlparse.urlsplit(email_context['verification_url'])[2] assert path == u'/edit/verify_email/' diff --git a/mediagoblin/tests/test_exif.py b/mediagoblin/tests/test_exif.py index 861b768a..ccc91d03 100644 --- a/mediagoblin/tests/test_exif.py +++ b/mediagoblin/tests/test_exif.py @@ -54,19 +54,19 @@ def test_exif_extraction(): expected = OrderedDict({'EXIF CVAPattern': {'field_length': 8, 'field_offset': 26224, 'field_type': 7, - 'printable': u'[0, 2, 0, 2, 1, 2, 0, 1]', + 'printable': '[0, 2, 0, 2, 1, 2, 0, 1]', 'tag': 41730, 'values': [0, 2, 0, 2, 1, 2, 0, 1]}, 'EXIF ColorSpace': {'field_length': 2, 'field_offset': 476, 'field_type': 3, - 'printable': u'sRGB', + 'printable': 'sRGB', 'tag': 40961, 'values': [1]}, 'EXIF ComponentsConfiguration': {'field_length': 4, 'field_offset': 308, 'field_type': 7, - 'printable': u'YCbCr', + 'printable': 'YCbCr', 'tag': 37121, 'values': [1, 2, 3, 0]}, 'EXIF CompressedBitsPerPixel': {'field_length': 8, diff --git a/mediagoblin/tests/test_http_callback.py b/mediagoblin/tests/test_http_callback.py index 11f02c97..38f1cfaf 100644 --- a/mediagoblin/tests/test_http_callback.py +++ b/mediagoblin/tests/test_http_callback.py @@ -51,7 +51,7 @@ class TestHTTPCallback(object): 'client_id': client_id, 'client_secret': client_secret}) - response_data = json.loads(response.body) + response_data = json.loads(response.body.decode()) return response_data['access_token'] diff --git a/mediagoblin/tests/test_notifications.py b/mediagoblin/tests/test_notifications.py index 37d61c41..385da569 100644 --- a/mediagoblin/tests/test_notifications.py +++ b/mediagoblin/tests/test_notifications.py @@ -135,13 +135,13 @@ otherperson@example.com\n\nSGkgb3RoZXJwZXJzb24sCmNocmlzIGNvbW1lbnRlZCBvbiB5b3VyI self.logout() self.login('otherperson', 'nosreprehto') - self.test_app.get(media_uri_slug + '/c/{0}/'.format(comment_id)) + self.test_app.get(media_uri_slug + 'c/{0}/'.format(comment_id)) notification = Notification.query.filter_by(id=notification_id).first() assert notification.seen == True - self.test_app.get(media_uri_slug + '/notifications/silence/') + self.test_app.get(media_uri_slug + 'notifications/silence/') subscription = CommentSubscription.query.filter_by(id=subscription_id)\ .first() diff --git a/mediagoblin/tests/test_oauth2.py b/mediagoblin/tests/test_oauth2.py index 014808a6..16372730 100644 --- a/mediagoblin/tests/test_oauth2.py +++ b/mediagoblin/tests/test_oauth2.py @@ -163,7 +163,7 @@ code={1}&client_secret={2}'.format(client_id, code, client.secret)) assert token_res.status_int == 200 - token_data = json.loads(token_res.body) + token_data = json.loads(token_res.body.decode()) assert not 'error' in token_data assert 'access_token' in token_data @@ -191,7 +191,7 @@ code={0}&client_secret={1}'.format(code, client.secret)) assert token_res.status_int == 200 - token_data = json.loads(token_res.body) + token_data = json.loads(token_res.body.decode()) assert 'error' in token_data assert not 'access_token' in token_data @@ -215,7 +215,7 @@ code={0}&client_secret={1}'.format(code, client.secret)) assert token_res.status_int == 200 - new_token_data = json.loads(token_res.body) + new_token_data = json.loads(token_res.body.decode()) assert not 'error' in new_token_data assert 'access_token' in new_token_data diff --git a/mediagoblin/tests/test_pdf.py b/mediagoblin/tests/test_pdf.py index b4d1940a..7e59de17 100644 --- a/mediagoblin/tests/test_pdf.py +++ b/mediagoblin/tests/test_pdf.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import collections import tempfile import shutil import os @@ -26,13 +27,13 @@ from .resources import GOOD_PDF as GOOD @pytest.mark.skipif("not check_prerequisites()") def test_pdf(): - good_dict = {'pdf_version_major': 1, 'pdf_title': '', + good_dict = collections.OrderedDict({'pdf_version_major': 1, 'pdf_title': '', 'pdf_page_size_width': 612, 'pdf_author': '', 'pdf_keywords': '', 'pdf_pages': 10, 'pdf_producer': 'dvips + GNU Ghostscript 7.05', 'pdf_version_minor': 3, 'pdf_creator': 'LaTeX with hyperref package', - 'pdf_page_size_height': 792} + 'pdf_page_size_height': 792}) assert pdf_info(GOOD) == good_dict temp_dir = tempfile.mkdtemp() create_pdf_thumb(GOOD, os.path.join(temp_dir, 'good_256_256.png'), 256, 256) diff --git a/mediagoblin/tests/test_piwigo.py b/mediagoblin/tests/test_piwigo.py index 16ad0111..33aea580 100644 --- a/mediagoblin/tests/test_piwigo.py +++ b/mediagoblin/tests/test_piwigo.py @@ -44,28 +44,23 @@ class Test_PWG(object): def test_session(self): resp = self.do_post("pwg.session.login", {"username": u"nouser", "password": "wrong"}) - assert resp.body == XML_PREFIX \ - + '' + assert resp.body == (XML_PREFIX + '').encode('ascii') resp = self.do_post("pwg.session.login", {"username": self.username, "password": "wrong"}) - assert resp.body == XML_PREFIX \ - + '' + assert resp.body == (XML_PREFIX + '').encode('ascii') resp = self.do_get("pwg.session.getStatus") - assert resp.body == XML_PREFIX \ - + 'guest' + assert resp.body == (XML_PREFIX + 'guest').encode('ascii') resp = self.do_post("pwg.session.login", {"username": self.username, "password": self.password}) - assert resp.body == XML_PREFIX + '1' + assert resp.body == (XML_PREFIX + '1').encode('ascii') resp = self.do_get("pwg.session.getStatus") - assert resp.body == XML_PREFIX \ - + 'chris' + assert resp.body == (XML_PREFIX + 'chris').encode('ascii') self.do_get("pwg.session.logout") resp = self.do_get("pwg.session.getStatus") - assert resp.body == XML_PREFIX \ - + 'guest' + assert resp.body == (XML_PREFIX + 'guest').encode('ascii') diff --git a/mediagoblin/tests/test_pluginapi.py b/mediagoblin/tests/test_pluginapi.py index b3f37e2a..2fd6df39 100644 --- a/mediagoblin/tests/test_pluginapi.py +++ b/mediagoblin/tests/test_pluginapi.py @@ -456,11 +456,10 @@ def test_plugin_staticdirect(static_plugin_app): Test that the staticdirect utilities pull up the right things """ result = json.loads( - static_plugin_app.get('/staticstuff/').body) + static_plugin_app.get('/staticstuff/').body.decode()) assert len(result) == 2 assert result['mgoblin_bunny_pic'] == '/test_static/images/bunny_pic.png' assert result['plugin_bunny_css'] == \ '/plugin_static/staticstuff/css/bunnify.css' - diff --git a/mediagoblin/tools/crypto.py b/mediagoblin/tools/crypto.py index 14a1a72d..cf6d31f6 100644 --- a/mediagoblin/tools/crypto.py +++ b/mediagoblin/tools/crypto.py @@ -61,7 +61,7 @@ def create_key(key_dir, key_filepath): key = str(getrandbits(192)) key_file = tempfile.NamedTemporaryFile(dir=key_dir, suffix='.bin', delete=False) - key_file.write(key) + key_file.write(key.encode('ascii')) key_file.flush() os.rename(key_file.name, key_filepath) key_file.close() -- 2.25.1