Exemple #1
0
    def test_get_statements_correct_status(self):
        api.CONNECT_ARGS['get'].return_value = MockResponse(200)
        api.get_statements({'dummy_time': 'dummy_value'})

        api.CONNECT_ARGS['get'].assert_called_with(
            'DUMMY_LL_URL/data/xAPI/statements',
            headers={
                'Authorization': 'Basic DUMMY_LL_AUTH_KEY',
                'X-Experience-API-Version': '1.0.3'
            },
            params={'dummy_time': 'dummy_value'},
            json=None)
def validate_statements(since, until=None, activity=None, verb=None):
    """
    Validate statements using the known-statements database. Unprocessed statements are added to the Failedstatements.

    :param since: String that returns statements stored after the given timestamp (exclusive).
    :param until: String that returns statements stored before the given timestamp (inclusive). Defaults to None.
    :param activity: String matching the statement’s object identifier. Defaults to None.
    :param verb: String matching the statement’s verb identifier. Defaults to None.
    """
    parameters = {'since': since}

    if until is not None:
        parameters['until'] = until
    if activity is not None:
        parameters['activity'] = activity
    if verb is not None:
        parameters['verb'] = verb

    statements = ll_api.get_statements(parameters)

    for statement in reversed(statements['statements']):
        statement_id = statement['id']
        statement_verb = statement['verb']['id']
        statement_type = statement['object']['definition']['type']

        _, created = ProcessedStatement.objects.get_or_create(
            statement_id=statement_id)

        # Edit_page_viewed event is allowed
        if (created and
            (statement_verb not in IGNORED_VERBS
             or statement_type == 'http://activitystrea.ms/schema/1.0/page')):
            FailedStatement.objects.create(statement=json.dumps(statement),
                                           error='Unforwarded statement')
Exemple #3
0
def get_quiz_questions(grouped_dict):
    """
    Get the quiz questions for all quizzes individually and combine them.

    :param grouped_dict: A dictionary with a list of each of the assessments and resources.
    :type grouped_dict: dict(str,list(dict(str, int)))
    :return: A dictionary with questions.
    :rtype: dict(int, list(dict(str, str)))
    """
    if 'quiz' not in grouped_dict:
        return []

    question_list = {}
    quiz_ids = [quiz['external_id'] for quiz in grouped_dict['quiz']]
    for quiz_id in quiz_ids:
        params = {
            "verb": "http://id.tincanapi.com/verb/viewed",
            "activity": f"{settings.MOODLE_BASE_URL}/mod/quiz/edit.php?cmid={quiz_id}",
            "limit": 1
        }

        questions = ll_get_parsers.parse_quiz_questions(learning_locker.get_statements(params))

        if quiz_id in questions:
            question_list[quiz_id] = questions[quiz_id]
        else:
            question_list[quiz_id] = []

    return question_list
Exemple #4
0
 def test_get_statements_incorrect_status(self):
     api.CONNECT_ARGS['get'].return_value = MockResponse(400)
     with self.assertRaises(Exception):
         api.get_statements({'dummy_time': 'dummy_value'})