Commit 33f6d3b8 by Jay Zoldak

Address code review comments

parent 751994b9
......@@ -225,7 +225,18 @@ def i_enabled_the_advanced_module(step, module):
@world.absorb
def add_unit():
def create_course_with_unit():
"""
Prepare for tests by creating a course with a section, subsection, and unit.
Performs the following:
Clear out all courseware
Create a course with a section, subsection, and unit
Create a user and make that user a course author
Log the user into studio
Open the course from the dashboard
Expand the section and click on the New Unit link
The end result is the page where the user is editing the new unit
"""
world.clear_courses()
course = world.CourseFactory.create()
world.scenario_dict['COURSE'] = course
......@@ -233,7 +244,8 @@ def add_unit():
world.ItemFactory.create(
parent_location=section.location,
category='sequential',
display_name='Subsection One',)
display_name='Subsection One',
)
user = create_studio_user(is_staff=False)
add_course_author(user, course)
......@@ -255,7 +267,7 @@ def add_unit():
@step('I have clicked the new unit button$')
@step(u'I am in Studio editing a new unit$')
def edit_new_unit(step):
add_unit()
create_course_with_unit()
@step('the save notification button is disabled')
......
......@@ -34,7 +34,7 @@ def add_a_multi_step_component(step, is_advanced, category):
step=step,
category='{}'.format(category.lower()),
component_type=step_hash['Component'],
is_advanced=is_advanced,
is_advanced=bool(is_advanced),
)
......
......@@ -41,6 +41,29 @@ def click_new_component_button(step, component_button_css):
world.css_click(component_button_css)
def _click_advanced():
css = 'ul.problem-type-tabs a[href="#tab2"]'
world.css_click(css)
my_css = 'ul.problem-type-tabs li.ui-state-active a[href="#tab2"]'
assert(world.css_find(my_css))
def _find_matching_link(category, component_type):
"""
Find the link with the specified text. There should be one and only one.
"""
# The tab shows links for the given category
links = world.css_find('div.new-component-{} a'.format(category))
# Find the link whose text matches what you're looking for
matched_links = [link for link in links if link.text == component_type]
# There should be one and only one
assert_equal(len(matched_links), 1)
return matched_links[0]
def click_component_from_menu(category, component_type, is_advanced):
"""
Creates a component for a category with more
......@@ -49,39 +72,19 @@ def click_component_from_menu(category, component_type, is_advanced):
the Advanced tab.
The component_type is the link text, e.g. "Blank Common Problem"
"""
def click_advanced():
css = 'ul.problem-type-tabs a[href="#tab2"]'
world.css_click(css)
my_css = 'ul.problem-type-tabs li.ui-state-active a[href="#tab2"]'
assert(world.css_find(my_css))
# True, not None or False
if is_advanced:
# Sometimes this click does not work if you go too fast.
world.retry_on_exception(click_advanced, max_attempts=5, ignored_exceptions=AssertionError)
def find_matching_link():
"""
Find the link with the specified text. There should be one and only one.
"""
# The tab shows links for the given category
links = world.css_find('div.new-component-{} a'.format(category))
# Find the link whose text matches what you're looking for
matched_links = [link for link in links if link.text == component_type]
# There should be one and only one
assert_equal(len(matched_links), 1)
return matched_links[0]
def click_link():
link.click()
world.retry_on_exception(_click_advanced,
ignored_exceptions=AssertionError)
# Retry this in case the list is empty because you tried too fast.
link = world.retry_on_exception(func=find_matching_link, ignored_exceptions=AssertionError)
link = world.retry_on_exception(
lambda: _find_matching_link(category, component_type),
ignored_exceptions=AssertionError
)
# Wait for the link to be clickable. If you go too fast it is not.
world.retry_on_exception(click_link)
world.retry_on_exception(lambda: link.click())
@world.absorb
......
......@@ -6,7 +6,7 @@ from lettuce import world, step
@step('I have created a Discussion Tag$')
def i_created_discussion_tag(step):
world.add_unit()
world.create_course_with_unit()
world.create_component_instance(
step=step,
category='discussion',
......
......@@ -6,7 +6,7 @@ from lettuce import world, step
@step('I have created a Blank HTML Page$')
def i_created_blank_html_page(step):
world.add_unit()
world.create_course_with_unit()
world.create_component_instance(
step=step,
category='html',
......@@ -21,7 +21,7 @@ def i_see_only_the_html_display_name(step):
@step('I have created an E-text Written in LaTeX$')
def i_created_etext_in_latex(step):
world.add_unit()
world.create_course_with_unit()
world.create_component_instance(
step=step,
category='html',
......
......@@ -17,7 +17,7 @@ SHOW_ANSWER = "Show Answer"
@step('I have created a Blank Common Problem$')
def i_created_blank_common_problem(step):
world.add_unit()
world.create_course_with_unit()
world.create_component_instance(
step=step,
category='problem',
......@@ -166,7 +166,7 @@ def cancel_does_not_save_changes(step):
@step('I have created a LaTeX Problem')
def create_latex_problem(step):
world.add_unit()
world.create_course_with_unit()
world.create_component_instance(
step=step,
category='problem',
......
......@@ -12,7 +12,7 @@ BUTTONS = {
@step('I have created a Video component$')
def i_created_a_video_component(step):
world.add_unit()
world.create_course_with_unit()
world.create_component_instance(
step=step,
category='video',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment