def test_make_raises_value_error_if_bad_fields(self): bad_fields = ['bad1', 'bad2'] for field in bad_fields: self.assertNotIn(field, fields._ALL) from_dict = dict(self.base) from_dict.update({b: None for b in bad_fields}) with self.assertRaisesRegexp( ValueError, 'bad fields: %s' % ', '.join(bad_fields)): fields.make(from_dict)
def test_make_overrides_defaults_from_from_dict(self): expected = dict(self.base) from_dict = { fields.LAUNCH_PRESENTATION_RETURN_URL: 'return_url_override', fields.LTI_VERSION: 'lti_version_override', fields.RESOURCE_LINK_ID: 'resource_link_id_override', } expected.update(from_dict) self.assertEqual(expected, fields.make(from_dict))
def test_make_sets_missing_defaults_and_includes_valid_passed_fields(self): expected = dict(self.base) from_dict = { fields.RESOURCE_LINK_ID: fields.RESOURCE_LINK_ID + '_value', 'custom_foo': 'custom_foo_value', } expected.update(from_dict) self.assertEqual(expected, fields.make(from_dict))
def _get_unsigned_launch_parameters(self, extra_fields, name, return_url, resource_link_id, url, user_id): from_dict = { fields.LAUNCH_PRESENTATION_RETURN_URL: return_url, fields.RESOURCE_LINK_ID: resource_link_id, # No support for other roles in CB yet. # Treat as module-protected. pylint: disable=protected-access fields.ROLES: fields._ROLE_STUDENT, } if extra_fields: from_dict.update(extra_fields) if user_id: from_dict.update({fields.USER_ID: user_id}) self.get_custom_unsigned_launch_parameters(from_dict, name) return fields.make(from_dict)
def test_make_raises_value_error_if_missing_fields(self): with self.assertRaisesRegexp( ValueError, 'Missing required fields: ' + fields.RESOURCE_LINK_ID): fields.make(self.base)