Skip to content

Commit

Permalink
change naming formate from aggregate course key to course key v2
Browse files Browse the repository at this point in the history
  • Loading branch information
zubair-arbi committed Mar 9, 2017
1 parent 12086b5 commit b1b4a1b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
6 changes: 3 additions & 3 deletions opaque_keys/edx/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@ def block_type(self): # pragma: no cover
raise NotImplementedError()


class AggregateCourseKey(OpaqueKey):
class CourseKeyV2(OpaqueKey):
"""
An :class:`opaque_keys.OpaqueKey` identifying a
serialized Course Key object.
"""
KEY_TYPE = 'aggregate_course_key'
KEY_TYPE = 'course_key_v2'
__slots__ = ()

@abstractproperty
def from_course_key(self, course_key): # pragma: no cover
"""
Get aggregate course key from the course run key.
Get course key v2 from the course run key.
Arguments:
course_key (:class:`CourseKey`): The course identifier.
Expand Down
14 changes: 7 additions & 7 deletions opaque_keys/edx/locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from six import string_types, text_type
from opaque_keys import OpaqueKey, InvalidKeyError
from opaque_keys.edx.keys import CourseKey, UsageKey, DefinitionKey, AssetKey, AggregateCourseKey
from opaque_keys.edx.keys import CourseKey, UsageKey, DefinitionKey, AssetKey, CourseKeyV2

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -1332,9 +1332,9 @@ def to_deprecated_list_repr(self):
AssetKey.set_deprecated_fallback(AssetLocator)


class AggregateCourseLocator(AggregateCourseKey): # pylint: disable=abstract-method
class CourseLocatorV2(CourseKeyV2): # pylint: disable=abstract-method
"""
An AggregateCourseKey implementation class.
An CourseKeyV2 implementation class.
"""
CANONICAL_NAMESPACE = 'course-v2'
KEY_FIELDS = ('org', 'course')
Expand All @@ -1348,22 +1348,22 @@ class AggregateCourseLocator(AggregateCourseKey): # pylint: disable=abstract-

def __init__(self, org=None, course=None, **kwargs):
"""
Construct a AggregateCourseLocator.
Construct a CourseLocatorV2.
Arguments:
org (string): Organization identifier for the course
course (string): Course number
"""
super(AggregateCourseLocator, self).__init__(org=org, course=course, **kwargs)
super(CourseLocatorV2, self).__init__(org=org, course=course, **kwargs)

if not (self.org and self.course):
raise InvalidKeyError(self.__class__, 'Both org and course must be set.')

@classmethod
def from_course_key(cls, course_key):
"""
Get aggregate course key from the course run key object.
Get course key v2 from the course run key object.
Arguments:
course_key (:class:`CourseKey`): The course identifier.
Expand All @@ -1374,7 +1374,7 @@ def from_course_key(cls, course_key):
@classmethod
def _from_string(cls, serialized):
"""
Return a AggregateCourseLocator parsing the given serialized string.
Return a CourseLocatorV2 parsing the given serialized string.
Arguments:
serialized: string for matching
Expand Down
44 changes: 22 additions & 22 deletions opaque_keys/edx/tests/test_locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from bson.objectid import ObjectId

from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import DefinitionKey, CourseKey, AggregateCourseKey
from opaque_keys.edx.locator import Locator, CourseLocator, DefinitionLocator, VersionTree, AggregateCourseLocator
from opaque_keys.edx.keys import DefinitionKey, CourseKey, CourseKeyV2
from opaque_keys.edx.locator import Locator, CourseLocator, DefinitionLocator, VersionTree, CourseLocatorV2


class LocatorTests(TestCase):
Expand Down Expand Up @@ -64,45 +64,45 @@ def test_version_tree(self):


@ddt.ddt
class AggregateCourseLocatorTests(TestCase):
class CourseLocatorV2Tests(TestCase):
"""
Tests for :class:`.AggregateCourseLocator`
Tests for :class:`.CourseLocatorV2`
"""

def test_aggregate_course_locator(self):
def test_course_locator_v2(self):
"""
Verify that the method "from_string" of class "AggregateCourseKey"
returns an object of "AggregateCourseLocator" for a valid course key.
Verify that the method "from_string" of class "CourseKeyV2"
returns an object of "CourseLocatorV2" for a valid course key.
"""
aggregate_course_key = 'course-v2:org+course'
aggregate_course_locator = AggregateCourseKey.from_string(aggregate_course_key)
expected_course_locator = AggregateCourseLocator(org='org', course='course')
self.assertEqual(expected_course_locator, aggregate_course_locator)
course_key_v2 = 'course-v2:org+course'
course_locator_v2 = CourseKeyV2.from_string(course_key_v2)
expected_course_locator = CourseLocatorV2(org='org', course='course')
self.assertEqual(expected_course_locator, course_locator_v2)

@ddt.data(
'org/course/run',
'course-v1:org+course+run',
)
def test_aggregate_course_locator_from_course_key(self, course_id):
def test_course_locator_v2_from_course_key(self, course_id):
"""
Verify that the method "from_course_key" of class "AggregateCourseLocator"
coverts a valid course run key to an aggregate course key.
Verify that the method "from_course_key" of class "CourseLocatorV2"
coverts a valid course run key to a course key v2.
"""
course_key = CourseKey.from_string(course_id)
expected_course_key = AggregateCourseLocator(org=course_key.org, course=course_key.course)
actual_course_key = AggregateCourseLocator.from_course_key(course_key)
expected_course_key = CourseLocatorV2(org=course_key.org, course=course_key.course)
actual_course_key = CourseLocatorV2.from_course_key(course_key)
self.assertEqual(expected_course_key, actual_course_key)

def test_serialize_to_string(self):
"""
Verify that the method "from_course_key" of class "AggregateCourseLocator"
coverts a valid course run key to an aggregate course key.
Verify that the method "_to_string" of class "CourseLocatorV2"
serializes a course key v2 to a string with expected format.
"""
course_key = CourseKey.from_string('course-v1:org+course+run')
aggregate_course_locator = AggregateCourseLocator(org=course_key.org, course=course_key.course)
course_locator_v2 = CourseLocatorV2(org=course_key.org, course=course_key.course)
expected_serialized_key = '{org}+{course}'.format(org=course_key.org, course=course_key.course)
# pylint: disable=protected-access
self.assertEqual(expected_serialized_key, aggregate_course_locator._to_string())
self.assertEqual(expected_serialized_key, course_locator_v2._to_string())

@ddt.data(
'org/course/run',
Expand All @@ -112,8 +112,8 @@ def test_serialize_to_string(self):
)
def test_invalid_format_course_key(self, course_key):
"""
Verify that the method "from_string" of class "AggregateCourseKey"
Verify that the method "from_string" of class "CourseKeyV2"
raises exception "InvalidKeyError" for unsupported key formats.
"""
with self.assertRaises(InvalidKeyError):
AggregateCourseKey.from_string(course_key)
CourseKeyV2.from_string(course_key)
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
# don't use slashes in any new code
'slashes = opaque_keys.edx.locator:CourseLocator',
],
'aggregate_course_key': [
'course-v2 = opaque_keys.edx.locator:AggregateCourseLocator',
'course_key_v2': [
'course-v2 = opaque_keys.edx.locator:CourseLocatorV2',
],
'usage_key': [
'block-v1 = opaque_keys.edx.locator:BlockUsageLocator',
Expand Down

0 comments on commit b1b4a1b

Please sign in to comment.