Commit 2f5ea630 by Will Daly

Cleaned up courseware test_tabs unittests

parent 0d1b3800
from django.test import TestCase
from mock import patch, MagicMock
from mock import MagicMock
import courseware.tabs as tabs
from courseware.access import has_access
from django.test.utils import override_settings
from collections import namedtuple
import logging
from django.conf import settings
from django.core.urlresolvers import reverse
from fs.errors import ResourceNotFoundError
from courseware.access import has_access
from xmodule.error_module import ErrorDescriptor
from xmodule.x_module import XModule, XModuleDescriptor
from xmodule.modulestore import Location
###############################################################################
class ProgressTestCase(TestCase):
......@@ -39,26 +24,20 @@ class ProgressTestCase(TestCase):
def test_progress(self):
self.assertEqual(tabs._progress(self.tab, self.mockuser0, self.course,
self.active_page0),
[])
self.active_page0), [])
self.assertEqual(tabs._progress(self.tab, self.mockuser1, self.course,
self.active_page1)[0].name,
'same')
self.active_page1)[0].name, 'same')
self.assertEqual(tabs._progress(self.tab, self.mockuser1, self.course,
self.active_page1)[0].link,
reverse('progress', args = [self.course.id]))
self.assertEqual(tabs._progress(self.tab, self.mockuser1, self.course,
self.active_page0)[0].is_active,
False)
self.active_page0)[0].is_active, False)
self.assertEqual(tabs._progress(self.tab, self.mockuser1, self.course,
self.active_page1)[0].is_active,
True)
###############################################################################
self.active_page1)[0].is_active, True)
class WikiTestCase(TestCase):
......@@ -95,10 +74,7 @@ class WikiTestCase(TestCase):
def test_wiki_enabled_false(self):
self.assertEqual(tabs._wiki(self.tab, self.user,
self.course, self.active_page1),
[])
###############################################################################
self.course, self.active_page1), [])
class ExternalLinkTestCase(TestCase):
......@@ -129,8 +105,6 @@ class ExternalLinkTestCase(TestCase):
self.course, self.active_page00)[0].is_active,
False)
###############################################################################
class StaticTabTestCase(TestCase):
......@@ -163,8 +137,6 @@ class StaticTabTestCase(TestCase):
self.course, self.active_page0)[0].is_active,
False)
###############################################################################
class TextbooksTestCase(TestCase):
......@@ -230,39 +202,6 @@ class TextbooksTestCase(TestCase):
self.assertEqual(tabs._textbooks(self.tab, self.mockuser0,
self.course, self.active_pageX), [])
###############################################################################
#
#class StaffGradingTestCase(TestCase):
#
# def setUp(self):
#
# self.tab = MagicMock()
# self.user = MagicMock()
# self.course = MagicMock()
# self.active_page1 = 'staff_grading'
# self.activate_page0 = 'shadowfax'
# self.course.id = 'edX/full/6.002_Spring_2012'
# self.link = reverse('staff_grading', args = [self.course.id])
#
#
# def test_staff_grading(self):
#
# self.assertEqual(tabs._staff_grading(self.tab, self.user,
# self.course, self.active_page1)[0].name,
# 'Staff grading')
#
# self.assertEqual(tabs._staff_grading(self.tab, self.user,
# self.course, self.active_page1)[0].link,
# self.link)
#
# self.assertEqual(tabs._staff_grading(self.tab, self.user,
# self.course, self.active_page1)[0].is_active,
# True)
#
#
###############################################################################
class KeyCheckerTestCase(TestCase):
def setUp(self):
......@@ -278,8 +217,6 @@ class KeyCheckerTestCase(TestCase):
tabs.key_checker(self.expected_keys0), self.dictio)
###############################################################################
class NullValidatorTestCase(TestCase):
def setUp(self):
......@@ -290,45 +227,33 @@ class NullValidatorTestCase(TestCase):
self.assertIsNone(tabs.null_validator(self.d))
###############################################################################
class ValidateTabsTestCase(TestCase):
def setUp(self):
self.course0 = MagicMock()
self.course1 = MagicMock()
self.course2 = MagicMock()
self.course3 = MagicMock()
self.course4 = MagicMock()
self.course5 = MagicMock()
self.course0.tabs = None
self.course1.tabs = [{'type':'courseware'}, {'type': 'fax'}]
self.course2.tabs = [{'type':'shadow'}, {'type': 'course_info'}]
self.course3.tabs = [{'type': 'set'}]
self.course4.tabs = [{'type':'courseware'},{'type':'course_info', 'name': 'alice'},
self.courses = [MagicMock() for i in range(0,5)]
self.courses[0].tabs = None
self.courses[1].tabs = [{'type':'courseware'}, {'type': 'fax'}]
self.courses[2].tabs = [{'type':'shadow'}, {'type': 'course_info'}]
self.courses[3].tabs = [{'type':'courseware'},{'type':'course_info', 'name': 'alice'},
{'type': 'wiki', 'name':'alice'}, {'type':'discussion', 'name': 'alice'},
{'type':'external_link', 'name': 'alice', 'link':'blink'},
{'type':'textbooks'}, {'type':'progress', 'name': 'alice'},
{'type':'static_tab', 'name':'alice', 'url_slug':'schlug'},
{'type': 'staff_grading'}]
self.course5.tabs = [{'type':'courseware'},{'type': 'course_info'}, {'type': 'flying'}]
self.courses[4].tabs = [{'type':'courseware'},{'type': 'course_info'}, {'type': 'flying'}]
def test_validate_tabs(self):
self.assertIsNone(tabs.validate_tabs(self.course0))
self.assertRaises(tabs.InvalidTabsException, tabs.validate_tabs, self.course3)
self.assertRaises(tabs.InvalidTabsException, tabs.validate_tabs, self.course2)
self.assertRaises(tabs.InvalidTabsException, tabs.validate_tabs, self.course1)
self.assertRaises(tabs.InvalidTabsException, tabs.validate_tabs, self.course5)
self.assertIsNone(tabs.validate_tabs(self.course4))
self.assertRaises(tabs.InvalidTabsException, tabs.validate_tabs, self.course5)
self.assertIsNone(tabs.validate_tabs(self.courses[0]))
self.assertRaises(tabs.InvalidTabsException, tabs.validate_tabs, self.courses[1])
self.assertRaises(tabs.InvalidTabsException, tabs.validate_tabs, self.courses[2])
self.assertIsNone(tabs.validate_tabs(self.courses[3]))
self.assertRaises(tabs.InvalidTabsException, tabs.validate_tabs, self.courses[4])
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