Commit 505a3824 by cahrens

Re-enable all the tests!

parent d631509a
""" Unit tests for checklist methods in views.py. """
from contentstore.utils import get_modulestore, get_url_reverse from contentstore.utils import get_modulestore, get_url_reverse
from contentstore.tests.test_course_settings import CourseTestCase from contentstore.tests.test_course_settings import CourseTestCase
from xmodule.modulestore.inheritance import own_metadata from xmodule.modulestore.inheritance import own_metadata
...@@ -5,16 +6,21 @@ from xmodule.modulestore.tests.factories import CourseFactory ...@@ -5,16 +6,21 @@ from xmodule.modulestore.tests.factories import CourseFactory
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
import json import json
class ChecklistTestCase(CourseTestCase): class ChecklistTestCase(CourseTestCase):
""" Test for checklist get and put methods. """
def setUp(self): def setUp(self):
""" Creates the test course. """
super(ChecklistTestCase, self).setUp() super(ChecklistTestCase, self).setUp()
self.course = CourseFactory.create(org='mitX', number='333', display_name='Checklists Course') self.course = CourseFactory.create(org='mitX', number='333', display_name='Checklists Course')
def get_persisted_checklists(self): def get_persisted_checklists(self):
""" Returns the checklists as persisted in the modulestore. """
modulestore = get_modulestore(self.course.location) modulestore = get_modulestore(self.course.location)
return modulestore.get_item(self.course.location).checklists return modulestore.get_item(self.course.location).checklists
def test_get_checklists(self): def test_get_checklists(self):
""" Tests the get checklists method. """
checklists_url = get_url_reverse('Checklists', self.course) checklists_url = get_url_reverse('Checklists', self.course)
response = self.client.get(checklists_url) response = self.client.get(checklists_url)
self.assertContains(response, "Getting Started With Studio") self.assertContains(response, "Getting Started With Studio")
...@@ -30,7 +36,7 @@ class ChecklistTestCase(CourseTestCase): ...@@ -30,7 +36,7 @@ class ChecklistTestCase(CourseTestCase):
self.assertEquals(payload, response.content) self.assertEquals(payload, response.content)
def test_update_checklists_no_index(self): def test_update_checklists_no_index(self):
# No checklist index, should return all of them. """ No checklist index, should return all of them. """
update_url = reverse('checklists_updates', kwargs={ update_url = reverse('checklists_updates', kwargs={
'org': self.course.location.org, 'org': self.course.location.org,
'course': self.course.location.course, 'course': self.course.location.course,
...@@ -40,7 +46,7 @@ class ChecklistTestCase(CourseTestCase): ...@@ -40,7 +46,7 @@ class ChecklistTestCase(CourseTestCase):
self.assertListEqual(self.get_persisted_checklists(), returned_checklists) self.assertListEqual(self.get_persisted_checklists(), returned_checklists)
def test_update_checklists_index_ignored_on_get(self): def test_update_checklists_index_ignored_on_get(self):
# Checklist index ignored on get. """ Checklist index ignored on get. """
update_url = reverse('checklists_updates', kwargs={'org': self.course.location.org, update_url = reverse('checklists_updates', kwargs={'org': self.course.location.org,
'course': self.course.location.course, 'course': self.course.location.course,
'name': self.course.location.name, 'name': self.course.location.name,
...@@ -50,7 +56,7 @@ class ChecklistTestCase(CourseTestCase): ...@@ -50,7 +56,7 @@ class ChecklistTestCase(CourseTestCase):
self.assertListEqual(self.get_persisted_checklists(), returned_checklists) self.assertListEqual(self.get_persisted_checklists(), returned_checklists)
def test_update_checklists_post_no_index(self): def test_update_checklists_post_no_index(self):
# No checklist index, will error on post. """ No checklist index, will error on post. """
update_url = reverse('checklists_updates', kwargs={'org': self.course.location.org, update_url = reverse('checklists_updates', kwargs={'org': self.course.location.org,
'course': self.course.location.course, 'course': self.course.location.course,
'name': self.course.location.name}) 'name': self.course.location.name})
...@@ -58,7 +64,7 @@ class ChecklistTestCase(CourseTestCase): ...@@ -58,7 +64,7 @@ class ChecklistTestCase(CourseTestCase):
self.assertContains(response, 'Could not save checklist', status_code=400) self.assertContains(response, 'Could not save checklist', status_code=400)
def test_update_checklists_index_out_of_range(self): def test_update_checklists_index_out_of_range(self):
# Checklist index out of range, will error on post. """ Checklist index out of range, will error on post. """
update_url = reverse('checklists_updates', kwargs={'org': self.course.location.org, update_url = reverse('checklists_updates', kwargs={'org': self.course.location.org,
'course': self.course.location.course, 'course': self.course.location.course,
'name': self.course.location.name, 'name': self.course.location.name,
...@@ -67,7 +73,7 @@ class ChecklistTestCase(CourseTestCase): ...@@ -67,7 +73,7 @@ class ChecklistTestCase(CourseTestCase):
self.assertContains(response, 'Could not save checklist', status_code=400) self.assertContains(response, 'Could not save checklist', status_code=400)
def test_update_checklists_index(self): def test_update_checklists_index(self):
# Check that an update of a particular checklist works. """ Check that an update of a particular checklist works. """
update_url = reverse('checklists_updates', kwargs={'org': self.course.location.org, update_url = reverse('checklists_updates', kwargs={'org': self.course.location.org,
'course': self.course.location.course, 'course': self.course.location.course,
'name': self.course.location.name, 'name': self.course.location.name,
...@@ -81,7 +87,7 @@ class ChecklistTestCase(CourseTestCase): ...@@ -81,7 +87,7 @@ class ChecklistTestCase(CourseTestCase):
self.assertEqual(self.get_persisted_checklists()[2], returned_checklist) self.assertEqual(self.get_persisted_checklists()[2], returned_checklist)
def test_update_checklists_delete_unsupported(self): def test_update_checklists_delete_unsupported(self):
# Delete operation is not supported. """ Delete operation is not supported. """
update_url = reverse('checklists_updates', kwargs={'org': self.course.location.org, update_url = reverse('checklists_updates', kwargs={'org': self.course.location.org,
'course': self.course.location.course, 'course': self.course.location.course,
'name': self.course.location.name, 'name': self.course.location.name,
......
""" Tests for utils. """
from contentstore import utils from contentstore import utils
import mock import mock
from django.test import TestCase from django.test import TestCase
...@@ -6,44 +7,66 @@ from .utils import ModuleStoreTestCase ...@@ -6,44 +7,66 @@ from .utils import ModuleStoreTestCase
class LMSLinksTestCase(TestCase): class LMSLinksTestCase(TestCase):
""" Tests for LMS links. """
def about_page_test(self): def about_page_test(self):
""" Get URL for about page. """
location = 'i4x', 'mitX', '101', 'course', 'test' location = 'i4x', 'mitX', '101', 'course', 'test'
utils.get_course_id = mock.Mock(return_value="mitX/101/test") utils.get_course_id = mock.Mock(return_value="mitX/101/test")
link = utils.get_lms_link_for_about_page(location) link = utils.get_lms_link_for_about_page(location)
self.assertEquals(link, "//localhost:8000/courses/mitX/101/test/about") self.assertEquals(link, "//localhost:8000/courses/mitX/101/test/about")
def ls_link_test(self): def lms_link_test(self):
""" Tests get_lms_link_for_item. """
location = 'i4x', 'mitX', '101', 'vertical', 'contacting_us' location = 'i4x', 'mitX', '101', 'vertical', 'contacting_us'
utils.get_course_id = mock.Mock(return_value="mitX/101/test") utils.get_course_id = mock.Mock(return_value="mitX/101/test")
link = utils.get_lms_link_for_item(location, False) link = utils.get_lms_link_for_item(location, False)
self.assertEquals(link, "//localhost:8000/courses/mitX/101/test/jump_to/i4x://mitX/101/vertical/contacting_us") self.assertEquals(link, "//localhost:8000/courses/mitX/101/test/jump_to/i4x://mitX/101/vertical/contacting_us")
link = utils.get_lms_link_for_item(location, True) link = utils.get_lms_link_for_item(location, True)
self.assertEquals(link, "//preview.localhost:8000/courses/mitX/101/test/jump_to/i4x://mitX/101/vertical/contacting_us") self.assertEquals(
link,
"//preview.localhost:8000/courses/mitX/101/test/jump_to/i4x://mitX/101/vertical/contacting_us"
)
class UrlReverseTestCase(ModuleStoreTestCase): class UrlReverseTestCase(ModuleStoreTestCase):
""" Tests for get_url_reverse """
def test_CoursePageNames(self): def test_CoursePageNames(self):
""" Test the defined course pages. """
course = CourseFactory.create(org='mitX', number='666', display_name='URL Reverse Course') course = CourseFactory.create(org='mitX', number='666', display_name='URL Reverse Course')
self.assertEquals('/manage_users/i4x://mitX/666/course/URL_Reverse_Course', self.assertEquals(
utils.get_url_reverse('ManageUsers', course)) '/manage_users/i4x://mitX/666/course/URL_Reverse_Course',
utils.get_url_reverse('ManageUsers', course)
)
self.assertEquals('/mitX/666/settings-details/URL_Reverse_Course', self.assertEquals(
utils.get_url_reverse('SettingsDetails', course)) '/mitX/666/settings-details/URL_Reverse_Course',
utils.get_url_reverse('SettingsDetails', course)
)
self.assertEquals('/mitX/666/settings-grading/URL_Reverse_Course', self.assertEquals(
utils.get_url_reverse('SettingsGrading', course)) '/mitX/666/settings-grading/URL_Reverse_Course',
utils.get_url_reverse('SettingsGrading', course)
)
self.assertEquals('/mitX/666/course/URL_Reverse_Course', self.assertEquals(
utils.get_url_reverse('CourseOutline', course)) '/mitX/666/course/URL_Reverse_Course',
utils.get_url_reverse('CourseOutline', course)
)
self.assertEquals('/mitX/666/checklists/URL_Reverse_Course', self.assertEquals(
utils.get_url_reverse('Checklists', course)) '/mitX/666/checklists/URL_Reverse_Course',
utils.get_url_reverse('Checklists', course)
)
def test_unknown_passes_through(self): def test_unknown_passes_through(self):
""" Test that unknown values pass through. """
course = CourseFactory.create(org='mitX', number='666', display_name='URL Reverse Course') course = CourseFactory.create(org='mitX', number='666', display_name='URL Reverse Course')
self.assertEquals('foobar', self.assertEquals(
utils.get_url_reverse('foobar', course)) 'foobar',
self.assertEquals('https://edge.edx.org/courses/edX/edX101/How_to_Create_an_edX_Course/about', utils.get_url_reverse('foobar', course)
utils.get_url_reverse('https://edge.edx.org/courses/edX/edX101/How_to_Create_an_edX_Course/about', course)) )
self.assertEquals(
'https://edge.edx.org/courses/edX/edX101/How_to_Create_an_edX_Course/about',
utils.get_url_reverse('https://edge.edx.org/courses/edX/edX101/How_to_Create_an_edX_Course/about', course)
)
\ No newline at end of file
...@@ -179,12 +179,13 @@ def get_url_reverse(course_page_name, course_module): ...@@ -179,12 +179,13 @@ def get_url_reverse(course_page_name, course_module):
return reverse(url_name, kwargs={"location": ctx_loc}) return reverse(url_name, kwargs={"location": ctx_loc})
elif url_name in [CoursePageNames.SettingsDetails, CoursePageNames.SettingsGrading, elif url_name in [CoursePageNames.SettingsDetails, CoursePageNames.SettingsGrading,
CoursePageNames.CourseOutline, CoursePageNames.Checklists]: CoursePageNames.CourseOutline, CoursePageNames.Checklists]:
return reverse(url_name, kwargs={'org' : ctx_loc.org, 'course' : ctx_loc.course, 'name': ctx_loc.name}) return reverse(url_name, kwargs={'org': ctx_loc.org, 'course': ctx_loc.course, 'name': ctx_loc.name})
else: else:
return course_page_name return course_page_name
class CoursePageNames: class CoursePageNames:
""" Constants for pages that are recognized by get_url_reverse method. """
ManageUsers = "manage_users" ManageUsers = "manage_users"
SettingsDetails = "settings_details" SettingsDetails = "settings_details"
SettingsGrading = "settings_grading" SettingsGrading = "settings_grading"
......
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