Commit 35083ad9 by Calen Pennington

Fix bad uses of course_id/location/locator in new code on master

parent 240fcc1d
......@@ -230,11 +230,10 @@ def container_handler(request, usage_key_string):
json: not currently supported
"""
if 'text/html' in request.META.get('HTTP_ACCEPT', 'text/html'):
usage_key = UsageKey.from_string(usage_key_string)
if not has_course_access(request.user, usage_key.course_key):
raise PermissionDenied()
try:
xblock = get_modulestore(usage_key).get_item(usage_key)
course, xblock, __ = _get_item_in_course(request, usage_key)
except ItemNotFoundError:
return HttpResponseBadRequest()
......
......@@ -2,6 +2,7 @@
Unit tests for the container page.
"""
import re
from contentstore.utils import compute_publish_state, PublishState
from contentstore.views.tests.utils import StudioPageTestCase
from xmodule.modulestore.django import modulestore
......@@ -30,19 +31,17 @@ class ContainerPageTestCase(StudioPageTestCase):
category="video", display_name="My Video")
def test_container_html(self):
branch_name = "MITx.999.Robot_Super_Course/branch/draft/block"
self._test_html_content(
self.child_container,
branch_name=branch_name,
expected_section_tag=(
'<section class="wrapper-xblock level-page is-hidden studio-xblock-wrapper" '
'data-locator="{0}" data-course-key="{0.course_key}">'.format(self.child_container.location)
),
expected_breadcrumbs=(
r'<a href="/unit/{branch_name}/Unit"\s*'
r'<a href="/unit/{}"\s*'
r'class="navigation-link navigation-parent">Unit</a>\s*'
r'<a href="#" class="navigation-link navigation-current">Split Test</a>'
).format(branch_name=branch_name)
).format(re.escape(unicode(self.vertical.location)))
)
def test_container_on_container_html(self):
......@@ -60,21 +59,22 @@ class ContainerPageTestCase(StudioPageTestCase):
)
def test_container_html(xblock):
branch_name = "MITx.999.Robot_Super_Course/branch/draft/block"
self._test_html_content(
xblock,
branch_name=branch_name,
expected_section_tag=(
'<section class="wrapper-xblock level-page is-hidden studio-xblock-wrapper" '
'data-locator="{0}" data-course-key="{0.course_key}">'.format(published_container.location)
),
expected_breadcrumbs=(
r'<a href="/unit/{branch_name}/Unit"\s*'
r'<a href="/unit/{unit}"\s*'
r'class="navigation-link navigation-parent">Unit</a>\s*'
r'<a href="/container/{branch_name}/Split_Test"\s*'
r'<a href="/container/{split_test}"\s*'
r'class="navigation-link navigation-parent">Split Test</a>\s*'
r'<a href="#" class="navigation-link navigation-current">Wrapper</a>'
).format(branch_name=branch_name)
).format(
unit=re.escape(unicode(self.vertical.location)),
split_test=re.escape(unicode(self.child_container.location))
)
)
# Test the published version of the container
......@@ -86,7 +86,7 @@ class ContainerPageTestCase(StudioPageTestCase):
draft_container = modulestore('draft').convert_to_draft(published_container.location)
test_container_html(draft_container)
def _test_html_content(self, xblock, branch_name, expected_section_tag, expected_breadcrumbs):
def _test_html_content(self, xblock, expected_section_tag, expected_breadcrumbs):
"""
Get the HTML for a container page and verify the section tag is correct
and the breadcrumbs trail is correct.
......@@ -100,12 +100,10 @@ class ContainerPageTestCase(StudioPageTestCase):
# Verify the link that allows users to change publish status.
expected_message = None
if publish_state == PublishState.public:
expected_message = 'you need to edit unit <a href="/unit/{branch_name}/Unit">Unit</a> as a draft.'
expected_message = 'you need to edit unit <a href="/unit/{}">Unit</a> as a draft.'
else:
expected_message = 'your changes will be published with unit <a href="/unit/{branch_name}/Unit">Unit</a>.'
expected_unit_link = expected_message.format(
branch_name=branch_name
)
expected_message = 'your changes will be published with unit <a href="/unit/{}">Unit</a>.'
expected_unit_link = expected_message.format(self.vertical.location)
self.assertIn(expected_unit_link, html)
def test_public_container_preview_html(self):
......
......@@ -621,7 +621,7 @@ class TestEditItem(ItemTest):
self.problem_update_url,
data={'publish': 'make_public'}
)
self.assertIsNotNone(self.get_item_from_modulestore(self.problem_locator, False))
self.assertIsNotNone(self.get_item_from_modulestore(self.problem_usage_key, False))
# Now make it draft, which means both versions will exist.
self.client.ajax_post(
self.problem_update_url,
......@@ -629,8 +629,8 @@ class TestEditItem(ItemTest):
'publish': 'create_draft'
}
)
self.assertIsNotNone(self.get_item_from_modulestore(self.problem_locator, False))
draft_1 = self.get_item_from_modulestore(self.problem_locator, True)
self.assertIsNotNone(self.get_item_from_modulestore(self.problem_usage_key, False))
draft_1 = self.get_item_from_modulestore(self.problem_usage_key, True)
self.assertIsNotNone(draft_1)
# Now check that when a user sends request to create a draft when there is already a draft version then
......@@ -641,7 +641,7 @@ class TestEditItem(ItemTest):
'publish': 'create_draft'
}
)
draft_2 = self.get_item_from_modulestore(self.problem_locator, True)
draft_2 = self.get_item_from_modulestore(self.problem_usage_key, True)
self.assertIsNotNone(draft_2)
self.assertEqual(draft_1, draft_2)
......@@ -655,7 +655,7 @@ class TestEditItem(ItemTest):
self.problem_update_url,
data={'publish': 'make_public'}
)
self.assertIsNotNone(self.get_item_from_modulestore(self.problem_locator, False))
self.assertIsNotNone(self.get_item_from_modulestore(self.problem_usage_key, False))
# Now make it private, and check that its published version not exists
resp = self.client.ajax_post(
......@@ -666,8 +666,8 @@ class TestEditItem(ItemTest):
)
self.assertEqual(resp.status_code, 200)
with self.assertRaises(ItemNotFoundError):
self.get_item_from_modulestore(self.problem_locator, False)
draft_1 = self.get_item_from_modulestore(self.problem_locator, True)
self.get_item_from_modulestore(self.problem_usage_key, False)
draft_1 = self.get_item_from_modulestore(self.problem_usage_key, True)
self.assertIsNotNone(draft_1)
# Now check that when a user sends request to make it private when it already is private then
......@@ -680,8 +680,8 @@ class TestEditItem(ItemTest):
)
self.assertEqual(resp.status_code, 200)
with self.assertRaises(ItemNotFoundError):
self.get_item_from_modulestore(self.problem_locator, False)
draft_2 = self.get_item_from_modulestore(self.problem_locator, True)
self.get_item_from_modulestore(self.problem_usage_key, False)
draft_2 = self.get_item_from_modulestore(self.problem_usage_key, True)
self.assertIsNotNone(draft_2)
self.assertEqual(draft_1, draft_2)
......
......@@ -6,7 +6,6 @@ import json
from contentstore.tests.utils import CourseTestCase
from contentstore.views.helpers import xblock_studio_url
from xmodule.modulestore.django import loc_mapper
from xmodule.modulestore.tests.factories import ItemFactory
......@@ -26,7 +25,7 @@ class StudioPageTestCase(CourseTestCase):
"""
Returns the HTML for the page representing the xblock.
"""
url = xblock_studio_url(xblock, self.course)
url = xblock_studio_url(xblock)
self.assertIsNotNone(url)
resp = self.client.get_html(url)
self.assertEqual(resp.status_code, 200)
......@@ -36,8 +35,7 @@ class StudioPageTestCase(CourseTestCase):
"""
Returns the HTML for the xblock when shown within a unit or container page.
"""
locator = loc_mapper().translate_location(self.course.id, xblock.location, published=False)
preview_url = '/xblock/{locator}/{view_name}'.format(locator=locator, view_name=view_name)
preview_url = '/xblock/{usage_key}/{view_name}'.format(usage_key=xblock.location, view_name=view_name)
resp = self.client.get_json(preview_url)
self.assertEqual(resp.status_code, 200)
resp_content = json.loads(resp.content)
......
......@@ -20,7 +20,6 @@ class StudioEditableModule(object):
fragment.add_frag_resources(rendered_child)
contents.append({
'id': child.id,
'content': rendered_child.content
})
......
......@@ -13,7 +13,6 @@ class BaseVerticalModuleTest(XModuleXmlImportTest):
test_html_2 = 'Test HTML 2'
def setUp(self):
self.course_id = 'test_org/test_course_number/test_run'
# construct module
course = xml.CourseFactory.build()
sequence = xml.SequenceFactory.build(parent=course)
......
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