Пример #1
0
    def test_generate_thumbnail(self):
        # Create exercise node (generated images are more predictable)
        node = ContentNode(title="Test Node", kind_id=content_kinds.EXERCISE)
        node.save()

        # Create assessment item with image
        assessment_item = AssessmentItem(contentnode=node)
        assessment_item.save()
        self.thumbnail_fobj.assessment_item = assessment_item
        self.thumbnail_fobj.preset_id = format_presets.EXERCISE_IMAGE
        self.thumbnail_fobj.save()

        # Call generate_thumbnail endpoint
        request = self.create_post_request(reverse_lazy('generate_thumbnail', kwargs={'contentnode_id': node.pk}))
        response = generate_thumbnail(request, node.pk)
        self.assertEqual(response.status_code, 200)
        file_data = json.loads(response.content)
        self.assertEqual(file_data['encoding'], generated_base64encoding())
Пример #2
0
def create_exercises(node, data):
    """ Generate exercise from data """
    with transaction.atomic():
        order = 0

        for question in data:
            question_obj = AssessmentItem(
                type = question.get('type'),
                question = question.get('question'),
                hints = question.get('hints'),
                answers = question.get('answers'),
                order = order,
                contentnode = node,
                assessment_id = question.get('assessment_id'),
                raw_data = question.get('raw_data'),
            )
            order += 1
            question_obj.save()
            map_files_to_assessment_item(question_obj, question['files'])
Пример #3
0
    def test_generate_thumbnail(self):
        # Create exercise node (generated images are more predictable)
        node = ContentNode(title="Test Node", kind_id=content_kinds.EXERCISE)
        node.save()

        # Create assessment item with image
        assessment_item = AssessmentItem(contentnode=node)
        assessment_item.save()
        self.thumbnail_fobj.assessment_item = assessment_item
        self.thumbnail_fobj.preset_id = format_presets.EXERCISE_IMAGE
        self.thumbnail_fobj.save()

        # Call generate_thumbnail endpoint
        request = self.create_post_request(
            reverse_lazy('generate_thumbnail',
                         kwargs={'contentnode_id': node.pk}))
        response = generate_thumbnail(request, node.pk)
        self.assertEqual(response.status_code, 200)
        file_data = json.loads(response.content)
        self.assertEqual(file_data['encoding'], generated_base64encoding())
Пример #4
0
def create_exercises(user, node, data):
    """ Generate exercise from data """
    with transaction.atomic():
        order = 0

        for question in data:
            question_obj = AssessmentItem(
                type=question.get('type'),
                question=question.get('question'),
                hints=question.get('hints'),
                answers=question.get('answers'),
                order=order,
                contentnode=node,
                assessment_id=question.get('assessment_id'),
                raw_data=question.get('raw_data'),
                source_url=question.get('source_url'),
                randomize=question.get('randomize') or False,
            )
            order += 1
            question_obj.save()
            map_files_to_assessment_item(user, question_obj, question['files'])