From f0133d861db8f08c0c1496fed60a3648b5b0ad2e Mon Sep 17 00:00:00 2001 From: Ayub khan Date: Mon, 14 Oct 2019 18:20:42 +0500 Subject: [PATCH] BOM Project Xblock Recommber integration tests fix Python3 json can not work with bytes type input so used simplejson instead of python json which works with both bytes and unicode type input. Previously we mistakenly updated StringIO to six.String io. which caused the tests failure. Used io.BytesIO to fix the issues as assci character bytes can not be converted to unicode. --- .../tests/xblock_integration/test_recommender.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/openedx/tests/xblock_integration/test_recommender.py b/openedx/tests/xblock_integration/test_recommender.py index a14e0f4bb2..60677641b8 100644 --- a/openedx/tests/xblock_integration/test_recommender.py +++ b/openedx/tests/xblock_integration/test_recommender.py @@ -6,9 +6,9 @@ recommender system from __future__ import absolute_import import codecs +from io import BytesIO import itertools -import json -from six import StringIO +import simplejson as json import unittest from copy import deepcopy @@ -651,14 +651,12 @@ class TestRecommenderFileUploading(TestRecommender): happens or is rejected as expected. """ if 'magic_number' in test_case: - if six.PY2: - f_handler = StringIO(codecs.decode(test_case['magic_number'], 'hex_codec')) - else: - f_handler = StringIO(codecs.decode(test_case['magic_number'], 'hex_codec').decode('utf-8')) + f_handler = BytesIO(codecs.decode(test_case['magic_number'], 'hex_codec')) elif content is not None: - f_handler = StringIO(json.dumps(content, sort_keys=True)) + f_handler = BytesIO( + json.dumps(content, sort_keys=True) if six.PY2 else json.dumps(content, sort_keys=True).encode('utf-8')) else: - f_handler = StringIO('') + f_handler = BytesIO(b'') f_handler.content_type = test_case['mimetypes'] f_handler.name = 'file' + test_case['suffixes']