From 0e697f972cf7212dc6cbbee10d8b7f2f0a71323f Mon Sep 17 00:00:00 2001 From: Alexander Kryklia Date: Fri, 30 Aug 2013 16:46:52 +0300 Subject: [PATCH] acceptance tests updated --- .../courseware/features/lti.feature | 4 ++ lms/djangoapps/courseware/features/lti.py | 64 ++++++++++++++++++- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/lms/djangoapps/courseware/features/lti.feature b/lms/djangoapps/courseware/features/lti.feature index e17144f545..b424113992 100644 --- a/lms/djangoapps/courseware/features/lti.feature +++ b/lms/djangoapps/courseware/features/lti.feature @@ -8,3 +8,7 @@ Feature: LTI component Scenario: LTI component in LMS is rendered Given the course has a LTI component filled with correct data 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 + 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 da6d14e759..db48bbd8b8 100644 --- a/lms/djangoapps/courseware/features/lti.py +++ b/lms/djangoapps/courseware/features/lti.py @@ -37,6 +37,31 @@ def lti_is_rendered(_step): with world.browser.get_iframe('ltiLaunchFrame') as iframe: # iframe does not contain functions from terrain/ui_helpers.py assert iframe.is_element_present_by_css('.result', wait_time=5) + assert ("This is LTI tool. Success." == world.retry_on_exception( + lambda: iframe.find_by_css('.result')[0].text, + max_attempts=5 + )) + + +@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') + + # error is hidden + assert (not world.css_visible('.error_message')) + + # iframe is visible + assert world.css_visible('iframe') + + #inside iframe test content is presented + with world.browser.get_iframe('ltiLaunchFrame') as iframe: + # iframe does not contain functions from terrain/ui_helpers.py + assert iframe.is_element_present_by_css('.result', wait_time=5) + assert ("Wrong LTI signature" == world.retry_on_exception( + lambda: iframe.find_by_css('.result')[0].text, + max_attempts=5 + )) @step('the course has a LTI component filled with correct data') @@ -75,6 +100,25 @@ def view_default_lti(_step): 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' + i_am_registered_for_the_course(_step, coursenum) + + 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) + + def add_correct_lti_to_course(course): category = 'lti' world.ItemFactory.create( @@ -82,9 +126,9 @@ def add_correct_lti_to_course(course): category=category, display_name='LTI', metadata={ - 'client_key': 'client_key', - 'clent_secret': 'client_secret', - 'lti_url': 'http://127.0.0.1:{}/correct_lti_endpoint'.format(world.lti_server_port) + 'client_key': world.lti_server.oauth_settings['client_key'], + 'client_secret': world.lti_server.oauth_settings['client_secret'], + 'lti_url': world.lti_server.oauth_settings['lti_base'] + world.lti_server.oauth_settings['lti_endpoint'] } ) @@ -96,3 +140,17 @@ def add_default_lti_to_course(course): category=category, display_name='LTI' ) + + +def wrong_data_lti_to_course(course): + category = 'lti' + world.ItemFactory.create( + parent_location=section_location(course), + category=category, + display_name='LTI', + metadata={ + 'client_key': world.lti_server.oauth_settings['client_key'], + 'client_secret': "wrong_secret", + 'lti_url': world.lti_server.oauth_settings['lti_base'] + world.lti_server.oauth_settings['lti_endpoint'] + } + )