Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xblock-drag-and-drop-v2
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
OpenEdx
xblock-drag-and-drop-v2
Commits
5d0ac94a
Commit
5d0ac94a
authored
Sep 23, 2014
by
E. Kolpakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests for html-containing items and zones
parent
2e53fa53
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
188 additions
and
17 deletions
+188
-17
tests/test_drag_and_drop_v2.py
+31
-17
tests/test_get_html_data.json
+68
-0
tests/test_html_data.json
+89
-0
No files found.
tests/test_drag_and_drop_v2.py
View file @
5d0ac94a
...
...
@@ -72,54 +72,61 @@ def test_studio_submit():
assert_equals
(
block
.
weight
,
5
)
assert_equals
(
block
.
data
,
{
'foo'
:
1
})
def
test_ajax
():
def
do_ajax
(
orig_file
,
get_file
):
assert_equals
.
__self__
.
maxDiff
=
None
block
=
make_block
()
with
open
(
'tests/test_data.json'
)
as
f
:
with
open
(
orig_file
)
as
f
:
block
.
data
=
json
.
load
(
f
)
with
open
(
'tests/test_get_data.json'
)
as
f
:
initial_data
=
block
.
data
zoneA
=
initial_data
[
"items"
][
0
][
"zone"
]
zoneB
=
initial_data
[
"items"
][
1
][
"zone"
]
feedback_finish
=
initial_data
[
"feedback"
][
"finish"
]
get_item_feedback
=
lambda
item
,
type
:
initial_data
[
"items"
][
item
][
"feedback"
][
type
]
with
open
(
get_file
)
as
f
:
get_data
=
json
.
loads
(
block
.
handle
(
'get_data'
,
Mock
())
.
body
)
assert_equals
(
json
.
load
(
f
),
get_data
)
# Wrong with feedback
data
=
json
.
dumps
({
"val"
:
0
,
"zone"
:
"Zone B"
,
"top"
:
"31px"
,
"left"
:
"216px"
})
data
=
json
.
dumps
({
"val"
:
0
,
"zone"
:
zoneB
,
"top"
:
"31px"
,
"left"
:
"216px"
})
res
=
json
.
loads
(
block
.
handle
(
'do_attempt'
,
make_request
(
data
))
.
body
)
assert_equals
(
res
,
{
"final_feedback"
:
None
,
"finished"
:
False
,
"correct"
:
False
,
"feedback"
:
"No A"
"feedback"
:
get_item_feedback
(
0
,
"incorrect"
)
})
with
open
(
'tests/test_get_data.json'
)
as
f
:
with
open
(
get_file
)
as
f
:
get_data
=
json
.
loads
(
block
.
handle
(
'get_data'
,
Mock
())
.
body
)
assert_equals
(
json
.
load
(
f
),
get_data
)
# Wrong without feedback
data
=
json
.
dumps
({
"val"
:
2
,
"zone"
:
"Zone B"
,
"top"
:
"42px"
,
"left"
:
"100px"
})
data
=
json
.
dumps
({
"val"
:
2
,
"zone"
:
zoneB
,
"top"
:
"42px"
,
"left"
:
"100px"
})
res
=
json
.
loads
(
block
.
handle
(
'do_attempt'
,
make_request
(
data
))
.
body
)
assert_equals
(
res
,
{
"final_feedback"
:
None
,
"finished"
:
False
,
"correct"
:
False
,
"feedback"
:
""
"feedback"
:
get_item_feedback
(
2
,
"incorrect"
)
})
with
open
(
'tests/test_get_data.json'
)
as
f
:
with
open
(
get_file
)
as
f
:
get_data
=
json
.
loads
(
block
.
handle
(
'get_data'
,
Mock
())
.
body
)
assert_equals
(
json
.
load
(
f
),
get_data
)
# Correct
data
=
json
.
dumps
({
"val"
:
0
,
"zone"
:
"Zone A"
,
"top"
:
"11px"
,
"left"
:
"111px"
})
data
=
json
.
dumps
({
"val"
:
0
,
"zone"
:
zoneA
,
"top"
:
"11px"
,
"left"
:
"111px"
})
res
=
json
.
loads
(
block
.
handle
(
'do_attempt'
,
make_request
(
data
))
.
body
)
assert_equals
(
res
,
{
"final_feedback"
:
None
,
"finished"
:
False
,
"correct"
:
True
,
"feedback"
:
"Yes A"
"feedback"
:
get_item_feedback
(
0
,
"correct"
)
})
with
open
(
'tests/test_get_data.json'
)
as
f
:
with
open
(
get_file
)
as
f
:
expected
=
json
.
load
(
f
)
expected
[
"state"
]
=
{
"items"
:
{
...
...
@@ -131,15 +138,15 @@ def test_ajax():
assert_equals
(
expected
,
get_data
)
# Final
data
=
json
.
dumps
({
"val"
:
1
,
"zone"
:
"Zone B"
,
"top"
:
"22px"
,
"left"
:
"222px"
})
data
=
json
.
dumps
({
"val"
:
1
,
"zone"
:
zoneB
,
"top"
:
"22px"
,
"left"
:
"222px"
})
res
=
json
.
loads
(
block
.
handle
(
'do_attempt'
,
make_request
(
data
))
.
body
)
assert_equals
(
res
,
{
"final_feedback"
:
"Final Feed"
,
"final_feedback"
:
feedback_finish
,
"finished"
:
True
,
"correct"
:
True
,
"feedback"
:
"Yes B"
"feedback"
:
get_item_feedback
(
1
,
"correct"
)
})
with
open
(
'tests/test_get_data.json'
)
as
f
:
with
open
(
get_file
)
as
f
:
expected
=
json
.
load
(
f
)
expected
[
"state"
]
=
{
"items"
:
{
...
...
@@ -148,10 +155,17 @@ def test_ajax():
},
"finished"
:
True
}
expected
[
"feedback"
][
"finish"
]
=
"Final Feed"
expected
[
"feedback"
][
"finish"
]
=
feedback_finish
get_data
=
json
.
loads
(
block
.
handle
(
'get_data'
,
Mock
())
.
body
)
assert_equals
(
expected
,
get_data
)
def
test_ajax
():
do_ajax
(
'tests/test_data.json'
,
'tests/test_get_data.json'
)
def
test_html_ajax
():
do_ajax
(
'tests/test_html_data.json'
,
'tests/test_get_html_data.json'
)
def
test_ajax_solve_and_reset
():
block
=
make_block
()
...
...
tests/test_get_html_data.json
0 → 100644
View file @
5d0ac94a
{
"zones"
:
[
{
"index"
:
1
,
"width"
:
200
,
"title"
:
"Zone <i>A</i>"
,
"height"
:
100
,
"y"
:
"200"
,
"x"
:
"100"
,
"id"
:
"zone-1"
},
{
"index"
:
2
,
"width"
:
200
,
"title"
:
"Zone <b>B</b>"
,
"height"
:
100
,
"y"
:
0
,
"x"
:
0
,
"id"
:
"zone-2"
}
],
"items"
:
[
{
"displayName"
:
"<b>A</b>"
,
"backgroundImage"
:
""
,
"id"
:
0
,
"size"
:
{
"width"
:
"190px"
,
"height"
:
"auto"
}
},
{
"displayName"
:
"<i>B</i>"
,
"backgroundImage"
:
""
,
"id"
:
1
,
"size"
:
{
"width"
:
"190px"
,
"height"
:
"auto"
}
},
{
"displayName"
:
"X"
,
"backgroundImage"
:
""
,
"id"
:
2
,
"size"
:
{
"width"
:
"100px"
,
"height"
:
"100px"
}
},
{
"displayName"
:
""
,
"backgroundImage"
:
"http://i1.kym-cdn.com/entries/icons/square/000/006/151/tumblr_lltzgnHi5F1qzib3wo1_400.jpg"
,
"id"
:
3
,
"size"
:
{
"width"
:
"190px"
,
"height"
:
"auto"
}
}
],
"state"
:
{
"items"
:
{},
"finished"
:
false
},
"feedback"
:
{
"start"
:
"Intro Feed"
},
"targetImg"
:
"http://i0.kym-cdn.com/photos/images/newsfeed/000/030/404/1260585284155.png"
}
tests/test_html_data.json
0 → 100644
View file @
5d0ac94a
{
"zones"
:
[
{
"index"
:
1
,
"width"
:
200
,
"title"
:
"Zone <i>A</i>"
,
"height"
:
100
,
"y"
:
"200"
,
"x"
:
"100"
,
"id"
:
"zone-1"
},
{
"index"
:
2
,
"width"
:
200
,
"title"
:
"Zone <b>B</b>"
,
"height"
:
100
,
"y"
:
0
,
"x"
:
0
,
"id"
:
"zone-2"
}
],
"items"
:
[
{
"displayName"
:
"<b>A</b>"
,
"feedback"
:
{
"incorrect"
:
"No <b>A</b>"
,
"correct"
:
"Yes <b>A</b>"
},
"zone"
:
"Zone <i>A</i>"
,
"backgroundImage"
:
""
,
"id"
:
0
,
"size"
:
{
"width"
:
"190px"
,
"height"
:
"auto"
}
},
{
"displayName"
:
"<i>B</i>"
,
"feedback"
:
{
"incorrect"
:
"No <i>B</i>"
,
"correct"
:
"Yes <i>B</i>"
},
"zone"
:
"Zone <b>B</b>"
,
"backgroundImage"
:
""
,
"id"
:
1
,
"size"
:
{
"width"
:
"190px"
,
"height"
:
"auto"
}
},
{
"displayName"
:
"X"
,
"feedback"
:
{
"incorrect"
:
""
,
"correct"
:
""
},
"zone"
:
"none"
,
"backgroundImage"
:
""
,
"id"
:
2
,
"size"
:
{
"width"
:
"100px"
,
"height"
:
"100px"
}
},
{
"displayName"
:
""
,
"feedback"
:
{
"incorrect"
:
""
,
"correct"
:
""
},
"zone"
:
"none"
,
"backgroundImage"
:
"http://i1.kym-cdn.com/entries/icons/square/000/006/151/tumblr_lltzgnHi5F1qzib3wo1_400.jpg"
,
"id"
:
3
,
"size"
:
{
"width"
:
"190px"
,
"height"
:
"auto"
}
}
],
"state"
:
{
"items"
:
{},
"finished"
:
true
},
"feedback"
:
{
"start"
:
"Intro Feed"
,
"finish"
:
"Final <b>Feed</b>"
},
"targetImg"
:
"http://i0.kym-cdn.com/photos/images/newsfeed/000/030/404/1260585284155.png"
}
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