Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
8f07072d
Commit
8f07072d
authored
May 13, 2013
by
Arthur Barrett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added unit tests to add/remove course tab utility functions.
parent
8cddec41
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
0 deletions
+78
-0
cms/djangoapps/contentstore/tests/test_utils.py
+78
-0
No files found.
cms/djangoapps/contentstore/tests/test_utils.py
View file @
8f07072d
""" Tests for utils. """
from
contentstore
import
utils
import
mock
import
collections
from
django.test
import
TestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
...
...
@@ -70,3 +71,80 @@ class UrlReverseTestCase(ModuleStoreTestCase):
'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
)
)
class
ExtraPanelTabTestCase
(
TestCase
):
""" Tests adding and removing extra course tabs. """
def
get_tab_type_dicts
(
self
,
tab_types
):
""" Returns an array of tab dictionaries. """
if
tab_types
:
return
[{
'tab_type'
:
tab_type
}
for
tab_type
in
tab_types
.
split
(
','
)]
else
:
return
[]
def
get_course_with_tabs
(
self
,
tabs
=
[]):
""" Returns a mock course object with a tabs attribute. """
course
=
collections
.
namedtuple
(
'MockCourse'
,
[
'tabs'
])
if
isinstance
(
tabs
,
basestring
):
course
.
tabs
=
self
.
get_tab_type_dicts
(
tabs
)
else
:
course
.
tabs
=
tabs
return
course
def
add_extra_panel_tab
(
self
):
""" Tests if a tab can be added to a course tab list. """
for
tab_type
in
utils
.
EXTRA_TAB_PANELS
.
keys
():
tab
=
utils
.
EXTRA_TAB_PANELS
.
get
(
tab_type
)
# test adding with changed = True
for
tab_setup
in
[
''
,
'x'
,
'x,y,z'
]:
course
=
self
.
get_course_with_tabs
(
tab_setup
)
expected_tabs
=
course
.
tabs
+
tab
changed
,
actual_tabs
=
utils
.
add_extra_panel_tab
(
tab_type
,
course
)
self
.
assertTrue
(
changed
)
self
.
assertEqual
(
actual_tabs
,
expected_tabs
)
# test adding with changed = False
tab_test_setup
=
[
[
tab
],
[
tab
,
self
.
get_tab_type_dicts
(
'x,y,z'
)],
[
self
.
get_tab_type_dicts
(
'x,y'
),
tab
,
self
.
get_tab_type_dicts
(
'z'
)],
[
self
.
get_tab_type_dicts
(
'x,y,z'
),
tab
]]
for
tab_setup
in
tab_test_setup
:
course
=
self
.
get_course_with_tabs
(
tab_setup
)
expected_tabs
=
course
.
tabs
changed
,
actual_tabs
=
utils
.
add_extra_panel_tab
(
tab_type
,
course
)
self
.
assertFalse
(
changed
)
self
.
assertEqual
(
actual_tabs
,
expected_tabs
)
def
remove_tab_test
(
self
):
""" Tests if a tab can be removed from a course tab list. """
for
tab_type
in
utils
.
EXTRA_TAB_PANELS
.
keys
():
tab
=
utils
.
EXTRA_TAB_PANELS
.
get
(
tab_type
)
# test removing with changed = True
tab_test_setup
=
[
[
tab
],
[
tab
,
self
.
get_tab_type_dicts
(
'x,y,z'
)],
[
self
.
get_tab_type_dicts
(
'x,y'
),
tab
,
self
.
get_tab_type_dicts
(
'z'
)],
[
self
.
get_tab_type_dicts
(
'x,y,z'
),
tab
]]
for
tab_setup
in
tab_test_setup
:
course
=
self
.
get_course_with_tabs
(
tab_setup
)
expected_tabs
=
[
t
for
t
in
course
.
tabs
if
t
!=
utils
.
EXTRA_TAB_PANELS
.
get
(
tab_type
)]
changed
,
actual_tabs
=
utils
.
remove_extra_panel_tab
(
tab_type
,
course
)
self
.
assertTrue
(
changed
)
self
.
assertEqual
(
actual_tabs
,
expected_tabs
)
# test removing with changed = False
for
tab_setup
in
[
''
,
'x'
,
'x,y,z'
]:
course
=
self
.
get_course_with_tabs
(
tab_setup
)
expected_tabs
=
course
.
tabs
print
"expected_tabs = "
print
expected_tabs
changed
,
actual_tabs
=
utils
.
remove_extra_panel_tab
(
tab_type
,
course
)
self
.
assertFalse
(
changed
)
self
.
assertEqual
(
actual_tabs
,
expected_tabs
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment