Ejemplo n.º 1
0
    def gen_entries(self):
        """Generate entries."""
        for journal in self.journals:
            for node in journal.node_set.all():
                if node.type == Node.ENTRYDEADLINE:
                    entry = factory.make_entry(node.preset.forced_template)
                    entry.late = faker.boolean()
                    entry.save()

                    factory.make_grade(entry, self.users['Teacher'].pk, random.randint(1, 10), faker.boolean())

                    node.entry = entry

            if journal.assignment.format.template_set.filter(archived=False, preset_only=False).count() > 0:
                random_entries = random.randint(0, 8)
                for _ in range(random_entries):
                    template = random.choice(journal.assignment.format.template_set.filter(archived=False,
                                                                                           preset_only=False))
                    entry = factory.make_entry(template)
                    entry.late = faker.boolean()
                    entry.save()

                    factory.make_grade(entry, self.users['Teacher'].pk, random.randint(1, 10), faker.boolean())

                    factory.make_node(journal, entry)
Ejemplo n.º 2
0
    def test_get_comments(self):
        """Test update comment function."""
        course = factory.make_course('Portfolio', 'PAV', author=self.rein)
        template = factory.make_entry_template('template')
        format = factory.make_format([template])
        assignment = factory.make_assignment('Colloq',
                                             'description1',
                                             format=format,
                                             courses=[course])
        student_user, student_pass, student = test.set_up_user_and_auth(
            'student', 'pass', '*****@*****.**')
        test.set_up_participation(student, course, 'Student')
        journal = factory.make_journal(assignment, student)
        entry = factory.make_entry(template)
        factory.make_node(journal, entry)
        comment = factory.make_comment(entry, self.rein, 'Excellent!', True)

        login = test.logging_in(self, self.rein_user, self.rein_pass)

        update_dict = {'text': 'Bad!'}
        test.api_patch_call(self, '/comments/' + str(comment.pk) + '/',
                            update_dict, login)

        q_comment = Comment.objects.get(pk=comment.pk)
        self.assertEquals(q_comment.text, 'Bad!')
Ejemplo n.º 3
0
    def test_replace_result_no_url(self):
        """Hopefully doesnt crash."""
        entry = factory.make_entry(
            Template.objects.filter(name='Default Template')[0])
        entry.published = True
        entry.save()
        factory.make_node(self.journal, entry)
        self.journal.sourcedid = None
        self.journal.grade_url = None
        self.journal.save()

        self.assertEqual(lti_grade.replace_result(self.journal), None)
Ejemplo n.º 4
0
 def test_change_Entry_vle_coupling(self):
     """Hopefully doesnt crash."""
     entry = factory.make_entry(
         Template.objects.filter(name='Default Template')[0])
     entry.published = True
     entry.save()
     factory.make_node(self.journal, entry)
     lti_grade.change_Entry_vle_coupling(self.journal, Entry.GRADING)
     for entry in Entry.objects.filter(
             published=True, node__journal=self.journal).exclude(
                 vle_coupling=Entry.LINK_COMPLETE):
         self.assertEqual(entry.vle_coupling, Entry.GRADING)
Ejemplo n.º 5
0
 def test_check_if_need_VLE_publish_journals(self):
     """Hopefully doesnt crash."""
     entry = factory.make_entry(
         Template.objects.filter(name='Default Template')[0])
     entry.published = True
     entry.vle_coupling = Entry.GRADING
     entry.save()
     factory.make_node(self.journal, entry)
     entry1 = factory.make_entry(
         Template.objects.filter(name='Default Template')[0])
     entry1.save()
     factory.make_node(self.journal, entry1)
     lti_grade.check_if_need_VLE_publish(self.assignment)
Ejemplo n.º 6
0
def update_journals(journals, preset, created):
    """Create or update the preset node in all relevant journals.

    Arguments:
    journals -- the journals to update.
    preset -- the preset node to update the journals with.
    created -- whether the preset node was newly created.
    """
    if created:
        for journal in journals:
            factory.make_node(journal, None, preset.type, preset)
    else:
        for journal in journals:
            journal.node_set.filter(preset=preset).update(type=preset.type)
Ejemplo n.º 7
0
def set_up_journal(assignment, template, user, n):
    """Set up a journal for an user with n entries.

    Arguments:
    assignment -- the assignment of the journal
    template -- the entry template for the entries
    user -- the user of the journal
    n -- number of entries

    Returns a journal with entries attached.
    """
    journal = factory.make_journal(assignment, user)

    for entry in set_up_entries(template, n):
        factory.make_node(journal, entry)

    return journal
Ejemplo n.º 8
0
    def test_json(self):
        """Test is the to dict function works correctly."""
        entry = factory.make_entry(self.template)
        factory.make_node(self.j_rick_colloq, entry)

        nodes = timeline.get_nodes(self.j_rick_colloq, self.u_rick)

        self.assertEquals(len(nodes), 4)

        self.assertEquals(nodes[0]['type'], 'd')
        self.assertEquals(nodes[0]['entry'], None)

        self.assertEquals(nodes[1]['type'], 'e')

        self.assertEquals(nodes[2]['type'], 'a')

        self.assertEquals(nodes[3]['type'], 'p')
        self.assertEquals(nodes[3]['target'], 10)
Ejemplo n.º 9
0
    def test_sorted(self):
        """Test is the sort function works."""
        entry = factory.make_entry(self.template)
        node = factory.make_node(self.j_rick_colloq, entry)
        nodes = timeline.get_sorted_nodes(self.j_rick_colloq)

        self.assertEquals(nodes[0].preset, self.deadlineentry)
        self.assertEquals(nodes[1], node)
        self.assertEquals(nodes[2].preset, self.progressnode)
Ejemplo n.º 10
0
    def test_get_comments(self):
        """Test get comments function."""
        course = factory.make_course('Portfolio', 'PAV', author=self.rein)
        template = factory.make_entry_template('template')
        format = factory.make_format([template])
        assignment = factory.make_assignment('Colloq',
                                             'description1',
                                             format=format,
                                             courses=[course])
        student_user, student_pass, student = test.set_up_user_and_auth(
            'student', 'pass', '*****@*****.**')
        test.set_up_participation(student, course, 'Student')
        journal = factory.make_journal(assignment, student)
        entry = factory.make_entry(template)
        factory.make_node(journal, entry)
        factory.make_comment(entry, self.rein, 'Excellent!', True)

        login = test.logging_in(self, student_user, student_pass)

        result = test.api_get_call(self,
                                   '/comments/',
                                   login,
                                   params={
                                       'entry_id': entry.pk
                                   }).json()
        self.assertEquals(result['comments'][0]['text'], 'Excellent!')

        # permissions and authorization check for the api call.
        login = test.logging_in(self, self.no_perm_user, self.no_perm_pass)
        test.api_get_call(self,
                          '/comments/',
                          login,
                          status=403,
                          params={'entry_id': entry.pk})
        test.api_get_call(self,
                          '/comments/',
                          login,
                          status=404,
                          params={'entry_id': self.not_found_pk})
        test.test_unauthorized_api_get_call(self,
                                            '/comments/',
                                            params={'entry_id': entry.pk})
Ejemplo n.º 11
0
    def test_journal_stats(self):
        """Test the journal stats functions in the serializer."""
        template = factory.make_entry_template('template_test')
        format = factory.make_format([template])
        assign = factory.make_assignment("Colloq", "In de opdracht...1", self.teacher, format=format)
        journal = factory.make_journal(assign, self.user)
        entries = test.set_up_entries(template, 4)

        for entry in entries:
            factory.make_node(journal, entry)

        journal = Journal.objects.get(user=self.user)
        entries = utils.get_journal_entries(journal)
        for i in range(len(entries)):
            if i > 0:
                entries[i].grade = 1
                entries[i].published = True
                entries[i].save()
        self.assertEquals(utils.get_acquired_points(entries), 3)
        self.assertEquals(utils.get_submitted_count(entries), 4)
        self.assertEquals(utils.get_graded_count(entries), 3)
Ejemplo n.º 12
0
    def gen_entries(self):
        """Generate entries."""
        for journal in self.journals:
            for node in journal.node_set.all():
                if node.type == Node.ENTRYDEADLINE:
                    entry = factory.make_entry(node.preset.forced_template)
                    entry.late = faker.boolean()
                    entry.grade = random.randint(1, 10)
                    entry.save()

                    node.entry = entry

            if journal.assignment.format.available_templates.count() > 0:
                random_entries = random.randint(0, 8)
                for _ in range(random_entries):
                    template = random.choice(journal.assignment.format.available_templates.all())
                    entry = factory.make_entry(template)
                    entry.late = faker.boolean()
                    entry.grade = random.randint(1, 10)
                    entry.save()

                    factory.make_node(journal, entry)
Ejemplo n.º 13
0
    def create(self, request):
        """Create a new entry.

        Deletes remaining temporary user files if successful.

        Arguments:
        request -- the request that was send with
            journal_id -- the journal id
            template_id -- the template id to create the entry with
            node_id -- optional: the node to bind the entry to (only for entrydeadlines)
            content -- the list of {tag, data} tuples to bind data to a template field.
        """
        journal_id, template_id, content_list = utils.required_params(
            request.data, "journal_id", "template_id", "content")
        node_id, = utils.optional_params(request.data, "node_id")

        journal = Journal.objects.get(pk=journal_id, user=request.user)
        assignment = journal.assignment
        template = Template.objects.get(pk=template_id)

        request.user.check_permission('can_have_journal', assignment)

        if assignment.is_locked():
            return response.forbidden(
                'The assignment is locked, entries can no longer be edited/changed.'
            )

        if journal.needs_lti_link():
            return response.forbidden(journal.outdated_link_warning_msg)

        # Check if the template is available
        if not (node_id or assignment.format.template_set.filter(
                archived=False, preset_only=False, pk=template.pk).exists()):
            return response.forbidden('Entry template is not available.')

        entry_utils.check_fields(template, content_list)

        # Node specific entry
        if node_id:
            node = Node.objects.get(pk=node_id, journal=journal)
            entry = entry_utils.add_entry_to_node(node, template)
        # Template specific entry
        else:
            entry = factory.make_entry(template)
            node = factory.make_node(journal, entry)

        for content in content_list:
            field_id, = utils.required_typed_params(content, (int, 'id'))
            data, = utils.required_params(content, 'data')
            field = Field.objects.get(pk=field_id)

            created_content = factory.make_content(node.entry, data, field)

            if field.type in field.FILE_TYPES:  # Image, file or PDF
                user_file = file_handling.get_temp_user_file(
                    request.user, assignment, content['data'])
                if user_file is None and field.required:
                    node.entry.delete()
                    # If there is a newly created node, delete that as well
                    if not node_id:
                        node.delete()
                    return response.bad_request(
                        'One of your files was not correctly uploaded, please try again.'
                    )
                elif user_file:
                    file_handling.make_permanent_file_content(
                        user_file, created_content, node)

        # Notify teacher on new entry
        if (node.journal.sourcedid
                and node.entry.vle_coupling == Entry.NEED_SUBMISSION):
            lti_tasks.needs_grading.delay(node.pk)

        # Delete old user files
        file_handling.remove_temp_user_files(request.user)

        return response.created({
            'added':
            entry_utils.get_node_index(journal, node, request.user),
            'nodes':
            timeline.get_nodes(journal, request.user),
            'entry':
            serialize.EntrySerializer(entry, context={
                'user': request.user
            }).data
        })