-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛(edx_imports) add utils to extract course_id from resource_link
OpenEdX resource link can have several shape, we add an util to manage all cases properly.
- Loading branch information
Showing
3 changed files
with
43 additions
and
7 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
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,28 @@ | ||
"""Test case for utils""" | ||
|
||
from django.test import TestCase | ||
|
||
from joanie.edx_imports.utils import extract_course_id | ||
|
||
|
||
class UtilsTestCase(TestCase): | ||
"""Test case for utils""" | ||
|
||
def test_utils_extract_course_id_no_match(self): | ||
"""If nothing match, None should be returned""" | ||
self.assertIsNone(extract_course_id("https://openedx.com")) | ||
|
||
def test_utils_extract_course_id_matches(self): | ||
"""It should support all kind of OpenEdX resource link.""" | ||
resource_links = [ | ||
("https://openedx.com/courses/%s/course", "course-v1:fun+101+run01"), | ||
("https://openedx.com/courses/%s/info", "course-v1:fun+101+run01"), | ||
("https://openedx.com/courses/%s/course/", "course-v1:fun+101+run01"), | ||
("https://openedx.com/courses/%s/info/", "course-v1:fun+101+run01"), | ||
("https://openedx.com/courses/%s/course/", "fun/101/run01"), | ||
("https://openedx.com/courses/%s/info/", "fun/101/run01"), | ||
] | ||
|
||
for url, course_id in resource_links: | ||
resource_link = url % course_id | ||
self.assertEqual(extract_course_id(resource_link), course_id) |