BOM-489 Studio tests with byte/str mismatch.

This commit is contained in:
Feanil Patel
2019-09-18 12:18:14 -04:00
parent 8f6286a1a2
commit cb64fed1af
5 changed files with 12 additions and 11 deletions

View File

@@ -69,7 +69,7 @@ class TestExportGit(CourseTestCase):
self.assertIn(
('giturl must be defined in your '
'course settings before you can export to git.'),
response.content
response.content.decode('utf-8')
)
response = self.client.get('{}?action=push'.format(self.test_url))
@@ -77,7 +77,7 @@ class TestExportGit(CourseTestCase):
self.assertIn(
('giturl must be defined in your '
'course settings before you can export to git.'),
response.content
response.content.decode('utf-8')
)
def test_course_export_failures(self):
@@ -88,7 +88,7 @@ class TestExportGit(CourseTestCase):
modulestore().update_item(self.course_module, self.user.id)
response = self.client.get('{}?action=push'.format(self.test_url))
self.assertIn('Export Failed:', response.content)
self.assertIn('Export Failed:', response.content.decode('utf-8'))
def test_exception_translation(self):
"""
@@ -98,7 +98,7 @@ class TestExportGit(CourseTestCase):
modulestore().update_item(self.course_module, self.user.id)
response = self.client.get('{}?action=push'.format(self.test_url))
self.assertNotIn('django.utils.functional.__proxy__', response.content)
self.assertNotIn('django.utils.functional.__proxy__', response.content.decode('utf-8'))
def test_course_export_success(self):
"""
@@ -107,7 +107,7 @@ class TestExportGit(CourseTestCase):
self.make_bare_repo_with_course('test_repo')
response = self.client.get('{}?action=push'.format(self.test_url))
self.assertIn('Export Succeeded', response.content)
self.assertIn('Export Succeeded', response.content.decode('utf-8'))
def test_repo_with_dots(self):
"""
@@ -115,7 +115,7 @@ class TestExportGit(CourseTestCase):
"""
self.make_bare_repo_with_course('test.repo')
response = self.client.get('{}?action=push'.format(self.test_url))
self.assertIn('Export Succeeded', response.content)
self.assertIn('Export Succeeded', response.content.decode('utf-8'))
def test_dirty_repo(self):
"""

View File

@@ -873,7 +873,7 @@ class TestGetTranscript(SharedModuleStoreTestCase):
Verify that `get_transcript` function returns correct data when transcript is in content store.
"""
base_filename = 'video_101.srt'
self.upload_file(self.create_srt_file(self.subs_srt), self.video.location, base_filename)
self.upload_file(self.create_srt_file(self.subs_srt.encode('utf-8')), self.video.location, base_filename)
self.create_transcript(subs_id, language, base_filename, youtube_id_1_0, html5_sources)
content, file_name, mimetype = transcripts_utils.get_transcript(
self.video,
@@ -935,7 +935,7 @@ class TestGetTranscript(SharedModuleStoreTestCase):
"""
Verify that `get_transcript` function returns correct exception when transcript content is empty.
"""
self.upload_file(self.create_srt_file(''), self.video.location, 'ur_video_101.srt')
self.upload_file(self.create_srt_file(b''), self.video.location, 'ur_video_101.srt')
self.create_transcript('', 'ur', 'ur_video_101.srt')
with self.assertRaises(NotFoundError) as no_content_exception:

View File

@@ -289,7 +289,7 @@ class TestAnnouncementsViews(MaintenanceViewTestCase):
"""
url = reverse("maintenance:announcement_index")
response = self.client.get(url)
self.assertIn('<div class="announcement-container">', response.content)
self.assertIn('<div class="announcement-container">', response.content.decode('utf-8'))
def test_create(self):
"""
@@ -308,7 +308,7 @@ class TestAnnouncementsViews(MaintenanceViewTestCase):
announcement.save()
url = reverse("maintenance:announcement_edit", kwargs={"pk": announcement.pk})
response = self.client.get(url)
self.assertIn('<div class="wrapper-form announcement-container">', response.content)
self.assertIn('<div class="wrapper-form announcement-container">', response.content.decode('utf-8'))
self.client.post(url, {"content": "Test Edit Announcement", "active": True})
announcement = Announcement.objects.get(pk=announcement.pk)
self.assertEquals(announcement.content, "Test Edit Announcement")

View File

@@ -99,6 +99,7 @@ class MongoContentStore(ContentStore):
import_path=content.import_path,
# getattr b/c caching may mean some pickled instances don't have attr
locked=getattr(content, 'locked', False)) as fp:
# It seems that this code thought that only some specific object would have the `__iter__` attribute
# but the bytes object in python 3 has one and should not use the chunking logic.
if hasattr(content.data, '__iter__') and not isinstance(content.data, six.binary_type):

View File

@@ -126,7 +126,7 @@ def save_subs_to_store(subs, subs_id, item, language='en'):
Returns: location of saved subtitles.
"""
filedata = json.dumps(subs, indent=2)
filedata = json.dumps(subs, indent=2).encode('utf-8')
filename = subs_filename(subs_id, language)
return save_to_store(filedata, filename, 'application/json', item.location)