Skip to content
Snippets Groups Projects
Commit 98ec44b5 authored by Awais Qureshi's avatar Awais Qureshi
Browse files

BOM-404

Fixing python3
parent e2743977
No related branches found
No related tags found
No related merge requests found
......@@ -618,7 +618,15 @@ def get_current_child(xmodule, min_depth=None, requested_child=None):
return _get_child(content_children) if content_children else None
child = None
if hasattr(xmodule, 'position'):
try:
# In python 3, hasattr() catches AttributeErrors only then returns False.
# All other exceptions bubble up the call stack.
has_position = hasattr(xmodule, 'position') # This conditions returns AssertionError from xblock.fields lib.
except AssertionError:
return child
if has_position:
children = xmodule.get_display_items()
if len(children) > 0:
if xmodule.position is not None and not requested_child:
......
......@@ -127,7 +127,7 @@ class MasqueradeTestCase(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
"""
Verifies that the staff debug control visibility is as expected (for staff only).
"""
content = self.get_courseware_page().content
content = self.get_courseware_page().content.decode('utf-8')
self.assertIn(self.sequential_display_name, content, "Subsection should be visible")
self.assertEqual(staff_debug_expected, 'Staff Debug Info' in content)
......@@ -150,7 +150,7 @@ class MasqueradeTestCase(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
"""
Verifies that "Show Answer" is only present when expected (for staff only).
"""
problem_html = json.loads(self.get_problem().content)['html']
problem_html = json.loads(self.get_problem().content.decode('utf-8'))['html']
self.assertIn(self.problem_display_name, problem_html)
self.assertEqual(show_answer_expected, "Show Answer" in problem_html)
......@@ -295,7 +295,7 @@ class TestStaffMasqueradeAsSpecificStudent(StaffMasqueradeTestCase, ProblemSubmi
The return value is a string like u'1/2'.
"""
json_data = json.loads(self.look_at_question(self.problem_display_name).content)
json_data = json.loads(self.look_at_question(self.problem_display_name).content.decode('utf-8'))
progress = '%s/%s' % (str(json_data['current_score']), str(json_data['total_possible']))
return progress
......@@ -329,7 +329,7 @@ class TestStaffMasqueradeAsSpecificStudent(StaffMasqueradeTestCase, ProblemSubmi
self.login_staff()
response = self.get_course_info_page()
self.assertEqual(response.status_code, 200)
content = response.content
content = response.content.decode('utf-8')
self.assertIn("OOGIE BLOOGIE", content)
# Masquerade as the student,enable the self paced configuration, and check we can see the info page.
......@@ -337,7 +337,7 @@ class TestStaffMasqueradeAsSpecificStudent(StaffMasqueradeTestCase, ProblemSubmi
self.update_masquerade(role='student', user_name=self.student_user.username)
response = self.get_course_info_page()
self.assertEqual(response.status_code, 200)
content = response.content
content = response.content.decode('utf-8')
self.assertIn("OOGIE BLOOGIE", content)
@ddt.data(
......@@ -421,12 +421,12 @@ class TestStaffMasqueradeAsSpecificStudent(StaffMasqueradeTestCase, ProblemSubmi
"""
# Log in as staff, and check we can see the info page.
self.login_staff()
content = self.get_course_info_page().content
content = self.get_course_info_page().content.decode('utf-8')
self.assertIn("OOGIE BLOOGIE", content)
# Masquerade as the student, and check we can see the info page.
self.update_masquerade(role='student', user_name=self.student_user.username)
content = self.get_course_info_page().content
content = self.get_course_info_page().content.decode('utf-8')
self.assertIn("OOGIE BLOOGIE", content)
def test_masquerade_as_specific_student_progress(self):
......@@ -436,20 +436,20 @@ class TestStaffMasqueradeAsSpecificStudent(StaffMasqueradeTestCase, ProblemSubmi
# Give the student some correct answers, check their progress page
self.login_student()
self.submit_answer('Correct', 'Correct')
student_progress = self.get_progress_page().content
student_progress = self.get_progress_page().content.decode('utf-8')
self.assertNotIn("1 of 2 possible points", student_progress)
self.assertIn("2 of 2 possible points", student_progress)
# Staff answers are slightly different
self.login_staff()
self.submit_answer('Incorrect', 'Correct')
staff_progress = self.get_progress_page().content
staff_progress = self.get_progress_page().content.decode('utf-8')
self.assertNotIn("2 of 2 possible points", staff_progress)
self.assertIn("1 of 2 possible points", staff_progress)
# Should now see the student's scores
self.update_masquerade(role='student', user_name=self.student_user.username)
masquerade_progress = self.get_progress_page().content
masquerade_progress = self.get_progress_page().content.decode('utf-8')
self.assertNotIn("1 of 2 possible points", masquerade_progress)
self.assertIn("2 of 2 possible points", masquerade_progress)
......
......@@ -3,6 +3,7 @@
import bleach
import json
import math
import six
from openedx.core.djangolib.js_utils import (
dump_js_escaped_json, js_escaped_string
......@@ -100,7 +101,7 @@ $(function () {
extraColorIndex = len(categories) #Keeping track of the next color to use for categories not in categories[]
if show_grade_breakdown:
for section in grade_summary['grade_breakdown'].itervalues():
for section in six.itervalues(grade_summary['grade_breakdown']):
if section['percent'] > 0:
if section['category'] in categories:
color = categories[ section['category'] ]['color']
......
......@@ -69,7 +69,12 @@ def dump_js_escaped_json(obj, cls=EdxJSONEncoder):
(string) Escaped encoded JSON.
"""
json_string = json.dumps(obj, ensure_ascii=True, cls=cls)
try:
json_string = json.dumps(obj, ensure_ascii=True, cls=cls)
except: # pylint: disable=bare-except
# in some cases dict_values appear here.
json_string = json.dumps(list(obj), ensure_ascii=True, cls=cls)
json_string = _escape_json_for_js(json_string)
return json_string
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment