diff --git a/tests/openedx_learning/apps/authoring/components/test_api.py b/tests/openedx_learning/apps/authoring/components/test_api.py index 7a9537b1..78ee79f8 100644 --- a/tests/openedx_learning/apps/authoring/components/test_api.py +++ b/tests/openedx_learning/apps/authoring/components/test_api.py @@ -415,6 +415,31 @@ def test_add(self): new_version.contents.get(componentversioncontent__key="nested/path/hello.txt") ) + def test_bytes_content(self): + bytes_content = b'raw content' + + version_1 = components_api.create_next_component_version( + self.problem.pk, + title="Problem Version 1", + content_to_replace={ + "raw.txt": bytes_content, + "no_ext": bytes_content, + }, + created=self.now, + ) + + content_txt = version_1.contents.get(componentversioncontent__key="raw.txt") + content_raw_txt = version_1.contents.get(componentversioncontent__key="no_ext") + + assert content_txt.size == len(bytes_content) + assert str(content_txt.media_type) == 'text/plain' + assert content_txt.read_file().read() == bytes_content + + assert content_raw_txt.size == len(bytes_content) + assert str(content_raw_txt.media_type) == 'application/octet-stream' + assert content_raw_txt.read_file().read() == bytes_content + + def test_multiple_versions(self): hello_content = contents_api.get_or_create_text_content( self.learning_package.id, @@ -442,14 +467,13 @@ def test_multiple_versions(self): content_to_replace={ "hello.txt": hello_content.pk, "goodbye.txt": goodbye_content.pk, - "raw.txt": b'raw content', }, created=self.now, ) assert version_1.version_num == 1 assert version_1.title == "Problem Version 1" version_1_contents = list(version_1.contents.all()) - assert len(version_1_contents) == 3 + assert len(version_1_contents) == 2 assert ( hello_content == version_1.contents @@ -473,7 +497,7 @@ def test_multiple_versions(self): created=self.now, ) assert version_2.version_num == 2 - assert version_2.contents.count() == 4 + assert version_2.contents.count() == 3 assert ( blank_content == version_2.contents @@ -504,7 +528,7 @@ def test_multiple_versions(self): created=self.now, ) assert version_3.version_num == 3 - assert version_3.contents.count() == 2 + assert version_3.contents.count() == 1 assert ( hello_content == version_3.contents