Change completion API to work with any learning context
This commit is contained in:
@@ -44,7 +44,7 @@ class CompletionSetUpMixin(CompletionWaffleTestMixin):
|
||||
self.block_key = UsageKey.from_string(u'block-v1:edx+test+run+type@video+block@doggos')
|
||||
self.completion = models.BlockCompletion.objects.create(
|
||||
user=self.user,
|
||||
course_key=self.block_key.course_key,
|
||||
context_key=self.block_key.context_key,
|
||||
block_type=self.block_key.block_type,
|
||||
block_key=self.block_key,
|
||||
completion=0.5,
|
||||
@@ -67,7 +67,6 @@ class SubmitCompletionTestCase(CompletionSetUpMixin, TestCase):
|
||||
# OTHER = user exists, completion exists
|
||||
completion, isnew = models.BlockCompletion.objects.submit_completion(
|
||||
user=self.user,
|
||||
course_key=self.block_key.course_key,
|
||||
block_key=self.block_key,
|
||||
completion=0.9,
|
||||
)
|
||||
@@ -80,7 +79,6 @@ class SubmitCompletionTestCase(CompletionSetUpMixin, TestCase):
|
||||
with self.assertNumQueries(SELECT + 2 * SAVEPOINT):
|
||||
completion, isnew = models.BlockCompletion.objects.submit_completion(
|
||||
user=self.user,
|
||||
course_key=self.block_key.course_key,
|
||||
block_key=self.block_key,
|
||||
completion=0.5,
|
||||
)
|
||||
@@ -94,7 +92,6 @@ class SubmitCompletionTestCase(CompletionSetUpMixin, TestCase):
|
||||
with self.assertNumQueries(SELECT + UPDATE + 4 * SAVEPOINT):
|
||||
_, isnew = models.BlockCompletion.objects.submit_completion(
|
||||
user=newuser,
|
||||
course_key=self.block_key.course_key,
|
||||
block_key=self.block_key,
|
||||
completion=0.0,
|
||||
)
|
||||
@@ -106,7 +103,6 @@ class SubmitCompletionTestCase(CompletionSetUpMixin, TestCase):
|
||||
with self.assertNumQueries(SELECT + UPDATE + 4 * SAVEPOINT):
|
||||
_, isnew = models.BlockCompletion.objects.submit_completion(
|
||||
user=self.user,
|
||||
course_key=newblock.course_key,
|
||||
block_key=newblock,
|
||||
completion=1.0,
|
||||
)
|
||||
@@ -117,7 +113,6 @@ class SubmitCompletionTestCase(CompletionSetUpMixin, TestCase):
|
||||
with self.assertRaises(ValidationError):
|
||||
models.BlockCompletion.objects.submit_completion(
|
||||
user=self.user,
|
||||
course_key=self.block_key.course_key,
|
||||
block_key=self.block_key,
|
||||
completion=1.2
|
||||
)
|
||||
@@ -143,7 +138,6 @@ class CompletionDisabledTestCase(CompletionSetUpMixin, TestCase):
|
||||
with self.assertRaises(RuntimeError):
|
||||
models.BlockCompletion.objects.submit_completion(
|
||||
user=self.user,
|
||||
course_key=self.block_key.course_key,
|
||||
block_key=self.block_key,
|
||||
completion=0.9,
|
||||
)
|
||||
@@ -167,7 +161,7 @@ class SubmitBatchCompletionTestCase(CompletionWaffleTestMixin, TestCase):
|
||||
|
||||
def test_submit_batch_completion(self):
|
||||
blocks = [(self.block_key, 1.0)]
|
||||
models.BlockCompletion.objects.submit_batch_completion(self.user, self.course_key_obj, blocks)
|
||||
models.BlockCompletion.objects.submit_batch_completion(self.user, blocks)
|
||||
self.assertEqual(models.BlockCompletion.objects.count(), 1)
|
||||
self.assertEqual(models.BlockCompletion.objects.last().completion, 1.0)
|
||||
|
||||
@@ -175,19 +169,19 @@ class SubmitBatchCompletionTestCase(CompletionWaffleTestMixin, TestCase):
|
||||
with waffle.waffle().override(waffle.ENABLE_COMPLETION_TRACKING, False):
|
||||
with self.assertRaises(RuntimeError):
|
||||
blocks = [(self.block_key, 1.0)]
|
||||
models.BlockCompletion.objects.submit_batch_completion(self.user, self.course_key_obj, blocks)
|
||||
models.BlockCompletion.objects.submit_batch_completion(self.user, blocks)
|
||||
|
||||
def test_submit_batch_completion_with_same_block_new_completion_value(self):
|
||||
blocks = [(self.block_key, 0.0)]
|
||||
self.assertEqual(models.BlockCompletion.objects.count(), 0)
|
||||
models.BlockCompletion.objects.submit_batch_completion(self.user, self.course_key_obj, blocks)
|
||||
models.BlockCompletion.objects.submit_batch_completion(self.user, blocks)
|
||||
self.assertEqual(models.BlockCompletion.objects.count(), 1)
|
||||
model = models.BlockCompletion.objects.first()
|
||||
self.assertEqual(model.completion, 0.0)
|
||||
blocks = [
|
||||
(UsageKey.from_string('block-v1:edx+test+run+type@video+block@doggos'), 1.0),
|
||||
]
|
||||
models.BlockCompletion.objects.submit_batch_completion(self.user, self.course_key_obj, blocks)
|
||||
models.BlockCompletion.objects.submit_batch_completion(self.user, blocks)
|
||||
self.assertEqual(models.BlockCompletion.objects.count(), 1)
|
||||
model = models.BlockCompletion.objects.first()
|
||||
self.assertEqual(model.completion, 1.0)
|
||||
@@ -207,20 +201,25 @@ class BatchCompletionMethodTests(CompletionWaffleTestMixin, TestCase):
|
||||
self.course_key = CourseKey.from_string("edX/MOOC101/2049_T2")
|
||||
self.other_course_key = CourseKey.from_string("course-v1:ReedX+Hum110+1904")
|
||||
self.block_keys = [UsageKey.from_string("i4x://edX/MOOC101/video/{}".format(number)) for number in range(5)]
|
||||
self.block_keys_with_runs = [key.replace(course_key=self.course_key) for key in self.block_keys]
|
||||
self.other_course_block_keys = [self.other_course_key.make_usage_key('html', '1')]
|
||||
|
||||
submit_completions_for_testing(self.user, self.course_key, self.block_keys[:3])
|
||||
submit_completions_for_testing(self.other_user, self.course_key, self.block_keys[2:])
|
||||
submit_completions_for_testing(self.user, self.other_course_key, [self.block_keys[4]])
|
||||
# Submit completions for the main course:
|
||||
submit_completions_for_testing(self.user, self.block_keys_with_runs[:3])
|
||||
# Different user:
|
||||
submit_completions_for_testing(self.other_user, self.block_keys_with_runs[2:])
|
||||
# Different course:
|
||||
submit_completions_for_testing(self.user, self.other_course_block_keys)
|
||||
|
||||
def test_get_course_completions_missing_runs(self):
|
||||
actual_completions = models.BlockCompletion.get_course_completions(self.user, self.course_key)
|
||||
expected_block_keys = [key.replace(course_key=self.course_key) for key in self.block_keys[:3]]
|
||||
def test_get_learning_context_completions_missing_runs(self):
|
||||
actual_completions = models.BlockCompletion.get_learning_context_completions(self.user, self.course_key)
|
||||
expected_block_keys = self.block_keys_with_runs[:3]
|
||||
expected_completions = dict(list(zip(expected_block_keys, [1.0, 0.8, 0.6])))
|
||||
self.assertEqual(expected_completions, actual_completions)
|
||||
|
||||
def test_get_course_completions_empty_result_set(self):
|
||||
def test_get_learning_context_completions_empty_result_set(self):
|
||||
self.assertEqual(
|
||||
models.BlockCompletion.get_course_completions(self.other_user, self.other_course_key),
|
||||
models.BlockCompletion.get_learning_context_completions(self.other_user, self.other_course_key),
|
||||
{}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user