Skip to content

Commit 1b9697a

Browse files
test: add concrete TestContainer model
1 parent 5d781a6 commit 1b9697a

6 files changed

Lines changed: 68 additions & 0 deletions

File tree

src/openedx_content/applets/publishing/models/container.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class Container(PublishableEntityMixin):
5454
we will also add support for dynamic containers which may contain different
5555
entities for different learners or at different times.
5656
"""
57+
5758
CONTAINER_TYPE: str = "" # Subclasses need to override this.
5859

5960
# The type of the container. Cannot be changed once the container is created.

test_settings.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def root(*args):
5959
"openedx_content",
6060
"openedx_catalog",
6161
*openedx_content_backcompat_apps_to_install(),
62+
# Apps with models that are only used for testing
63+
"tests.test_django_app",
6264
]
6365

6466
AUTHENTICATION_BACKENDS = [
@@ -97,3 +99,27 @@ def root(*args):
9799
}
98100

99101
STATIC_URL = 'static/'
102+
103+
# Required for Django admin which is required because it's referenced by projects.urls (ROOT_URLCONF)
104+
TEMPLATES = [
105+
{
106+
'NAME': 'django',
107+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
108+
# Don't look for template source files inside installed applications.
109+
# 'APP_DIRS': False,
110+
# Instead, look for template source files in these dirs.
111+
# 'DIRS': [],
112+
'OPTIONS': {
113+
'context_processors': [
114+
'django.template.context_processors.request',
115+
'django.contrib.messages.context_processors.messages',
116+
'django.contrib.auth.context_processors.auth',
117+
],
118+
}
119+
},
120+
]
121+
MIDDLEWARE = [
122+
"django.contrib.sessions.middleware.SessionMiddleware",
123+
"django.contrib.auth.middleware.AuthenticationMiddleware",
124+
"django.contrib.messages.middleware.MessageMiddleware",
125+
]

tests/openedx_content/applets/publishing/test_api.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@
2727
User = get_user_model()
2828

2929

30+
class TestContainer(Container):
31+
"""
32+
A fake subclass of Container used for test purposes.
33+
"""
34+
CONTAINER_TYPE = "fake_test"
35+
36+
class Meta:
37+
app_label = "openedx_content"
38+
39+
3040
class LearningPackageTestCase(TestCase):
3141
"""
3242
Test creating a LearningPackage
@@ -1068,6 +1078,7 @@ def test_bulk_parent_child_side_effects(self) -> None:
10681078
"my_container",
10691079
created=self.now,
10701080
created_by=None,
1081+
container_cls=TestContainer,
10711082
)
10721083
container_v1: ContainerVersion = publishing_api.create_container_version(
10731084
container.pk,

tests/test_django_app/__init__.py

Whitespace-only changes.

tests/test_django_app/apps.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
Test Django app config
3+
"""
4+
5+
from django.apps import AppConfig
6+
7+
8+
class TestAppConfig(AppConfig):
9+
"""
10+
Configuration for the test Django application.
11+
"""
12+
13+
name = "tests.test_django_app"
14+
label = "test_django_app"

tests/test_django_app/models.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
Models that are only for use in tests
3+
"""
4+
5+
from openedx_content.applets.publishing.models import Container
6+
7+
8+
class TestContainer(Container):
9+
"""
10+
A fake subclass of Container used for test purposes.
11+
"""
12+
13+
CONTAINER_TYPE = "fake_test"
14+
15+
class Meta:
16+
app_label = "openedx_content"

0 commit comments

Comments
 (0)