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
238bbe21
Commit
238bbe21
authored
Jan 07, 2016
by
Tim Krones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix existing tests.
parent
b426335e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
18 deletions
+35
-18
drag_and_drop_v2/drag_and_drop_v2.py
+2
-2
tests/unit/test_advanced.py
+22
-6
tests/unit/test_basics.py
+11
-10
No files found.
drag_and_drop_v2/drag_and_drop_v2.py
View file @
238bbe21
...
@@ -228,7 +228,7 @@ class DragAndDropBlock(XBlock):
...
@@ -228,7 +228,7 @@ class DragAndDropBlock(XBlock):
is_correct
=
False
is_correct
=
False
is_correct_location
=
False
is_correct_location
=
False
if
'input'
in
attempt
:
if
'input'
in
attempt
:
# Student submitted numerical value for item
state
=
self
.
_get_item_state
()
.
get
(
str
(
item
[
'id'
]))
state
=
self
.
_get_item_state
()
.
get
(
str
(
item
[
'id'
]))
if
state
:
if
state
:
state
[
'input'
]
=
attempt
[
'input'
]
state
[
'input'
]
=
attempt
[
'input'
]
...
@@ -238,7 +238,7 @@ class DragAndDropBlock(XBlock):
...
@@ -238,7 +238,7 @@ class DragAndDropBlock(XBlock):
feedback
=
item
[
'feedback'
][
'correct'
]
feedback
=
item
[
'feedback'
][
'correct'
]
else
:
else
:
is_correct
=
False
is_correct
=
False
elif
item
[
'zone'
]
==
attempt
[
'zone'
]:
elif
item
[
'zone'
]
==
attempt
[
'zone'
]:
# Student placed item in zone
is_correct_location
=
True
is_correct_location
=
True
if
'inputOptions'
in
item
:
if
'inputOptions'
in
item
:
# Input value will have to be provided for the item.
# Input value will have to be provided for the item.
...
...
tests/unit/test_advanced.py
View file @
238bbe21
...
@@ -87,6 +87,7 @@ class BaseDragAndDropAjaxFixture(TestCaseMixin):
...
@@ -87,6 +87,7 @@ class BaseDragAndDropAjaxFixture(TestCaseMixin):
})
})
def
test_do_attempt_with_input
(
self
):
def
test_do_attempt_with_input
(
self
):
# Drop item that requires numerical input
data
=
{
"val"
:
1
,
"zone"
:
self
.
ZONE_2
,
"x_percent"
:
"0
%
"
,
"y_percent"
:
"85
%
"
}
data
=
{
"val"
:
1
,
"zone"
:
self
.
ZONE_2
,
"x_percent"
:
"0
%
"
,
"y_percent"
:
"85
%
"
}
res
=
self
.
call_handler
(
'do_attempt'
,
data
)
res
=
self
.
call_handler
(
'do_attempt'
,
data
)
self
.
assertEqual
(
res
,
{
self
.
assertEqual
(
res
,
{
...
@@ -99,13 +100,16 @@ class BaseDragAndDropAjaxFixture(TestCaseMixin):
...
@@ -99,13 +100,16 @@ class BaseDragAndDropAjaxFixture(TestCaseMixin):
expected_state
=
{
expected_state
=
{
'items'
:
{
'items'
:
{
"1"
:
{
"x_percent"
:
"0
%
"
,
"y_percent"
:
"85
%
"
,
"correct_input"
:
False
},
"1"
:
{
"x_percent"
:
"0
%
"
,
"y_percent"
:
"85
%
"
,
"correct_input"
:
False
,
"zone"
:
self
.
ZONE_2
,
},
},
},
'finished'
:
False
,
'finished'
:
False
,
'overall_feedback'
:
self
.
initial_feedback
(),
'overall_feedback'
:
self
.
initial_feedback
(),
}
}
self
.
assertEqual
(
expected_state
,
self
.
call_handler
(
'get_user_state'
,
method
=
"GET"
))
self
.
assertEqual
(
expected_state
,
self
.
call_handler
(
'get_user_state'
,
method
=
"GET"
))
# Submit incorrect value
data
=
{
"val"
:
1
,
"input"
:
"250"
}
data
=
{
"val"
:
1
,
"input"
:
"250"
}
res
=
self
.
call_handler
(
'do_attempt'
,
data
)
res
=
self
.
call_handler
(
'do_attempt'
,
data
)
self
.
assertEqual
(
res
,
{
self
.
assertEqual
(
res
,
{
...
@@ -118,13 +122,17 @@ class BaseDragAndDropAjaxFixture(TestCaseMixin):
...
@@ -118,13 +122,17 @@ class BaseDragAndDropAjaxFixture(TestCaseMixin):
expected_state
=
{
expected_state
=
{
'items'
:
{
'items'
:
{
"1"
:
{
"x_percent"
:
"0
%
"
,
"y_percent"
:
"85
%
"
,
"input"
:
"250"
,
"correct_input"
:
False
},
"1"
:
{
"x_percent"
:
"0
%
"
,
"y_percent"
:
"85
%
"
,
"correct_input"
:
False
,
"zone"
:
self
.
ZONE_2
,
"input"
:
"250"
,
},
},
},
'finished'
:
False
,
'finished'
:
False
,
'overall_feedback'
:
self
.
initial_feedback
(),
'overall_feedback'
:
self
.
initial_feedback
(),
}
}
self
.
assertEqual
(
expected_state
,
self
.
call_handler
(
'get_user_state'
,
method
=
"GET"
))
self
.
assertEqual
(
expected_state
,
self
.
call_handler
(
'get_user_state'
,
method
=
"GET"
))
# Submit correct value
data
=
{
"val"
:
1
,
"input"
:
"103"
}
data
=
{
"val"
:
1
,
"input"
:
"103"
}
res
=
self
.
call_handler
(
'do_attempt'
,
data
)
res
=
self
.
call_handler
(
'do_attempt'
,
data
)
self
.
assertEqual
(
res
,
{
self
.
assertEqual
(
res
,
{
...
@@ -137,7 +145,10 @@ class BaseDragAndDropAjaxFixture(TestCaseMixin):
...
@@ -137,7 +145,10 @@ class BaseDragAndDropAjaxFixture(TestCaseMixin):
expected_state
=
{
expected_state
=
{
'items'
:
{
'items'
:
{
"1"
:
{
"x_percent"
:
"0
%
"
,
"y_percent"
:
"85
%
"
,
"input"
:
"103"
,
"correct_input"
:
True
},
"1"
:
{
"x_percent"
:
"0
%
"
,
"y_percent"
:
"85
%
"
,
"correct_input"
:
True
,
"zone"
:
self
.
ZONE_2
,
"input"
:
"103"
,
},
},
},
'finished'
:
False
,
'finished'
:
False
,
'overall_feedback'
:
self
.
initial_feedback
(),
'overall_feedback'
:
self
.
initial_feedback
(),
...
@@ -177,7 +188,7 @@ class BaseDragAndDropAjaxFixture(TestCaseMixin):
...
@@ -177,7 +188,7 @@ class BaseDragAndDropAjaxFixture(TestCaseMixin):
expected_state
=
{
expected_state
=
{
"items"
:
{
"items"
:
{
"0"
:
{
"x_percent"
:
"33
%
"
,
"y_percent"
:
"11
%
"
,
"correct_input"
:
True
}
"0"
:
{
"x_percent"
:
"33
%
"
,
"y_percent"
:
"11
%
"
,
"correct_input"
:
True
,
"zone"
:
self
.
ZONE_1
}
},
},
"finished"
:
False
,
"finished"
:
False
,
'overall_feedback'
:
self
.
initial_feedback
(),
'overall_feedback'
:
self
.
initial_feedback
(),
...
@@ -198,8 +209,13 @@ class BaseDragAndDropAjaxFixture(TestCaseMixin):
...
@@ -198,8 +209,13 @@ class BaseDragAndDropAjaxFixture(TestCaseMixin):
expected_state
=
{
expected_state
=
{
"items"
:
{
"items"
:
{
"0"
:
{
"x_percent"
:
"33
%
"
,
"y_percent"
:
"11
%
"
,
"correct_input"
:
True
},
"0"
:
{
"1"
:
{
"x_percent"
:
"22
%
"
,
"y_percent"
:
"22
%
"
,
"input"
:
"99"
,
"correct_input"
:
True
}
"x_percent"
:
"33
%
"
,
"y_percent"
:
"11
%
"
,
"correct_input"
:
True
,
"zone"
:
self
.
ZONE_1
,
},
"1"
:
{
"x_percent"
:
"22
%
"
,
"y_percent"
:
"22
%
"
,
"correct_input"
:
True
,
"zone"
:
self
.
ZONE_2
,
"input"
:
"99"
,
}
},
},
"finished"
:
True
,
"finished"
:
True
,
'overall_feedback'
:
self
.
FINAL_FEEDBACK
,
'overall_feedback'
:
self
.
FINAL_FEEDBACK
,
...
...
tests/unit/test_basics.py
View file @
238bbe21
import
unittest
import
unittest
from
drag_and_drop_v2.default_data
import
(
from
drag_and_drop_v2.default_data
import
(
TARGET_IMG_DESCRIPTION
,
START_FEEDBACK
,
FINISH_FEEDBACK
,
DEFAULT_DATA
TARGET_IMG_DESCRIPTION
,
TOP_ZONE_TITLE
,
MIDDLE_ZONE_TITLE
,
BOTTOM_ZONE_TITLE
,
START_FEEDBACK
,
FINISH_FEEDBACK
,
DEFAULT_DATA
)
)
from
..utils
import
make_block
,
TestCaseMixin
from
..utils
import
make_block
,
TestCaseMixin
...
@@ -62,25 +63,25 @@ class BasicTests(TestCaseMixin, unittest.TestCase):
...
@@ -62,25 +63,25 @@ class BasicTests(TestCaseMixin, unittest.TestCase):
assert_user_state_empty
()
assert_user_state_empty
()
# Drag three items into the correct spot:
# Drag three items into the correct spot:
data
=
{
"val"
:
0
,
"zone"
:
"The Top Zone"
,
"x_percent"
:
"33
%
"
,
"y_percent"
:
"11
%
"
}
data
=
{
"val"
:
0
,
"zone"
:
TOP_ZONE_TITLE
,
"x_percent"
:
"33
%
"
,
"y_percent"
:
"11
%
"
}
self
.
call_handler
(
'do_attempt'
,
data
)
self
.
call_handler
(
'do_attempt'
,
data
)
data
=
{
"val"
:
1
,
"zone"
:
"The Middle Zone"
,
"x_percent"
:
"67
%
"
,
"y_percent"
:
"80
%
"
}
data
=
{
"val"
:
1
,
"zone"
:
MIDDLE_ZONE_TITLE
,
"x_percent"
:
"67
%
"
,
"y_percent"
:
"80
%
"
}
self
.
call_handler
(
'do_attempt'
,
data
)
self
.
call_handler
(
'do_attempt'
,
data
)
data
=
{
"val"
:
2
,
"zone"
:
"The Bottom Zone"
,
"x_percent"
:
"99
%
"
,
"y_percent"
:
"95
%
"
}
data
=
{
"val"
:
2
,
"zone"
:
BOTTOM_ZONE_TITLE
,
"x_percent"
:
"99
%
"
,
"y_percent"
:
"95
%
"
}
self
.
call_handler
(
'do_attempt'
,
data
)
self
.
call_handler
(
'do_attempt'
,
data
)
# Check the result:
# Check the result:
self
.
assertTrue
(
self
.
block
.
completed
)
self
.
assertTrue
(
self
.
block
.
completed
)
self
.
assertEqual
(
self
.
block
.
item_state
,
{
self
.
assertEqual
(
self
.
block
.
item_state
,
{
'0'
:
{
'x_percent'
:
'33
%
'
,
'y_percent'
:
'11
%
'
},
'0'
:
{
'x_percent'
:
'33
%
'
,
'y_percent'
:
'11
%
'
,
'zone'
:
TOP_ZONE_TITLE
},
'1'
:
{
'x_percent'
:
'67
%
'
,
'y_percent'
:
'80
%
'
},
'1'
:
{
'x_percent'
:
'67
%
'
,
'y_percent'
:
'80
%
'
,
'zone'
:
MIDDLE_ZONE_TITLE
},
'2'
:
{
'x_percent'
:
'99
%
'
,
'y_percent'
:
'95
%
'
},
'2'
:
{
'x_percent'
:
'99
%
'
,
'y_percent'
:
'95
%
'
,
'zone'
:
BOTTOM_ZONE_TITLE
},
})
})
self
.
assertEqual
(
self
.
call_handler
(
'get_user_state'
),
{
self
.
assertEqual
(
self
.
call_handler
(
'get_user_state'
),
{
'items'
:
{
'items'
:
{
'0'
:
{
'x_percent'
:
'33
%
'
,
'y_percent'
:
'11
%
'
,
'correct_input'
:
True
},
'0'
:
{
'x_percent'
:
'33
%
'
,
'y_percent'
:
'11
%
'
,
'correct_input'
:
True
,
'zone'
:
TOP_ZONE_TITLE
},
'1'
:
{
'x_percent'
:
'67
%
'
,
'y_percent'
:
'80
%
'
,
'correct_input'
:
True
},
'1'
:
{
'x_percent'
:
'67
%
'
,
'y_percent'
:
'80
%
'
,
'correct_input'
:
True
,
'zone'
:
MIDDLE_ZONE_TITLE
},
'2'
:
{
'x_percent'
:
'99
%
'
,
'y_percent'
:
'95
%
'
,
'correct_input'
:
True
},
'2'
:
{
'x_percent'
:
'99
%
'
,
'y_percent'
:
'95
%
'
,
'correct_input'
:
True
,
'zone'
:
BOTTOM_ZONE_TITLE
},
},
},
'finished'
:
True
,
'finished'
:
True
,
'overall_feedback'
:
FINISH_FEEDBACK
,
'overall_feedback'
:
FINISH_FEEDBACK
,
...
...
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