Commit 055ca30c by Saqib

Merge pull request #655 from edx-solutions/msaqib52/YONK-279

Update static page detail api to fetch by name
parents 5fb7932b 0e5639e4
...@@ -211,6 +211,8 @@ class ItemFactory(XModuleFactory): ...@@ -211,6 +211,8 @@ class ItemFactory(XModuleFactory):
:data: (optional): the data for the item :data: (optional): the data for the item
(e.g. XML problem definition for a problem item) (e.g. XML problem definition for a problem item)
:name: (optional): the name of the item
:display_name: (optional): the display name of the item :display_name: (optional): the display name of the item
:metadata: (optional): dictionary of metadata attributes :metadata: (optional): dictionary of metadata attributes
...@@ -284,8 +286,9 @@ class ItemFactory(XModuleFactory): ...@@ -284,8 +286,9 @@ class ItemFactory(XModuleFactory):
) )
course = store.get_course(location.course_key) course = store.get_course(location.course_key)
name = kwargs.pop('name', 'Static Tab')
course.tabs.append( course.tabs.append(
CourseTab.load('static_tab', name='Static Tab', url_slug=location.name) CourseTab.load('static_tab', name=name, url_slug=location.name)
) )
store.update_item(course, user_id) store.update_item(course, user_id)
......
...@@ -197,7 +197,8 @@ class CoursesApiTests(ModuleStoreTestCase): ...@@ -197,7 +197,8 @@ class CoursesApiTests(ModuleStoreTestCase):
category="static_tab", category="static_tab",
parent_location=self.course.location, parent_location=self.course.location,
data=TEST_STATIC_TAB1_CONTENT, data=TEST_STATIC_TAB1_CONTENT,
display_name="syllabus" display_name="syllabus",
name="Static+Tab"
) )
self.static_tab2 = ItemFactory.create( self.static_tab2 = ItemFactory.create(
...@@ -882,13 +883,15 @@ class CoursesApiTests(ModuleStoreTestCase): ...@@ -882,13 +883,15 @@ class CoursesApiTests(ModuleStoreTestCase):
response = self.do_get(test_uri) response = self.do_get(test_uri)
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
def test_static_tab_detail_get(self): def test_static_tab_detail_get_by_name(self):
test_uri = self.base_courses_uri + '/' + self.test_course_id + '/static_tabs/syllabus' # get course static tab by tab name
test_uri = self.base_courses_uri + '/' + self.test_course_id + '/static_tabs/Static+Tab'
response = self.do_get(test_uri) response = self.do_get(test_uri)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertGreater(len(response.data), 0) self.assertGreater(len(response.data), 0)
tab = response.data tab = response.data
self.assertEqual(tab['id'], u'syllabus') self.assertEqual(tab['id'], u'syllabus')
self.assertEqual(tab['name'], u'Static+Tab')
self.assertEqual(tab['content'], self.static_tab1.data) self.assertEqual(tab['content'], self.static_tab1.data)
# now try to get syllabus tab contents from cache # now try to get syllabus tab contents from cache
...@@ -900,6 +903,8 @@ class CoursesApiTests(ModuleStoreTestCase): ...@@ -900,6 +903,8 @@ class CoursesApiTests(ModuleStoreTestCase):
self.assertTrue(tab_contents is not None) self.assertTrue(tab_contents is not None)
self.assertEqual(tab_contents, self.static_tab1.data) self.assertEqual(tab_contents, self.static_tab1.data)
def test_static_tab_detail_get_by_url_slug(self):
# get course static tab by url_slug
test_uri = self.base_courses_uri + '/' + self.test_course_id + '/static_tabs/readings' test_uri = self.base_courses_uri + '/' + self.test_course_id + '/static_tabs/readings'
response = self.do_get(test_uri) response = self.do_get(test_uri)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
......
...@@ -23,7 +23,10 @@ urlpatterns = patterns( ...@@ -23,7 +23,10 @@ urlpatterns = patterns(
url(r'^{0}/groups/(?P<group_id>[0-9]+)$'.format(COURSE_ID_PATTERN), courses_views.CoursesGroupsDetail.as_view()), url(r'^{0}/groups/(?P<group_id>[0-9]+)$'.format(COURSE_ID_PATTERN), courses_views.CoursesGroupsDetail.as_view()),
url(r'^{0}/groups/*$'.format(COURSE_ID_PATTERN), courses_views.CoursesGroupsList.as_view()), url(r'^{0}/groups/*$'.format(COURSE_ID_PATTERN), courses_views.CoursesGroupsList.as_view()),
url(r'^{0}/overview/*$'.format(COURSE_ID_PATTERN), courses_views.CoursesOverview.as_view()), url(r'^{0}/overview/*$'.format(COURSE_ID_PATTERN), courses_views.CoursesOverview.as_view()),
url(r'^{0}/static_tabs/(?P<tab_id>[a-zA-Z0-9_+\/:-]+)$'.format(COURSE_ID_PATTERN), courses_views.CoursesStaticTabsDetail.as_view()), url(r'^{0}/static_tabs/(?P<tab_id>[a-zA-Z0-9_+\/:-]+)$'.format(COURSE_ID_PATTERN),
courses_views.CoursesStaticTabsDetail.as_view()),
url(r'^{0}/static_tabs/(?P<tab_id>[a-zA-Z0-9_+\s\/:-]+)$'.format(COURSE_ID_PATTERN),
courses_views.CoursesStaticTabsDetail.as_view()),
url(r'^{0}/static_tabs/*$'.format(COURSE_ID_PATTERN), courses_views.CoursesStaticTabsList.as_view()), url(r'^{0}/static_tabs/*$'.format(COURSE_ID_PATTERN), courses_views.CoursesStaticTabsList.as_view()),
url(r'^{0}/completions/*$'.format(COURSE_ID_PATTERN), courses_views.CourseModuleCompletionList.as_view(), name='completion-list'), url(r'^{0}/completions/*$'.format(COURSE_ID_PATTERN), courses_views.CourseModuleCompletionList.as_view(), name='completion-list'),
url(r'^{0}/projects/*$'.format(COURSE_ID_PATTERN), courses_views.CoursesProjectList.as_view(), name='courseproject-list'), url(r'^{0}/projects/*$'.format(COURSE_ID_PATTERN), courses_views.CoursesProjectList.as_view(), name='courseproject-list'),
......
...@@ -947,19 +947,19 @@ class CoursesStaticTabsDetail(SecureAPIView): ...@@ -947,19 +947,19 @@ class CoursesStaticTabsDetail(SecureAPIView):
""" """
**Use Case** **Use Case**
CoursesStaticTabsDetail returns a collection of custom pages in the CoursesStaticTabsDetail returns a custom page in the course,
course, including the page content. including the page content.
**Example Requests** **Example Requests**
GET /api/courses/{course_id}/static_tabs/{tab_id} GET /api/courses/{course_id}/static_tabs/{tab_url_slug}
GET /api/courses/{course_id}/static_tabs/{tab_name}
**Response Values** **Response Values**
* tabs: The collection of custom pages in the course. Each object in the * tab: A custom page in the course. containing following keys:
collection conains the following keys:
* id: The ID of the custom page. * id: The url_slug of the custom page.
* name: The Display Name of the custom page. * name: The Display Name of the custom page.
...@@ -975,7 +975,7 @@ class CoursesStaticTabsDetail(SecureAPIView): ...@@ -975,7 +975,7 @@ class CoursesStaticTabsDetail(SecureAPIView):
return Response({}, status=status.HTTP_404_NOT_FOUND) return Response({}, status=status.HTTP_404_NOT_FOUND)
response_data = OrderedDict() response_data = OrderedDict()
for tab in course_descriptor.tabs: for tab in course_descriptor.tabs:
if tab.type == 'static_tab' and tab.url_slug == tab_id: if tab.type == 'static_tab' and (tab.url_slug == tab_id or tab.name == tab_id):
response_data['id'] = tab.url_slug response_data['id'] = tab.url_slug
response_data['name'] = tab.name response_data['name'] = tab.name
response_data['content'] = _get_static_tab_contents( response_data['content'] = _get_static_tab_contents(
...@@ -983,10 +983,10 @@ class CoursesStaticTabsDetail(SecureAPIView): ...@@ -983,10 +983,10 @@ class CoursesStaticTabsDetail(SecureAPIView):
course_descriptor, course_descriptor,
tab tab
) )
if not response_data:
return Response({}, status=status.HTTP_404_NOT_FOUND)
return Response(response_data, status=status.HTTP_200_OK) return Response(response_data, status=status.HTTP_200_OK)
return Response({}, status=status.HTTP_404_NOT_FOUND)
class CoursesUsersList(SecureAPIView): class CoursesUsersList(SecureAPIView):
""" """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment