From 06c7e3e4e9f03ed8b8a7838941ff992582054fa9 Mon Sep 17 00:00:00 2001 From: Ayub khan Date: Fri, 13 Sep 2019 17:35:38 +0500 Subject: [PATCH] BOM-420 fixed all file tests --- .../django_comment_client/tests/group_id.py | 4 ++-- lms/djangoapps/discussion/tests/test_views.py | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lms/djangoapps/discussion/django_comment_client/tests/group_id.py b/lms/djangoapps/discussion/django_comment_client/tests/group_id.py index 18a7b42f6e..9c705a1c1c 100644 --- a/lms/djangoapps/discussion/django_comment_client/tests/group_id.py +++ b/lms/djangoapps/discussion/django_comment_client/tests/group_id.py @@ -32,10 +32,10 @@ class GroupIdAssertionMixin(object): def _assert_html_response_contains_group_info(self, response): group_info = {"group_id": None, "group_name": None} - match = re.search(r'"group_id": (\d*),', response.content) + match = re.search(r'"group_id": (\d*),', response.content.decode('utf-8')) if match and match.group(1) != '': group_info["group_id"] = int(match.group(1)) - match = re.search(r'"group_name": "(\w*)",', response.content) + match = re.search(r'"group_name": "(\w*)"', response.content.decode('utf-8')) if match: group_info["group_name"] = match.group(1) self._assert_thread_contains_group_info(group_info) diff --git a/lms/djangoapps/discussion/tests/test_views.py b/lms/djangoapps/discussion/tests/test_views.py index d7f4896d43..d25bb79752 100644 --- a/lms/djangoapps/discussion/tests/test_views.py +++ b/lms/djangoapps/discussion/tests/test_views.py @@ -561,7 +561,7 @@ class SingleCohortedThreadTestCase(CohortedTestCase): self.assertEquals(response.status_code, 200) self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8') - html = response.content + html = response.content.decode('utf-8') # Verify that the group name is correctly included in the HTML self.assertRegexpMatches(html, r'"group_name": "student_cohort"') @@ -1319,7 +1319,7 @@ class UserProfileTestCase(ForumsEnableMixin, UrlResetMixin, ModuleStoreTestCase) response = self.get_response(mock_request, params) self.assertEqual(response.status_code, 200) self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8') - html = response.content + html = response.content.decode('utf-8') self.assertRegexpMatches(html, r'data-page="1"') self.assertRegexpMatches(html, r'data-num-pages="1"') self.assertRegexpMatches(html, r'1 discussion started') @@ -1327,7 +1327,10 @@ class UserProfileTestCase(ForumsEnableMixin, UrlResetMixin, ModuleStoreTestCase) self.assertRegexpMatches(html, u''id': '{}''.format(self.TEST_THREAD_ID)) self.assertRegexpMatches(html, u''title': '{}''.format(self.TEST_THREAD_TEXT)) self.assertRegexpMatches(html, u''body': '{}''.format(self.TEST_THREAD_TEXT)) - self.assertRegexpMatches(html, u''username': u'{}''.format(self.student.username)) + if six.PY2: + self.assertRegexpMatches(html, u''username': u'{}''.format(self.student.username)) + else: + self.assertRegexpMatches(html, u''username': '{}''.format(self.student.username)) def check_ajax(self, mock_request, **params): response = self.get_response(mock_request, params, HTTP_X_REQUESTED_WITH="XMLHttpRequest") @@ -1549,6 +1552,7 @@ class ForumDiscussionXSSTestCase(ForumsEnableMixin, UrlResetMixin, ModuleStoreTe Test that XSS attack is prevented """ mock_user.return_value.to_dict.return_value = {} + mock_req.return_value.status_code = 200 reverse_url = "%s%s" % (reverse( "forum_form_discussion", kwargs={"course_id": six.text_type(self.course.id)}), '/forum_form_discussion') @@ -1556,7 +1560,7 @@ class ForumDiscussionXSSTestCase(ForumsEnableMixin, UrlResetMixin, ModuleStoreTe url = "%s?%s=%s" % (reverse_url, 'sort_key', malicious_code) resp = self.client.get(url) self.assertEqual(resp.status_code, 200) - self.assertNotIn(malicious_code, resp.content) + self.assertNotIn(malicious_code, resp.content.decode('utf-8')) @ddt.data('">', '', '') @patch('student.models.cc.User.from_django_user') @@ -1579,7 +1583,7 @@ class ForumDiscussionXSSTestCase(ForumsEnableMixin, UrlResetMixin, ModuleStoreTe url_string = "%s?%s=%s" % (url, 'page', malicious_code) resp = self.client.get(url_string) self.assertEqual(resp.status_code, 200) - self.assertNotIn(malicious_code, resp.content) + self.assertNotIn(malicious_code, resp.content.decode('utf-8')) class ForumDiscussionSearchUnicodeTestCase(ForumsEnableMixin, SharedModuleStoreTestCase, UnicodeTestMixin):