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
085a590b
Commit
085a590b
authored
Jun 17, 2013
by
Don Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
timezone conversion: more unit tests
and code reorganization
parent
9d464701
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
9 deletions
+38
-9
cms/djangoapps/contentstore/tests/tests.py
+22
-0
common/lib/xmodule/xmodule/fields.py
+16
-9
No files found.
cms/djangoapps/contentstore/tests/tests.py
View file @
085a590b
...
@@ -3,6 +3,10 @@ from django.core.urlresolvers import reverse
...
@@ -3,6 +3,10 @@ from django.core.urlresolvers import reverse
from
.utils
import
parse_json
,
user
,
registration
from
.utils
import
parse_json
,
user
,
registration
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
contentstore.tests.test_course_settings
import
CourseTestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
import
datetime
from
pytz
import
UTC
class
ContentStoreTestCase
(
ModuleStoreTestCase
):
class
ContentStoreTestCase
(
ModuleStoreTestCase
):
...
@@ -162,3 +166,21 @@ class AuthTestCase(ContentStoreTestCase):
...
@@ -162,3 +166,21 @@ class AuthTestCase(ContentStoreTestCase):
self
.
assertEqual
(
resp
.
status_code
,
302
)
self
.
assertEqual
(
resp
.
status_code
,
302
)
# Logged in should work.
# Logged in should work.
class
ForumTestCase
(
CourseTestCase
):
def
setUp
(
self
):
""" Creates the test course. """
super
(
ForumTestCase
,
self
)
.
setUp
()
self
.
course
=
CourseFactory
.
create
(
org
=
'testX'
,
number
=
'727'
,
display_name
=
'Forum Course'
)
def
test_blackouts
(
self
):
now
=
datetime
.
datetime
.
now
(
UTC
)
self
.
course
.
discussion_blackouts
=
[(
t
.
isoformat
(),
t2
.
isoformat
())
for
t
,
t2
in
[(
now
-
datetime
.
timedelta
(
days
=
14
),
now
-
datetime
.
timedelta
(
days
=
11
)),
(
now
+
datetime
.
timedelta
(
days
=
24
),
now
+
datetime
.
timedelta
(
days
=
30
))]]
self
.
assertTrue
(
self
.
course
.
forum_posts_allowed
)
self
.
course
.
discussion_blackouts
=
[(
t
.
isoformat
(),
t2
.
isoformat
())
for
t
,
t2
in
[(
now
-
datetime
.
timedelta
(
days
=
14
),
now
+
datetime
.
timedelta
(
days
=
2
)),
(
now
+
datetime
.
timedelta
(
days
=
24
),
now
+
datetime
.
timedelta
(
days
=
30
))]]
self
.
assertFalse
(
self
.
course
.
forum_posts_allowed
)
common/lib/xmodule/xmodule/fields.py
View file @
085a590b
...
@@ -19,17 +19,11 @@ class Date(ModelType):
...
@@ -19,17 +19,11 @@ class Date(ModelType):
CURRENT_YEAR
=
datetime
.
datetime
.
now
(
UTC
)
.
year
CURRENT_YEAR
=
datetime
.
datetime
.
now
(
UTC
)
.
year
DEFAULT_DATE0
=
datetime
.
datetime
(
CURRENT_YEAR
,
1
,
1
,
tzinfo
=
UTC
)
DEFAULT_DATE0
=
datetime
.
datetime
(
CURRENT_YEAR
,
1
,
1
,
tzinfo
=
UTC
)
DEFAULT_DATE1
=
datetime
.
datetime
(
CURRENT_YEAR
,
2
,
2
,
tzinfo
=
UTC
)
DEFAULT_DATE1
=
datetime
.
datetime
(
CURRENT_YEAR
,
2
,
2
,
tzinfo
=
UTC
)
def
from_json
(
self
,
field
):
def
_parse_date_wo_default_month_day
(
self
,
field
):
"""
"""
Parse an optional metadata key containing a time: if present, complain
Parse the field as an iso string but prevent dateutils from defaulting the day or month while
if it doesn't parse.
allowing it to default the other fields.
Return None if not present or invalid.
"""
"""
if
field
is
None
:
return
field
elif
field
is
""
:
return
None
elif
isinstance
(
field
,
basestring
):
# It's not trivial to replace dateutil b/c parsing timezones as Z, +03:30, -400 is hard in python
# It's not trivial to replace dateutil b/c parsing timezones as Z, +03:30, -400 is hard in python
# however, we don't want dateutil to default the month or day (but some tests at least expect
# however, we don't want dateutil to default the month or day (but some tests at least expect
# us to default year); so, we'll see if dateutil uses the defaults for these the hard way
# us to default year); so, we'll see if dateutil uses the defaults for these the hard way
...
@@ -41,6 +35,19 @@ class Date(ModelType):
...
@@ -41,6 +35,19 @@ class Date(ModelType):
if
result
.
tzinfo
is
None
:
if
result
.
tzinfo
is
None
:
result
=
result
.
replace
(
tzinfo
=
UTC
)
result
=
result
.
replace
(
tzinfo
=
UTC
)
return
result
return
result
def
from_json
(
self
,
field
):
"""
Parse an optional metadata key containing a time: if present, complain
if it doesn't parse.
Return None if not present or invalid.
"""
if
field
is
None
:
return
field
elif
field
is
""
:
return
None
elif
isinstance
(
field
,
basestring
):
return
self
.
_parse_date_wo_default_month_day
(
field
)
elif
isinstance
(
field
,
(
int
,
long
,
float
)):
elif
isinstance
(
field
,
(
int
,
long
,
float
)):
return
datetime
.
datetime
.
fromtimestamp
(
field
/
1000
,
UTC
)
return
datetime
.
datetime
.
fromtimestamp
(
field
/
1000
,
UTC
)
elif
isinstance
(
field
,
time
.
struct_time
):
elif
isinstance
(
field
,
time
.
struct_time
):
...
...
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