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
fe2c92e6
Commit
fe2c92e6
authored
Nov 23, 2016
by
jagonzalr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add unit tests
parent
9cf08261
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
1 deletions
+61
-1
cms/djangoapps/contentstore/tests/utils.py
+12
-0
cms/djangoapps/contentstore/views/tests/test_course_index.py
+33
-1
common/lib/xmodule/xmodule/modulestore/tests/django_utils.py
+16
-0
No files found.
cms/djangoapps/contentstore/tests/utils.py
View file @
fe2c92e6
...
...
@@ -100,6 +100,18 @@ class CourseTestCase(ProceduralCourseTestMixin, ModuleStoreTestCase):
nonstaff
.
is_authenticated
=
lambda
:
authenticate
return
client
,
nonstaff
def
create_staff_authed_user_client
(
self
,
authenticate
=
True
):
"""
Create a staff user, log them in (if authenticate=True), and return the client, user to use for testing.
"""
staff
,
password
=
self
.
create_staff_user
()
client
=
AjaxEnabledTestClient
()
if
authenticate
:
client
.
login
(
username
=
staff
.
username
,
password
=
password
)
staff
.
is_authenticated
=
lambda
:
authenticate
return
client
,
staff
def
reload_course
(
self
):
"""
Reloads the course object from the database
...
...
cms/djangoapps/contentstore/views/tests/test_course_index.py
View file @
fe2c92e6
...
...
@@ -16,7 +16,7 @@ from contentstore.courseware_index import CoursewareSearchIndexer, SearchIndexin
from
contentstore.tests.utils
import
CourseTestCase
from
contentstore.utils
import
reverse_course_url
,
reverse_library_url
,
add_instructor
,
reverse_usage_url
from
contentstore.views.course
import
(
course_outline_initial_state
,
reindex_course_and_check_access
,
_deprecated_blocks_info
course_outline_initial_state
,
reindex_course_and_check_access
,
_deprecated_blocks_info
,
_get_library_creator_status
)
from
contentstore.views.item
import
create_xblock_info
,
VisibilityState
from
course_action_state.managers
import
CourseRerunUIStateManager
...
...
@@ -30,6 +30,8 @@ from xmodule.modulestore import ModuleStoreEnum
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.tests.factories
import
CourseFactory
,
ItemFactory
,
LibraryFactory
from
student
import
auth
from
student.roles
import
CourseCreatorRole
class
TestCourseIndex
(
CourseTestCase
):
...
...
@@ -48,6 +50,36 @@ class TestCourseIndex(CourseTestCase):
display_name
=
'dotted.course.name-2'
,
)
@mock.patch
(
"contentstore.views.library.LIBRARIES_ENABLED"
,
False
)
def
test_library_creator_status_libraries_not_enabled
(
self
):
_
,
nostaff_user
=
self
.
create_non_staff_authed_user_client
()
self
.
assertEqual
(
_get_library_creator_status
(
nostaff_user
),
"disallowed_for_this_site"
)
@mock.patch
(
"contentstore.views.library.LIBRARIES_ENABLED"
,
True
)
def
test_library_creator_status_with_is_staff_user
(
self
):
_
,
staff_user
=
self
.
create_staff_authed_user_client
()
self
.
assertEqual
(
_get_library_creator_status
(
staff_user
),
"granted"
)
@mock.patch
(
"contentstore.views.library.LIBRARIES_ENABLED"
,
True
)
def
test_library_creator_status_with_disable_library_creation
(
self
):
_
,
nostaff_user
=
self
.
create_non_staff_authed_user_client
()
with
mock
.
patch
.
dict
(
'django.conf.settings.FEATURES'
,
{
"DISABLE_LIBRARY_CREATION"
:
True
}):
self
.
assertEqual
(
_get_library_creator_status
(
nostaff_user
),
"disallowed_for_this_site"
)
@mock.patch
(
"contentstore.views.library.LIBRARIES_ENABLED"
,
True
)
def
test_library_creator_status_with_course_creator_role
(
self
):
_
,
staff_user
=
self
.
create_staff_authed_user_client
()
_
,
nostaff_user
=
self
.
create_non_staff_authed_user_client
()
auth
.
add_users
(
staff_user
,
CourseCreatorRole
(),
nostaff_user
)
self
.
assertEqual
(
_get_library_creator_status
(
nostaff_user
),
"granted"
)
@mock.patch
(
"contentstore.views.library.LIBRARIES_ENABLED"
,
True
)
def
test_library_creator_status_with_no_course_creator_role_no_is_staff_no_disable_library_creation
(
self
):
_
,
nostaff_user
=
self
.
create_non_staff_authed_user_client
()
with
mock
.
patch
.
dict
(
'django.conf.settings.FEATURES'
,
{
"DISABLE_LIBRARY_CREATION"
:
False
}):
self
.
assertEqual
(
_get_library_creator_status
(
nostaff_user
),
"disallowed_for_this_site"
)
def
check_index_and_outline
(
self
,
authed_client
):
"""
Test getting the list of courses and then pulling up their outlines
...
...
common/lib/xmodule/xmodule/modulestore/tests/django_utils.py
View file @
fe2c92e6
...
...
@@ -436,6 +436,22 @@ class ModuleStoreTestCase(ModuleStoreIsolationMixin, TestCase):
nonstaff_user
.
save
()
return
nonstaff_user
,
password
def
create_staff_user
(
self
):
"""
Creates a staff test user.
Returns the staff test user and its password.
"""
uname
=
'teststaff'
password
=
'bar'
staff_user
=
User
.
objects
.
create_user
(
uname
,
'test+staff@edx.org'
,
password
)
# Note that we do not actually need to do anything
# for registration if we directly mark them active.
staff_user
.
is_active
=
True
staff_user
.
is_staff
=
True
staff_user
.
save
()
return
staff_user
,
password
def
update_course
(
self
,
course
,
user_id
):
"""
Updates the version of course in the modulestore
...
...
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