Esempio n. 1
0
    def test_data_2_tincan(self):
        args = []
        opts = {}
        obj = Activity(
            id="block-v1:Polimi+FIS101+2015_M9+type@video+block@W1M1L1_video",
            definition=ActivityDefinition(
                name=LanguageMap({'en-US': OAI_PREFIX + COURSE_ID}),
                type="http://adlnet.gov/expapi/activities/course"
            )
        )
        verb = LearnerAccessesMoocVerb.get_verb()
        timestamp = datetime(2012, 1, 1, tzinfo=UTC).isoformat()
        course_parent = {
            "id":  OAI_PREFIX + COURSE_ID,
            "objectType": "Activity",
            "definition": {
                "name": {
                    "en-US": "COURSE_TEST"
                },
                "description": {
                    "en-US": "TESTING"
                },
                "type": "http://adlnet.gov/expapi/activities/course"
            }
        }
        parents = []
        parents.append(course_parent)

        context = {
            "contextActivities": {
                "parent": parents
            }
        }
        actor = {
            "objectType": "Agent",
            "account": {
                "homePage": "%s?user=%s" % (TEST_HOMEPAGE_URL, TEST_UID),
                "name": TEST_UID
            }
        }
        statement = {
            'actor': actor,
            'verb': verb.to_json(),
            'object': obj.to_json(),
            'timestamp': timestamp,
            'context': context
        }

        tldat = TrackingLog(
            dtcreated=timestamp,
            user_id=1,
            course_id=COURSE_ID,
            statement=json.dumps(statement)
        ).save()
        call_command('send_data_2_tincan', *args, **opts)
        tldat = TrackingLog.objects.all()[:1].get()
        self.assertTrue(tldat.exported)
        self.assertIsNotNone(tldat.tincan_key)
        self.assertEqual(json.loads(tldat.tincan_key)['result'].lower(), "ok")
Esempio n. 2
0
    def handle(self, *args, **options):
        # make sure file option is present
        if options['extract_event_number'] is None:
            extract_event_number = 100
        else:
            extract_event_number = int(options['extract_event_number'])

        evt_list = TrackingLog.objects \
                              .filter(tincan_error='WRONG_VERB_OBJECT') \
                              .order_by('dtcreated')[:extract_event_number]
        for evt in evt_list:
            statement_json = json.loads(evt.statement)
            statement = {
                'actor': Agent.from_json(json.dumps(statement_json['actor'])),
                'verb': Verb.from_json(json.dumps(statement_json['verb'])),
                'object': Activity.from_json(json.dumps(statement_json['object'])),
                'timestamp': statement_json['timestamp'],
                'context': Context.from_json(json.dumps(statement_json['context'])),
            }
            evt.statement = json.dumps(statement)
            evt.tincan_error = "CONVERTED"
            evt.save()
Esempio n. 3
0
 def test_Init(self):
     alist = ActivityList(
         [Activity(id='test1', object_type='Activity'), Activity(id='test2', object_type='Activity')]
     )
     self.listVerificationHelper(alist)
Esempio n. 4
0
 def test_extendExceptionNotComponent(self):
     a1 = Activity(id='test1', object_type='Activity')
     arglist = [a1, 'not Activity']
     alist = ActivityList([Activity()])
     with self.assertRaises(TypeError):
         alist.extend(arglist)
Esempio n. 5
0
 def test_AsVersionNotEmpty(self):
     activity = Activity(id='test')
     activity2 = activity.as_version()
     self.assertEqual(activity2, {'id': 'test', "objectType": "Activity"})
Esempio n. 6
0
 def test_FromJSONExceptionEmptyObject(self):
     activity = Activity.from_json('{}')
     self.assertIsInstance(activity, Activity)
     self.assertIsNone(activity.id, None)
Esempio n. 7
0
 def compair(cls):
     return Activity(id=XAPIResourceIRI.compair(),
                     definition=ActivityDefinition(
                         type=XAPIActivity.activity_types.get('service'),
                         name=LanguageMap({'en-US': "ComPAIR"})))
Esempio n. 8
0
 def user_profile(cls, user):
     return Activity(
         id=XAPIResourceIRI.user_profile(user.uuid),
         definition=ActivityDefinition(
             type=XAPIActivity.activity_types.get('user profile'),
             name=LanguageMap({'en-US': "user profile"})))
Esempio n. 9
0
 def test_FromJSONExceptionEmptyObject(self):
     activity = Activity.from_json('{}')
     self.assertIsInstance(activity, Activity)
     self.assertIsNone(activity.id, None)
Esempio n. 10
0
 def test_FromJSONExcpetionEmptyId(self):
     with self.assertRaises(ValueError):
         activity = Activity.from_json('{"id": ""}')
Esempio n. 11
0
 def test_FromJSON(self):
     activity = Activity.from_json('{"id": "test", "definition": {}, "object_type": "Activity"}')
     self.activityVerificationHelper(activity)
Esempio n. 12
0
 def test_setId(self):
     activity = Activity()
     activity.id = 'test'
     self.assertEqual(activity.id, 'test')
Esempio n. 13
0
 def test_setIdException(self):
     activity = Activity()
     with self.assertRaises(ValueError):
         activity.id = ''
Esempio n. 14
0
 def test_setObjectType(self):
     activity = Activity()
     activity.object_type = 'Activity'
     self.assertEqual(activity.object_type, 'Activity')
Esempio n. 15
0
 def test_InitExceptionNotActivity(self):
     with self.assertRaises(TypeError):
         ActivityList([Activity(), 'not InteractionComponent'])
Esempio n. 16
0
 def answer(cls, answer):
     return Activity(id=XAPIResourceIRI.answer(answer.uuid),
                     definition=ActivityDefinition(
                         type=XAPIActivity.activity_types.get('solution'),
                         name=LanguageMap({'en-US': "Assignment answer"})))
Esempio n. 17
0
 def test_AsVersionEmpty(self):
     activity = Activity()
     activity2 = activity.as_version()
     self.assertEqual(activity2, {"objectType": "Activity"})
Esempio n. 18
0
 def report(cls, file_name):
     return Activity(id=XAPIResourceIRI.report(file_name),
                     definition=ActivityDefinition(
                         type=XAPIActivity.activity_types.get('file'),
                         name=LanguageMap({'en-US': "Report"})))
Esempio n. 19
0
 def test_AsVersionNotEmpty(self):
     activity = Activity(id='test')
     activity2 = activity.as_version()
     self.assertEqual(activity2, {'id': 'test', "objectType": "Activity"})
 def test_InitActivityObject(self):
     substatement = SubStatement(object=Activity(id='test'))
     self.activityVerificationHelper(substatement.object)
Esempio n. 21
0
 def test_AsVersion(self):
     activity = Activity(id='test', definition=ActivityDefinition(), object_type='Activity')
     activity2 = activity.as_version()
     self.assertEqual(activity2, {'id': 'test', 'definition': {}, 'objectType': 'Activity'})
Esempio n. 22
0
 def test_setDefinition(self):
     activity = Activity()
     activity.definition = ActivityDefinition()
     self.assertIsInstance(activity.definition, ActivityDefinition)
Esempio n. 23
0
 def test_ToJSONFromJSON(self):
     json_str = '{"id": "test", "definition": {}, "object_type": "Activity"}'
     check_str = '{"definition": {}, "id": "test", "objectType": "Activity"}'
     activity = Activity.from_json(json_str)
     self.activityVerificationHelper(activity)
     self.assertEqual(activity.to_json(), check_str)
Esempio n. 24
0
 def test_AsVersionEmpty(self):
     activity = Activity()
     activity2 = activity.as_version()
     self.assertEqual(activity2, {"objectType": "Activity"})
Esempio n. 25
0
 def test_ToJSON(self):
     check_str = '{"definition": {}, "id": "test", "objectType": "Activity"}'
     activity = Activity(**{'id':'test', 'definition':{}, 'object_type':'Activity'})
     self.assertEqual(activity.to_json(), check_str)
Esempio n. 26
0
 def test_setItem(self):
     alist = ActivityList([Activity(), Activity()])
     alist[0] = {"id": "test1"}
     alist[1] = Activity(id="test2")
     self.listVerificationHelper(alist)
Esempio n. 27
0
 def test_setDefinition(self):
     activity = Activity()
     activity.definition = ActivityDefinition()
     self.assertIsInstance(activity.definition, ActivityDefinition)
Esempio n. 28
0
 def test_insertExceptionNotComponent(self):
     a1 = Activity(id='test1', object_type='Activity')
     a2 = Activity(id='test3')
     alist = ActivityList([a1, a2])
     with self.assertRaises(TypeError):
         alist.insert(1, 'not Activity')
Esempio n. 29
0
 def test_setObjectType(self):
     activity = Activity()
     activity.object_type = 'Activity'
     self.assertEqual(activity.object_type, 'Activity')
Esempio n. 30
0
 def test_InitActivityList(self):
     a1 = Activity(id='test1', object_type='Activity')
     a2 = Activity(id='test2', object_type='Activity')
     arg = ActivityList([a1, a2])
     alist = ActivityList(arg)
     self.listVerificationHelper(alist)
Esempio n. 31
0
 def test_setIdException(self):
     activity = Activity()
     with self.assertRaises(ValueError):
         activity.id = ''
Esempio n. 32
0
def put_statement(request, user, verb, object, target, language=XAPI_LANGUAGE):

    # construct an LRS
    lrs = RemoteLRS(
        version=settings.LRS_VERSION,
        endpoint=settings.LRS_ENDPOINT,
        auth=settings.LRS_AUTH,
    )

    # construct the actor of the statement
    # IMPORTANT - account is OK but cannot coexist with mbox or other way of uniquely identifying the actor
    try:
        actor = Agent(
            name=user.get_display_name(),
            mbox='mailto:%s' % user.email,
            # account=AgentAccount(name=str(user.pk), home_page='https://www.commonspaces.eu')
        )
    except:
        return False

    # construct the verb of the statement
    verb = XAPI_VERB_ALIASES.get(verb,
                                 verb)  # for compatibility with CommonSpaces
    verb = Verb(
        id=xapi_verbs[verb]['id'],
        display=LanguageMap(**xapi_verbs[verb]['display']),
    )

    action = object.__class__.__name__
    action = XAPI_ACTIVITY_ALIASES.get(
        action, action)  # for compatibility with CommonSpaces
    activity_type = xapi_activities[action]['type']
    object_id = get_object_id(request,
                              object)  # 190307 GT: defined get_object_id
    object_name = get_name(object)  # 190307 GT: defined get_name
    object_description = get_description(object)
    object_language = get_language(object)
    activity_definition = ActivityDefinition(
        name=LanguageMap(**{object_language: object_name}),
        description=object_description
        and LanguageMap(**{object_language: object_description}) or None,
        type=activity_type,
    )

    # construct the object of the statement
    object = Activity(
        id=object_id,
        definition=activity_definition,
    )

    context = {'platform': XAPI_PLATFORM, 'language': get_current_language()}
    """ 190308 GT: would produce the exception "Object of type 'UUID' is not JSON serializable" in getting the response
    if request:
        context['registration'] = str(get_registration(request))
    """
    if target:
        target_type = target.__class__.__name__
        context_activities = {}
        if target_type in ['Folder', 'Forum', 'LearningPath']:
            context_activities['parent'] = {
                'objectType': 'Activity',
                'id': get_object_id(request, target),
                'definition': {
                    'type':
                    xapi_activities[XAPI_ACTIVITY_ALIASES.get(
                        target_type, target_type)]['type'],
                    'name': {
                        'en': get_name(target)
                    }
                }
            }
            if target_type == 'Folder':
                project = target.get_project()
                if project:
                    context_activities['grouping'] = get_context_grouping(
                        request, project)
            elif target_type == 'Forum':
                # project = target.forum_get_project()
                project = target.get_project()
                if project:
                    context_activities['grouping'] = get_context_grouping(
                        request, project)
            elif target_type == 'LearningPath':
                if target.project:
                    context_activities['grouping'] = get_context_grouping(
                        request, target.project)
        elif target_type == 'Project':
            context_activities['grouping'] = get_context_grouping(
                request, target)
        if context_activities:
            context['context_activities'] = context_activities
    context = Context(**context)

    # construct the actual statement
    statement = Statement(
        actor=actor,
        verb=verb,
        object=object,
        context=context,
    )
    return send_statement(statement)
Esempio n. 33
0
 def test_setId(self):
     activity = Activity()
     activity.id = 'test'
     self.assertEqual(activity.id, 'test')
Esempio n. 34
0
 def assignment_comment(cls, assignment_comment):
     return Activity(id=XAPIResourceIRI.assignment_comment(
         assignment_comment.uuid),
                     definition=ActivityDefinition(
                         type=XAPIActivity.activity_types.get('comment'),
                         name=LanguageMap({'en-US': "Assignment comment"})))
Esempio n. 35
0
 def test_InitEmpty(self):
     activity = Activity()
     self.assertIsNone(activity.id)
Esempio n. 36
0
 def assignment_attachment(cls, file):
     return Activity(id=XAPIResourceIRI.attachment(file.name),
                     definition=ActivityDefinition(
                         type=XAPIActivity.activity_types.get('file'),
                         name=LanguageMap(
                             {'en-US': "Assignment attachment"})))
Esempio n. 37
0
 def test_InitExceptionEmptyId(self):
     with self.assertRaises(ValueError):
         activity = Activity(id='')
Esempio n. 38
0
 def comparison(cls, comparison):
     return Activity(id=XAPIResourceIRI.comparison(comparison.uuid),
                     definition=ActivityDefinition(
                         type=XAPIActivity.activity_types.get('solution'),
                         name=LanguageMap(
                             {'en-US': "Assignment comparison"})))
Esempio n. 39
0
 def test_Init(self):
     activity = Activity(id='test',
                         definition=ActivityDefinition(),
                         object_type='Activity')
     self.activityVerificationHelper(activity)
 def test_ToJSON(self):
     substatement = SubStatement(object_type='SubStatement', actor=Agent(name='test'), verb=Verb(id='test'),
                                 object=Activity(id='test'))
     self.assertEqual(json.loads(substatement.to_json()),
                      json.loads('{"verb": {"id": "test"}, "object": {"id": "test", "objectType": "Activity"}, '
                                 '"actor": {"name": "test", "objectType": "Agent"}, "objectType": "SubStatement"}'))
Esempio n. 41
0
 def test_InitUnpackExceptionEmptyId(self):
     obj = {'id': ''}
     with self.assertRaises(ValueError):
         activity = Activity(**obj)
Esempio n. 42
0
 def test_ToJSONFromJSON(self):
     json_str = '{"id": "test", "definition": {}, "object_type": "Activity"}'
     check_str = '{"definition": {}, "id": "test", "objectType": "Activity"}'
     activity = Activity.from_json(json_str)
     self.activityVerificationHelper(activity)
     self.assertEqual(json.loads(activity.to_json()), json.loads(check_str))
Esempio n. 43
0
 def test_FromJSON(self):
     activity = Activity.from_json(
         '{"id": "test", "definition": {}, "object_type": "Activity"}')
     self.activityVerificationHelper(activity)
Esempio n. 44
0
 def test_FromJSONExcpetionEmptyId(self):
     with self.assertRaises(ValueError):
         activity = Activity.from_json('{"id": ""}')
Esempio n. 45
0
 def test_setDefinitionException(self):
     activity = Activity()
     with self.assertRaises(AttributeError):
         activity.definition = {"invalid": "definition"}