Commit d5639293 by Alexander Kryklia

Add correct acceptance tests for LTI

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