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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
40 deletions
+43
-40
common/lib/xmodule/xmodule/course_module.py
+2
-1
common/lib/xmodule/xmodule/tests/test_course_module.py
+41
-39
No files found.
common/lib/xmodule/xmodule/course_module.py
View file @
e44c6b6b
...
@@ -233,7 +233,8 @@ class CourseDescriptor(CourseFields, SequenceDescriptor):
...
@@ -233,7 +233,8 @@ class CourseDescriptor(CourseFields, SequenceDescriptor):
self
.
_grading_policy
=
{}
self
.
_grading_policy
=
{}
self
.
set_grading_policy
(
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
=
[]
self
.
test_center_exams
=
[]
test_center_info
=
self
.
testcenter_info
test_center_info
=
self
.
testcenter_info
...
...
common/lib/xmodule/xmodule/tests/test_course_module.py
View file @
e44c6b6b
...
@@ -40,34 +40,20 @@ class DummySystem(ImportSystem):
...
@@ -40,34 +40,20 @@ class DummySystem(ImportSystem):
)
)
class
IsNewCourseTestCase
(
unittest
.
TestCase
):
def
get_dummy_course
(
start
,
announcement
=
None
,
is_new
=
None
,
advertised_start
=
None
,
end
=
None
):
"""Make sure the property is_new works on courses"""
"""Get a dummy course"""
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
):
"""Get a dummy course"""
system
=
DummySystem
(
load_error_modules
=
True
)
system
=
DummySystem
(
load_error_modules
=
True
)
def
to_attrb
(
n
,
v
):
def
to_attrb
(
n
,
v
):
return
''
if
v
is
None
else
'{0}="{1}"'
.
format
(
n
,
v
)
.
lower
()
return
''
if
v
is
None
else
'{0}="{1}"'
.
format
(
n
,
v
)
.
lower
()
is_new
=
to_attrb
(
'is_new'
,
is_new
)
is_new
=
to_attrb
(
'is_new'
,
is_new
)
announcement
=
to_attrb
(
'announcement'
,
announcement
)
announcement
=
to_attrb
(
'announcement'
,
announcement
)
advertised_start
=
to_attrb
(
'advertised_start'
,
advertised_start
)
advertised_start
=
to_attrb
(
'advertised_start'
,
advertised_start
)
end
=
to_attrb
(
'end'
,
end
)
end
=
to_attrb
(
'end'
,
end
)
start_xml
=
'''
start_xml
=
'''
<course org="{org}" course="{course}"
<course org="{org}" course="{course}"
graceperiod="1 day" url_name="test"
graceperiod="1 day" url_name="test"
start="{start}"
start="{start}"
...
@@ -80,9 +66,23 @@ class IsNewCourseTestCase(unittest.TestCase):
...
@@ -80,9 +66,23 @@ class IsNewCourseTestCase(unittest.TestCase):
</chapter>
</chapter>
</course>
</course>
'''
.
format
(
org
=
ORG
,
course
=
COURSE
,
start
=
start
,
is_new
=
is_new
,
'''
.
format
(
org
=
ORG
,
course
=
COURSE
,
start
=
start
,
is_new
=
is_new
,
announcement
=
announcement
,
advertised_start
=
advertised_start
,
end
=
end
)
announcement
=
announcement
,
advertised_start
=
advertised_start
,
end
=
end
)
return
system
.
process_xml
(
start_xml
)
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'
)
@patch
(
'xmodule.course_module.time.gmtime'
)
def
test_sorting_score
(
self
,
gmtime_mock
):
def
test_sorting_score
(
self
,
gmtime_mock
):
...
@@ -120,8 +120,8 @@ class IsNewCourseTestCase(unittest.TestCase):
...
@@ -120,8 +120,8 @@ class IsNewCourseTestCase(unittest.TestCase):
]
]
for
a
,
b
,
assertion
in
dates
:
for
a
,
b
,
assertion
in
dates
:
a_score
=
self
.
get_dummy_course
(
start
=
a
[
0
],
announcement
=
a
[
1
],
advertised_start
=
a
[
2
])
.
sorting_score
a_score
=
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
b_score
=
get_dummy_course
(
start
=
b
[
0
],
announcement
=
b
[
1
],
advertised_start
=
b
[
2
])
.
sorting_score
print
"Comparing
%
s to
%
s"
%
(
a
,
b
)
print
"Comparing
%
s to
%
s"
%
(
a
,
b
)
assertion
(
a_score
,
b_score
)
assertion
(
a_score
,
b_score
)
...
@@ -138,40 +138,42 @@ class IsNewCourseTestCase(unittest.TestCase):
...
@@ -138,40 +138,42 @@ class IsNewCourseTestCase(unittest.TestCase):
]
]
for
s
in
settings
:
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
])
print
"Checking start=
%
s advertised=
%
s"
%
(
s
[
0
],
s
[
1
])
self
.
assertEqual
(
d
.
start_date_text
,
s
[
2
])
self
.
assertEqual
(
d
.
start_date_text
,
s
[
2
])
def
test_is_newish
(
self
):
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
)
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
)
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
)
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
)
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
)
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
)
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
)
assert
(
descriptor
.
is_newish
is
True
)
def
test_end_date_text
(
self
):
def
test_end_date_text
(
self
):
# No end date set, returns empty string.
# 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
)
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
)
self
.
assertEqual
(
'Sep 04, 2014'
,
d
.
end_date_text
)
class
DiscussionTopicsTestCase
(
unittest
.
TestCase
):
def
test_default_discussion_topics
(
self
):
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
)
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