Exemplo n.º 1
0
    def test_filter_view_queryset__private_channel(self):
        channel = testdata.channel()
        assessment_item = create_assessment_item(channel.main_tree_id)

        queryset = AssessmentItem.filter_view_queryset(
            self.base_queryset, user=self.forbidden_user)
        self.assertQuerysetDoesNotContain(queryset, pk=assessment_item.id)

        user = testdata.user()
        channel.viewers.add(user)
        queryset = AssessmentItem.filter_view_queryset(self.base_queryset,
                                                       user=user)
        self.assertQuerysetContains(queryset, pk=assessment_item.id)
Exemplo n.º 2
0
    def test_filter_edit_queryset__private_channel__anonymous(self):
        channel = testdata.channel()
        assessment_item = create_assessment_item(channel.main_tree_id)

        queryset = AssessmentItem.filter_edit_queryset(
            self.base_queryset, user=self.anonymous_user)
        self.assertQuerysetDoesNotContain(queryset, pk=assessment_item.id)
Exemplo n.º 3
0
    def test_filter_view_queryset__public_channel__anonymous(self):
        channel = self.public_channel
        assessment_item = create_assessment_item(channel.main_tree_id)

        queryset = AssessmentItem.filter_view_queryset(
            self.base_queryset, user=self.anonymous_user)
        self.assertQuerysetContains(queryset, pk=assessment_item.id)
Exemplo n.º 4
0
 def generate_question(self, contentnode_id, order, question, question_type,
                       answers):
     hints = [
         {
             "hint": "Hint 1",
             "order": 1
         },
         {
             "hint": "Hint 2",
             "order": 2
         },
         {
             "hint": "Hint 3",
             "order": 3
         },
     ]
     ai = AssessmentItem(
         contentnode_id=contentnode_id,
         type=question_type,
         question=question,
         hints=json.dumps(hints),
         answers=json.dumps(answers),
         order=order,
         assessment_id=uuid4_hex(),
     )
     self.assessment_items.append(ai)
Exemplo n.º 5
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())
Exemplo n.º 6
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'])
Exemplo n.º 7
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())
Exemplo n.º 8
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'])