From 67224f401a74ae21522decaca8668e9dfe40c594 Mon Sep 17 00:00:00 2001 From: Ayub khan Date: Mon, 19 Aug 2019 18:47:51 +0500 Subject: [PATCH] BOM-90 Made all tests py3 compatible. --- common/lib/xmodule/xmodule/modulestore/xml.py | 6 ++++-- common/lib/xmodule/xmodule/x_module.py | 2 +- lms/djangoapps/course_goals/handlers.py | 1 + lms/djangoapps/courseware/access_response.py | 4 +++- lms/djangoapps/courseware/tests/test_tabs.py | 8 ++++---- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/xml.py b/common/lib/xmodule/xmodule/modulestore/xml.py index cf595b685c..0da3a4b368 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml.py +++ b/common/lib/xmodule/xmodule/modulestore/xml.py @@ -1,7 +1,9 @@ from __future__ import absolute_import +import codecs import glob import hashlib +import io import itertools import json import logging @@ -623,7 +625,7 @@ class XMLModuleStore(ModuleStoreReadBase): if filepath.endswith('~'): # skip *~ files continue - with open(filepath) as f: + with io.open(filepath) as f: try: if filepath.find('.json') != -1: # json file with json data content @@ -645,7 +647,7 @@ class XMLModuleStore(ModuleStoreReadBase): slug = os.path.splitext(os.path.basename(filepath))[0] loc = course_descriptor.scope_ids.usage_id.replace(category=category, name=slug) # html file with html data content - html = f.read().decode('utf-8') + html = f.read() try: module = system.load_item(loc) module.data = html diff --git a/common/lib/xmodule/xmodule/x_module.py b/common/lib/xmodule/xmodule/x_module.py index 360e87529a..ad7f1372c2 100644 --- a/common/lib/xmodule/xmodule/x_module.py +++ b/common/lib/xmodule/xmodule/x_module.py @@ -1121,7 +1121,7 @@ class XModuleDescriptorToXBlockMixin(object): Interpret the parsed XML in `node`, creating an XModuleDescriptor. """ # It'd be great to not reserialize and deserialize the xml - xml = etree.tostring(node) + xml = etree.tostring(node).decode('utf-8') block = cls.from_xml(xml, runtime, id_generator) return block diff --git a/lms/djangoapps/course_goals/handlers.py b/lms/djangoapps/course_goals/handlers.py index ef4afb8c9f..2992ba9a28 100644 --- a/lms/djangoapps/course_goals/handlers.py +++ b/lms/djangoapps/course_goals/handlers.py @@ -3,6 +3,7 @@ Signal handlers for course goals. """ from __future__ import absolute_import +import six from django.db import models from django.dispatch import receiver diff --git a/lms/djangoapps/courseware/access_response.py b/lms/djangoapps/courseware/access_response.py index 781468a4e0..1b27eef4a8 100644 --- a/lms/djangoapps/courseware/access_response.py +++ b/lms/djangoapps/courseware/access_response.py @@ -38,7 +38,7 @@ class AccessResponse(object): if has_access: assert error_code is None - def __nonzero__(self): + def __bool__(self): """ Overrides bool(). @@ -52,6 +52,8 @@ class AccessResponse(object): """ return self.has_access + __nonzero__ = __bool__ + def to_json(self): """ Creates a serializable JSON representation of an AccessResponse object. diff --git a/lms/djangoapps/courseware/tests/test_tabs.py b/lms/djangoapps/courseware/tests/test_tabs.py index 148b4f5e67..394c519b0d 100644 --- a/lms/djangoapps/courseware/tests/test_tabs.py +++ b/lms/djangoapps/courseware/tests/test_tabs.py @@ -254,13 +254,13 @@ class StaticTabDateTestCase(LoginEnrollmentTestCase, SharedModuleStoreTestCase): url = reverse('static_tab', args=[text_type(self.course.id), 'new_tab']) resp = self.client.get(url) self.assertEqual(resp.status_code, 200) - self.assertIn("OOGIE BLOOGIE", resp.content) + self.assertIn("OOGIE BLOOGIE", resp.content.decode('utf-8')) def test_anonymous_user(self): url = reverse('static_tab', args=[text_type(self.course.id), 'new_tab']) resp = self.client.get(url) self.assertEqual(resp.status_code, 200) - self.assertIn("OOGIE BLOOGIE", resp.content) + self.assertIn("OOGIE BLOOGIE", resp.content.decode('utf-8')) def test_invalid_course_key(self): self.setup_user() @@ -329,14 +329,14 @@ class StaticTabDateTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase): url = reverse('static_tab', args=[text_type(self.xml_course_key), self.xml_url]) resp = self.client.get(url) self.assertEqual(resp.status_code, 200) - self.assertIn(self.xml_data, resp.content) + self.assertIn(self.xml_data, resp.content.decode('utf-8')) @patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False}) def test_anonymous_user_xml(self): url = reverse('static_tab', args=[text_type(self.xml_course_key), self.xml_url]) resp = self.client.get(url) self.assertEqual(resp.status_code, 200) - self.assertIn(self.xml_data, resp.content) + self.assertIn(self.xml_data, resp.content.decode('utf-8')) @patch.dict('django.conf.settings.FEATURES', {'ENTRANCE_EXAMS': True})