From d9716a72494a6a3933bc9202a429c99371b4cb60 Mon Sep 17 00:00:00 2001 From: Peter Fogg Date: Mon, 1 Jul 2013 12:32:37 -0400 Subject: [PATCH] Update acceptance tests for course settings. --- .../contentstore/features/common.py | 34 +++++++++------- .../features/course-settings.feature | 17 +++++++- .../contentstore/features/course-settings.py | 40 +++++++++++++------ .../contentstore/features/grading.feature | 20 +++++----- .../contentstore/features/grading.py | 8 ++++ 5 files changed, 80 insertions(+), 39 deletions(-) diff --git a/cms/djangoapps/contentstore/features/common.py b/cms/djangoapps/contentstore/features/common.py index d7ac27089e..37daebabd9 100644 --- a/cms/djangoapps/contentstore/features/common.py +++ b/cms/djangoapps/contentstore/features/common.py @@ -56,34 +56,40 @@ def i_press_the_category_delete_icon(_step, category): def i_have_opened_a_new_course(_step): open_new_course() + @step(u'I press the "([^"]*)" notification button$') -def press_the_notification_button(step, name): +def press_the_notification_button(_step, name): css = 'a.action-%s' % name.lower() - # Save was clicked if either the save notification bar is gone, or we have a error notification - # overlaying it (expected in the case of typing Object into display_name). - def save_clicked(): + # The button was clicked if either the notification bar is gone, + # or we see an error overlaying it (expected for invalid inputs). + def button_clicked(): confirmation_dismissed = world.is_css_not_present('.is-shown.wrapper-notification-warning') error_showing = world.is_css_present('.is-shown.wrapper-notification-error') return confirmation_dismissed or error_showing - assert_true(world.css_click(css, success_condition=save_clicked), 'Save button not clicked after 5 attempts.') + assert_true(world.css_click(css, success_condition=button_clicked), '%s button not clicked after 5 attempts.' % name) @step('I change the "(.*)" field to "(.*)"$') -def i_change_field_to_value(step, field, value): - # Special casing this because we should type into CodeMirror +def i_change_field_to_value(_step, field, value): field_css = '#%s' % '-'.join([s.lower() for s in field.split()]) - if field_css == '#course-overview': - type_in_codemirror(0, value) - else: - ele = world.css_find(field_css).first - ele.fill(value) - ele._element.send_keys(Keys.ENTER) + ele = world.css_find(field_css).first + ele.fill(value) + ele._element.send_keys(Keys.ENTER) @step('I reset the database') -def reset_the_db(step): +def reset_the_db(_step): + """ + When running Lettuce tests using examples (i.e. "Confirmation is + shown on save" in course-settings.feature), the normal hooks + aren't called between examples. reset_data should run before each + scenario to flush the test database. When this doesn't happen we + get errors due to trying to insert a non-unique entry. So instead, + we delete the database manually. This has the effect of removing + any users and courses that have been created during the test run. + """ reset_data(None) diff --git a/cms/djangoapps/contentstore/features/course-settings.feature b/cms/djangoapps/contentstore/features/course-settings.feature index 9307cbe719..cafedd6d97 100644 --- a/cms/djangoapps/contentstore/features/course-settings.feature +++ b/cms/djangoapps/contentstore/features/course-settings.feature @@ -32,9 +32,15 @@ Feature: Course Settings Given I have set course dates And I press the "Save" notification button When I change fields - And I press the "Cancel" notification button Then I do not see the new changes persisted on refresh + Scenario: Settings are reset on cancel + Given I have set course dates + And I press the "Save" notification button + When I change fields + And I press the "Cancel" notification button + Then I do not see the changes + Scenario: Confirmation is shown on save Given I have opened a new course in Studio When I select Schedule and Details @@ -49,6 +55,13 @@ Feature: Course Settings Examples: | field | value | | Course Start Time | 11:00 | - | Course Overview |

Overview

| | Course Introduction Video | 4r7wHMg5Yjg | | Course Effort | 200:00 | + + # Special case because we have to type in code mirror + Scenario: Changes in Course Overview show a confirmation + Given I have opened a new course in Studio + When I select Schedule and Details + And I change the course overview + And I press the "Save" notification button + Then I see a confirmation that my changes have been saved diff --git a/cms/djangoapps/contentstore/features/course-settings.py b/cms/djangoapps/contentstore/features/course-settings.py index 85a11ec9ec..53a3fa7870 100644 --- a/cms/djangoapps/contentstore/features/course-settings.py +++ b/cms/djangoapps/contentstore/features/course-settings.py @@ -5,7 +5,6 @@ from lettuce import world, step from terrain.steps import reload_the_page from selenium.webdriver.common.keys import Keys from common import type_in_codemirror -import time from nose.tools import assert_true, assert_false, assert_equal @@ -52,16 +51,7 @@ def test_and_i_set_course_dates(step): @step('Then I see the set dates on refresh$') def test_then_i_see_the_set_dates_on_refresh(step): reload_the_page(step) - verify_date_or_time(COURSE_START_DATE_CSS, '12/20/2013') - verify_date_or_time(COURSE_END_DATE_CSS, '12/26/2013') - verify_date_or_time(ENROLLMENT_START_DATE_CSS, '12/01/2013') - verify_date_or_time(ENROLLMENT_END_DATE_CSS, '12/10/2013') - - verify_date_or_time(COURSE_START_TIME_CSS, DUMMY_TIME) - # Unset times get set to 12 AM once the corresponding date has been set. - verify_date_or_time(COURSE_END_TIME_CSS, DEFAULT_TIME) - verify_date_or_time(ENROLLMENT_START_TIME_CSS, DEFAULT_TIME) - verify_date_or_time(ENROLLMENT_END_TIME_CSS, DUMMY_TIME) + i_see_the_set_dates() @step('And I clear all the dates except start$') @@ -143,10 +133,20 @@ def test_i_change_fields(step): @step('I do not see the new changes persisted on refresh$') def test_changes_not_shown_on_refresh(step): - reload_the_page(step) step.then('Then I see the set dates on refresh') +@step('I do not see the changes') +def test_i_do_not_see_changes(_step): + i_see_the_set_dates() + + +@step('I change the course overview') +def test_change_course_overview(_step): + type_in_codemirror(0, "

Overview

") + + + ############### HELPER METHODS #################### def set_date_or_time(css, date_or_time): """ @@ -163,3 +163,19 @@ def verify_date_or_time(css, date_or_time): Verifies date or time field. """ assert_equal(date_or_time, world.css_find(css).first.value) + + +def i_see_the_set_dates(): + """ + Ensure that each field has the value set in `test_and_i_set_course_dates`. + """ + verify_date_or_time(COURSE_START_DATE_CSS, '12/20/2013') + verify_date_or_time(COURSE_END_DATE_CSS, '12/26/2013') + verify_date_or_time(ENROLLMENT_START_DATE_CSS, '12/01/2013') + verify_date_or_time(ENROLLMENT_END_DATE_CSS, '12/10/2013') + + verify_date_or_time(COURSE_START_TIME_CSS, DUMMY_TIME) + # Unset times get set to 12 AM once the corresponding date has been set. + verify_date_or_time(COURSE_END_TIME_CSS, DEFAULT_TIME) + verify_date_or_time(ENROLLMENT_START_TIME_CSS, DEFAULT_TIME) + verify_date_or_time(ENROLLMENT_END_TIME_CSS, DUMMY_TIME) diff --git a/cms/djangoapps/contentstore/features/grading.feature b/cms/djangoapps/contentstore/features/grading.feature index 1526c17d9f..303cf5db9d 100644 --- a/cms/djangoapps/contentstore/features/grading.feature +++ b/cms/djangoapps/contentstore/features/grading.feature @@ -60,22 +60,20 @@ Feature: Course Grading And I have populated the course And I am viewing the grading settings When I change assignment type "Homework" to "New Type" - And I press the "Cancel" notification button Then I do not see the changes persisted on refresh + Scenario: Settings are reset on cancel + Given I have opened a new course in Studio + And I have populated the course + And I am viewing the grading settings + When I change assignment type "Homework" to "New Type" + And I press the "Cancel" notification button + Then I see the assignment type "Homework" + Scenario: Confirmation is shown on save Given I have opened a new course in Studio And I have populated the course And I am viewing the grading settings - When I change the "" field to "" + When I change assignment type "Homework" to "New Type" And I press the "Save" notification button Then I see a confirmation that my changes have been saved - # Lettuce hooks don't get called between each example, so we need - # to run the before.each_scenario hook manually to avoid database - # errors. - And I reset the database - - Examples: - | field | value | - | Course Grading Graceperiod | 1:00 | - | Course Grading Assignment Name | New Assignment Name | diff --git a/cms/djangoapps/contentstore/features/grading.py b/cms/djangoapps/contentstore/features/grading.py index ae672c78a4..504dcf7ef3 100644 --- a/cms/djangoapps/contentstore/features/grading.py +++ b/cms/djangoapps/contentstore/features/grading.py @@ -112,6 +112,14 @@ def changes_not_persisted(step): assert(ele.value == 'Homework') +@step(u'I see the assignment type "(.*)"$') +def i_see_the_assignment_type(_step, name): + assignment_css = '#course-grading-assignment-name' + assignments = world.css_find(assignment_css) + types = [ele['value'] for ele in assignments] + assert name in types + + def get_type_index(name): name_id = '#course-grading-assignment-name' f = world.css_find(name_id)