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
9bb6f6e8
Commit
9bb6f6e8
authored
Oct 22, 2015
by
Zia Fazal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use a generic function check if entrance_exam is enabled or not
parent
450e625d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
127 additions
and
125 deletions
+127
-125
cms/djangoapps/contentstore/views/course.py
+4
-4
cms/djangoapps/contentstore/views/entrance_exam.py
+0
-7
cms/djangoapps/contentstore/views/helpers.py
+3
-2
cms/djangoapps/contentstore/views/item.py
+2
-1
cms/djangoapps/contentstore/views/tests/test_entrance_exam.py
+0
-0
common/djangoapps/student/models.py
+2
-1
common/djangoapps/util/milestones_helpers.py
+8
-0
lms/djangoapps/courseware/entrance_exams.py
+2
-10
lms/djangoapps/courseware/module_render.py
+1
-1
lms/djangoapps/courseware/tests/test_tabs.py
+105
-99
No files found.
cms/djangoapps/contentstore/views/course.py
View file @
9bb6f6e8
...
...
@@ -67,8 +67,7 @@ from contentstore.tasks import rerun_course
from
contentstore.views.entrance_exam
import
(
create_entrance_exam
,
update_entrance_exam
,
delete_entrance_exam
,
is_entrance_exams_enabled
delete_entrance_exam
)
from
.library
import
LIBRARIES_ENABLED
...
...
@@ -89,7 +88,8 @@ from student.auth import has_course_author_access
from
util.milestones_helpers
import
(
set_prerequisite_courses
,
is_valid_course_key
,
is_prerequisite_courses_enabled
is_prerequisite_courses_enabled
,
is_entrance_exams_enabled
)
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -983,7 +983,7 @@ def settings_handler(request, course_key_string):
# feature-specific settings and handle them accordingly
# We have to be careful that we're only executing the following logic if we actually
# need to create or delete an entrance exam from the specified course
if
settings
.
FEATURES
.
get
(
'ENTRANCE_EXAMS'
,
False
):
if
is_entrance_exams_enabled
(
):
course_entrance_exam_present
=
course_module
.
entrance_exam_enabled
entrance_exam_enabled
=
request
.
json
.
get
(
'entrance_exam_enabled'
,
''
)
==
'true'
ee_min_score_pct
=
request
.
json
.
get
(
'entrance_exam_minimum_score_pct'
,
None
)
...
...
cms/djangoapps/contentstore/views/entrance_exam.py
View file @
9bb6f6e8
...
...
@@ -54,13 +54,6 @@ def check_feature_enabled(feature_name):
return
_check_feature_enabled
def
is_entrance_exams_enabled
():
"""
Returns a boolean indicating entrance exam feature is enable or not.
"""
return
settings
.
FEATURES
.
get
(
'ENTRANCE_EXAMS'
,
False
)
@login_required
@ensure_csrf_cookie
@check_feature_enabled
(
feature_name
=
'ENTRANCE_EXAMS'
)
...
...
cms/djangoapps/contentstore/views/helpers.py
View file @
9bb6f6e8
...
...
@@ -22,6 +22,7 @@ from xmodule.tabs import StaticTab
from
contentstore.utils
import
reverse_course_url
,
reverse_library_url
,
reverse_usage_url
from
models.settings.course_grading
import
CourseGradingModel
from
util.milestones_helpers
import
is_entrance_exams_enabled
__all__
=
[
'edge'
,
'event'
,
'landing'
]
...
...
@@ -226,7 +227,7 @@ def create_xblock(parent_locator, user, category, display_name, boilerplate=None
# Entrance Exams: Chapter module positioning
child_position
=
None
if
settings
.
FEATURES
.
get
(
'ENTRANCE_EXAMS'
,
False
):
if
is_entrance_exams_enabled
(
):
if
category
==
'chapter'
and
is_entrance_exam
:
fields
[
'is_entrance_exam'
]
=
is_entrance_exam
fields
[
'in_entrance_exam'
]
=
True
# Inherited metadata, all children will have it
...
...
@@ -250,7 +251,7 @@ def create_xblock(parent_locator, user, category, display_name, boilerplate=None
)
# Entrance Exams: Grader assignment
if
settings
.
FEATURES
.
get
(
'ENTRANCE_EXAMS'
,
False
):
if
is_entrance_exams_enabled
(
):
course_key
=
usage_key
.
course_key
course
=
store
.
get_course
(
course_key
)
if
hasattr
(
course
,
'entrance_exam_enabled'
)
and
course
.
entrance_exam_enabled
:
...
...
cms/djangoapps/contentstore/views/item.py
View file @
9bb6f6e8
...
...
@@ -38,6 +38,7 @@ from django.contrib.auth.models import User
from
util.date_utils
import
get_default_time_display
from
util.json_request
import
expect_json
,
JsonResponse
from
util.milestones_helpers
import
is_entrance_exams_enabled
from
student.auth
import
has_studio_write_access
,
has_studio_read_access
from
contentstore.utils
import
(
...
...
@@ -89,7 +90,7 @@ def _filter_entrance_exam_grader(graders):
views/controls like the 'Grade as' dropdown that allows a course author to select
the grader type for a given section of a course
"""
if
settings
.
FEATURES
.
get
(
'ENTRANCE_EXAMS'
,
False
):
if
is_entrance_exams_enabled
(
):
graders
=
[
grader
for
grader
in
graders
if
grader
.
get
(
'type'
)
!=
u'Entrance Exam'
]
return
graders
...
...
cms/djangoapps/contentstore/views/tests/test_entrance_exam.py
View file @
9bb6f6e8
This diff is collapsed.
Click to expand it.
common/djangoapps/student/models.py
View file @
9bb6f6e8
...
...
@@ -52,6 +52,7 @@ import lms.lib.comment_client as cc
from
openedx.core.djangoapps.content.course_overviews.models
import
CourseOverview
from
util.model_utils
import
emit_field_changed_events
,
get_changed_fields_dict
from
util.query
import
use_read_replica_if_available
from
util.milestones_helpers
import
is_entrance_exams_enabled
UNENROLL_DONE
=
Signal
(
providing_args
=
[
"course_enrollment"
,
"skip_refund"
])
...
...
@@ -1896,7 +1897,7 @@ class EntranceExamConfiguration(models.Model):
Return True if given user can skip entrance exam for given course otherwise False.
"""
can_skip
=
False
if
settings
.
FEATURES
.
get
(
'ENTRANCE_EXAMS'
,
False
):
if
is_entrance_exams_enabled
(
):
try
:
record
=
EntranceExamConfiguration
.
objects
.
get
(
user
=
user
,
course_id
=
course_key
)
can_skip
=
record
.
skip_entrance_exam
...
...
common/djangoapps/util/milestones_helpers.py
View file @
9bb6f6e8
...
...
@@ -24,6 +24,14 @@ def get_namespace_choices():
return
NAMESPACE_CHOICES
def
is_entrance_exams_enabled
():
"""
Checks to see if the Entrance Exams feature is enabled
Use this operation instead of checking the feature flag all over the place
"""
return
settings
.
FEATURES
.
get
(
'ENTRANCE_EXAMS'
,
False
)
def
is_prerequisite_courses_enabled
():
"""
Returns boolean indicating prerequisite courses enabled system wide or not.
...
...
lms/djangoapps/courseware/entrance_exams.py
View file @
9bb6f6e8
...
...
@@ -8,24 +8,16 @@ from courseware.model_data import FieldDataCache, ScoresClient
from
opaque_keys.edx.keys
import
UsageKey
from
opaque_keys.edx.locator
import
BlockUsageLocator
from
student.models
import
EntranceExamConfiguration
from
util.milestones_helpers
import
get_required_content
from
util.milestones_helpers
import
get_required_content
,
is_entrance_exams_enabled
from
util.module_utils
import
yield_dynamic_descriptor_descendants
from
xmodule.modulestore.django
import
modulestore
def
feature_is_enabled
():
"""
Checks to see if the Entrance Exams feature is enabled
Use this operation instead of checking the feature flag all over the place
"""
return
settings
.
FEATURES
.
get
(
'ENTRANCE_EXAMS'
,
False
)
def
course_has_entrance_exam
(
course
):
"""
Checks to see if a course is properly configured for an entrance exam
"""
if
not
feature_i
s_enabled
():
if
not
is_entrance_exam
s_enabled
():
return
False
if
not
course
.
entrance_exam_enabled
:
return
False
...
...
lms/djangoapps/courseware/module_render.py
View file @
9bb6f6e8
...
...
@@ -470,7 +470,7 @@ def get_module_system_for_user(user, student_data, # TODO # pylint: disable=to
# Fulfillment Use Case: Entrance Exam
# If this module is part of an entrance exam, we'll need to see if the student
# has reached the point at which they can collect the associated milestone
if
settings
.
FEATURES
.
get
(
'ENTRANCE_EXAMS'
,
False
):
if
milestones_helpers
.
is_entrance_exams_enabled
(
):
course
=
modulestore
()
.
get_course
(
course_key
)
content
=
modulestore
()
.
get_item
(
content_key
)
entrance_exam_enabled
=
getattr
(
course
,
'entrance_exam_enabled'
,
False
)
...
...
lms/djangoapps/courseware/tests/test_tabs.py
View file @
9bb6f6e8
...
...
@@ -19,7 +19,13 @@ from courseware.tests.factories import InstructorFactory, StaffFactory
from
courseware.views
import
get_static_tab_contents
,
static_tab
from
student.models
import
CourseEnrollment
from
student.tests.factories
import
UserFactory
from
util
import
milestones_helpers
from
util.milestones_helpers
import
(
seed_milestone_relationship_types
,
get_milestone_relationship_types
,
add_milestone
,
add_course_milestone
,
add_course_content_milestone
)
from
xmodule
import
tabs
as
xmodule_tabs
from
xmodule.modulestore.tests.django_utils
import
(
TEST_DATA_MIXED_TOY_MODULESTORE
,
TEST_DATA_MIXED_CLOSED_MODULESTORE
...
...
@@ -303,112 +309,112 @@ class StaticTabDateTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase):
@attr
(
'shard_1'
)
@patch.dict
(
'django.conf.settings.FEATURES'
,
{
'ENTRANCE_EXAMS'
:
True
,
'MILESTONES_APP'
:
True
})
class
EntranceExamsTabsTestCase
(
LoginEnrollmentTestCase
,
ModuleStoreTestCase
):
"""
Validate tab behavior when dealing with Entrance Exams
"""
MODULESTORE
=
TEST_DATA_MIXED_CLOSED_MODULESTORE
if
settings
.
FEATURES
.
get
(
'ENTRANCE_EXAMS'
,
False
):
@patch.dict
(
'django.conf.settings.FEATURES'
,
{
'ENTRANCE_EXAMS'
:
True
,
'MILESTONES_APP'
:
True
})
def
setUp
(
self
):
"""
Test case scaffolding
"""
super
(
EntranceExamsTabsTestCase
,
self
)
.
setUp
()
def
setUp
(
self
):
"""
Test case scaffolding
"""
super
(
EntranceExamsTabsTestCase
,
self
)
.
setUp
()
self
.
course
=
CourseFactory
.
create
()
self
.
instructor_tab
=
ItemFactory
.
create
(
category
=
"instructor"
,
parent_location
=
self
.
course
.
location
,
data
=
"Instructor Tab"
,
display_name
=
"Instructor"
)
self
.
extra_tab_2
=
ItemFactory
.
create
(
category
=
"static_tab"
,
parent_location
=
self
.
course
.
location
,
data
=
"Extra Tab"
,
display_name
=
"Extra Tab 2"
)
self
.
extra_tab_3
=
ItemFactory
.
create
(
category
=
"static_tab"
,
parent_location
=
self
.
course
.
location
,
data
=
"Extra Tab"
,
display_name
=
"Extra Tab 3"
)
self
.
setup_user
()
self
.
enroll
(
self
.
course
)
self
.
user
.
is_staff
=
True
seed_milestone_relationship_types
()
self
.
relationship_types
=
get_milestone_relationship_types
()
self
.
course
=
CourseFactory
.
create
()
self
.
instructor_tab
=
ItemFactory
.
create
(
category
=
"instructor"
,
parent_location
=
self
.
course
.
location
,
data
=
"Instructor Tab"
,
display_name
=
"Instructor"
)
self
.
extra_tab_2
=
ItemFactory
.
create
(
category
=
"static_tab"
,
parent_location
=
self
.
course
.
location
,
data
=
"Extra Tab"
,
display_name
=
"Extra Tab 2"
)
self
.
extra_tab_3
=
ItemFactory
.
create
(
category
=
"static_tab"
,
parent_location
=
self
.
course
.
location
,
data
=
"Extra Tab"
,
display_name
=
"Extra Tab 3"
)
self
.
setup_user
()
self
.
enroll
(
self
.
course
)
self
.
user
.
is_staff
=
True
self
.
relationship_types
=
milestones_helpers
.
get_milestone_relationship_types
()
milestones_helpers
.
seed_milestone_relationship_types
()
def
test_get_course_tabs_list_entrance_exam_enabled
(
self
):
"""
Unit Test: test_get_course_tabs_list_entrance_exam_enabled
"""
entrance_exam
=
ItemFactory
.
create
(
category
=
"chapter"
,
parent_location
=
self
.
course
.
location
,
data
=
"Exam Data"
,
display_name
=
"Entrance Exam"
,
is_entrance_exam
=
True
)
milestone
=
{
'name'
:
'Test Milestone'
,
'namespace'
:
'{}.entrance_exams'
.
format
(
unicode
(
self
.
course
.
id
)),
'description'
:
'Testing Courseware Tabs'
}
self
.
user
.
is_staff
=
False
request
=
get_request_for_user
(
self
.
user
)
self
.
course
.
entrance_exam_enabled
=
True
self
.
course
.
entrance_exam_id
=
unicode
(
entrance_exam
.
location
)
milestone
=
milestones_helpers
.
add_milestone
(
milestone
)
milestones_helpers
.
add_course_milestone
(
unicode
(
self
.
course
.
id
),
self
.
relationship_types
[
'REQUIRES'
],
milestone
)
milestones_helpers
.
add_course_content_milestone
(
unicode
(
self
.
course
.
id
),
unicode
(
entrance_exam
.
location
),
self
.
relationship_types
[
'FULFILLS'
],
milestone
)
course_tab_list
=
get_course_tab_list
(
request
,
self
.
course
)
self
.
assertEqual
(
len
(
course_tab_list
),
1
)
self
.
assertEqual
(
course_tab_list
[
0
][
'tab_id'
],
'courseware'
)
self
.
assertEqual
(
course_tab_list
[
0
][
'name'
],
'Entrance Exam'
)
def
test_get_course_tabs_list_skipped_entrance_exam
(
self
):
"""
Tests tab list is not limited if user is allowed to skip entrance exam.
"""
#create a user
student
=
UserFactory
()
# login as instructor hit skip entrance exam api in instructor app
instructor
=
InstructorFactory
(
course_key
=
self
.
course
.
id
)
self
.
client
.
logout
()
self
.
client
.
login
(
username
=
instructor
.
username
,
password
=
'test'
)
url
=
reverse
(
'mark_student_can_skip_entrance_exam'
,
kwargs
=
{
'course_id'
:
unicode
(
self
.
course
.
id
)})
response
=
self
.
client
.
post
(
url
,
{
'unique_student_identifier'
:
student
.
email
,
})
self
.
assertEqual
(
response
.
status_code
,
200
)
# log in again as student
self
.
client
.
logout
()
self
.
login
(
self
.
email
,
self
.
password
)
request
=
get_request_for_user
(
self
.
user
)
course_tab_list
=
get_course_tab_list
(
request
,
self
.
course
)
self
.
assertEqual
(
len
(
course_tab_list
),
5
)
def
test_course_tabs_list_for_staff_members
(
self
):
"""
Tests tab list is not limited if user is member of staff
and has not passed entrance exam.
"""
# Login as member of staff
self
.
client
.
logout
()
staff_user
=
StaffFactory
(
course_key
=
self
.
course
.
id
)
self
.
client
.
login
(
username
=
staff_user
.
username
,
password
=
'test'
)
request
=
get_request_for_user
(
staff_user
)
course_tab_list
=
get_course_tab_list
(
request
,
self
.
course
)
self
.
assertEqual
(
len
(
course_tab_list
),
5
)
def
test_get_course_tabs_list_entrance_exam_enabled
(
self
):
"""
Unit Test: test_get_course_tabs_list_entrance_exam_enabled
"""
entrance_exam
=
ItemFactory
.
create
(
category
=
"chapter"
,
parent_location
=
self
.
course
.
location
,
data
=
"Exam Data"
,
display_name
=
"Entrance Exam"
,
is_entrance_exam
=
True
)
milestone
=
{
'name'
:
'Test Milestone'
,
'namespace'
:
'{}.entrance_exams'
.
format
(
unicode
(
self
.
course
.
id
)),
'description'
:
'Testing Courseware Tabs'
}
self
.
user
.
is_staff
=
False
request
=
get_request_for_user
(
self
.
user
)
self
.
course
.
entrance_exam_enabled
=
True
self
.
course
.
entrance_exam_id
=
unicode
(
entrance_exam
.
location
)
milestone
=
add_milestone
(
milestone
)
add_course_milestone
(
unicode
(
self
.
course
.
id
),
self
.
relationship_types
[
'REQUIRES'
],
milestone
)
add_course_content_milestone
(
unicode
(
self
.
course
.
id
),
unicode
(
entrance_exam
.
location
),
self
.
relationship_types
[
'FULFILLS'
],
milestone
)
course_tab_list
=
get_course_tab_list
(
request
,
self
.
course
)
self
.
assertEqual
(
len
(
course_tab_list
),
1
)
self
.
assertEqual
(
course_tab_list
[
0
][
'tab_id'
],
'courseware'
)
self
.
assertEqual
(
course_tab_list
[
0
][
'name'
],
'Entrance Exam'
)
def
test_get_course_tabs_list_skipped_entrance_exam
(
self
):
"""
Tests tab list is not limited if user is allowed to skip entrance exam.
"""
#create a user
student
=
UserFactory
()
# login as instructor hit skip entrance exam api in instructor app
instructor
=
InstructorFactory
(
course_key
=
self
.
course
.
id
)
self
.
client
.
logout
()
self
.
client
.
login
(
username
=
instructor
.
username
,
password
=
'test'
)
url
=
reverse
(
'mark_student_can_skip_entrance_exam'
,
kwargs
=
{
'course_id'
:
unicode
(
self
.
course
.
id
)})
response
=
self
.
client
.
post
(
url
,
{
'unique_student_identifier'
:
student
.
email
,
})
self
.
assertEqual
(
response
.
status_code
,
200
)
# log in again as student
self
.
client
.
logout
()
self
.
login
(
self
.
email
,
self
.
password
)
request
=
get_request_for_user
(
self
.
user
)
course_tab_list
=
get_course_tab_list
(
request
,
self
.
course
)
self
.
assertEqual
(
len
(
course_tab_list
),
5
)
def
test_course_tabs_list_for_staff_members
(
self
):
"""
Tests tab list is not limited if user is member of staff
and has not passed entrance exam.
"""
# Login as member of staff
self
.
client
.
logout
()
staff_user
=
StaffFactory
(
course_key
=
self
.
course
.
id
)
self
.
client
.
login
(
username
=
staff_user
.
username
,
password
=
'test'
)
request
=
get_request_for_user
(
staff_user
)
course_tab_list
=
get_course_tab_list
(
request
,
self
.
course
)
self
.
assertEqual
(
len
(
course_tab_list
),
5
)
@attr
(
'shard_1'
)
...
...
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