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
e44c6b6b
Commit
e44c6b6b
authored
May 03, 2013
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't reach in to default value.
parent
32d67be5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
29 deletions
+32
-29
common/lib/xmodule/xmodule/course_module.py
+2
-1
common/lib/xmodule/xmodule/tests/test_course_module.py
+30
-28
No files found.
common/lib/xmodule/xmodule/course_module.py
View file @
e44c6b6b
...
...
@@ -233,7 +233,8 @@ class CourseDescriptor(CourseFields, SequenceDescriptor):
self
.
_grading_policy
=
{}
self
.
set_grading_policy
(
self
.
grading_policy
)
CourseFields
.
discussion_topics
.
_default
=
{
'General'
:
{
'id'
:
self
.
location
.
html_id
()}}
if
self
.
discussion_topics
==
{}:
self
.
discussion_topics
=
{
'General'
:
{
'id'
:
self
.
location
.
html_id
()}}
self
.
test_center_exams
=
[]
test_center_info
=
self
.
testcenter_info
...
...
common/lib/xmodule/xmodule/tests/test_course_module.py
View file @
e44c6b6b
...
...
@@ -40,21 +40,7 @@ class DummySystem(ImportSystem):
)
class
IsNewCourseTestCase
(
unittest
.
TestCase
):
"""Make sure the property is_new works on courses"""
def
setUp
(
self
):
# Needed for test_is_newish
datetime_patcher
=
patch
.
object
(
xmodule
.
course_module
,
'datetime'
,
Mock
(
wraps
=
datetime
.
datetime
)
)
mocked_datetime
=
datetime_patcher
.
start
()
mocked_datetime
.
utcnow
.
return_value
=
time_to_datetime
(
NOW
)
self
.
addCleanup
(
datetime_patcher
.
stop
)
@staticmethod
def
get_dummy_course
(
start
,
announcement
=
None
,
is_new
=
None
,
advertised_start
=
None
,
end
=
None
):
def
get_dummy_course
(
start
,
announcement
=
None
,
is_new
=
None
,
advertised_start
=
None
,
end
=
None
):
"""Get a dummy course"""
system
=
DummySystem
(
load_error_modules
=
True
)
...
...
@@ -84,6 +70,20 @@ class IsNewCourseTestCase(unittest.TestCase):
return
system
.
process_xml
(
start_xml
)
class
IsNewCourseTestCase
(
unittest
.
TestCase
):
"""Make sure the property is_new works on courses"""
def
setUp
(
self
):
# Needed for test_is_newish
datetime_patcher
=
patch
.
object
(
xmodule
.
course_module
,
'datetime'
,
Mock
(
wraps
=
datetime
.
datetime
)
)
mocked_datetime
=
datetime_patcher
.
start
()
mocked_datetime
.
utcnow
.
return_value
=
time_to_datetime
(
NOW
)
self
.
addCleanup
(
datetime_patcher
.
stop
)
@patch
(
'xmodule.course_module.time.gmtime'
)
def
test_sorting_score
(
self
,
gmtime_mock
):
gmtime_mock
.
return_value
=
NOW
...
...
@@ -120,8 +120,8 @@ class IsNewCourseTestCase(unittest.TestCase):
]
for
a
,
b
,
assertion
in
dates
:
a_score
=
self
.
get_dummy_course
(
start
=
a
[
0
],
announcement
=
a
[
1
],
advertised_start
=
a
[
2
])
.
sorting_score
b_score
=
self
.
get_dummy_course
(
start
=
b
[
0
],
announcement
=
b
[
1
],
advertised_start
=
b
[
2
])
.
sorting_score
a_score
=
get_dummy_course
(
start
=
a
[
0
],
announcement
=
a
[
1
],
advertised_start
=
a
[
2
])
.
sorting_score
b_score
=
get_dummy_course
(
start
=
b
[
0
],
announcement
=
b
[
1
],
advertised_start
=
b
[
2
])
.
sorting_score
print
"Comparing
%
s to
%
s"
%
(
a
,
b
)
assertion
(
a_score
,
b_score
)
...
...
@@ -138,40 +138,42 @@ class IsNewCourseTestCase(unittest.TestCase):
]
for
s
in
settings
:
d
=
self
.
get_dummy_course
(
start
=
s
[
0
],
advertised_start
=
s
[
1
])
d
=
get_dummy_course
(
start
=
s
[
0
],
advertised_start
=
s
[
1
])
print
"Checking start=
%
s advertised=
%
s"
%
(
s
[
0
],
s
[
1
])
self
.
assertEqual
(
d
.
start_date_text
,
s
[
2
])
def
test_is_newish
(
self
):
descriptor
=
self
.
get_dummy_course
(
start
=
'2012-12-02T12:00'
,
is_new
=
True
)
descriptor
=
get_dummy_course
(
start
=
'2012-12-02T12:00'
,
is_new
=
True
)
assert
(
descriptor
.
is_newish
is
True
)
descriptor
=
self
.
get_dummy_course
(
start
=
'2013-02-02T12:00'
,
is_new
=
False
)
descriptor
=
get_dummy_course
(
start
=
'2013-02-02T12:00'
,
is_new
=
False
)
assert
(
descriptor
.
is_newish
is
False
)
descriptor
=
self
.
get_dummy_course
(
start
=
'2013-02-02T12:00'
,
is_new
=
True
)
descriptor
=
get_dummy_course
(
start
=
'2013-02-02T12:00'
,
is_new
=
True
)
assert
(
descriptor
.
is_newish
is
True
)
descriptor
=
self
.
get_dummy_course
(
start
=
'2013-01-15T12:00'
)
descriptor
=
get_dummy_course
(
start
=
'2013-01-15T12:00'
)
assert
(
descriptor
.
is_newish
is
True
)
descriptor
=
self
.
get_dummy_course
(
start
=
'2013-03-01T12:00'
)
descriptor
=
get_dummy_course
(
start
=
'2013-03-01T12:00'
)
assert
(
descriptor
.
is_newish
is
True
)
descriptor
=
self
.
get_dummy_course
(
start
=
'2012-10-15T12:00'
)
descriptor
=
get_dummy_course
(
start
=
'2012-10-15T12:00'
)
assert
(
descriptor
.
is_newish
is
False
)
descriptor
=
self
.
get_dummy_course
(
start
=
'2012-12-31T12:00'
)
descriptor
=
get_dummy_course
(
start
=
'2012-12-31T12:00'
)
assert
(
descriptor
.
is_newish
is
True
)
def
test_end_date_text
(
self
):
# No end date set, returns empty string.
d
=
self
.
get_dummy_course
(
'2012-12-02T12:00'
)
d
=
get_dummy_course
(
'2012-12-02T12:00'
)
self
.
assertEqual
(
''
,
d
.
end_date_text
)
d
=
self
.
get_dummy_course
(
'2012-12-02T12:00'
,
end
=
'2014-9-04T12:00'
)
d
=
get_dummy_course
(
'2012-12-02T12:00'
,
end
=
'2014-9-04T12:00'
)
self
.
assertEqual
(
'Sep 04, 2014'
,
d
.
end_date_text
)
class
DiscussionTopicsTestCase
(
unittest
.
TestCase
):
def
test_default_discussion_topics
(
self
):
d
=
self
.
get_dummy_course
(
'2012-12-02T12:00'
)
d
=
get_dummy_course
(
'2012-12-02T12:00'
)
self
.
assertEqual
({
'General'
:
{
'id'
:
'i4x-test_org-test_course-course-test'
}},
d
.
discussion_topics
)
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