Skip to content

Commit

Permalink
tests: test LearningPackage modification
Browse files Browse the repository at this point in the history
  • Loading branch information
ormsbee committed Jan 29, 2024
1 parent 9f57f60 commit f62f8c5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion openedx_learning/core/components/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def get_component_by_key(
local_key: str,
) -> Component:
"""
Get Componet by it unique namespace/type/local_key tuple.
Get a Component by its unique (namespace, type, local_key) tuple.
"""
return (
Component
Expand Down
5 changes: 5 additions & 0 deletions openedx_learning/core/publishing/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,11 @@ def get_draft_version(publishable_entity_id: int) -> PublishableEntityVersion |


def get_published_version(publishable_entity_id: int) -> PublishableEntityVersion | None:
"""
Return current published PublishableEntityVersion for this PublishableEntity.
This function will return None if there is no current published version.
"""
try:
published = Published.objects.select_related("version").get(
entity_id=publishable_entity_id
Expand Down
16 changes: 15 additions & 1 deletion tests/openedx_learning/core/publishing/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from openedx_learning.lib.test_utils import TestCase


class CreateLearningPackageTestCase(TestCase):
class LearningPackageTestCase(TestCase):
"""
Test creating a LearningPackage
"""
Expand All @@ -35,6 +35,7 @@ def test_normal(self) -> None: # Note: we must specify '-> None' to opt in to t

assert package.key == "my_key"
assert package.title == "My Excellent Title with Emoji 🔥"
assert package.description == "A fun Description!"
assert package.created == created
assert package.updated == created

Expand All @@ -44,6 +45,19 @@ def test_normal(self) -> None: # Note: we must specify '-> None' to opt in to t
# Having an actual value here means we were persisted to the database.
assert isinstance(package.id, int)

# Now test editing the fields.
updated_package = publishing_api.update_learning_package(
package.id,
key="new_key",
title="new title",
description="new description",
)
assert updated_package.key == "new_key"
assert updated_package.title == "new title"
assert updated_package.description == "new description"
assert updated_package.created == created
assert updated_package.updated != created # new time would be auto-generated

def test_auto_datetime(self) -> None:
"""
Auto-generated created datetime works as expected.
Expand Down

0 comments on commit f62f8c5

Please sign in to comment.