Skip to content

Commit 9053c86

Browse files
committed
test: modified field in course block index
1 parent ae4ff4f commit 9053c86

File tree

3 files changed

+52
-34
lines changed

3 files changed

+52
-34
lines changed

openedx/core/djangoapps/content/search/tests/test_api.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,27 @@ def setUp(self):
6161
# Clear the Meilisearch client to avoid side effects from other tests
6262
api.clear_meilisearch_client()
6363

64+
modified_date = datetime(2024, 5, 6, 7, 8, 9, tzinfo=timezone.utc)
6465
# Create course
65-
self.course = self.store.create_course(
66-
"org1",
67-
"test_course",
68-
"test_run",
69-
self.user_id,
70-
fields={"display_name": "Test Course"},
71-
)
72-
course_access, _ = SearchAccess.objects.get_or_create(context_key=self.course.id)
73-
self.course_block_key = "block-v1:org1+test_course+test_run+type@course+block@course"
74-
75-
# Create XBlocks
76-
self.sequential = self.store.create_child(self.user_id, self.course.location, "sequential", "test_sequential")
66+
with freeze_time(modified_date):
67+
self.course = self.store.create_course(
68+
"org1",
69+
"test_course",
70+
"test_run",
71+
self.user_id,
72+
fields={"display_name": "Test Course"},
73+
)
74+
course_access, _ = SearchAccess.objects.get_or_create(context_key=self.course.id)
75+
self.course_block_key = "block-v1:org1+test_course+test_run+type@course+block@course"
76+
77+
# Create XBlocks
78+
self.sequential = self.store.create_child(
79+
self.user_id,
80+
self.course.location,
81+
"sequential",
82+
"test_sequential"
83+
)
84+
self.store.create_child(self.user_id, self.sequential.location, "vertical", "test_vertical")
7785
self.doc_sequential = {
7886
"id": "block-v1org1test_coursetest_runtypesequentialblocktest_sequential-f702c144",
7987
"type": "course_block",
@@ -90,8 +98,8 @@ def setUp(self):
9098
],
9199
"content": {},
92100
"access_id": course_access.id,
101+
"modified": modified_date.timestamp(),
93102
}
94-
self.store.create_child(self.user_id, self.sequential.location, "vertical", "test_vertical")
95103
self.doc_vertical = {
96104
"id": "block-v1org1test_coursetest_runtypeverticalblocktest_vertical-e76a10a4",
97105
"type": "course_block",
@@ -112,6 +120,7 @@ def setUp(self):
112120
],
113121
"content": {},
114122
"access_id": course_access.id,
123+
"modified": modified_date.timestamp(),
115124
}
116125
# Make sure the CourseOverview for the course is created:
117126
CourseOverview.get_from_id(self.course.id)
@@ -130,7 +139,6 @@ def setUp(self):
130139
self.problem1 = library_api.create_library_block(self.library.key, "problem", "p1")
131140
self.problem2 = library_api.create_library_block(self.library.key, "problem", "p2")
132141
# Update problem1, freezing the date so we can verify modified date serializes correctly.
133-
modified_date = datetime(2024, 5, 6, 7, 8, 9, tzinfo=timezone.utc)
134142
with freeze_time(modified_date):
135143
library_api.set_library_block_olx(self.problem1.usage_key, "<problem />")
136144

openedx/core/djangoapps/content/search/tests/test_documents.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,23 @@ class StudioDocumentsTest(SharedModuleStoreTestCase):
5252
def setUpClass(cls):
5353
super().setUpClass()
5454
cls.store = modulestore()
55-
cls.org = Organization.objects.create(name="edX", short_name="edX")
56-
cls.toy_course = ToyCourseFactory.create() # See xmodule/modulestore/tests/sample_courses.py
57-
cls.toy_course_key = cls.toy_course.id
58-
59-
# Get references to some blocks in the toy course
60-
cls.html_block_key = cls.toy_course_key.make_usage_key("html", "toyjumpto")
61-
# Create a problem in course
62-
cls.problem_block = BlockFactory.create(
63-
category="problem",
64-
parent_location=cls.toy_course_key.make_usage_key("vertical", "vertical_test"),
65-
display_name='Test Problem',
66-
data="<problem>What is a test?<multiplechoiceresponse></multiplechoiceresponse></problem>",
67-
)
68-
6955
# Create a library and collection with a block
70-
created_date = datetime(2023, 4, 5, 6, 7, 8, tzinfo=timezone.utc)
71-
with freeze_time(created_date):
56+
cls.created_date = datetime(2023, 4, 5, 6, 7, 8, tzinfo=timezone.utc)
57+
with freeze_time(cls.created_date):
58+
# Get references to some blocks in the toy course
59+
cls.org = Organization.objects.create(name="edX", short_name="edX")
60+
cls.toy_course = ToyCourseFactory.create() # See xmodule/modulestore/tests/sample_courses.py
61+
cls.toy_course_key = cls.toy_course.id
62+
63+
cls.html_block_key = cls.toy_course_key.make_usage_key("html", "toyjumpto")
64+
# Create a problem in course
65+
cls.problem_block = BlockFactory.create(
66+
category="problem",
67+
parent_location=cls.toy_course_key.make_usage_key("vertical", "vertical_test"),
68+
display_name='Test Problem',
69+
data="<problem>What is a test?<multiplechoiceresponse></multiplechoiceresponse></problem>",
70+
)
71+
7272
cls.library = library_api.create_library(
7373
org=cls.org,
7474
slug="2012_Fall",
@@ -190,6 +190,7 @@ def test_problem_block(self):
190190
'usage_key': 'block-v1:edX+toy+2012_Fall+type@vertical+block@vertical_test',
191191
},
192192
],
193+
"modified": self.created_date.timestamp(),
193194
"content": {
194195
"capa_content": "What is a test?",
195196
"problem_types": ["multiplechoiceresponse"],
@@ -223,6 +224,7 @@ def test_html_block(self):
223224
"display_name": "Text",
224225
"description": "This is a link to another page and some Chinese 四節比分和七年前 Some "
225226
"more Chinese 四節比分和七年前 ",
227+
"modified": self.created_date.timestamp(),
226228
"breadcrumbs": [
227229
{
228230
'display_name': 'Toy Course',
@@ -276,6 +278,7 @@ def test_video_block_untagged(self):
276278
},
277279
],
278280
"content": {},
281+
"modified": self.created_date.timestamp(),
279282
# This video has no tags.
280283
}
281284

openedx/core/djangoapps/content/search/tests/test_handlers.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def test_create_delete_xblock(self, meilisearch_client):
5959
course_access, _ = SearchAccess.objects.get_or_create(context_key=course.id)
6060

6161
# Create XBlocks
62-
sequential = self.store.create_child(self.user_id, course.location, "sequential", "test_sequential")
62+
created_date = datetime(2023, 4, 5, 6, 7, 8, tzinfo=timezone.utc)
63+
with freeze_time(created_date):
64+
sequential = self.store.create_child(self.user_id, course.location, "sequential", "test_sequential")
6365
doc_sequential = {
6466
"id": "block-v1orgatest_coursetest_runtypesequentialblocktest_sequential-0cdb9395",
6567
"type": "course_block",
@@ -76,10 +78,11 @@ def test_create_delete_xblock(self, meilisearch_client):
7678
],
7779
"content": {},
7880
"access_id": course_access.id,
79-
81+
"modified": created_date.timestamp(),
8082
}
8183
meilisearch_client.return_value.index.return_value.update_documents.assert_called_with([doc_sequential])
82-
vertical = self.store.create_child(self.user_id, sequential.location, "vertical", "test_vertical")
84+
with freeze_time(created_date):
85+
vertical = self.store.create_child(self.user_id, sequential.location, "vertical", "test_vertical")
8386
doc_vertical = {
8487
"id": "block-v1orgatest_coursetest_runtypeverticalblocktest_vertical-011f143b",
8588
"type": "course_block",
@@ -100,18 +103,22 @@ def test_create_delete_xblock(self, meilisearch_client):
100103
],
101104
"content": {},
102105
"access_id": course_access.id,
106+
"modified": created_date.timestamp(),
103107
}
104108

105109
meilisearch_client.return_value.index.return_value.update_documents.assert_called_with([doc_vertical])
106110

107111
# Update the XBlock
108112
sequential = self.store.get_item(sequential.location, self.user_id) # Refresh the XBlock
109113
sequential.display_name = "Updated Sequential"
110-
self.store.update_item(sequential, self.user_id)
114+
modified_date = datetime(2024, 5, 6, 7, 8, 9, tzinfo=timezone.utc)
115+
with freeze_time(modified_date):
116+
self.store.update_item(sequential, self.user_id)
111117

112118
# The display name and the child's breadcrumbs should be updated
113119
doc_sequential["display_name"] = "Updated Sequential"
114120
doc_vertical["breadcrumbs"][1]["display_name"] = "Updated Sequential"
121+
doc_sequential["modified"] = modified_date.timestamp()
115122
meilisearch_client.return_value.index.return_value.update_documents.assert_called_with([
116123
doc_sequential,
117124
doc_vertical,

0 commit comments

Comments
 (0)