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
b1c9b2ca
Commit
b1c9b2ca
authored
Dec 13, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more tests of DbModel
parent
eb1ab3ea
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
6 deletions
+44
-6
common/lib/xmodule/xmodule/tests/test_runtime.py
+44
-6
No files found.
common/lib/xmodule/xmodule/tests/test_runtime.py
View file @
b1c9b2ca
...
...
@@ -4,6 +4,7 @@ from mock import patch
from
xmodule.model
import
*
from
xmodule.runtime
import
*
class
Metaclass
(
NamespacesMetaclass
,
ParentModelMetaclass
,
ModelMetaclass
):
pass
...
...
@@ -53,15 +54,52 @@ class DictKeyValueStore(KeyValueStore):
Usage
=
namedtuple
(
'Usage'
,
'id, def_id'
)
def
test_empty
():
def
check_field
(
collection
,
field
):
print
"Getting
%
s from
%
r"
%
(
field
.
name
,
collection
)
assert_equals
(
field
.
default
,
getattr
(
collection
,
field
.
name
))
new_value
=
'new '
+
field
.
name
print
"Setting
%
s to
%
s on
%
r"
%
(
field
.
name
,
new_value
,
collection
)
setattr
(
collection
,
field
.
name
,
new_value
)
print
"Checking
%
s on
%
r"
%
(
field
.
name
,
collection
)
assert_equals
(
new_value
,
getattr
(
collection
,
field
.
name
))
print
"Deleting
%
s from
%
r"
%
(
field
.
name
,
collection
)
delattr
(
collection
,
field
.
name
)
print
"Back to defaults for
%
s in
%
r"
%
(
field
.
name
,
collection
)
assert_equals
(
field
.
default
,
getattr
(
collection
,
field
.
name
))
def
test_namespace_actions
():
tester
=
TestModel
(
DbModel
(
DictKeyValueStore
(),
TestModel
,
's0'
,
Usage
(
'u0'
,
'd0'
)))
for
collection
in
(
tester
,
tester
.
test
):
for
field
in
collection
.
fields
:
print
"Getting
%
s from
%
r"
%
(
field
.
name
,
collection
)
assert_equals
(
field
.
default
,
getattr
(
collection
,
field
.
name
))
yield
check_field
,
collection
,
field
def
test_db_model_keys
():
key_store
=
DictKeyValueStore
()
tester
=
TestModel
(
DbModel
(
key_store
,
TestModel
,
's0'
,
Usage
(
'u0'
,
'd0'
)))
for
collection
in
(
tester
,
tester
.
test
):
for
field
in
collection
.
fields
:
new_value
=
'new '
+
field
.
name
print
"Setting
%
s to
%
s on
%
r"
%
(
field
.
name
,
new_value
,
collection
)
setattr
(
collection
,
field
.
name
,
new_value
)
print
"Checking
%
s on
%
r"
%
(
field
.
name
,
collection
)
assert_equals
(
new_value
,
getattr
(
collection
,
field
.
name
))
print
key_store
.
db
assert_equals
(
'new content'
,
key_store
.
db
[
KeyValueStore
.
Key
(
Scope
.
content
,
None
,
'd0'
,
'content'
)])
assert_equals
(
'new settings'
,
key_store
.
db
[
KeyValueStore
.
Key
(
Scope
.
settings
,
None
,
'u0'
,
'settings'
)])
assert_equals
(
'new student_state'
,
key_store
.
db
[
KeyValueStore
.
Key
(
Scope
.
student_state
,
's0'
,
'u0'
,
'student_state'
)])
assert_equals
(
'new student_preferences'
,
key_store
.
db
[
KeyValueStore
.
Key
(
Scope
.
student_preferences
,
's0'
,
'TestModel'
,
'student_preferences'
)])
assert_equals
(
'new student_info'
,
key_store
.
db
[
KeyValueStore
.
Key
(
Scope
.
student_info
,
's0'
,
None
,
'student_info'
)])
assert_equals
(
'new by_type'
,
key_store
.
db
[
KeyValueStore
.
Key
(
Scope
(
False
,
ModuleScope
.
TYPE
),
None
,
'TestModel'
,
'by_type'
)])
assert_equals
(
'new for_all'
,
key_store
.
db
[
KeyValueStore
.
Key
(
Scope
(
False
,
ModuleScope
.
ALL
),
None
,
None
,
'for_all'
)])
assert_equals
(
'new student_def'
,
key_store
.
db
[
KeyValueStore
.
Key
(
Scope
(
True
,
ModuleScope
.
DEFINITION
),
's0'
,
'd0'
,
'student_def'
)])
assert_equals
(
'new n_content'
,
key_store
.
db
[
KeyValueStore
.
Key
(
Scope
.
content
,
None
,
'd0'
,
'n_content'
)])
assert_equals
(
'new n_settings'
,
key_store
.
db
[
KeyValueStore
.
Key
(
Scope
.
settings
,
None
,
'u0'
,
'n_settings'
)])
assert_equals
(
'new n_student_state'
,
key_store
.
db
[
KeyValueStore
.
Key
(
Scope
.
student_state
,
's0'
,
'u0'
,
'n_student_state'
)])
assert_equals
(
'new n_student_preferences'
,
key_store
.
db
[
KeyValueStore
.
Key
(
Scope
.
student_preferences
,
's0'
,
'TestModel'
,
'n_student_preferences'
)])
assert_equals
(
'new n_student_info'
,
key_store
.
db
[
KeyValueStore
.
Key
(
Scope
.
student_info
,
's0'
,
None
,
'n_student_info'
)])
assert_equals
(
'new n_by_type'
,
key_store
.
db
[
KeyValueStore
.
Key
(
Scope
(
False
,
ModuleScope
.
TYPE
),
None
,
'TestModel'
,
'n_by_type'
)])
assert_equals
(
'new n_for_all'
,
key_store
.
db
[
KeyValueStore
.
Key
(
Scope
(
False
,
ModuleScope
.
ALL
),
None
,
None
,
'n_for_all'
)])
assert_equals
(
'new n_student_def'
,
key_store
.
db
[
KeyValueStore
.
Key
(
Scope
(
True
,
ModuleScope
.
DEFINITION
),
's0'
,
'd0'
,
'n_student_def'
)])
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