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
f77aaec3
Commit
f77aaec3
authored
Apr 03, 2013
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Need to mock datetime.datetime.utcnow.
parent
8cd11f4f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
4 deletions
+15
-4
common/lib/xmodule/xmodule/tests/test_course_module.py
+15
-4
No files found.
common/lib/xmodule/xmodule/tests/test_course_module.py
View file @
f77aaec3
import
unittest
import
unittest
from
time
import
strptime
from
time
import
strptime
import
datetime
from
fs.memoryfs
import
MemoryFS
from
fs.memoryfs
import
MemoryFS
from
mock
import
Mock
,
patch
from
mock
import
Mock
,
patch
from
xmodule.modulestore.xml
import
ImportSystem
,
XMLModuleStore
from
xmodule.modulestore.xml
import
ImportSystem
,
XMLModuleStore
import
xmodule.course_module
from
xmodule.util.date_utils
import
time_to_datetime
ORG
=
'test_org'
ORG
=
'test_org'
...
@@ -39,6 +42,17 @@ class DummySystem(ImportSystem):
...
@@ -39,6 +42,17 @@ class DummySystem(ImportSystem):
class
IsNewCourseTestCase
(
unittest
.
TestCase
):
class
IsNewCourseTestCase
(
unittest
.
TestCase
):
"""Make sure the property is_new works on courses"""
"""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
@staticmethod
def
get_dummy_course
(
start
,
announcement
=
None
,
is_new
=
None
,
advertised_start
=
None
):
def
get_dummy_course
(
start
,
announcement
=
None
,
is_new
=
None
,
advertised_start
=
None
):
"""Get a dummy course"""
"""Get a dummy course"""
...
@@ -126,10 +140,7 @@ class IsNewCourseTestCase(unittest.TestCase):
...
@@ -126,10 +140,7 @@ class IsNewCourseTestCase(unittest.TestCase):
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
])
@patch
(
'xmodule.course_module.time.gmtime'
)
def
test_is_newish
(
self
):
def
test_is_newish
(
self
,
gmtime_mock
):
gmtime_mock
.
return_value
=
NOW
descriptor
=
self
.
get_dummy_course
(
start
=
'2012-12-02T12:00'
,
is_new
=
True
)
descriptor
=
self
.
get_dummy_course
(
start
=
'2012-12-02T12:00'
,
is_new
=
True
)
assert
(
descriptor
.
is_newish
is
True
)
assert
(
descriptor
.
is_newish
is
True
)
...
...
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