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
5edfc479
Commit
5edfc479
authored
May 09, 2014
by
Filippo Valsorda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add xmodule fields enforce_type tests
parent
04820387
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
+33
-0
common/lib/xmodule/xmodule/tests/test_fields.py
+33
-0
No files found.
common/lib/xmodule/xmodule/tests/test_fields.py
View file @
5edfc479
...
...
@@ -41,6 +41,19 @@ class DateTest(unittest.TestCase):
DateTest
.
date
.
from_json
(
"2013-01-01T00:00:00+01:00"
),
datetime
.
timedelta
(
hours
=
1
,
seconds
=
1
))
def
test_enforce_type
(
self
):
self
.
assertEqual
(
DateTest
.
date
.
enforce_type
(
None
),
None
)
self
.
assertEqual
(
DateTest
.
date
.
enforce_type
(
""
),
None
)
self
.
assertEqual
(
DateTest
.
date
.
enforce_type
(
"2012-12-31T23:00:01"
),
datetime
.
datetime
(
2012
,
12
,
31
,
23
,
0
,
1
,
tzinfo
=
UTC
()))
self
.
assertEqual
(
DateTest
.
date
.
enforce_type
(
1234567890000
),
datetime
.
datetime
(
2009
,
2
,
13
,
23
,
31
,
30
,
tzinfo
=
UTC
()))
self
.
assertEqual
(
DateTest
.
date
.
enforce_type
(
datetime
.
datetime
(
2014
,
5
,
9
,
21
,
1
,
27
,
tzinfo
=
UTC
())),
datetime
.
datetime
(
2014
,
5
,
9
,
21
,
1
,
27
,
tzinfo
=
UTC
()))
with
self
.
assertRaises
(
TypeError
):
DateTest
.
date
.
enforce_type
([
1
])
def
test_return_None
(
self
):
self
.
assertIsNone
(
DateTest
.
date
.
from_json
(
""
))
self
.
assertIsNone
(
DateTest
.
date
.
from_json
(
None
))
...
...
@@ -102,6 +115,16 @@ class TimedeltaTest(unittest.TestCase):
datetime
.
timedelta
(
days
=
1
,
seconds
=
46799
)
)
def
test_enforce_type
(
self
):
self
.
assertEqual
(
TimedeltaTest
.
delta
.
enforce_type
(
None
),
None
)
self
.
assertEqual
(
TimedeltaTest
.
delta
.
enforce_type
(
datetime
.
timedelta
(
days
=
1
,
seconds
=
46799
)),
datetime
.
timedelta
(
days
=
1
,
seconds
=
46799
))
self
.
assertEqual
(
TimedeltaTest
.
delta
.
enforce_type
(
'1 day 46799 seconds'
),
datetime
.
timedelta
(
days
=
1
,
seconds
=
46799
))
with
self
.
assertRaises
(
TypeError
):
TimedeltaTest
.
delta
.
enforce_type
([
1
])
def
test_to_json
(
self
):
self
.
assertEqual
(
'1 days 46799 seconds'
,
...
...
@@ -143,6 +166,16 @@ class RelativeTimeTest(unittest.TestCase):
with
self
.
assertRaises
(
ValueError
):
RelativeTimeTest
.
delta
.
from_json
(
"77:77:77"
)
def
test_enforce_type
(
self
):
self
.
assertEqual
(
RelativeTimeTest
.
delta
.
enforce_type
(
None
),
None
)
self
.
assertEqual
(
RelativeTimeTest
.
delta
.
enforce_type
(
datetime
.
timedelta
(
days
=
1
,
seconds
=
46799
)),
datetime
.
timedelta
(
days
=
1
,
seconds
=
46799
))
self
.
assertEqual
(
RelativeTimeTest
.
delta
.
enforce_type
(
'0:05:07'
),
datetime
.
timedelta
(
seconds
=
307
))
with
self
.
assertRaises
(
TypeError
):
RelativeTimeTest
.
delta
.
enforce_type
([
1
])
def
test_to_json
(
self
):
self
.
assertEqual
(
"01:02:03"
,
...
...
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