def test_non_spec_params(self): lp = LaunchParams() lp.set_non_spec_param('foo', 'bar') self.assertEqual(lp.get_non_spec_param('foo'), 'bar') self.assertEqual(lp._params['foo'], 'bar') with self.assertRaises(KeyError): lp['foo']
def test_non_spec_params(self): lp = LaunchParams() lp.set_non_spec_param('foo', 'bar') self.assertEqual(lp.get_non_spec_param('foo'), 'bar') self.assertEqual(lp._params['foo'], 'bar') with self.assertRaises(KeyError): lp['foo']
def create_tp(key=None, secret=None, lp=None, launch_url=None, launch_headers=None, tp_class=ToolProvider): key = key or generate_client_id() secret = secret or generate_token() launch_params = LaunchParams() if lp is not None: launch_params.update(lp) launch_url = launch_url or "http://example.edu" launch_headers = launch_headers or {} return tp_class(key, secret, launch_params, launch_url, launch_headers)
def test_constructor(self): lp = LaunchParams() self.assertTrue(lp['lti_version'], DEFAULT_LTI_VERSION) self.assertTrue(lp['lti_message_type'], 'basic-lti-launch-request') lp = LaunchParams({ 'lti_version': 'LTI-foo', 'lti_message_type': 'bar', 'resource_link_id': 123 }) self.assertTrue(lp['resource_link_id'], 123) self.assertTrue(lp['lti_version'], 'LTI-foo')
def create_tp(key=None, secret=None, lp=None, launch_url=None, launch_headers=None, tp_class=ToolProvider): key = key or generate_client_id() secret = secret or generate_token() launch_params = LaunchParams() if lp is not None: launch_params.update(lp) launch_url = launch_url or "http://example.edu" launch_headers = launch_headers or {} return tp_class(key, secret, launch_params, launch_url, launch_headers)
def test_constructor(self): client_id = generate_client_id() client_secret = generate_token() tc = ContentItemResponse(client_id, client_secret, launch_url='http://example.edu') self.assertIsInstance(tc.launch_params, LaunchParams) lp = LaunchParams() tc = ContentItemResponse(client_id, client_secret, launch_url='http://example.edu', params=lp) self.assertEqual(tc.launch_params, lp) lp_dict = {'resource_link_id': 1} tc = ContentItemResponse(client_id, client_secret, launch_url='http://example.edu', params=lp_dict) self.assertIsInstance(tc.launch_params, LaunchParams) self.assertEqual(tc.launch_params._params.get('resource_link_id'), 1) # no launch_url should raise exception self.failUnlessRaises(InvalidLTIConfigError, ContentItemResponse, client_id, client_secret, params=lp_dict) # but confirm that 'launch_url' can still be passed in params # (backwards compatibility) lp_dict['launch_url'] = 'http://example.edu' tc = ContentItemResponse(client_id, client_secret, params=lp_dict) self.assertEqual(tc.launch_url, 'http://example.edu')
def test_dict_behavior(self): lp = LaunchParams({'lti_version': 'foo', 'lti_message_type': 'bar'}) self.assertEqual(len(lp), 2) lp.update({'resource_link_id': 1}) self.assertEqual(len(lp), 3) self.assertEqual( set(lp.keys()), {'lti_version', 'lti_message_type', 'resource_link_id'}) self.assertEqual(dict(lp), { 'lti_version': 'foo', 'lti_message_type': 'bar', 'resource_link_id': 1 })
def test_constructor(self): tb = create_tb() self.assertIsInstance(tb.launch_params, LaunchParams) lp = LaunchParams({'resource_link_id': 1}) tb = create_tb(lp=lp) self.assertEqual(tb.launch_params, lp) lp_dict = {'resource_link_id': 3} tb = create_tb(lp=lp_dict) self.assertEqual(tb.launch_params['resource_link_id'], 3)
def test_list_params(self): lp = LaunchParams({'roles': 'foo,bar,baz'}) self.assertEqual(lp['roles'], ['foo', 'bar', 'baz']) self.assertEqual(lp._params['roles'], 'foo,bar,baz') lp['roles'] = ['bar', 'baz'] self.assertEqual(lp['roles'], ['bar', 'baz']) self.assertEqual(lp._params['roles'], 'bar,baz') lp['roles'] = 'blah, bluh ' self.assertEqual(lp['roles'], ['blah', 'bluh'])
def test_is_valid_request_no_key_or_secret(self): """ Checks that the key and secret will be populated during validation. """ key = 'spamspamspam' secret_ = 'eggseggsegss' lp = LaunchParams({ 'lti_version': 'foo', 'lti_message_type': 'bar', 'resource_link_id': '123', 'oauth_consumer_key': key, 'oauth_nonce': '9069031379649850801466828504', 'oauth_timestamp': '1466828504', 'oauth_version': '1.0', 'oauth_signature_method': 'HMAC-SHA1', 'oauth_signature': 'WZ9IHyFnKgDKBvnAfNSL3aOVteg=', }) launch_url = 'https://example.edu/foo/bar' launch_headers = {'Content-Type': 'application/x-www-form-urlencoded'} class TpValidator(RequestValidator): dummy_client = '' def validate_timestamp_and_nonce(self, timestamp, nonce, request, request_token=None, access_token=None): return True def validate_client_key(self, client_key, request): return True def get_client_secret(self, client_key, request): return secret_ secret = secret_ # Fool the ProxyValidator tp = ToolProvider(params=lp, launch_url=launch_url, launch_headers=launch_headers) SOE = SignatureOnlyEndpoint with patch.object(SOE, '_check_mandatory_parameters'): with patch.object(SOE, '_check_signature', return_value=True): self.assertTrue(tp.is_valid_request(SOE, TpValidator())) self.assertEqual(tp.consumer_key, key) self.assertEqual(tp.consumer_secret, secret_)
def test_dict_behavior(self): lp = LaunchParams({ 'lti_version': 'foo', 'lti_message_type': 'bar' }) self.assertEqual(len(lp), 2) lp.update({'resource_link_id': 1}) self.assertEqual(len(lp), 3) self.failUnlessRaises(InvalidLaunchParamError, lp.update, { 'foo': 'bar' }) self.assertEqual( set(lp.keys()), {'lti_version', 'lti_message_type', 'resource_link_id'} ) self.assertEqual(dict(lp), { 'lti_version': 'foo', 'lti_message_type': 'bar', 'resource_link_id': 1 })
def create_tb(key=None, secret=None, lp=None): key = key or generate_client_id() secret = secret or generate_token() lp = lp or LaunchParams() return ToolBase(key, secret, lp)
def test_non_spec_params(self): lp = LaunchParams() lp.set_non_spec_param('foo', 'bar') self.assertEqual(lp.get_non_spec_param('foo'), 'bar') self.assertEqual(lp._params['foo'], 'bar')
def test_set_item(self): lp = LaunchParams() lp['lti_version'] = 'bar' self.assertEqual(lp['lti_version'], 'bar')
def test_get_item(self): lp = LaunchParams() self.assertEqual(lp['lti_version'], DEFAULT_LTI_VERSION) with self.assertRaises(KeyError): foo = lp['foo']