-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from edx/resume-button-completion-side
EDUCATOR 2190: completion-side resume button work
- Loading branch information
Showing
9 changed files
with
137 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
Alex Dusenbery <[email protected]> | ||
Simon Chen <[email protected]> | ||
Gregory Martin <[email protected]> | ||
Alessandro Roux <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
''' | ||
This file contains custom exceptions used by the completion repository. | ||
''' | ||
from __future__ import unicode_literals, absolute_import | ||
|
||
|
||
class UnavailableCompletionData(Exception): | ||
''' | ||
UnavailableCompletionData should be raised when a method is unable to gather | ||
completion data from BlockCompletion. | ||
''' | ||
|
||
def __init__(self, course_key): | ||
Exception.__init__( | ||
self, "The learner does not have completion data within course {}".format(course_key)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
''' | ||
The unit tests for utilities.py. | ||
''' | ||
from __future__ import unicode_literals | ||
from mock import patch | ||
|
||
from django.test import TestCase | ||
from opaque_keys.edx.keys import CourseKey | ||
from six import text_type | ||
|
||
from ..exceptions import UnavailableCompletionData | ||
from ..utilities import get_key_to_last_completed_course_block | ||
from ..test_utils import UserFactory, CompletionSetUpMixin, submit_completions_for_testing | ||
|
||
|
||
class TestCompletionUtilities(CompletionSetUpMixin, TestCase): | ||
''' | ||
Tests methods in completion's external-facing API. | ||
''' | ||
|
||
COMPLETION_SWITCH_ENABLED = True | ||
|
||
def setUp(self): | ||
super(TestCompletionUtilities, self).setUp() | ||
self.user = UserFactory.create() | ||
self.course_key = CourseKey.from_string("course-v1:edX+MOOC101+2049_T2") | ||
self.block_keys = [ | ||
self.course_key.make_usage_key('video', text_type(number)) | ||
for number in range(5) | ||
] | ||
submit_completions_for_testing(self.user, self.course_key, self.block_keys) | ||
|
||
def test_can_get_key_to_last_completed_course_block(self): | ||
with patch('completion.utilities.visual_progress_enabled', return_value=True): | ||
last_block_key = get_key_to_last_completed_course_block( | ||
self.user, | ||
self.course_key | ||
) | ||
|
||
expected_block_usage_key = self.course_key.make_usage_key( | ||
"video", | ||
text_type(4) | ||
) | ||
self.assertEqual(last_block_key, expected_block_usage_key) | ||
|
||
def test_getting_last_completed_course_block_in_untouched_enrollment_throws(self): | ||
course_key = CourseKey.from_string("edX/NotACourse/2049_T2") | ||
|
||
with patch('completion.utilities.visual_progress_enabled', return_value=True): | ||
with self.assertRaises(UnavailableCompletionData): | ||
get_key_to_last_completed_course_block(self.user, course_key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
''' | ||
File is the public API for BlockCompletion. It is the interface that prevents | ||
external users from depending on the BlockCompletion model. Methods working with | ||
the BlockCompletion model should be included here. | ||
''' | ||
from __future__ import unicode_literals, absolute_import | ||
|
||
from .exceptions import UnavailableCompletionData | ||
from .models import BlockCompletion | ||
from .waffle import visual_progress_enabled | ||
|
||
|
||
def get_key_to_last_completed_course_block(user, course_key): | ||
''' | ||
Returns the last block a "user" completed in a course (stated as "course_key"). | ||
raises UnavailableCompletionData when the user has not completed blocks in | ||
the course. | ||
raises UnavailableCompletionData when the visual progress waffle flag is | ||
disabled. | ||
''' | ||
if not visual_progress_enabled(course_key): | ||
raise UnavailableCompletionData(course_key) | ||
|
||
last_completed_block = BlockCompletion.get_latest_block_completed(user, course_key) | ||
|
||
if last_completed_block is not None: | ||
return last_completed_block.block_key | ||
|
||
raise UnavailableCompletionData(course_key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters