From 862bb3f8bc34ff14618d92f91c5cbb9dbf458928 Mon Sep 17 00:00:00 2001 From: JonahStanley Date: Tue, 4 Jun 2013 11:34:52 -0400 Subject: [PATCH 1/6] Added the beginnings of the navigation tests I still need to refactor the methods but at this point, all tests work --- .../courseware/features/navigation.feature | 27 ++ .../courseware/features/navigation.py | 242 ++++++++++++++++++ 2 files changed, 269 insertions(+) create mode 100644 lms/djangoapps/courseware/features/navigation.feature create mode 100644 lms/djangoapps/courseware/features/navigation.py diff --git a/lms/djangoapps/courseware/features/navigation.feature b/lms/djangoapps/courseware/features/navigation.feature new file mode 100644 index 0000000000..f9cee87c89 --- /dev/null +++ b/lms/djangoapps/courseware/features/navigation.feature @@ -0,0 +1,27 @@ +Feature: Navigate Course + As a student in an edX course + In order to view the course properly + I want to be able to navigate through the content + + Scenario: I can navigate to a section + Given I am viewing a course with multiple sections + When I click on section "2" + Then I see the content of section "2" + + + Scenario: I can navigate to subsections + Given I am viewing a section with multiple subsections + When I click on subsection "2" + Then I see the content of subsection "2" + + Scenario: I can navigate to sequences + Given I am viewing a section with multiple sequences + When I click on sequence "2" + Then I see the content of sequence "2" + + Scenario: I can go back to where I was after I log out and back in + Given I am viewing a course with multiple sections + When I click on section "2" + And I visit the homepage + And I go to the section + Then I should see "You were most recently in Test Section2" somewhere on the page diff --git a/lms/djangoapps/courseware/features/navigation.py b/lms/djangoapps/courseware/features/navigation.py new file mode 100644 index 0000000000..2f7f19f39a --- /dev/null +++ b/lms/djangoapps/courseware/features/navigation.py @@ -0,0 +1,242 @@ +#pylint: disable=C0111 +#pylint: disable=W0621 + +from lettuce import world, step +from django.contrib.auth.models import User +from lettuce.django import django_url +from student.models import CourseEnrollment +from common import course_id +from xmodule.modulestore import Location +from problems_setup import PROBLEM_DICT + +TEST_COURSE_ORG = 'edx' +TEST_COURSE_NAME = 'Test Course' +TEST_SECTION_NAME = 'Test Section' +SUBSECTION_2_LOC = None + + +@step(u'I am viewing a course with multiple sections') +def view_course_multiple_sections(step): + # First clear the modulestore so we don't try to recreate + # the same course twice + # This also ensures that the necessary templates are loaded + world.clear_courses() + + # Create the course + # We always use the same org and display name, + # but vary the course identifier (e.g. 600x or 191x) + course = world.CourseFactory.create(org=TEST_COURSE_ORG, + number="model_course", + display_name=TEST_COURSE_NAME) + + # Add a section to the course to contain problems + section1 = world.ItemFactory.create(parent_location=course.location, + display_name=TEST_SECTION_NAME+"1") + + # Add a section to the course to contain problems + section2 = world.ItemFactory.create(parent_location=course.location, + display_name=TEST_SECTION_NAME+"2") + + world.ItemFactory.create(parent_location=section1.location, + template='i4x://edx/templates/sequential/Empty', + display_name=TEST_SECTION_NAME+"1") + + world.ItemFactory.create(parent_location=section2.location, + template='i4x://edx/templates/sequential/Empty', + display_name=TEST_SECTION_NAME+"2") + + add_problem_to_course_section('model_course', 'multiple choice', section=1) + add_problem_to_course_section('model_course', 'drop down', section=2) + + # Create the user + world.create_user('robot') + u = User.objects.get(username='robot') + + # If the user is not already enrolled, enroll the user. + # TODO: change to factory + CourseEnrollment.objects.get_or_create(user=u, course_id=course_id("model_course")) + + world.log_in('robot', 'test') + chapter_name = (TEST_SECTION_NAME+"1").replace(" ", "_") + section_name = chapter_name + url = django_url('/courses/edx/model_course/Test_Course/courseware/%s/%s' % + (chapter_name, section_name)) + + world.browser.visit(url) + + +@step(u'I am viewing a section with multiple subsections') +def view_course_multiple_subsections(step): + # First clear the modulestore so we don't try to recreate + # the same course twice + # This also ensures that the necessary templates are loaded + world.clear_courses() + + # Create the course + # We always use the same org and display name, + # but vary the course identifier (e.g. 600x or 191x) + course = world.CourseFactory.create(org=TEST_COURSE_ORG, + number="model_course", + display_name=TEST_COURSE_NAME) + + # Add a section to the course to contain problems + section1 = world.ItemFactory.create(parent_location=course.location, + display_name=TEST_SECTION_NAME+"1") + + world.ItemFactory.create(parent_location=section1.location, + template='i4x://edx/templates/sequential/Empty', + display_name=TEST_SECTION_NAME+"1") + + section2 = world.ItemFactory.create(parent_location=section1.location, + display_name=TEST_SECTION_NAME+"2") + + global SUBSECTION_2_LOC + SUBSECTION_2_LOC = section2.location + + + add_problem_to_course_section('model_course', 'multiple choice', section=1) + add_problem_to_course_section('model_course', 'drop down', section=1, subsection=2) + + # Create the user + world.create_user('robot') + u = User.objects.get(username='robot') + + # If the user is not already enrolled, enroll the user. + # TODO: change to factory + CourseEnrollment.objects.get_or_create(user=u, course_id=course_id("model_course")) + + world.log_in('robot', 'test') + chapter_name = (TEST_SECTION_NAME+"1").replace(" ", "_") + section_name = chapter_name + url = django_url('/courses/edx/model_course/Test_Course/courseware/%s/%s' % + (chapter_name, section_name)) + + world.browser.visit(url) + + +@step(u'I am viewing a section with multiple sequences') +def view_course_multiple_sequences(step): + # First clear the modulestore so we don't try to recreate + # the same course twice + # This also ensures that the necessary templates are loaded + world.clear_courses() + + # Create the course + # We always use the same org and display name, + # but vary the course identifier (e.g. 600x or 191x) + course = world.CourseFactory.create(org=TEST_COURSE_ORG, + number="model_course", + display_name=TEST_COURSE_NAME) + + # Add a section to the course to contain problems + section1 = world.ItemFactory.create(parent_location=course.location, + display_name=TEST_SECTION_NAME+"1") + + + world.ItemFactory.create(parent_location=section1.location, + template='i4x://edx/templates/sequential/Empty', + display_name=TEST_SECTION_NAME+"1") + + add_problem_to_course_section('model_course', 'multiple choice', section=1) + add_problem_to_course_section('model_course', 'drop down', section=1) + + # Create the user + world.create_user('robot') + u = User.objects.get(username='robot') + + # If the user is not already enrolled, enroll the user. + # TODO: change to factory + CourseEnrollment.objects.get_or_create(user=u, course_id=course_id("model_course")) + + world.log_in('robot', 'test') + chapter_name = (TEST_SECTION_NAME+"1").replace(" ", "_") + section_name = chapter_name + url = django_url('/courses/edx/model_course/Test_Course/courseware/%s/%s' % + (chapter_name, section_name)) + + world.browser.visit(url) + + +@step(u'I click on section "([^"]*)"') +def click_on_section(step, section): + section_css = 'h3[tabindex="-1"]' + elist = world.css_find(section_css) + assert not elist.is_empty() + elist.click() + subid = "ui-accordion-accordion-panel-"+str(int(section)-1) + subsection_css = 'ul[id="%s"]>li[class=" "] a' % subid + elist = world.css_find(subsection_css) + assert not elist.is_empty() + elist.click() + + +@step(u'I click on subsection "([^"]*)"') +def click_on_subsection(step, subsection): + subsection_css = 'ul[id="ui-accordion-accordion-panel-0"]>li[class=" "] a' + elist = world.css_find(subsection_css) + assert not elist.is_empty() + elist.click() + +@step(u'I click on sequence "([^"]*)"') +def click_on_subsection(step, sequence): + sequence_css = 'a[data-element="%s"]' % sequence + elist = world.css_find(sequence_css) + assert not elist.is_empty() + elist.click() + + +@step(u'I see the content of (?:sub)?section "([^"]*)"') +def see_section_content(step, section): + if section == "2": + text = 'The correct answer is Option 2' + elif section == "1": + text = 'The correct answer is Choice 3' + step.given('I should see "' + text + '" somewhere on the page') + + +@step(u'I see the content of sequence "([^"]*)"') +def see_sequence_content(step, sequence): + step.given('I see the content of section "2"') + + +@step(u'I go to the section') +def return_to_course(step): + world.click_link("View Course") + world.click_link("Courseware") + +### +#HELPERS +### + + +def add_problem_to_course_section(course, problem_type, extraMeta=None, section=1, subsection=1): + ''' + Add a problem to the course we have created using factories. + ''' + + assert(problem_type in PROBLEM_DICT) + + # Generate the problem XML using capa.tests.response_xml_factory + factory_dict = PROBLEM_DICT[problem_type] + problem_xml = factory_dict['factory'].build_xml(**factory_dict['kwargs']) + metadata = {'rerandomize': 'always'} if not 'metadata' in factory_dict else factory_dict['metadata'] + if extraMeta: + metadata = dict(metadata, **extraMeta) + + # Create a problem item using our generated XML + # We set rerandomize=always in the metadata so that the "Reset" button + # will appear. + template_name = "i4x://edx/templates/problem/Blank_Common_Problem" + world.ItemFactory.create(parent_location=section_location(course, section) if subsection == 1 else SUBSECTION_2_LOC, + template=template_name, + display_name=str(problem_type), + data=problem_xml, + metadata=metadata) + + +def section_location(course_num, section_num): + return Location(loc_or_tag="i4x", + org=TEST_COURSE_ORG, + course=course_num, + category='sequential', + name=(TEST_SECTION_NAME+str(section_num)).replace(" ", "_")) From c62cc23bc23967307b86f7f4ae5d060db35cbe3d Mon Sep 17 00:00:00 2001 From: JonahStanley Date: Tue, 4 Jun 2013 13:06:18 -0400 Subject: [PATCH 2/6] Refactored Navigation Methods --- .../courseware/features/navigation.feature | 9 +- .../courseware/features/navigation.py | 196 +++++++----------- 2 files changed, 75 insertions(+), 130 deletions(-) diff --git a/lms/djangoapps/courseware/features/navigation.feature b/lms/djangoapps/courseware/features/navigation.feature index f9cee87c89..182a8ad4a9 100644 --- a/lms/djangoapps/courseware/features/navigation.feature +++ b/lms/djangoapps/courseware/features/navigation.feature @@ -6,22 +6,21 @@ Feature: Navigate Course Scenario: I can navigate to a section Given I am viewing a course with multiple sections When I click on section "2" - Then I see the content of section "2" + Then I should see the content of section "2" Scenario: I can navigate to subsections Given I am viewing a section with multiple subsections When I click on subsection "2" - Then I see the content of subsection "2" + Then I should see the content of subsection "2" Scenario: I can navigate to sequences Given I am viewing a section with multiple sequences When I click on sequence "2" - Then I see the content of sequence "2" + Then I should see the content of sequence "2" Scenario: I can go back to where I was after I log out and back in Given I am viewing a course with multiple sections When I click on section "2" - And I visit the homepage - And I go to the section + And I return later Then I should see "You were most recently in Test Section2" somewhere on the page diff --git a/lms/djangoapps/courseware/features/navigation.py b/lms/djangoapps/courseware/features/navigation.py index 2f7f19f39a..06271a3002 100644 --- a/lms/djangoapps/courseware/features/navigation.py +++ b/lms/djangoapps/courseware/features/navigation.py @@ -13,28 +13,18 @@ TEST_COURSE_ORG = 'edx' TEST_COURSE_NAME = 'Test Course' TEST_SECTION_NAME = 'Test Section' SUBSECTION_2_LOC = None +COURSE_LOC = None @step(u'I am viewing a course with multiple sections') def view_course_multiple_sections(step): - # First clear the modulestore so we don't try to recreate - # the same course twice - # This also ensures that the necessary templates are loaded - world.clear_courses() - - # Create the course - # We always use the same org and display name, - # but vary the course identifier (e.g. 600x or 191x) - course = world.CourseFactory.create(org=TEST_COURSE_ORG, - number="model_course", - display_name=TEST_COURSE_NAME) - + create_course() # Add a section to the course to contain problems - section1 = world.ItemFactory.create(parent_location=course.location, + section1 = world.ItemFactory.create(parent_location=COURSE_LOC, display_name=TEST_SECTION_NAME+"1") # Add a section to the course to contain problems - section2 = world.ItemFactory.create(parent_location=course.location, + section2 = world.ItemFactory.create(parent_location=COURSE_LOC, display_name=TEST_SECTION_NAME+"2") world.ItemFactory.create(parent_location=section1.location, @@ -48,39 +38,15 @@ def view_course_multiple_sections(step): add_problem_to_course_section('model_course', 'multiple choice', section=1) add_problem_to_course_section('model_course', 'drop down', section=2) - # Create the user - world.create_user('robot') - u = User.objects.get(username='robot') - - # If the user is not already enrolled, enroll the user. - # TODO: change to factory - CourseEnrollment.objects.get_or_create(user=u, course_id=course_id("model_course")) - - world.log_in('robot', 'test') - chapter_name = (TEST_SECTION_NAME+"1").replace(" ", "_") - section_name = chapter_name - url = django_url('/courses/edx/model_course/Test_Course/courseware/%s/%s' % - (chapter_name, section_name)) - - world.browser.visit(url) + create_user_and_visit_course() @step(u'I am viewing a section with multiple subsections') def view_course_multiple_subsections(step): - # First clear the modulestore so we don't try to recreate - # the same course twice - # This also ensures that the necessary templates are loaded - world.clear_courses() - - # Create the course - # We always use the same org and display name, - # but vary the course identifier (e.g. 600x or 191x) - course = world.CourseFactory.create(org=TEST_COURSE_ORG, - number="model_course", - display_name=TEST_COURSE_NAME) + create_course() # Add a section to the course to contain problems - section1 = world.ItemFactory.create(parent_location=course.location, + section1 = world.ItemFactory.create(parent_location=COURSE_LOC, display_name=TEST_SECTION_NAME+"1") world.ItemFactory.create(parent_location=section1.location, @@ -93,43 +59,17 @@ def view_course_multiple_subsections(step): global SUBSECTION_2_LOC SUBSECTION_2_LOC = section2.location - add_problem_to_course_section('model_course', 'multiple choice', section=1) add_problem_to_course_section('model_course', 'drop down', section=1, subsection=2) - # Create the user - world.create_user('robot') - u = User.objects.get(username='robot') - - # If the user is not already enrolled, enroll the user. - # TODO: change to factory - CourseEnrollment.objects.get_or_create(user=u, course_id=course_id("model_course")) - - world.log_in('robot', 'test') - chapter_name = (TEST_SECTION_NAME+"1").replace(" ", "_") - section_name = chapter_name - url = django_url('/courses/edx/model_course/Test_Course/courseware/%s/%s' % - (chapter_name, section_name)) - - world.browser.visit(url) + create_user_and_visit_course() @step(u'I am viewing a section with multiple sequences') def view_course_multiple_sequences(step): - # First clear the modulestore so we don't try to recreate - # the same course twice - # This also ensures that the necessary templates are loaded - world.clear_courses() - - # Create the course - # We always use the same org and display name, - # but vary the course identifier (e.g. 600x or 191x) - course = world.CourseFactory.create(org=TEST_COURSE_ORG, - number="model_course", - display_name=TEST_COURSE_NAME) - + create_course() # Add a section to the course to contain problems - section1 = world.ItemFactory.create(parent_location=course.location, + section1 = world.ItemFactory.create(parent_location=COURSE_LOC, display_name=TEST_SECTION_NAME+"1") @@ -140,12 +80,70 @@ def view_course_multiple_sequences(step): add_problem_to_course_section('model_course', 'multiple choice', section=1) add_problem_to_course_section('model_course', 'drop down', section=1) - # Create the user + create_user_and_visit_course() + + +@step(u'I click on section "([^"]*)"') +def click_on_section(step, section): + section_css = 'h3[tabindex="-1"]' + world.css_click(section_css) + + subid = "ui-accordion-accordion-panel-"+str(int(section)-1) + subsection_css = 'ul[id="%s"]>li[class=" "] a' % subid + world.css_click(subsection_css) + + +@step(u'I click on subsection "([^"]*)"') +def click_on_subsection(step, subsection): + subsection_css = 'ul[id="ui-accordion-accordion-panel-0"]>li[class=" "]>a' + world.css_click(subsection_css) + + +@step(u'I click on sequence "([^"]*)"') +def click_on_sequence(step, sequence): + sequence_css = 'a[data-element="%s"]' % sequence + world.css_click(sequence_css) + + +@step(u'I should see the content of (?:sub)?section "([^"]*)"') +def see_section_content(step, section): + if section == "2": + text = 'The correct answer is Option 2' + elif section == "1": + text = 'The correct answer is Choice 3' + step.given('I should see "' + text + '" somewhere on the page') + + +@step(u'I should see the content of sequence "([^"]*)"') +def see_sequence_content(step, sequence): + step.given('I should see the content of section "2"') + + +@step(u'I return later') +def return_to_course(step): + step.given('I visit the homepage') + world.click_link("View Course") + world.click_link("Courseware") + +##################### +# HELPERS +##################### + + +def create_course(): + world.clear_courses() + + course = world.CourseFactory.create(org=TEST_COURSE_ORG, + number="model_course", + display_name=TEST_COURSE_NAME) + global COURSE_LOC + COURSE_LOC = course.location + + +def create_user_and_visit_course(): world.create_user('robot') u = User.objects.get(username='robot') - # If the user is not already enrolled, enroll the user. - # TODO: change to factory CourseEnrollment.objects.get_or_create(user=u, course_id=course_id("model_course")) world.log_in('robot', 'test') @@ -157,58 +155,6 @@ def view_course_multiple_sequences(step): world.browser.visit(url) -@step(u'I click on section "([^"]*)"') -def click_on_section(step, section): - section_css = 'h3[tabindex="-1"]' - elist = world.css_find(section_css) - assert not elist.is_empty() - elist.click() - subid = "ui-accordion-accordion-panel-"+str(int(section)-1) - subsection_css = 'ul[id="%s"]>li[class=" "] a' % subid - elist = world.css_find(subsection_css) - assert not elist.is_empty() - elist.click() - - -@step(u'I click on subsection "([^"]*)"') -def click_on_subsection(step, subsection): - subsection_css = 'ul[id="ui-accordion-accordion-panel-0"]>li[class=" "] a' - elist = world.css_find(subsection_css) - assert not elist.is_empty() - elist.click() - -@step(u'I click on sequence "([^"]*)"') -def click_on_subsection(step, sequence): - sequence_css = 'a[data-element="%s"]' % sequence - elist = world.css_find(sequence_css) - assert not elist.is_empty() - elist.click() - - -@step(u'I see the content of (?:sub)?section "([^"]*)"') -def see_section_content(step, section): - if section == "2": - text = 'The correct answer is Option 2' - elif section == "1": - text = 'The correct answer is Choice 3' - step.given('I should see "' + text + '" somewhere on the page') - - -@step(u'I see the content of sequence "([^"]*)"') -def see_sequence_content(step, sequence): - step.given('I see the content of section "2"') - - -@step(u'I go to the section') -def return_to_course(step): - world.click_link("View Course") - world.click_link("Courseware") - -### -#HELPERS -### - - def add_problem_to_course_section(course, problem_type, extraMeta=None, section=1, subsection=1): ''' Add a problem to the course we have created using factories. From 8d15b74a9751a2d42a0e4662effb3b2b3bbc4f13 Mon Sep 17 00:00:00 2001 From: JonahStanley Date: Thu, 6 Jun 2013 14:38:59 -0400 Subject: [PATCH 3/6] Fixed errors in spacing and refactoring out of scenario --- .../courseware/features/navigation.feature | 3 +-- .../courseware/features/navigation.py | 27 ++++++++++++------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lms/djangoapps/courseware/features/navigation.feature b/lms/djangoapps/courseware/features/navigation.feature index 182a8ad4a9..8fd8b54c1a 100644 --- a/lms/djangoapps/courseware/features/navigation.feature +++ b/lms/djangoapps/courseware/features/navigation.feature @@ -8,7 +8,6 @@ Feature: Navigate Course When I click on section "2" Then I should see the content of section "2" - Scenario: I can navigate to subsections Given I am viewing a section with multiple subsections When I click on subsection "2" @@ -23,4 +22,4 @@ Feature: Navigate Course Given I am viewing a course with multiple sections When I click on section "2" And I return later - Then I should see "You were most recently in Test Section2" somewhere on the page + Then I should see that I was most recently in section "2" diff --git a/lms/djangoapps/courseware/features/navigation.py b/lms/djangoapps/courseware/features/navigation.py index 06271a3002..1f6308c6c5 100644 --- a/lms/djangoapps/courseware/features/navigation.py +++ b/lms/djangoapps/courseware/features/navigation.py @@ -21,19 +21,19 @@ def view_course_multiple_sections(step): create_course() # Add a section to the course to contain problems section1 = world.ItemFactory.create(parent_location=COURSE_LOC, - display_name=TEST_SECTION_NAME+"1") + display_name=section_name(1)) # Add a section to the course to contain problems section2 = world.ItemFactory.create(parent_location=COURSE_LOC, - display_name=TEST_SECTION_NAME+"2") + display_name=section_name(2)) world.ItemFactory.create(parent_location=section1.location, template='i4x://edx/templates/sequential/Empty', - display_name=TEST_SECTION_NAME+"1") + display_name=section_name(1)) world.ItemFactory.create(parent_location=section2.location, template='i4x://edx/templates/sequential/Empty', - display_name=TEST_SECTION_NAME+"2") + display_name=section_name(2)) add_problem_to_course_section('model_course', 'multiple choice', section=1) add_problem_to_course_section('model_course', 'drop down', section=2) @@ -47,14 +47,14 @@ def view_course_multiple_subsections(step): # Add a section to the course to contain problems section1 = world.ItemFactory.create(parent_location=COURSE_LOC, - display_name=TEST_SECTION_NAME+"1") + display_name=section_name(1)) world.ItemFactory.create(parent_location=section1.location, template='i4x://edx/templates/sequential/Empty', - display_name=TEST_SECTION_NAME+"1") + display_name=section_name(1)) section2 = world.ItemFactory.create(parent_location=section1.location, - display_name=TEST_SECTION_NAME+"2") + display_name=section_name(2)) global SUBSECTION_2_LOC SUBSECTION_2_LOC = section2.location @@ -70,12 +70,12 @@ def view_course_multiple_sequences(step): create_course() # Add a section to the course to contain problems section1 = world.ItemFactory.create(parent_location=COURSE_LOC, - display_name=TEST_SECTION_NAME+"1") + display_name=section_name(1)) world.ItemFactory.create(parent_location=section1.location, template='i4x://edx/templates/sequential/Empty', - display_name=TEST_SECTION_NAME+"1") + display_name=section_name(1)) add_problem_to_course_section('model_course', 'multiple choice', section=1) add_problem_to_course_section('model_course', 'drop down', section=1) @@ -125,11 +125,20 @@ def return_to_course(step): world.click_link("View Course") world.click_link("Courseware") + +@step(u'I should see that I was most recently in section "([^"]*)"') +def see_recent_section(step, section): + step.given('I should see "You were most recently in %s" somewhere on the page' % section_name(int(section))) + ##################### # HELPERS ##################### +def section_name(section): + return TEST_SECTION_NAME+str(section) + + def create_course(): world.clear_courses() From 1fefec2176d7af23b17a197a0ebb4115c3c53288 Mon Sep 17 00:00:00 2001 From: JonahStanley Date: Thu, 6 Jun 2013 15:28:45 -0400 Subject: [PATCH 4/6] Fixed the need of a global variable --- .../courseware/features/navigation.py | 67 +++++++------------ 1 file changed, 25 insertions(+), 42 deletions(-) diff --git a/lms/djangoapps/courseware/features/navigation.py b/lms/djangoapps/courseware/features/navigation.py index 1f6308c6c5..8bf81c0ec5 100644 --- a/lms/djangoapps/courseware/features/navigation.py +++ b/lms/djangoapps/courseware/features/navigation.py @@ -5,38 +5,35 @@ from lettuce import world, step from django.contrib.auth.models import User from lettuce.django import django_url from student.models import CourseEnrollment -from common import course_id -from xmodule.modulestore import Location +from common import course_id, course_location from problems_setup import PROBLEM_DICT TEST_COURSE_ORG = 'edx' TEST_COURSE_NAME = 'Test Course' TEST_SECTION_NAME = 'Test Section' -SUBSECTION_2_LOC = None -COURSE_LOC = None @step(u'I am viewing a course with multiple sections') def view_course_multiple_sections(step): create_course() # Add a section to the course to contain problems - section1 = world.ItemFactory.create(parent_location=COURSE_LOC, + section1 = world.ItemFactory.create(parent_location=course_location('model_course'), display_name=section_name(1)) # Add a section to the course to contain problems - section2 = world.ItemFactory.create(parent_location=COURSE_LOC, + section2 = world.ItemFactory.create(parent_location=course_location('model_course'), display_name=section_name(2)) - world.ItemFactory.create(parent_location=section1.location, + place1 = world.ItemFactory.create(parent_location=section1.location, template='i4x://edx/templates/sequential/Empty', display_name=section_name(1)) - world.ItemFactory.create(parent_location=section2.location, + place2 = world.ItemFactory.create(parent_location=section2.location, template='i4x://edx/templates/sequential/Empty', display_name=section_name(2)) - add_problem_to_course_section('model_course', 'multiple choice', section=1) - add_problem_to_course_section('model_course', 'drop down', section=2) + add_problem_to_course_section('model_course', 'multiple choice', place1.location) + add_problem_to_course_section('model_course', 'drop down', place2.location) create_user_and_visit_course() @@ -46,21 +43,18 @@ def view_course_multiple_subsections(step): create_course() # Add a section to the course to contain problems - section1 = world.ItemFactory.create(parent_location=COURSE_LOC, + section1 = world.ItemFactory.create(parent_location=course_location('model_course'), display_name=section_name(1)) - world.ItemFactory.create(parent_location=section1.location, + place1 = world.ItemFactory.create(parent_location=section1.location, template='i4x://edx/templates/sequential/Empty', display_name=section_name(1)) - section2 = world.ItemFactory.create(parent_location=section1.location, + place2 = world.ItemFactory.create(parent_location=section1.location, display_name=section_name(2)) - global SUBSECTION_2_LOC - SUBSECTION_2_LOC = section2.location - - add_problem_to_course_section('model_course', 'multiple choice', section=1) - add_problem_to_course_section('model_course', 'drop down', section=1, subsection=2) + add_problem_to_course_section('model_course', 'multiple choice', place1.location) + add_problem_to_course_section('model_course', 'drop down', place2.location) create_user_and_visit_course() @@ -69,21 +63,20 @@ def view_course_multiple_subsections(step): def view_course_multiple_sequences(step): create_course() # Add a section to the course to contain problems - section1 = world.ItemFactory.create(parent_location=COURSE_LOC, + section1 = world.ItemFactory.create(parent_location=course_location('model_course'), display_name=section_name(1)) - - world.ItemFactory.create(parent_location=section1.location, + place1 = world.ItemFactory.create(parent_location=section1.location, template='i4x://edx/templates/sequential/Empty', display_name=section_name(1)) - add_problem_to_course_section('model_course', 'multiple choice', section=1) - add_problem_to_course_section('model_course', 'drop down', section=1) + add_problem_to_course_section('model_course', 'multiple choice', place1.location) + add_problem_to_course_section('model_course', 'drop down', place1.location) create_user_and_visit_course() -@step(u'I click on section "([^"]*)"') +@step(u'I click on section "([^"]*)"$') def click_on_section(step, section): section_css = 'h3[tabindex="-1"]' world.css_click(section_css) @@ -93,19 +86,19 @@ def click_on_section(step, section): world.css_click(subsection_css) -@step(u'I click on subsection "([^"]*)"') +@step(u'I click on subsection "([^"]*)"$') def click_on_subsection(step, subsection): subsection_css = 'ul[id="ui-accordion-accordion-panel-0"]>li[class=" "]>a' world.css_click(subsection_css) -@step(u'I click on sequence "([^"]*)"') +@step(u'I click on sequence "([^"]*)"$') def click_on_sequence(step, sequence): sequence_css = 'a[data-element="%s"]' % sequence world.css_click(sequence_css) -@step(u'I should see the content of (?:sub)?section "([^"]*)"') +@step(u'I should see the content of (?:sub)?section "([^"]*)"$') def see_section_content(step, section): if section == "2": text = 'The correct answer is Option 2' @@ -114,7 +107,7 @@ def see_section_content(step, section): step.given('I should see "' + text + '" somewhere on the page') -@step(u'I should see the content of sequence "([^"]*)"') +@step(u'I should see the content of sequence "([^"]*)"$') def see_sequence_content(step, sequence): step.given('I should see the content of section "2"') @@ -126,7 +119,7 @@ def return_to_course(step): world.click_link("Courseware") -@step(u'I should see that I was most recently in section "([^"]*)"') +@step(u'I should see that I was most recently in section "([^"]*)"$') def see_recent_section(step, section): step.given('I should see "You were most recently in %s" somewhere on the page' % section_name(int(section))) @@ -142,11 +135,9 @@ def section_name(section): def create_course(): world.clear_courses() - course = world.CourseFactory.create(org=TEST_COURSE_ORG, + world.CourseFactory.create(org=TEST_COURSE_ORG, number="model_course", display_name=TEST_COURSE_NAME) - global COURSE_LOC - COURSE_LOC = course.location def create_user_and_visit_course(): @@ -164,7 +155,7 @@ def create_user_and_visit_course(): world.browser.visit(url) -def add_problem_to_course_section(course, problem_type, extraMeta=None, section=1, subsection=1): +def add_problem_to_course_section(course, problem_type, parent_location, extraMeta=None): ''' Add a problem to the course we have created using factories. ''' @@ -182,16 +173,8 @@ def add_problem_to_course_section(course, problem_type, extraMeta=None, section= # We set rerandomize=always in the metadata so that the "Reset" button # will appear. template_name = "i4x://edx/templates/problem/Blank_Common_Problem" - world.ItemFactory.create(parent_location=section_location(course, section) if subsection == 1 else SUBSECTION_2_LOC, + world.ItemFactory.create(parent_location=parent_location, template=template_name, display_name=str(problem_type), data=problem_xml, metadata=metadata) - - -def section_location(course_num, section_num): - return Location(loc_or_tag="i4x", - org=TEST_COURSE_ORG, - course=course_num, - category='sequential', - name=(TEST_SECTION_NAME+str(section_num)).replace(" ", "_")) From e843f80e1f47ca2487c3c06cfb1b136e1f3bf0f1 Mon Sep 17 00:00:00 2001 From: JonahStanley Date: Tue, 11 Jun 2013 17:09:39 -0400 Subject: [PATCH 5/6] Fixed naming issue and hopefully clicking issue --- .../courseware/features/navigation.py | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/lms/djangoapps/courseware/features/navigation.py b/lms/djangoapps/courseware/features/navigation.py index 8bf81c0ec5..3fecb7bb13 100644 --- a/lms/djangoapps/courseware/features/navigation.py +++ b/lms/djangoapps/courseware/features/navigation.py @@ -11,6 +11,7 @@ from problems_setup import PROBLEM_DICT TEST_COURSE_ORG = 'edx' TEST_COURSE_NAME = 'Test Course' TEST_SECTION_NAME = 'Test Section' +TEST_SUBSECTION_NAME = 'Test Subsection' @step(u'I am viewing a course with multiple sections') @@ -26,11 +27,11 @@ def view_course_multiple_sections(step): place1 = world.ItemFactory.create(parent_location=section1.location, template='i4x://edx/templates/sequential/Empty', - display_name=section_name(1)) + display_name=subsection_name(1)) place2 = world.ItemFactory.create(parent_location=section2.location, template='i4x://edx/templates/sequential/Empty', - display_name=section_name(2)) + display_name=subsection_name(2)) add_problem_to_course_section('model_course', 'multiple choice', place1.location) add_problem_to_course_section('model_course', 'drop down', place2.location) @@ -48,10 +49,10 @@ def view_course_multiple_subsections(step): place1 = world.ItemFactory.create(parent_location=section1.location, template='i4x://edx/templates/sequential/Empty', - display_name=section_name(1)) + display_name=subsection_name(1)) place2 = world.ItemFactory.create(parent_location=section1.location, - display_name=section_name(2)) + display_name=subsection_name(2)) add_problem_to_course_section('model_course', 'multiple choice', place1.location) add_problem_to_course_section('model_course', 'drop down', place2.location) @@ -68,7 +69,7 @@ def view_course_multiple_sequences(step): place1 = world.ItemFactory.create(parent_location=section1.location, template='i4x://edx/templates/sequential/Empty', - display_name=section_name(1)) + display_name=subsection_name(1)) add_problem_to_course_section('model_course', 'multiple choice', place1.location) add_problem_to_course_section('model_course', 'drop down', place1.location) @@ -81,15 +82,15 @@ def click_on_section(step, section): section_css = 'h3[tabindex="-1"]' world.css_click(section_css) - subid = "ui-accordion-accordion-panel-"+str(int(section)-1) - subsection_css = 'ul[id="%s"]>li[class=" "] a' % subid + subid = "ui-accordion-accordion-panel-" + str(int(section) - 1) + subsection_css = 'ul[id="%s"]> li > a' % subid world.css_click(subsection_css) @step(u'I click on subsection "([^"]*)"$') def click_on_subsection(step, subsection): - subsection_css = 'ul[id="ui-accordion-accordion-panel-0"]>li[class=" "]>a' - world.css_click(subsection_css) + subsection_css = 'ul[id="ui-accordion-accordion-panel-0"]> li > a' + world.css_find(subsection_css)[int(subsection) - 1].click() @step(u'I click on sequence "([^"]*)"$') @@ -121,7 +122,7 @@ def return_to_course(step): @step(u'I should see that I was most recently in section "([^"]*)"$') def see_recent_section(step, section): - step.given('I should see "You were most recently in %s" somewhere on the page' % section_name(int(section))) + step.given('I should see "You were most recently in %s" somewhere on the page' % subsection_name(int(section))) ##################### # HELPERS @@ -129,7 +130,11 @@ def see_recent_section(step, section): def section_name(section): - return TEST_SECTION_NAME+str(section) + return TEST_SECTION_NAME + str(section) + + +def subsection_name(section): + return TEST_SUBSECTION_NAME + str(section) def create_course(): @@ -147,8 +152,8 @@ def create_user_and_visit_course(): CourseEnrollment.objects.get_or_create(user=u, course_id=course_id("model_course")) world.log_in('robot', 'test') - chapter_name = (TEST_SECTION_NAME+"1").replace(" ", "_") - section_name = chapter_name + chapter_name = (TEST_SECTION_NAME + "1").replace(" ", "_") + section_name = (TEST_SUBSECTION_NAME + "1").replace(" ", "_") url = django_url('/courses/edx/model_course/Test_Course/courseware/%s/%s' % (chapter_name, section_name)) From daf5ef146e306a30a8290efac179743c01d7b950 Mon Sep 17 00:00:00 2001 From: JonahStanley Date: Thu, 13 Jun 2013 16:33:39 -0400 Subject: [PATCH 6/6] Fixed weird issue of needed to sometimes first find then click instead of css_click --- lms/djangoapps/courseware/features/navigation.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/courseware/features/navigation.py b/lms/djangoapps/courseware/features/navigation.py index 3fecb7bb13..edd748e46f 100644 --- a/lms/djangoapps/courseware/features/navigation.py +++ b/lms/djangoapps/courseware/features/navigation.py @@ -84,7 +84,8 @@ def click_on_section(step, section): subid = "ui-accordion-accordion-panel-" + str(int(section) - 1) subsection_css = 'ul[id="%s"]> li > a' % subid - world.css_click(subsection_css) + #for some reason needed to do it in two steps + world.css_find(subsection_css).click() @step(u'I click on subsection "([^"]*)"$')