Skip to content

Commit

Permalink
test: add tests for bytes content
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Oct 25, 2024
1 parent ff8f794 commit 7226354
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions tests/openedx_learning/apps/authoring/components/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7226354

Please sign in to comment.