Esempio n. 1
0
    def _set_up_course_run(self, with_policy=True, with_grading_policy=True):
        """ Create a simple edX course with course, run, and a set of chapter -> sequential -> vertical
              compositions."""
        # Make sure to set the run_repo as my_osid_object, with a course_repo as parent
        course_genus = Type(**COMPOSITION_GENUS_TYPES['course'])
        course_repo_record = Type(**REPOSITORY_RECORD_TYPES['course-repo'])
        run_repo_record = Type(**REPOSITORY_RECORD_TYPES['run-repo'])
        run_repo_genus = Type(**REPOSITORY_GENUS_TYPES['course-run-repo'])
        lore_repo_record = Type(**REPOSITORY_RECORD_TYPES['lore-repo'])
        edx_composition_record = Type(**COMPOSITION_RECORD_TYPES['edx-composition'])

        form = self.rm.get_repository_form_for_create([lore_repo_record, course_repo_record])
        form.display_name = '6.001x'
        form.set_org('UniX')
        course_repo = self.rm.create_repository(form)

        form = self.rm.get_repository_form_for_create([lore_repo_record, run_repo_record])
        form.display_name = '2017_Fall'
        form.set_genus_type(run_repo_genus)

        if with_policy:
            form.set_policy('Stuff was due yesterday')

        if with_grading_policy:
            form.set_grading_policy('Everything is important')

        run_repo = self.rm.create_repository(form)

        self.rm.add_child_repository(course_repo.ident, run_repo.ident)

        # start by making the vertical, so that when we set children, we have the IDs available
        form = run_repo.get_composition_form_for_create([edx_composition_record])
        form.display_name = 'A vertical!'
        form.set_genus_type(Type(**COMPOSITION_GENUS_TYPES['vertical']))
        form.set_file_name('vertical/a-vertical.xml')
        vertical = run_repo.create_composition(form)

        form = run_repo.get_composition_form_for_create([edx_composition_record])
        form.display_name = 'A sequential!'
        form.set_genus_type(Type(**COMPOSITION_GENUS_TYPES['sequential']))
        form.set_file_name('sequential/a-sequential.xml')
        form.set_children([vertical.ident])
        sequential = run_repo.create_composition(form)

        form = run_repo.get_composition_form_for_create([edx_composition_record])
        form.display_name = 'A chapter!'
        form.set_genus_type(Type(**COMPOSITION_GENUS_TYPES['chapter']))
        form.set_file_name('chapter/a-chapter.xml')
        form.set_children([sequential.ident])
        chapter = run_repo.create_composition(form)

        form = run_repo.get_composition_form_for_create([edx_composition_record])
        form.set_genus_type(course_genus)
        form.set_file_name('course.xml')
        form.set_sequestered(True)
        form.set_children([chapter.ident])
        course_composition = run_repo.create_composition(form)

        return course_repo, run_repo
Esempio n. 2
0
    def get_display_name(self):
        """Gets a display name for this service implementation.

        return: (osid.locale.DisplayText) - a display name
        *compliance: mandatory -- This method must be implemented.*

        """
        return DisplayText(
            text = profile.DISPLAYNAME,
            language_type=Type(**profile.LANGUAGETYPE),
            script_type=Type(**profile.SCRIPTTYPE),
            format_type=Type(**profile.FORMATTYPE))
Esempio n. 3
0
    def get_description(self):
        """Gets a description of this service implementation.

        return: (osid.locale.DisplayText) - a description
        *compliance: mandatory -- This method must be implemented.*

        """
        return DisplayText(
            text=profile.DESCRIPTION,
            language_type=Type(**profile.LANGUAGETYPE),
            script_type=Type(**profile.SCRIPTTYPE),
            format_type=Type(**profile.FORMATTYPE))
Esempio n. 4
0
 def test_can_create_display_text_with_kwargs(self):
     result = DisplayText(
         text='foo',
         language_type=Type('639-2%3AHIN%40ISO'),
         format_type=Type('TextFormats%3APLAIN%40okapia.net'),
         script_type=Type('15924%3ADEVA%40ISO'))
     assert result._text == 'foo'
     assert isinstance(result._language_type, Type)
     assert str(result._language_type) == '639-2%3AHIN%40ISO'
     assert isinstance(result._format_type, Type)
     assert str(result._format_type) == 'TextFormats%3APLAIN%40okapia.net'
     assert isinstance(result._script_type, Type)
     assert str(result._script_type) == '15924%3ADEVA%40ISO'
Esempio n. 5
0
    def test_can_clone_to_new_repo(self):
        edx_composition_record = Type(
            **COMPOSITION_RECORD_TYPES['edx-composition'])

        form = self.rm.get_repository_form_for_create([])
        form.display_name = 'Test Repo 1'
        test_repo_1 = self.rm.create_repository(form)

        form = self.rm.get_repository_form_for_create([])
        form.display_name = 'Test Repo 2'
        test_repo_2 = self.rm.create_repository(form)

        form = test_repo_1.get_composition_form_for_create(
            [edx_composition_record])
        form.display_name = 'A vertical!'
        form.set_genus_type(Type(**COMPOSITION_GENUS_TYPES['vertical']))
        form.set_file_name('vertical/a-vertical.xml')
        vertical = test_repo_1.create_composition(form)

        form = test_repo_1.get_composition_form_for_create(
            [edx_composition_record])
        form.display_name = 'A sequential!'
        form.set_genus_type(Type(**COMPOSITION_GENUS_TYPES['sequential']))
        form.set_file_name('sequential/a-sequential.xml')
        form.set_children([vertical.ident])
        sequential = test_repo_1.create_composition(form)

        form = test_repo_2.get_composition_form_for_create(
            [edx_composition_record])
        form.display_name = 'A chapter!'
        form.set_genus_type(Type(**COMPOSITION_GENUS_TYPES['chapter']))
        form.set_file_name('chapter/a-chapter.xml')
        form.set_children([sequential.ident])
        chapter = test_repo_2.create_composition(form)

        assert test_repo_2.get_compositions().available() == 1
        assert chapter.get_child_ids().available() == 1
        assert str(next(chapter.get_child_ids())) == str(sequential.ident)

        updated_sequential = sequential.clone_to(test_repo_2, chapter)

        assert updated_sequential._my_map['provenanceId'] == str(
            sequential.ident)

        assert test_repo_2.get_compositions().available() == 2
        assert str(updated_sequential.ident) != str(sequential.ident)

        chapter = test_repo_2.get_composition(chapter.ident)
        assert chapter.get_child_ids().available() == 1
        assert str(next(chapter.get_child_ids())) == str(
            updated_sequential.ident)
Esempio n. 6
0
    def _set_up_course_run(self, with_policy=True, with_grading_policy=True):
        """ Create a simple edX course with course, run, and a set of chapter -> sequential -> vertical
              compositions."""
        # Make sure to set the run_repo as my_osid_object, with a course_repo as parent
        edx_composition_record = Type(
            **COMPOSITION_RECORD_TYPES['edx-composition'])
        course_run_composition_record = Type(
            **COMPOSITION_RECORD_TYPES['edx-course-run'])

        form = self.rm.get_repository_form_for_create([])
        form.display_name = 'Test Repo'
        test_repo = self.rm.create_repository(form)

        # start by making the vertical, so that when we set children, we have the IDs available
        form = test_repo.get_composition_form_for_create(
            [edx_composition_record])
        form.display_name = 'A vertical!'
        form.set_genus_type(Type(**COMPOSITION_GENUS_TYPES['vertical']))
        form.set_file_name('vertical/a-vertical.xml')
        vertical = test_repo.create_composition(form)

        form = test_repo.get_composition_form_for_create(
            [edx_composition_record])
        form.display_name = 'A sequential!'
        form.set_genus_type(Type(**COMPOSITION_GENUS_TYPES['sequential']))
        form.set_file_name('sequential/a-sequential.xml')
        form.set_children([vertical.ident])
        sequential = test_repo.create_composition(form)

        form = test_repo.get_composition_form_for_create(
            [edx_composition_record])
        form.display_name = 'A chapter!'
        form.set_genus_type(Type(**COMPOSITION_GENUS_TYPES['chapter']))
        form.set_file_name('chapter/a-chapter.xml')
        form.set_children([sequential.ident])
        chapter = test_repo.create_composition(form)

        form = test_repo.get_composition_form_for_create(
            [course_run_composition_record])
        form.display_name = '2017_Fall'
        form.set_children([chapter.ident])
        run_composition = test_repo.create_composition(form)

        form = test_repo.get_composition_form_for_create(
            [edx_composition_record])
        form.display_name = '6.001x'
        form.set_children([run_composition.ident])
        course_composition = test_repo.create_composition(form)

        return course_composition, run_composition
Esempio n. 7
0
 def __init__(self, object_map):
     super(EdXCompositionRecord, self).__init__(object_map)
     if (not hasattr(self.my_osid_object, '_supported_record_type_ids') or
             self.my_osid_object._supported_record_type_ids is None):
         self.my_osid_object._supported_record_type_ids = []
     self.my_osid_object._supported_record_type_ids.append(
         str(Type(**COMPOSITION_RECORD_TYPES['edx-composition'])))
Esempio n. 8
0
File: objects.py Progetto: UOC/dlkit
    def get_calendar_type(self):
        """Gets the calendar ``Type``.

        return: (osid.type.Type) - the calendar type
        *compliance: mandatory -- This method must be implemented.*

        """
        return Type(**calendar.get_type_data(self._calendar_type_identifier))
Esempio n. 9
0
File: objects.py Progetto: UOC/dlkit
    def get_time_type(self):
        """Gets the time ``Type``.

        return: (osid.type.Type) - the time type
        *compliance: mandatory -- This method must be implemented.*

        """
        return Type(**time.get_type_data(self._time_type_identifier))
Esempio n. 10
0
File: objects.py Progetto: UOC/dlkit
    def get_coordinate_format_type(self):
        """Gets the coordinate format ``Type``.

        return: (osid.type.Type) - the coordinate format type
        *compliance: mandatory -- This method must be implemented.*

        """
        return Type(**coordinate_format.get_type_data(
            self._coordinate_format_type_identifier))
Esempio n. 11
0
File: objects.py Progetto: UOC/dlkit
    def get_unit_system_type(self):
        """Gets the unit system ``Type``.

        return: (osid.type.Type) - the unit system type
        *compliance: mandatory -- This method must be implemented.*

        """
        return Type(
            **unit_system.get_type_data(self._unit_system_type_identifier))
Esempio n. 12
0
def remove_media_description_language(repo, asset_id, language_type):
    asset_contents = repo.get_asset_contents_by_genus_type_for_asset(
        MEDIA_DESCRIPTION_ASSET_CONTENT_GENUS_TYPE, asset_id)
    if asset_contents.available() > 0:
        if isinstance(language_type, basestring):
            language_type = Type(language_type)
        asset_content = asset_contents.next()
        form = repo.get_asset_content_form_for_update(asset_content.ident)
        form.remove_media_description_language(language_type)
        repo.update_asset_content(form)
Esempio n. 13
0
 def test_set_priority(self):
     """Tests set_priority"""
     # From test_templates/logging.py::LogEntryForm::set_priority_template
     if not is_never_authz(self.service_config):
         self.form.set_priority(
             Type('type.Type%3Afake-type-id%40ODL.MIT.EDU'))
         assert self.form._my_map[
             'priority'] == 'type.Type%3Afake-type-id%40ODL.MIT.EDU'
         with pytest.raises(errors.InvalidArgument):
             self.form.set_priority(True)
Esempio n. 14
0
def remove_vtt_file_language(repo, asset_id, language_type):
    asset_contents = repo.get_asset_contents_by_genus_type_for_asset(
        VTT_ASSET_CONTENT_GENUS_TYPE, asset_id)
    if asset_contents.available() > 0:
        if isinstance(language_type, basestring):
            language_type = Type(language_type)
        asset_content = asset_contents.next()
        form = repo.get_asset_content_form_for_update(asset_content.ident)
        form.remove_vtt_file_language(language_type)
        repo.update_asset_content(form)
Esempio n. 15
0
 def test_clear_priority(self):
     """Tests clear_priority"""
     # From test_templates/logging.py::LogEntryForm::clear_priority_template
     if not is_never_authz(self.service_config):
         self.form.set_priority(
             Type('type.Type%3Afake-type-id%40ODL.MIT.EDU'))
         assert self.form._my_map[
             'priority'] == 'type.Type%3Afake-type-id%40ODL.MIT.EDU'
         self.form.clear_priority()
         assert self.form._my_map[
             'priorityId'] == self.form.get_priority_metadata(
             ).get_default_type_values()[0]
Esempio n. 16
0
 def get_genus_type(self):
     """Overrides get_genus_type of extended object"""
     enclosed_object_id = self.get_enclosed_object_id()
     package = enclosed_object_id.get_identifier_namespace().split('.')[0]
     obj = enclosed_object_id.get_identifier_namespace().split('.')[1]
     return Type(
         authority='OSID.ORG',
         namespace=package,
         identifier=obj,
         display_name=obj,
         display_label=obj,
         description=package + ' ' + obj + ' type',
         domain=package + '.' + obj)
Esempio n. 17
0
    def test_clean_up_removes_all_run_compositions_and_assets(self):
        course_repo, run_repo = self._set_up_course_run(with_policy=False)

        lore_repo_record = Type(**REPOSITORY_RECORD_TYPES['lore-repo'])
        form = self.rm.get_repository_form_for_create([lore_repo_record])
        form.display_name = 'test user repository'
        user_repo = self.rm.create_repository(form)

        run_repo.clean_up(user_repo)

        with self.assertRaises(errors.NotFound):
            self.rm.get_repository(run_repo.ident)

        self.assertEqual(self.rm.get_child_repositories(course_repo.ident).available(), 0)
Esempio n. 18
0
 def course_node(self):
     rm = self.my_osid_object._get_provider_manager('REPOSITORY')
     if self.my_osid_object._proxy is None:
         cls = rm.get_composition_lookup_session_for_repository(
             self.my_osid_object.ident)
     else:
         cls = rm.get_composition_lookup_session_for_repository(
             self.my_osid_object.ident, proxy=self.my_osid_object._proxy)
     cls.use_unsequestered_composition_view()
     try:
         return next(
             cls.get_compositions_by_genus_type(
                 Type(**COMPOSITION_GENUS_TYPES['course'])))
     except StopIteration:
         raise AttributeError
Esempio n. 19
0
    def test_can_get_course_node(self):
        """Tests course_node"""
        course_genus = Type(**COMPOSITION_GENUS_TYPES['course'])
        form = self.rm.get_repository_form_for_create([])
        form.display_name = 'test repo'
        repo = self.rm.create_repository(form)
        form = repo.get_composition_form_for_create([])
        form.set_genus_type(course_genus)
        composition = repo.create_composition(form)
        self.lore_repository.my_osid_object._my_map['_id'] = repo.ident.identifier
        self.assertTrue(isinstance(self.lore_repository.course_node, Composition))
        self.assertEqual(str(self.lore_repository.course_node.genus_type),
                         str(course_genus))

        repo.delete_composition(composition.ident)
        self.rm.delete_repository(repo.ident)
Esempio n. 20
0
def make_catalog_map(cat_name, identifier=PHANTOM_ROOT_IDENTIFIER, default_text='Default'):
    return ({
        '_id': ObjectId(identifier),
        'displayName': {'text': default_text + ' ' + cat_name,
                        'languageTypeId': str(Type(**types.Language().get_type_data('DEFAULT'))),
                        'scriptTypeId': str(Type(**types.Script().get_type_data('DEFAULT'))),
                        'formatTypeId': str(Type(**types.Format().get_type_data('DEFAULT'))), },
        'description': {'text': default_text + ' ' + cat_name,
                        'languageTypeId': str(Type(**types.Language().get_type_data('DEFAULT'))),
                        'scriptTypeId': str(Type(**types.Script().get_type_data('DEFAULT'))),
                        'formatTypeId': str(Type(**types.Format().get_type_data('DEFAULT'))), },
        'genusTypeId': str(Type(**types.Genus().get_type_data('DEFAULT'))),
        'recordTypeIds': []
    })
Esempio n. 21
0
    def _set_up_simple_structure(self):
        edx_composition_record = Type(
            **COMPOSITION_RECORD_TYPES['edx-composition'])
        edx_asset_record = Type(**ASSET_RECORD_TYPES['edx-asset'])
        edx_asset_content_record = Type(
            **ASSET_CONTENT_RECORD_TYPES['edx-asset-content-text-files'])
        edx_asset_content_genus = Type(**ASSET_CONTENT_GENUS_TYPES['html'])

        form = self.rm.get_repository_form_for_create([])
        form.display_name = 'Test Repo'
        test_repo = self.rm.create_repository(form)

        form = test_repo.get_composition_form_for_create(
            [edx_composition_record])
        form.display_name = 'A vertical!'
        form.set_genus_type(Type(**COMPOSITION_GENUS_TYPES['vertical']))
        form.set_file_name('vertical/a-vertical.xml')
        self.vertical = test_repo.create_composition(form)

        form = test_repo.get_composition_form_for_create(
            [edx_composition_record])
        form.display_name = 'A (non-) vertical!'
        form.set_genus_type(Type(**COMPOSITION_GENUS_TYPES['vertical']))
        form.set_sequestered(True)
        sequestered_vertical = test_repo.create_composition(form)

        form = test_repo.get_composition_form_for_create(
            [edx_composition_record])
        form.display_name = 'A sequential!'
        form.set_genus_type(Type(**COMPOSITION_GENUS_TYPES['sequential']))
        form.set_file_name('sequential/a-sequential.xml')
        form.set_children([self.vertical.ident, sequestered_vertical.ident])
        sequential = test_repo.create_composition(form)

        form = test_repo.get_asset_form_for_create([edx_asset_record])
        form.display_name = 'Introduction to Python'
        asset = test_repo.create_asset(form)

        form = test_repo.get_asset_content_form_for_create(
            asset.ident, [edx_asset_content_record])
        form.set_text('<html><body><div>foo!</div></body></html>')
        form.set_genus_type(edx_asset_content_genus)
        test_repo.create_asset_content(form)
        self.asset = test_repo.get_asset(asset.ident)

        test_repo.add_asset(self.asset.ident, sequestered_vertical.ident)

        return sequential
Esempio n. 22
0
def get_asset_content_genus_type(file_name):
    extension = get_file_extension(file_name).lower()
    if 'png' in extension:
        ac_genus_type = PNG_ASSET_CONTENT_GENUS_TYPE
    elif 'jpg' in extension or 'jpeg' in extension:
        ac_genus_type = JPG_ASSET_CONTENT_GENUS_TYPE
    elif 'svg' in extension:
        ac_genus_type = SVG_ASSET_CONTENT_GENUS_TYPE
    elif 'mp3' in extension:
        ac_genus_type = MP3_ASSET_CONTENT_GENUS_TYPE
    elif 'wav' in extension:
        ac_genus_type = WAV_ASSET_CONTENT_GENUS_TYPE
    else:
        # since this is used for the extension, let's derive it
        # more gracefully
        ac_genus_type = Type(identifier=extension,
                             namespace='asset-content-genus-type',
                             authority='ODL.MIT.EDU')
        # ac_genus_type = GENERIC_ASSET_CONTENT_GENUS_TYPE
    return ac_genus_type
Esempio n. 23
0
"""

from dlkit.json_.osid import record_templates as osid_records
from dlkit.json_.osid import objects as osid_objects
from dlkit.json_ import types, utilities
from dlkit.json_.osid.metadata import Metadata
from dlkit.json_.learning.objects import ObjectiveList

from dlkit.abstract_osid.osid.errors import InvalidArgument, IllegalState, NoAccess
from dlkit.primordium.id.primitives import Id
from dlkit.primordium.type.primitives import Type
from dlkit.primordium.locale.primitives import DisplayText

from ...osid.base_records import ObjectInitRecord, MultiLanguageUtils

DEFAULT_LANGUAGE_TYPE = Type(**types.Language().get_type_data('DEFAULT'))
DEFAULT_SCRIPT_TYPE = Type(**types.Script().get_type_data('DEFAULT'))
DEFAULT_FORMAT_TYPE = Type(**types.Format().get_type_data('DEFAULT'))


class FeedbackAnswerRecord(ObjectInitRecord):
    """
    This is really only a marker implementation to indicate that
    this answer includes a hint / feedback text.
    """
    _implemented_record_type_identifiers = [
        'answer-with-feedback', 'texts-answer'
    ]

    def has_feedback(self):
        if self.my_osid_object._my_map['feedback']:
Esempio n. 24
0
from dlkit.primordium.id.primitives import Id
from dlkit.primordium.type.primitives import Type

from .orthographic_records import FirstAngleProjectionFormRecord,\
    FirstAngleProjectionRecord,\
    BaseInitMixin
from ..basic.simple_records import QuestionFilesRecord,\
    QuestionFilesFormRecord
from ..basic.multi_choice_records import MultiChoiceFileQuestionRecord,\
    MultiChoiceFileQuestionFormRecord,\
    MultiChoiceFileAnswerRecord,\
    MultiChoiceFileAnswerFormRecord

from ...registry import ASSET_GENUS_TYPES, ASSET_CONTENT_GENUS_TYPES

MANIP_ASSET_TYPE = Type(**ASSET_GENUS_TYPES['manipulateable-asset-type'])  # This may be obsolete
O3D_ASSET_TYPE = Type(**ASSET_GENUS_TYPES['ortho3d-asset-type'])
MANIP_ASSET_CONTENT_TYPE = Type(**ASSET_CONTENT_GENUS_TYPES['manipulateable-asset-content'])
OV_SET_ASSET_TYPE = Type(**ASSET_GENUS_TYPES['ortho-view-set-asset'])  # This may be obsolete
OV_SET_SMALL_ASSET_CONTENT_TYPE = Type(**ASSET_CONTENT_GENUS_TYPES['ortho-view-set-small'])
OV_SET_LARGE_ASSET_CONTENT_TYPE = Type(**ASSET_CONTENT_GENUS_TYPES['ortho-view-set-large'])


class MultiChoiceOrthoQuestionRecord(MultiChoiceFileQuestionRecord,
                                     QuestionFilesRecord,
                                     FirstAngleProjectionRecord):
    """multiple choice ortho3D question...files for Q and choices"""
    _implemented_record_type_identifiers = [
        'multi-choice-ortho',
        'multi-choice-file',
        'question-text',
Esempio n. 25
0
from dlkit.primordium.id.primitives import Id
from dlkit.primordium.transport.objects import DataInputStream
from dlkit.primordium.type.primitives import Type
from dlkit.json_ import types

from dlkit.runtime import PROXY_SESSION, RUNTIME
from dlkit.runtime.errors import NotFound
from dlkit.runtime.primitives import InitializableLocale
from dlkit.runtime.proxy_example import SimpleRequest

from dlkit.records import registry

import utilities

DEFAULT_LANGUAGE_TYPE = Type(**types.Language().get_type_data('DEFAULT'))
DEFAULT_SCRIPT_TYPE = Type(**types.Script().get_type_data('DEFAULT'))
DEFAULT_FORMAT_TYPE = Type(**types.Format().get_type_data('DEFAULT'))

IMAGE_ASSET_GENUS_TYPE = Type(**registry.ASSET_GENUS_TYPES['image'])
JPG_ASSET_CONTENT_GENUS_TYPE = Type(
    **registry.ASSET_CONTENT_GENUS_TYPES['jpg'])
GENERIC_ASSET_CONTENT_GENUS_TYPE = Type(
    **registry.ASSET_CONTENT_GENUS_TYPES['generic'])
MP3_ASSET_CONTENT_GENUS_TYPE = Type(
    **registry.ASSET_CONTENT_GENUS_TYPES['mp3'])
PNG_ASSET_CONTENT_GENUS_TYPE = Type(
    **registry.ASSET_CONTENT_GENUS_TYPES['png'])
SVG_ASSET_CONTENT_GENUS_TYPE = Type(
    **registry.ASSET_CONTENT_GENUS_TYPES['svg'])
WAV_ASSET_CONTENT_GENUS_TYPE = Type(
Esempio n. 26
0
    def all_children(self, repository=None):
        child_objects = []
        rm = self.my_osid_object._get_provider_manager('REPOSITORY')
        if repository is None:
            repository_id = Id(self.my_osid_object.object_map['assignedRepositoryIds'][0])
            if self.my_osid_object._proxy is None:
                rls = rm.get_repository_lookup_session()
            else:
                rls = rm.get_repository_lookup_session(proxy=self.my_osid_object._proxy)

            repository = rls.get_repository(repository_id)
        append_error_child = False
        error_compositions = []
        missing_child_ids = []

        for child_id in self.my_osid_object.get_child_ids():
            if repository._proxy is not None:
                composition_lookup_session = rm.get_composition_lookup_session_for_repository(
                    repository.ident,
                    proxy=repository._proxy
                )
            else:
                composition_lookup_session = rm.get_composition_lookup_session_for_repository(repository.ident)
            composition_lookup_session.use_federated_repository_view()
            composition_lookup_session.use_unsequestered_composition_view()

            try:
                child = composition_lookup_session.get_composition(child_id)
                if child.is_sequestered():
                    try:
                        for asset in child.assets:
                            child_objects.append((asset, False))  # For now, cannot edit assets...
                    except NotFound:
                        # no assets
                        pass
                else:
                    child_objects.append((child, True))
            except NotFound:
                try:
                    # append the child, but flag it as not belonging to the user...
                    if repository._proxy is not None:
                        composition_lookup_session = rm.get_composition_lookup_session(proxy=repository._proxy)
                    else:
                        composition_lookup_session = rm.get_composition_lookup_session()
                    composition_lookup_session.use_federated_repository_view()
                    composition_lookup_session.use_unsequestered_composition_view()
                    child = composition_lookup_session.get_composition(child_id)
                    if child.is_sequestered():
                        try:
                            for asset in child.assets:
                                child_objects.append((asset, False))
                        except NotFound:
                            # no assets
                            pass
                    else:
                        child_objects.append((child, False))
                except NotFound:
                    # the composition must be deleted or no longer accessible to
                    # the user. Remove the ID from the child_ids list, and
                    # add a sequestered child here notifying the user
                    if repository._proxy is not None:
                        cas = rm.get_composition_admin_session_for_repository(
                            repository.ident,
                            proxy=repository._proxy
                        )
                    else:
                        cas = rm.get_composition_admin_session_for_repository(repository.ident)
                    form = cas.get_composition_form_for_create([Type(**COMPOSITION_RECORD_TYPES['edx-composition'])])
                    form.set_genus_type(Type(**COMPOSITION_GENUS_TYPES['error-deleted']))
                    form.display_name = 'Missing composition: ' + str(child_id)
                    form.description = 'This composition has been deleted, or you no longer have access to it.'
                    error_composition = cas.create_composition(form)
                    error_compositions.append(error_composition)
                    missing_child_ids.append(str(child_id))
                    append_error_child = True
                    child_objects.append((error_composition, False))

        if append_error_child:
            current_child_ids = self.my_osid_object.get_child_ids()
            current_child_idstrs = [str(i) for i in current_child_ids]
            for index, child_id in enumerate(current_child_idstrs):
                if child_id in missing_child_ids:
                    current_child_idstrs[index] = str(error_compositions[missing_child_ids.index(child_id)].ident)

            updated_child_ids = [Id(i) for i in current_child_idstrs]
            if repository._proxy is not None:
                cas = rm.get_composition_admin_session_for_repository(
                    repository.ident,
                    proxy=repository._proxy
                )
            else:
                cas = rm.get_composition_admin_session_for_repository(repository.ident)
            form = cas.get_composition_form_for_update(self.my_osid_object.ident)
            form.set_children(updated_child_ids)
            cas.update_composition(form)
        return child_objects
Esempio n. 27
0
from six import BytesIO

from bs4 import BeautifulSoup

from dlkit.abstract_osid.repository import record_templates as abc_repository_records
from dlkit.abstract_osid.osid.errors import IllegalState, NotFound
from dlkit.primordium.id.primitives import Id
from dlkit.primordium.type.primitives import Type

from ...osid.base_records import TextsRecord, TextsFormRecord

from ..registry import COMPOSITION_GENUS_TYPES, COMPOSITION_RECORD_TYPES

from ..edx.utilities import EdXUtilitiesMixin, clean_str

EDX_COMPOSITION_RECORD_TYPE = Type(
    **COMPOSITION_RECORD_TYPES['edx-composition'])


class LoreRepositoryRecord(TextsRecord,
                           abc_repository_records.RepositoryRecord):
    """basic LORE repository content"""
    _implemented_record_type_identifiers = ['lore-repo', 'texts']

    @property
    def id(self):
        return self.my_osid_object.ident

    @property
    def name(self):
        return self.my_osid_object.display_name
Esempio n. 28
0
from ..utilities.general import is_never_authz, is_no_authz, uses_cataloging, uses_filesystem_only
from dlkit.abstract_osid.osid import errors
from dlkit.primordium.id.primitives import Id
from dlkit.primordium.type.primitives import Type
from dlkit.runtime import PROXY_SESSION, proxy_example
from dlkit.runtime.managers import Runtime

REQUEST = proxy_example.SimpleRequest()
CONDITION = PROXY_SESSION.get_proxy_condition()
CONDITION.set_http_request(REQUEST)
PROXY = PROXY_SESSION.get_proxy(CONDITION)

DEFAULT_TYPE = Type(**{
    'identifier': 'DEFAULT',
    'namespace': 'DEFAULT',
    'authority': 'DEFAULT'
})


@pytest.fixture(scope="class",
                params=[
                    'TEST_SERVICE', 'TEST_SERVICE_ALWAYS_AUTHZ',
                    'TEST_SERVICE_NEVER_AUTHZ', 'TEST_SERVICE_CATALOGING',
                    'TEST_SERVICE_FILESYSTEM', 'TEST_SERVICE_MEMCACHE'
                ])
def resource_query_class_fixture(request):
    # From test_templates/resource.py::ResourceQuery::init_template
    request.cls.service_config = request.param
    request.cls.svc_mgr = Runtime().get_service_manager(
        'RESOURCE', proxy=PROXY, implementation=request.cls.service_config)
Esempio n. 29
0
 def test_get_log_entry_form_record(self):
     """Tests get_log_entry_form_record"""
     if not is_never_authz(self.service_config):
         with pytest.raises(errors.Unsupported):
             self.form.get_log_entry_form_record(
                 Type('osid.Osid%3Afake-record%40ODL.MIT.EDU'))
Esempio n. 30
0
JANE_CONDITION = PROXY_SESSION.get_proxy_condition()
JANE_CONDITION.set_http_request(JANE_REQUEST)
JANE_PROXY = PROXY_SESSION.get_proxy(JANE_CONDITION)

LOOKUP_AUTHORIZATION_FUNCTION_ID = Id(**{'identifier': 'lookup', 'namespace': 'authorization.Authorization', 'authority': 'ODL.MIT.EDU'})
SEARCH_AUTHORIZATION_FUNCTION_ID = Id(**{'identifier': 'search', 'namespace': 'authorization.Authorization', 'authority': 'ODL.MIT.EDU'})
CREATE_AUTHORIZATION_FUNCTION_ID = Id(**{'identifier': 'create', 'namespace': 'authorization.Authorization', 'authority': 'ODL.MIT.EDU'})
DELETE_AUTHORIZATION_FUNCTION_ID = Id(**{'identifier': 'delete', 'namespace': 'authorization.Authorization', 'authority': 'ODL.MIT.EDU'})
ASSIGN_AUTHORIZATION_FUNCTION_ID = Id(**{'identifier': 'assign', 'namespace': 'authorization.AuthorizationVault', 'authority': 'ODL.MIT.EDU'})
CREATE_VAULT_FUNCTION_ID = Id(**{'identifier': 'create', 'namespace': 'authorization.Vault', 'authority': 'ODL.MIT.EDU'})
DELETE_VAULT_FUNCTION_ID = Id(**{'identifier': 'delete', 'namespace': 'authorization.Vault', 'authority': 'ODL.MIT.EDU'})
LOOKUP_VAULT_FUNCTION_ID = Id(**{'identifier': 'lookup', 'namespace': 'authorization.Vault', 'authority': 'ODL.MIT.EDU'})
ACCESS_VAULT_HIERARCHY_FUNCTION_ID = Id(**{'identifier': 'access', 'namespace': 'authorization.Vault', 'authority': 'ODL.MIT.EDU'})
MODIFY_VAULT_HIERARCHY_FUNCTION_ID = Id(**{'identifier': 'modify', 'namespace': 'authorization.Vault', 'authority': 'ODL.MIT.EDU'})
ROOT_QUALIFIER_ID = Id('authorization.Vault%3AROOT%40ODL.MIT.EDU')
BOOTSTRAP_VAULT_TYPE = Type(authority='ODL.MIT.EDU', namespace='authorization.Vault', identifier='bootstrap_vault')
OVERRIDE_VAULT_TYPE = Type(authority='ODL.MIT.EDU', namespace='authorization.Vault', identifier='override_vault')
DEFAULT_TYPE = Type(**{'identifier': 'DEFAULT', 'namespace': 'DEFAULT', 'authority': 'DEFAULT'})
DEFAULT_GENUS_TYPE = Type(**{'identifier': 'DEFAULT', 'namespace': 'GenusType', 'authority': 'DLKIT.MIT.EDU'})
ALIAS_ID = Id(**{'identifier': 'ALIAS', 'namespace': 'ALIAS', 'authority': 'ALIAS'})
AGENT_ID = Id(**{'identifier': 'jane_doe', 'namespace': 'osid.agent.Agent', 'authority': 'MIT-ODL'})
NEW_TYPE = Type(**{'identifier': 'NEW', 'namespace': 'MINE', 'authority': 'YOURS'})
NEW_TYPE_2 = Type(**{'identifier': 'NEW 2', 'namespace': 'MINE', 'authority': 'YOURS'})
BLUE_TYPE = Type(authority='BLUE', namespace='BLUE', identifier='BLUE')


@pytest.fixture(scope="class",
                params=['TEST_SERVICE'])
def authz_adapter_class_fixture(request):
    request.cls.service_config = request.param
    request.cls.authz_mgr = Runtime().get_manager(