Commit e7e03f10 by Renzo Lucioni

Refactor tab tests

parent f1ccf1c0
...@@ -13,37 +13,36 @@ from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE ...@@ -13,37 +13,36 @@ from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
FAKE_REQUEST = None FAKE_REQUEST = None
def tab_constructor(active_page, course, user, tab={'name': 'same'}, generator=tabs._progress):
return generator(tab, user, course, active_page, FAKE_REQUEST)
class ProgressTestCase(TestCase): class ProgressTestCase(TestCase):
def setUp(self): def setUp(self):
self.mockuser1 = MagicMock() self.user = MagicMock()
self.mockuser0 = MagicMock() self.anonymous_user = MagicMock()
self.course = MagicMock() self.course = MagicMock()
self.mockuser1.is_authenticated.return_value = True self.user.is_authenticated.return_value = True
self.mockuser0.is_authenticated.return_value = False self.anonymous_user.is_authenticated.return_value = False
self.course.id = 'edX/toy/2012_Fall' self.course.id = 'edX/toy/2012_Fall'
self.tab = {'name': 'same'} self.tab = {'name': 'same'}
self.active_page1 = 'progress' self.progress_page = 'progress'
self.active_page0 = 'stagnation' self.stagnation_page = 'stagnation'
def test_progress(self): def test_progress(self):
self.assertEqual(tabs._progress(self.tab, self.mockuser0, self.course, self.assertEqual(tab_constructor(self.stagnation_page, self.course, self.anonymous_user), [])
self.active_page0, FAKE_REQUEST), [])
self.assertEqual(tabs._progress(self.tab, self.mockuser1, self.course, self.assertEqual(tab_constructor(self.progress_page, self.course, self.user)[0].name, 'same')
self.active_page1, FAKE_REQUEST)[0].name, 'same')
self.assertEqual(tabs._progress(self.tab, self.mockuser1, self.course, tab_list = tab_constructor(self.progress_page, self.course, self.user)
self.active_page1, FAKE_REQUEST)[0].link, expected_link = reverse('progress', args=[self.course.id])
reverse('progress', args=[self.course.id])) self.assertEqual(tab_list[0].link, expected_link)
self.assertEqual(tabs._progress(self.tab, self.mockuser1, self.course, self.assertEqual(tab_constructor(self.stagnation_page, self.course, self.user)[0].is_active, False)
self.active_page0, FAKE_REQUEST)[0].is_active, False)
self.assertEqual(tabs._progress(self.tab, self.mockuser1, self.course, self.assertEqual(tab_constructor(self.progress_page, self.course, self.user)[0].is_active, True)
self.active_page1, FAKE_REQUEST)[0].is_active, True)
class WikiTestCase(TestCase): class WikiTestCase(TestCase):
...@@ -54,33 +53,30 @@ class WikiTestCase(TestCase): ...@@ -54,33 +53,30 @@ class WikiTestCase(TestCase):
self.course = MagicMock() self.course = MagicMock()
self.course.id = 'edX/toy/2012_Fall' self.course.id = 'edX/toy/2012_Fall'
self.tab = {'name': 'same'} self.tab = {'name': 'same'}
self.active_page1 = 'wiki' self.wiki_page = 'wiki'
self.active_page0 = 'miki' self.miki_page = 'miki'
@override_settings(WIKI_ENABLED=True) @override_settings(WIKI_ENABLED=True)
def test_wiki_enabled(self): def test_wiki_enabled(self):
self.assertEqual(tabs._wiki(self.tab, self.user, tab_list = tab_constructor(self.wiki_page, self.course, self.user, generator=tabs._wiki)
self.course, self.active_page1, FAKE_REQUEST)[0].name, self.assertEqual(tab_list[0].name, 'same')
'same')
self.assertEqual(tabs._wiki(self.tab, self.user, tab_list = tab_constructor(self.wiki_page, self.course, self.user, generator=tabs._wiki)
self.course, self.active_page1, FAKE_REQUEST)[0].link, expected_link = reverse('course_wiki', args=[self.course.id])
reverse('course_wiki', args=[self.course.id])) self.assertEqual(tab_list[0].link, expected_link)
self.assertEqual(tabs._wiki(self.tab, self.user, tab_list = tab_constructor(self.wiki_page, self.course, self.user, generator=tabs._wiki)
self.course, self.active_page1, FAKE_REQUEST)[0].is_active, self.assertEqual(tab_list[0].is_active, True)
True)
self.assertEqual(tabs._wiki(self.tab, self.user, tab_list = tab_constructor(self.miki_page, self.course, self.user, generator=tabs._wiki)
self.course, self.active_page0, FAKE_REQUEST)[0].is_active, self.assertEqual(tab_list[0].is_active, False)
False)
@override_settings(WIKI_ENABLED=False) @override_settings(WIKI_ENABLED=False)
def test_wiki_enabled_false(self): def test_wiki_enabled_false(self):
self.assertEqual(tabs._wiki(self.tab, self.user, tab_list = tab_constructor(self.wiki_page, self.course, self.user, generator=tabs._wiki)
self.course, self.active_page1, FAKE_REQUEST), []) self.assertEqual(tab_list, [])
class ExternalLinkTestCase(TestCase): class ExternalLinkTestCase(TestCase):
...@@ -90,26 +86,30 @@ class ExternalLinkTestCase(TestCase): ...@@ -90,26 +86,30 @@ class ExternalLinkTestCase(TestCase):
self.user = MagicMock() self.user = MagicMock()
self.course = MagicMock() self.course = MagicMock()
self.tabby = {'name': 'same', 'link': 'blink'} self.tabby = {'name': 'same', 'link': 'blink'}
self.active_page0 = None self.no_page = None
self.active_page00 = True self.true = True
def test_external_link(self): def test_external_link(self):
self.assertEqual(tabs._external_link(self.tabby, self.user, tab_list = tab_constructor(
self.course, self.active_page0, FAKE_REQUEST)[0].name, self.no_page, self.course, self.user, tab=self.tabby, generator=tabs._external_link
'same') )
self.assertEqual(tab_list[0].name, 'same')
self.assertEqual(tabs._external_link(self.tabby, self.user, tab_list = tab_constructor(
self.course, self.active_page0, FAKE_REQUEST)[0].link, self.no_page, self.course, self.user, tab=self.tabby, generator=tabs._external_link
'blink') )
self.assertEqual(tab_list[0].link, 'blink')
self.assertEqual(tabs._external_link(self.tabby, self.user, tab_list = tab_constructor(
self.course, self.active_page0, FAKE_REQUEST)[0].is_active, self.no_page, self.course, self.user, tab=self.tabby, generator=tabs._external_link
False) )
self.assertEqual(tab_list[0].is_active, False)
self.assertEqual(tabs._external_link(self.tabby, self.user, tab_list = tab_constructor(
self.course, self.active_page00, FAKE_REQUEST)[0].is_active, self.true, self.course, self.user, tab=self.tabby, generator=tabs._external_link
False) )
self.assertEqual(tab_list[0].is_active, False)
class StaticTabTestCase(TestCase): class StaticTabTestCase(TestCase):
...@@ -120,107 +120,124 @@ class StaticTabTestCase(TestCase): ...@@ -120,107 +120,124 @@ class StaticTabTestCase(TestCase):
self.course = MagicMock() self.course = MagicMock()
self.tabby = {'name': 'same', 'url_slug': 'schmug'} self.tabby = {'name': 'same', 'url_slug': 'schmug'}
self.course.id = 'edX/toy/2012_Fall' self.course.id = 'edX/toy/2012_Fall'
self.active_page1 = 'static_tab_schmug' self.schmug = 'static_tab_schmug'
self.active_page0 = 'static_tab_schlug' self.schlug = 'static_tab_schlug'
def test_static_tab(self): def test_static_tab(self):
self.assertEqual(tabs._static_tab(self.tabby, self.user, tab_list = tab_constructor(
self.course, self.active_page1, FAKE_REQUEST)[0].name, self.schmug, self.course, self.user, tab=self.tabby, generator=tabs._static_tab
'same') )
self.assertEqual(tab_list[0].name, 'same')
self.assertEqual(tabs._static_tab(self.tabby, self.user, tab_list = tab_constructor(
self.course, self.active_page1, FAKE_REQUEST)[0].link, self.schmug, self.course, self.user, tab=self.tabby, generator=tabs._static_tab
reverse('static_tab', args=[self.course.id, )
self.tabby['url_slug']])) expected_link = reverse('static_tab', args=[self.course.id,self.tabby['url_slug']])
self.assertEqual(tab_list[0].link, expected_link)
self.assertEqual(tabs._static_tab(self.tabby, self.user, tab_list = tab_constructor(
self.course, self.active_page1, FAKE_REQUEST)[0].is_active, self.schmug, self.course, self.user, tab=self.tabby, generator=tabs._static_tab
True) )
self.assertEqual(tab_list[0].is_active, True)
self.assertEqual(tabs._static_tab(self.tabby, self.user,
self.course, self.active_page0, FAKE_REQUEST)[0].is_active,
False)
tab_list = tab_constructor(
self.schlug, self.course, self.user, tab=self.tabby, generator=tabs._static_tab
)
self.assertEqual(tab_list[0].is_active, False)
class TextbooksTestCase(TestCase): class TextbooksTestCase(TestCase):
def setUp(self): def setUp(self):
self.mockuser1 = MagicMock() self.user = MagicMock()
self.mockuser0 = MagicMock() self.anonymous_user = MagicMock()
self.course = MagicMock() self.course = MagicMock()
self.tab = MagicMock() self.tab = MagicMock()
A = MagicMock() A = MagicMock()
T = MagicMock() T = MagicMock()
self.mockuser1.is_authenticated.return_value = True
self.mockuser0.is_authenticated.return_value = False
self.course.id = 'edX/toy/2012_Fall'
self.active_page0 = 'textbook/0'
self.active_page1 = 'textbook/1'
self.active_pageX = 'you_shouldnt_be_seein_this'
A.title = 'Algebra' A.title = 'Algebra'
T.title = 'Topology' T.title = 'Topology'
self.course.textbooks = [A, T] self.course.textbooks = [A, T]
self.user.is_authenticated.return_value = True
self.anonymous_user.is_authenticated.return_value = False
self.course.id = 'edX/toy/2012_Fall'
self.textbook_0 = 'textbook/0'
self.textbook_1 = 'textbook/1'
self.prohibited_page = 'you_shouldnt_be_seein_this'
@override_settings(MITX_FEATURES={'ENABLE_TEXTBOOK': True}) @override_settings(MITX_FEATURES={'ENABLE_TEXTBOOK': True})
def test_textbooks1(self): def test_textbooks1(self):
self.assertEqual(tabs._textbooks(self.tab, self.mockuser1, tab_list = tab_constructor(
self.course, self.active_page0, FAKE_REQUEST)[0].name, self.textbook_0, self.course, self.user, tab=self.tab, generator=tabs._textbooks
'Algebra') )
self.assertEqual(tab_list[0].name, 'Algebra')
self.assertEqual(tabs._textbooks(self.tab, self.mockuser1,
self.course, self.active_page0, FAKE_REQUEST)[0].link, tab_list = tab_constructor(
reverse('book', args=[self.course.id, 0])) self.textbook_0, self.course, self.user, tab=self.tab, generator=tabs._textbooks
)
self.assertEqual(tabs._textbooks(self.tab, self.mockuser1, expected_link = reverse('book', args=[self.course.id, 0])
self.course, self.active_page0, FAKE_REQUEST)[0].is_active, self.assertEqual(tab_list[0].link, expected_link)
True)
tab_list = tab_constructor(
self.assertEqual(tabs._textbooks(self.tab, self.mockuser1, self.textbook_0, self.course, self.user, tab=self.tab, generator=tabs._textbooks
self.course, self.active_pageX, FAKE_REQUEST)[0].is_active, )
False) self.assertEqual(tab_list[0].is_active, True)
self.assertEqual(tabs._textbooks(self.tab, self.mockuser1, tab_list = tab_constructor(
self.course, self.active_page1, FAKE_REQUEST)[1].name, self.prohibited_page, self.course, self.user, tab=self.tab, generator=tabs._textbooks
'Topology') )
self.assertEqual(tab_list[0].is_active, False)
self.assertEqual(tabs._textbooks(self.tab, self.mockuser1,
self.course, self.active_page1, FAKE_REQUEST)[1].link, tab_list = tab_constructor(
reverse('book', args=[self.course.id, 1])) self.textbook_1, self.course, self.user, tab=self.tab, generator=tabs._textbooks
)
self.assertEqual(tabs._textbooks(self.tab, self.mockuser1, self.assertEqual(tab_list[1].name, 'Topology')
self.course, self.active_page1, FAKE_REQUEST)[1].is_active,
True) tab_list = tab_constructor(
self.textbook_1, self.course, self.user, tab=self.tab, generator=tabs._textbooks
self.assertEqual(tabs._textbooks(self.tab, self.mockuser1, )
self.course, self.active_pageX, FAKE_REQUEST)[1].is_active, expected_link = reverse('book', args=[self.course.id, 1])
False) self.assertEqual(tab_list[1].link, expected_link)
tab_list = tab_constructor(
self.textbook_1, self.course, self.user, tab=self.tab, generator=tabs._textbooks
)
self.assertEqual(tab_list[1].is_active, True)
tab_list = tab_constructor(
self.prohibited_page, self.course, self.user, tab=self.tab, generator=tabs._textbooks
)
self.assertEqual(tab_list[1].is_active, False)
@override_settings(MITX_FEATURES={'ENABLE_TEXTBOOK': False}) @override_settings(MITX_FEATURES={'ENABLE_TEXTBOOK': False})
def test_textbooks0(self): def test_textbooks0(self):
self.assertEqual(tabs._textbooks(self.tab, self.mockuser1, tab_list = tab_constructor(
self.course, self.active_pageX, FAKE_REQUEST), []) self.prohibited_page, self.course, self.user, tab=self.tab, generator=tabs._textbooks
)
self.assertEqual(tab_list, [])
self.assertEqual(tabs._textbooks(self.tab, self.mockuser0, tab_list = tab_constructor(
self.course, self.active_pageX, FAKE_REQUEST), []) self.prohibited_page, self.course, self.anonymous_user, tab=self.tab, generator=tabs._textbooks
)
self.assertEqual(tab_list, [])
class KeyCheckerTestCase(TestCase): class KeyCheckerTestCase(TestCase):
def setUp(self): def setUp(self):
self.expected_keys1 = ['a', 'b'] self.valid_keys = ['a', 'b']
self.expected_keys0 = ['a', 'v', 'g'] self.invalid_keys = ['a', 'v', 'g']
self.dictio = {'a': 1, 'b': 2, 'c': 3} self.dictio = {'a': 1, 'b': 2, 'c': 3}
def test_key_checker(self): def test_key_checker(self):
self.assertIsNone(tabs.key_checker(self.expected_keys1)(self.dictio)) self.assertIsNone(tabs.key_checker(self.valid_keys)(self.dictio))
self.assertRaises(tabs.InvalidTabsException, self.assertRaises(tabs.InvalidTabsException,
tabs.key_checker(self.expected_keys0), self.dictio) tabs.key_checker(self.invalid_keys), self.dictio)
class NullValidatorTestCase(TestCase): class NullValidatorTestCase(TestCase):
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
<% active_flags = " + ".join(waffle.get_flags(request)) %> <% active_flags = " + ".join(waffle.get_flags(request)) %>
<!-- <script src="${ reverse('wafflejs') }"></script> -->
<script type="text/javascript"> <script type="text/javascript">
var analytics=analytics||[];analytics.load=function(e){var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src=("https:"===document.location.protocol?"https://":"http://")+"d2dq2ahtl5zl1z.cloudfront.net/analytics.js/v1/"+e+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n);var r=function(e){return function(){analytics.push([e].concat(Array.prototype.slice.call(arguments,0)))}},i=["identify","track","trackLink","trackForm","trackClick","trackSubmit","pageview","ab","alias","ready"];for(var s=0;s<i.length;s++)analytics[i[s]]=r(i[s])}; var analytics=analytics||[];analytics.load=function(e){var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src=("https:"===document.location.protocol?"https://":"http://")+"d2dq2ahtl5zl1z.cloudfront.net/analytics.js/v1/"+e+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n);var r=function(e){return function(){analytics.push([e].concat(Array.prototype.slice.call(arguments,0)))}},i=["identify","track","trackLink","trackForm","trackClick","trackSubmit","pageview","ab","alias","ready"];for(var s=0;s<i.length;s++)analytics[i[s]]=r(i[s])};
analytics.load("${ settings.SEGMENT_IO_LMS_KEY }"); analytics.load("${ settings.SEGMENT_IO_LMS_KEY }");
......
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