Implement 'from_string_or_404' util and its example usage.

This commit is contained in:
Muhammad Rehan
2015-11-23 17:49:33 +05:00
committed by Qubad786
parent 7eb079df3e
commit 771a7d06ca
3 changed files with 64 additions and 4 deletions

View File

@@ -0,0 +1,32 @@
"""
Tests for util.course_key_utils
"""
from nose.tools import assert_equals, assert_raises # pylint: disable=no-name-in-module
from util.course_key_utils import from_string_or_404
from opaque_keys.edx.keys import CourseKey
from django.http import Http404
def test_from_string_or_404():
#testing with split style course keys
assert_raises(
Http404,
from_string_or_404,
"/some.invalid.key/course-v1:TTT+CS01+2015_T0"
)
assert_equals(
CourseKey.from_string("course-v1:TTT+CS01+2015_T0"),
from_string_or_404("course-v1:TTT+CS01+2015_T0")
)
#testing with mongo style course keys
assert_raises(
Http404,
from_string_or_404,
"/some.invalid.key/TTT/CS01/2015_T0"
)
assert_equals(
CourseKey.from_string("TTT/CS01/2015_T0"),
from_string_or_404("TTT/CS01/2015_T0")
)