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
3e1567d8
Commit
3e1567d8
authored
Sep 29, 2014
by
E. Kolpakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Further improved test scenario discovery
Added plain text tests (broken)
parent
5092ba6e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
28 deletions
+60
-28
tests/integration/test_base.py
+13
-6
tests/integration/test_block_contents_plain.py
+19
-0
tests/integration/test_block_parameters.py
+3
-8
tests/utils.py
+25
-14
No files found.
tests/integration/test_base.py
View file @
3e1567d8
...
...
@@ -13,17 +13,14 @@ class BaseIntegrationTest(SeleniumTest):
def
setUp
(
self
):
super
(
BaseIntegrationTest
,
self
)
.
setUp
()
# Use test scenarios
self
.
browser
.
get
(
self
.
live_server_url
)
# Needed to load tests once
self
.
browser
.
get
(
self
.
live_server_url
)
# Needed to load scenarios once
scenarios
.
SCENARIOS
.
clear
()
for
identifier
,
title
,
xml
in
self
.
_get_scenarios_for_test
():
scenarios
.
add_xml_scenario
(
identifier
,
title
,
xml
)
self
.
addCleanup
(
scenarios
.
remove_scenario
,
identifier
)
# Suzy opens the browser to visit the workbench
self
.
browser
.
get
(
self
.
live_server_url
)
# She knows it's the site by the header
header1
=
self
.
browser
.
find_element_by_css_selector
(
'h1'
)
self
.
assertEqual
(
header1
.
text
,
'XBlock scenarios'
)
...
...
@@ -40,4 +37,14 @@ class BaseIntegrationTest(SeleniumTest):
return
self
.
browser
.
find_element_by_css_selector
(
css_selector
)
def
get_element_html
(
self
,
element
):
return
element
.
get_attribute
(
'innerHTML'
)
.
strip
()
\ No newline at end of file
return
element
.
get_attribute
(
'innerHTML'
)
.
strip
()
class
SingleScenarioIntegrationTest
(
BaseIntegrationTest
):
def
setUp
(
self
):
super
(
SingleScenarioIntegrationTest
,
self
)
.
setUp
()
def
_get_scenarios_for_test
(
self
):
identifier
,
title
,
scenario
=
self
.
_get_scenario_for_test
()
self
.
_page_title
=
title
return
[(
identifier
,
title
,
scenario
)]
\ No newline at end of file
tests/integration/test_block_contents_plain.py
0 → 100644
View file @
3e1567d8
from
tests.integration.test_base
import
SingleScenarioIntegrationTest
from
tests.utils
import
load_scenario_from_file
class
TestBlockContentsPlain
(
SingleScenarioIntegrationTest
):
def
_get_scenario_for_test
(
self
):
return
load_scenario_from_file
(
'integration/data/drag_and_drop-whats_up.json'
)
def
test_check_item_labels
(
self
):
page
=
self
.
go_to_page
(
self
.
_page_title
)
items_container
=
page
.
find_element_by_css_selector
(
'ul.items'
)
items
=
items_container
.
find_elements_by_css_selector
(
'li.option'
)
self
.
assertEqual
(
len
(
items
),
3
)
self
.
assertEqual
(
items
[
0
]
.
text
,
'A'
)
self
.
assertEqual
(
items
[
1
]
.
text
,
'B'
)
self
.
assertEqual
(
items
[
2
]
.
text
,
'X'
)
\ No newline at end of file
tests/integration/test_block_parameters.py
View file @
3e1567d8
from
xml.sax.saxutils
import
escape
from
nose_parameterized
import
parameterized
from
tests.utils
import
make_scenario_from_data
from
workbench
import
scenarios
from
tests.integration.test_base
import
BaseIntegrationTest
...
...
@@ -15,14 +16,8 @@ class TestBlockParameters(BaseIntegrationTest):
def
test_block_parameters
(
self
,
_
,
display_name
,
question_text
):
const_page_name
=
"Test block parameters"
const_page_id
=
'test_block_title'
scenarios
.
add_xml_scenario
(
const_page_id
,
const_page_name
,
"""
<vertical_demo><drag-and-drop-v2
display_name='{display_name}' question_text='{question_text}'
/></vertical_demo>
"""
.
format
(
display_name
=
escape
(
display_name
),
question_text
=
escape
(
question_text
))
)
scenario_xml
=
make_scenario_from_data
(
None
,
display_name
,
question_text
,
False
)
scenarios
.
add_xml_scenario
(
const_page_id
,
const_page_name
,
scenario_xml
)
self
.
addCleanup
(
scenarios
.
remove_scenario
,
const_page_id
)
page
=
self
.
go_to_page
(
const_page_name
)
...
...
tests/utils.py
View file @
3e1567d8
import
os
import
json
import
pkg_resources
from
xml.sax.saxutils
import
escape
def
load_resource
(
resource_path
):
"""
Gets the content of a resource
...
...
@@ -11,15 +14,17 @@ def load_resource(resource_path):
def
make_scenario_from_data
(
data
,
display_name
,
question_text
,
completed
):
return
"""
<vertical_demo>
<drag-and-drop-v2
display_name='{display_name}' question_text='{question_text}'
weight='1' completed='{completed}'
data='{data}'
/>
</vertical_demo>
"""
.
format
(
data
=
escape
(
data
),
display_name
=
display_name
,
question_text
=
question_text
,
completed
=
completed
)
parameters
=
{
'data'
:
data
,
'display_name'
:
display_name
,
'question_text'
:
question_text
,
'completed'
:
completed
,
'weight'
:
'1'
}
attributes
=
[
"{0}='{1}'"
.
format
(
key
,
escape
(
value
))
for
key
,
value
in
parameters
.
items
()
if
value
]
attributes_str
=
" "
.
join
(
attributes
)
return
"""<vertical_demo><drag-and-drop-v2 {attrs}/></vertical_demo>"""
.
format
(
attrs
=
attributes_str
)
def
format_name
(
raw_name
):
return
raw_name
.
replace
(
'_'
,
' '
)
.
title
()
...
...
@@ -38,7 +43,7 @@ def get_scenarios_from_path(scenarios_path, include_identifier=False):
for
template
in
os
.
listdir
(
scenarios_fullpath
):
if
not
template
.
endswith
(
'.json'
):
continue
identifier
,
title
,
scenario
=
get_scenario_from_file
(
template
,
scenarios_path
)
identifier
,
title
,
scenario
=
get_scenario_from_file
(
scenarios_path
,
template
)
if
not
include_identifier
:
scenarios
.
append
((
title
,
scenario
))
else
:
...
...
@@ -47,12 +52,13 @@ def get_scenarios_from_path(scenarios_path, include_identifier=False):
return
scenarios
def
get_scenario_from_file
(
filename
,
scenarios_path
):
def
get_scenario_from_file
(
scenarios_path
,
filename
):
identifier
=
filename
[:
-
5
]
block_title
,
question_text
=
map
(
format_name
,
identifier
.
split
(
'-'
))
title
=
identifier
.
replace
(
'_'
,
' '
)
.
replace
(
'-'
,
' '
)
.
title
()
scenario_file
=
os
.
path
.
join
(
scenarios_path
,
filename
)
scenario
=
make_scenario_from_data
(
scenario_file
,
block_title
,
question_text
,
False
)
scenario_data
=
json
.
loads
(
load_resource
(
scenario_file
))
scenario
=
make_scenario_from_data
(
scenario_data
,
block_title
,
question_text
,
False
)
return
identifier
,
title
,
scenario
...
...
@@ -60,4 +66,10 @@ def load_scenarios_from_path(scenarios_path):
"""
Load all xml files contained in a specified directory, as workbench scenarios
"""
return
get_scenarios_from_path
(
scenarios_path
,
include_identifier
=
True
)
\ No newline at end of file
return
get_scenarios_from_path
(
scenarios_path
,
include_identifier
=
True
)
def
load_scenario_from_file
(
filename
):
scenario_path
,
template
=
os
.
path
.
split
(
filename
)
return
get_scenario_from_file
(
scenario_path
,
template
)
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