Exemplo n.º 1
0
def add_file_ids_to_form(form, file_ids):
    """
    Add existing asset_ids to a form
    :param form:
    :param image_ids:
    :return:
    """
    for label, file_id in file_ids.iteritems():
        form.add_asset(Id(file_id['assetId']), label,
                       Id(file_id['assetContentTypeId']))
    return form
Exemplo n.º 2
0
def set_item_learning_objectives(data, form):
    # over-writes current ID list
    id_list = []
    if not isinstance(data['learningObjectiveIds'], list):
        data['learningObjectiveIds'] = [data['learningObjectiveIds']]
    for _id in data['learningObjectiveIds']:
        if '@' in _id:
            id_list.append(Id(quote(_id)))
        else:
            id_list.append(Id(_id))
    form.set_learning_objectives(id_list)
    return form
Exemplo n.º 3
0
    def _get_test_store_path(runtime):
        try:
            full_path_param_id = Id('parameter:dataStoreFullPath@json')
            full_path = runtime.get_configuration().get_value_by_parameter(
                full_path_param_id).get_string_value()

            path_param_id = Id('parameter:dataStorePath@json')
            rel_path = runtime.get_configuration().get_value_by_parameter(
                path_param_id).get_string_value()

            return os.path.join(full_path, rel_path)
        except (AttributeError, KeyError, NotFound):
            pass
        return None
Exemplo n.º 4
0
 def _init_metadata(self):
     """stub"""
     self._n_of_m_metadata = {
         'element_id':
         Id(self.my_osid_object_form._authority,
            self.my_osid_object_form._namespace, 'nOfM'),
         'element_label':
         'nOfM',
         'instructions':
         'Student is expected to do N of M questions',
         'required':
         False,
         'read_only':
         False,
         'linked':
         False,
         'array':
         False,
         'default_object_values': [-1],
         'syntax':
         'INTEGER',
         'object_set': [],
         'minimum_integer':
         None,
         'maximum_integer':
         None,
         'integer_set': []
     }
Exemplo n.º 5
0
 def _init_metadata(self):
     """stub"""
     self._min_string_length = None
     self._max_string_length = None
     self._unlock_previous_metadata = {
         'element_id':
         Id(self.my_osid_object_form._authority,
            self.my_osid_object_form._namespace, 'unlock_previous'),
         'element_label':
         'unlock_previous',
         'instructions':
         'Indicator to UI on how to treat the previous button',
         'required':
         False,
         'read_only':
         False,
         'linked':
         False,
         'array':
         False,
         'default_string_values': ['always'],
         'syntax':
         'STRING',
         'minimum_string_length':
         self._min_string_length,
         'maximum_string_length':
         self._max_string_length,
         'string_set': []
     }
Exemplo n.º 6
0
    def test_match_learning_objective(self):
        assert self.query._my_osid_query._query_terms == {}

        self.query.match_learning_objective(Id('fake%3Aidentifier%40MIT'),
                                            True)
        assert 'learningObjectiveIds' in self.query._my_osid_query._query_terms
        assert self.query._my_osid_query._query_terms[
            'learningObjectiveIds'] == {
                '$in': ['fake%3Aidentifier%40MIT']
            }
Exemplo n.º 7
0
def edx_asset_content_class_fixture(request):
    obj_map = deepcopy(utilities.TEST_OBJECT_MAP)
    request.cls.osid_object = OsidObject(object_name='TEST_OBJECT',
                                         osid_object_map=obj_map)
    request.cls.asset_content = edXAssetContentRecord(request.cls.osid_object)

    request.cls.test_file = open(
        os.path.join(ABS_PATH, '..', '..', '..', 'tests', 'fixtures', 'assets',
                     'draggable.green.dot.png'), 'rb')

    request.cls.rm = get_repository_manager()
    form = request.cls.rm.get_repository_form_for_create([])
    form.display_name = 'Test repo'
    request.cls.repo = request.cls.rm.create_repository(form)

    form = request.cls.repo.get_asset_form_for_create([])
    form.display_name = 'test asset'
    asset = request.cls.repo.create_asset(form)

    asset_content_type_list = []
    try:
        config = request.cls.repo._catalog._runtime.get_configuration()
        parameter_id = Id('parameter:assetContentRecordTypeForFiles@json')
        asset_content_type_list.append(
            config.get_value_by_parameter(parameter_id).get_type_value())
    except (AttributeError, KeyError, errors.NotFound):
        pass

    form = request.cls.repo.get_asset_content_form_for_create(
        asset.ident, asset_content_type_list)
    form.set_data(DataInputStream(request.cls.test_file))
    request.cls.repo.create_asset_content(form)

    request.cls.asset = request.cls.repo.get_asset(asset.ident)

    def class_tear_down():
        request.cls.test_file.close()
        for asset in request.cls.repo.get_assets():
            request.cls.repo.delete_asset(asset.ident)
        request.cls.rm.delete_repository(request.cls.repo.ident)

    request.addfinalizer(class_tear_down)
Exemplo n.º 8
0
def create_qualifier_id(identifier, namespace, authority='ODL.MIT.EDU'):
    if identifier == 'ROOT':
        authority = 'ODL.MIT.EDU'
    return Id(identifier=identifier, namespace=namespace, authority=authority)
Exemplo n.º 9
0
def create_function_id(function, namespace):
    return Id(identifier=function,
              namespace=namespace,
              authority='ODL.MIT.EDU')
Exemplo n.º 10
0
def create_agent_id(username, authority='MIT-ODL'):
    return Id(identifier=username,
              namespace='osid.agent.Agent',
              authority=authority)