def test_generate_xml(self): ''' Should generate the expected config xml. ''' config = ToolConfig(title = "Test Config", secure_launch_url = "https://www.example.com/lti", custom_params = {"custom1": "customval1"}) config.description ='Description of boringness' config.launch_url = 'http://www.example.com/lti' config.icon = 'http://wil.to/_/beardslap.gif' config.vendor_code = 'test' config.vendor_name = 'test.tool' config.vendor_description = 'We test things' config.vendor_url = 'http://www.example.com/about' config.vendor_contact_email = '*****@*****.**' config.vendor_contact_name = 'Joe Support' config.set_custom_param('custom2', 'customval2') config.set_ext_params('example.com', { 'extkey1': 'extval1' }) config.set_ext_param('example.com', 'extkey2', 'extval2') config.set_ext_param('example.com', 'extopt1', { 'optkey1': 'optval1', 'optkey2': 'optval2' }) config.set_ext_param('two.example.com', 'ext1key', 'ext1val') config.cartridge_bundle = 'BLTI001_Bundle' xml = config.to_xml() self.assertEqual(xml, cc_lti_xml)
def tool_launch(): # Parse form and ensure necessary parameters are included for param in ['tool_name', 'launch_url', 'consumer_key', 'consumer_secret']: if request.form.get(param) == None: return redirect(url_for('tool_config?message=Please%20set%20all%values')) # Create a new tool configuration config = ToolConfig(title = request.form.get('tool_name'), launch_url = request.form.get('launch_url')) config.set_custom_param('message_from_flask', 'hey from the flask example consumer') # Create LTI tool consumer consumer = ToolConsumer(request.form.get('consumer_key'), request.form.get('consumer_secret')) consumer.set_config(config) # Set some launch data from: http://www.imsglobal.org/LTI/v1p1pd/ltiIMGv1p1pd.html#_Toc309649684 # Only this first one is required, but the rest are recommended consumer.resource_link_id = 'thisistotallyunique' consumer.launch_presentation_return_url = request.url + '/tool_return' consumer.lis_person_name_given = session['username'] hash = hashlib.md5() hash.update(session['username']) consumer.user_id = hash.hexdigest() consumer.roles = 'learner' consumer.context_id = 'bestcourseever' consumer.context_title = 'Example Flask Tool Consumer' consumer.tool_consumer_instance_name = 'Frankie' if request.form.get('assignment'): consumer.lis_outcome_service_url = request.scheme + '://' + request.host + '/grade_passback' consumer.lis_result_sourcedid = 'oi' autolaunch = True if request.form.get('autolaunch') else False return render_template('tool_launch.html', autolaunch=autolaunch, launch_data=consumer.generate_launch_data(), launch_url=consumer.launch_url)
def test_generate_xml(self): ''' Should generate the expected config xml. ''' config = ToolConfig(title="Test Config", secure_launch_url="https://www.example.com/lti", custom_params={"custom1": "customval1"}) config.description = 'Description of boringness' config.launch_url = 'http://www.example.com/lti' config.icon = 'http://wil.to/_/beardslap.gif' config.vendor_code = 'test' config.vendor_name = 'test.tool' config.vendor_description = 'We test things' config.vendor_url = 'http://www.example.com/about' config.vendor_contact_email = '*****@*****.**' config.vendor_contact_name = 'Joe Support' config.set_custom_param('custom2', 'customval2') config.set_ext_params('example.com', {'extkey1': 'extval1'}) config.set_ext_param('example.com', 'extkey2', 'extval2') config.set_ext_param('example.com', 'extopt1', { 'optkey1': 'optval1', 'optkey2': 'optval2' }) config.set_ext_param('two.example.com', 'ext1key', 'ext1val') config.cartridge_bundle = 'BLTI001_Bundle' xml = config.to_xml() self.assertEqual(xml, cc_lti_xml)
def test_allow_suboptions(self): config = ToolConfig(title = "Test Config", secure_launch_url = "https://www.example.com/lti", custom_params = {"custom1": "customval1"}) config.description ='Description of boringness' config.launch_url = 'http://www.example.com/lti' config.icon = 'http://wil.to/_/beardslap.gif' config.vendor_code = 'test' config.vendor_name = 'test.tool' config.vendor_description = 'We test things' config.vendor_url = 'http://www.example.com/about' config.vendor_contact_email = '*****@*****.**' config.vendor_contact_name = 'Joe Support' config.set_custom_param('custom2', 'customval2') config.set_ext_params('example.com', { 'extkey1': 'extval1' }) config.set_ext_param('example.com', 'extkey2', 'extval2') config.set_ext_param('example.com', 'extopt1', { 'optkey1': 'optval1', 'optkey2': 'optval2' }) config.set_ext_param('example.com', 'extopt1', { 'labels':{ 'en':'Image Library', 'es':'Biblioteca de Imagenes' } }) config.set_ext_param('two.example.com', 'ext1key', 'ext1val') config.cartridge_bundle = 'BLTI001_Bundle' xml = config.to_xml() self.assertEqual(self.normalize(xml), self.normalize(cc_lti_with_sub_options))