diff --git a/lms/djangoapps/courseware/features/lti.feature b/lms/djangoapps/courseware/features/lti.feature index b424113992..80ffeaa56a 100644 --- a/lms/djangoapps/courseware/features/lti.feature +++ b/lms/djangoapps/courseware/features/lti.feature @@ -2,13 +2,16 @@ Feature: LTI component As a student, I want to view LTI component in LMS. Scenario: LTI component in LMS is not rendered - Given the course has a LTI component with empty fields + Given the course has correct LTI credentials + And the course has a LTI component with incorrect fields Then I view the LTI and it is not rendered Scenario: LTI component in LMS is rendered - Given the course has a LTI component filled with correct data + Given the course has correct LTI credentials + And the course has a LTI component filled with correct fields Then I view the LTI and it is rendered Scenario: LTI component in LMS is rendered incorreclty - Given the course has a LTI component filled with correct url and client_key, but incorrect client_secret + Given the course has a incorrect LTI credentials + And the course has a LTI component filled with correct fields Then I view the LTI but incorrect_signature warning is rendered \ No newline at end of file diff --git a/lms/djangoapps/courseware/features/lti.py b/lms/djangoapps/courseware/features/lti.py index 3508bd0b61..0ff6bbb809 100644 --- a/lms/djangoapps/courseware/features/lti.py +++ b/lms/djangoapps/courseware/features/lti.py @@ -5,15 +5,10 @@ from lettuce import world, step from lettuce.django import django_url from common import section_location, course_id -from django.contrib.auth.models import User from student.models import CourseEnrollment -from xmodule.modulestore import Location -from xmodule.modulestore.django import modulestore -from xmodule.course_module import CourseDescriptor -from courseware.courses import get_course_by_id -from xmodule import seq_module, vertical_module -@step('I view the LTI and it is not rendered') + +@step('I view the LTI and it is not rendered$') def lti_is_not_rendered(_step): # lti div has no class rendered assert world.is_css_not_present('div.lti.rendered') @@ -30,7 +25,7 @@ def lti_is_not_rendered(_step): assert iframe.is_element_not_present_by_css('.result', wait_time=5) -@step('I view the LTI and it is rendered') +@step('I view the LTI and it is rendered$') def lti_is_rendered(_step): # lti div has class rendered assert world.is_css_present('div.lti.rendered') @@ -51,7 +46,7 @@ def lti_is_rendered(_step): )) -@step('I view the LTI but incorrect_signature warning is rendered') +@step('I view the LTI but incorrect_signature warning is rendered$') def incorrect_lti_is_rendered(_step): # lti div has class rendered assert world.is_css_present('div.lti.rendered') @@ -72,108 +67,80 @@ def incorrect_lti_is_rendered(_step): )) -@step('the course has a LTI component filled with correct data') -def view_lti_with_data(_step): +@step('the course has correct LTI credentials$') +def set_correct_lti_passport(_step): coursenum = 'test_course' - metadata = { - 'LTIs': ["test_lti_id:{}:{}".format( + metadata = { + 'LTIs': ["correct_lti_id:{}:{}".format( world.lti_server.oauth_settings['client_key'], world.lti_server.oauth_settings['client_secret'] )] } - i_am_registered_for_the_course(_step, coursenum, metadata) - add_correct_lti_to_course(coursenum) - chapter_name = world.scenario_dict['SECTION'].display_name.replace( - " ", "_") - section_name = chapter_name - url = django_url('/courses/%s/%s/%s/courseware/%s/%s' % ( - world.scenario_dict['COURSE'].org, - world.scenario_dict['COURSE'].number, - world.scenario_dict['COURSE'].display_name.replace(' ', '_'), - chapter_name, section_name,) - ) - world.browser.visit(url) + i_am_registered_for_the_course(coursenum, metadata) -@step('the course has a LTI component with empty fields') -def view_default_lti(_step): +@step('the course has a incorrect LTI credentials$') +def set_incorrect_lti_passport(_step): coursenum = 'test_course' - metadata = {} - i_am_registered_for_the_course(_step, coursenum, {}) - add_default_lti_to_course(coursenum) - chapter_name = world.scenario_dict['SECTION'].display_name.replace( - " ", "_") - section_name = chapter_name - url = django_url('/courses/%s/%s/%s/courseware/%s/%s' % ( - world.scenario_dict['COURSE'].org, - world.scenario_dict['COURSE'].number, - world.scenario_dict['COURSE'].display_name.replace(' ', '_'), - chapter_name, section_name,) - ) - world.browser.visit(url) - - -@step('the course has a LTI component filled with correct url \ -and client_key, but incorrect client_secret') -def view_wrong_data_lti(_step): - coursenum = 'test_course' - metadata = { + metadata = { 'LTIs': ["test_lti_id:{}:{}".format( world.lti_server.oauth_settings['client_key'], - world.lti_server.oauth_settings['client_secret'] + "incorrect_lti_secret_key" )] } - i_am_registered_for_the_course(_step, coursenum, metadata) - wrong_data_lti_to_course(coursenum) - chapter_name = world.scenario_dict['SECTION'].display_name.replace( - " ", "_") - section_name = chapter_name - url = django_url('/courses/%s/%s/%s/courseware/%s/%s' % ( - world.scenario_dict['COURSE'].org, - world.scenario_dict['COURSE'].number, - world.scenario_dict['COURSE'].display_name.replace(' ', '_'), - chapter_name, section_name,) - ) - world.browser.visit(url) + i_am_registered_for_the_course(coursenum, metadata) -def add_correct_lti_to_course(course): +@step('the course has a LTI component filled with correct fields$') +def add_correct_lti_to_course(_step): category = 'lti' world.ItemFactory.create( - parent_location=section_location(course), + # parent_location=section_location(course), + parent_location=world.scenario_dict['SEQUENTIAL'].location, category=category, display_name='LTI', metadata={ - 'lti_id': 'test_lti_id', + 'lti_id': 'correct_lti_id', 'launch_url': world.lti_server.oauth_settings['lti_base'] + world.lti_server.oauth_settings['lti_endpoint'] } ) - - -def add_default_lti_to_course(course): - category = 'lti' - world.ItemFactory.create( - parent_location=section_location(course), - category=category, - display_name='LTI' + chapter_name = world.scenario_dict['SECTION'].display_name.replace( + " ", "_") + section_name = chapter_name + url = django_url('/courses/%s/%s/%s/courseware/%s/%s' % ( + world.scenario_dict['COURSE'].org, + world.scenario_dict['COURSE'].number, + world.scenario_dict['COURSE'].display_name.replace(' ', '_'), + chapter_name, section_name,) ) + world.browser.visit(url) -def wrong_data_lti_to_course(course): +@step('the course has a LTI component with incorrect fields$') +def add_incorrect_lti_to_course(_step): category = 'lti' world.ItemFactory.create( - parent_location=section_location(course), + parent_location=world.scenario_dict['SEQUENTIAL'].location, category=category, display_name='LTI', metadata={ - 'lti_id': 'test_lti_id', + 'lti_id': 'incorrect_lti_id', 'lti_url': world.lti_server.oauth_settings['lti_base'] + world.lti_server.oauth_settings['lti_endpoint'] } ) + chapter_name = world.scenario_dict['SECTION'].display_name.replace( + " ", "_") + section_name = chapter_name + url = django_url('/courses/%s/%s/%s/courseware/%s/%s' % ( + world.scenario_dict['COURSE'].org, + world.scenario_dict['COURSE'].number, + world.scenario_dict['COURSE'].display_name.replace(' ', '_'), + chapter_name, section_name,) + ) + world.browser.visit(url) -@step(u'The course "([^"]*)" exists$') -def create_course(_step, course, metadata): +def create_course(course, metadata): # First clear the modulestore so we don't try to recreate # the same course twice @@ -183,32 +150,33 @@ def create_course(_step, course, metadata): # Create the course # We always use the same org and display name, # but vary the course identifier (e.g. 600x or 191x) - world.scenario_dict['COURSE'] = world.CourseFactory.create(org='edx', - number=course, - display_name='Test Course', - metadata=metadata) + world.scenario_dict['COURSE'] = world.CourseFactory.create( + org='edx', + number=course, + display_name='Test Course', + metadata=metadata + ) # Add a section to the course to contain problems - world.scenario_dict['SECTION'] = world.ItemFactory.create(parent_location=world.scenario_dict['COURSE'].location, - display_name='Test Section') - - world.ItemFactory.create( + world.scenario_dict['SECTION'] = world.ItemFactory.create( + parent_location=world.scenario_dict['COURSE'].location, + display_name='Test Section' + ) + world.scenario_dict['SEQUENTIAL'] = world.ItemFactory.create( parent_location=world.scenario_dict['SECTION'].location, category='sequential', display_name='Test Section') -@step(u'I am registered for the course "([^"]*)"$') -def i_am_registered_for_the_course(step, course, metadata): +def i_am_registered_for_the_course(course, metadata): # Create the course - create_course(step, course, metadata) + create_course(course, metadata) # Create the user world.create_user('robot', 'test') - u = User.objects.get(username='robot') + usr = User.objects.get(username='robot') # If the user is not already enrolled, enroll the user. - # TODO: change to factory - CourseEnrollment.enroll(u, course_id(course)) + CourseEnrollment.enroll(usr, course_id(course)) world.log_in(username='robot', password='test')