예제 #1
0
    def setUp(self):
        """Setup."""
        self.u1 = factory.make_user("Zi", "pass", "*****@*****.**")

        self.jf1 = factory.make_format()
        self.jf2 = factory.make_format()

        self.a1 = factory.make_assignment('tcolloq', 'description', format=self.jf1)

        self.et1 = factory.make_entry_template('temp1')
        self.et2 = factory.make_entry_template('temp2')

        self.f1 = factory.make_field(self.et1, "test0", "1")
        self.f2 = factory.make_field(self.et1, "test2", "2")
        self.f3 = factory.make_field(self.et2, "test1", "1")

        self.j1 = factory.make_journal(self.a1, self.u1)

        self.e1 = factory.make_entry(self.et1)
        self.e2 = factory.make_entry(self.et2)

        self.c1 = factory.make_content(self.e1, "testcontent1", self.f1)
        self.c2 = factory.make_content(self.e1, "testcontent2", self.f2)
        self.c3 = factory.make_content(self.e2, "testcontent3", self.f3)

        self.jf1.available_templates.add()
        self.jf2.available_templates.add()

        self.usr = factory.make_user('teun', '1234', email='*****@*****.**', lti_id='a')
        self.crs = factory.make_course('test course please ignore', 'XXXX', startdate=datetime.date.today())
예제 #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!')
예제 #3
0
    def test_update_format(self):
        """Test update format 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])

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

        update_dict = {
            'assignment_details': {
                'name': 'Colloq',
                'description': 'description1',
                'is_published': True
            },
            'templates': [
                serialize.TemplateSerializer(template).data
                for template in format.available_templates.all()
            ],
            'removed_presets': [],
            'removed_templates': [],
            'presets': [],
            'unused_templates': []
        }

        test.api_patch_call(self, '/formats/' + str(assignment.pk) + '/',
                            update_dict, login)
예제 #4
0
    def gen_format(self):
        """Generate a format."""
        format_examples = [
            {
                "templates": [0, 1],
                "presets": [
                    {"type": Node.PROGRESS, "points": 10},
                ]
            },
            {
                "templates": [0],
                "presets": [
                    {"type": Node.PROGRESS, "points": 5},
                    {"type": Node.ENTRYDEADLINE, "template": 1},
                ]
            },
        ]

        self.formats = []
        for f in format_examples:
            templates = [self.templates[template] for template in f["templates"]]
            format = factory.make_format(templates)

            for p in f["presets"]:
                deadline_date = faker.date_time_between(start_date="now", end_date="+1y", tzinfo=None)

                if p["type"] == Node.PROGRESS:
                    factory.make_progress_node(format, deadline_date, p["points"])
                elif p["type"] == Node.ENTRYDEADLINE:
                    factory.make_entrydeadline_node(format, deadline_date, self.templates[p["template"]])

            self.formats.append(format)
예제 #5
0
    def test_get_names(self):
        """Test get names 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],
                                             is_published=True)
        student_user, student_pass, student = test.set_up_user_and_auth(
            'student', 'pass', '*****@*****.**', 'first', 'last')
        test.set_up_participation(student, course, 'Student')
        journal = test.set_up_journal(assignment, template, student, 4)

        login = test.logging_in(self, student_user, student_pass)
        url = '/names/{}/{}/{}/'.format(course.pk, assignment.pk, journal.pk)
        result = test.api_get_call(self, url, login).json()
        self.assertEquals(result['names']['course'], 'Portfolio')
        self.assertEquals(result['names']['journal'], 'first last')
        self.assertEquals(result['names']['assignment'], 'Colloq')

        # 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, url, login, status=403)
예제 #6
0
    def test_get_format(self):
        """Test get format."""
        course1 = factory.make_course('Portfolio2016', 'PAV', author=self.rein)
        course2 = factory.make_course('Portfolio2017', 'PAV', author=self.rein)
        course3 = factory.make_course('Portfolio2018', 'PAV')
        template = factory.make_entry_template('template')
        format = factory.make_format([template])
        assignment = factory.make_assignment(
            'Colloq',
            'description1',
            format=format,
            courses=[course1, course2, course3])
        login = test.logging_in(self, self.rein_user, self.rein_pass)
        response = test.api_get_call(self,
                                     '/formats/' + str(assignment.pk) + '/',
                                     login)
        self.assertEquals(response.json()['format']['templates'][0]['name'],
                          'template')

        # 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,
                          '/formats/' + str(assignment.pk) + '/',
                          login,
                          status=403)
        test.api_get_call(self,
                          '/formats/' + str(self.not_found_pk) + '/',
                          login,
                          status=404)
        test.test_unauthorized_api_get_call(
            self, '/formats/' + str(assignment.pk) + '/')
예제 #7
0
    def test_create_entry(self):
        """"Test create entry."""
        _, _, user2 = test.set_up_user_and_auth('testh', 'test123h',
                                                '*****@*****.**')

        course = factory.make_course('Portfolio', 'PAV', author=user2)
        template = factory.make_entry_template("some_template")
        format = factory.make_format([template])
        assignment = factory.make_assignment("Assignment",
                                             "Your favorite assignment",
                                             format=format,
                                             courses=[course])
        journal = factory.make_journal(assignment, self.user)
        field = factory.make_field(template, 'Some field', 0)
        login = test.logging_in(self, self.username, self.password)
        format.available_templates.add(template)

        role = factory.make_role_default_no_perms("student",
                                                  course,
                                                  can_have_journal=True)
        factory.make_participation(user=self.user, course=course, role=role)

        create_entry_dict = {
            'journal_id': journal.id,
            'template_id': template.id,
            'content': [{
                'id': field.pk,
                'data': "This is some data"
            }]
        }

        test.api_post_call(self, '/entries/', create_entry_dict, login, 201)
        self.assertTrue(Entry.objects.filter(node__journal=journal).exists())
        self.assertEquals(
            Content.objects.get(entry=1).data, "This is some data")
예제 #8
0
    def test_get_assignment_data(self):
        """Test the get assignment data function."""
        course = factory.make_course('Portfolio', 'PAV', author=self.rein)
        template = factory.make_entry_template('template')
        format1 = factory.make_format([template])
        format2 = factory.make_format([template])
        assignment1 = factory.make_assignment('Colloq',
                                              'description1',
                                              format=format1,
                                              courses=[course],
                                              is_published=True)
        assignment2 = factory.make_assignment('Portfolio',
                                              'description2',
                                              format=format2,
                                              courses=[course],
                                              is_published=True)

        test.set_up_participation(self.user, course, 'Student')

        login_user = test.logging_in(self, self.username, self.password)
        resp = test.api_get_call(self,
                                 '/assignments/' + str(assignment1.pk) + '/',
                                 login_user)
        self.assertEquals(resp.json()['assignment']['name'], 'Colloq')
        self.assertIn('journal', resp.json()['assignment'])

        login_rein = test.logging_in(self, self.rein_user, self.rein_pass)
        resp = test.api_get_call(self,
                                 '/assignments/' + str(assignment2.pk) + '/',
                                 login_rein)
        self.assertEquals(resp.json()['assignment']['name'], 'Portfolio')

        # 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,
                          '/assignments/{}/'.format(assignment1.pk),
                          login,
                          status=403)
        test.api_get_call(self,
                          '/assignments/{}/'.format(assignment2.pk),
                          login,
                          status=403)
        test.test_unauthorized_api_get_call(
            self, '/assignments/{}/'.format(assignment1.pk))
예제 #9
0
    def test_foreignkeys(self):
        """Test the foreign keys in the database."""
        user_test = factory.make_user('lers', 'lers123', '*****@*****.**', '123456')
        course_test = factory.make_course('tname', 'XXXX', datetime.date.today())
        factory.make_format()
        template = factory.make_entry_template("some_template")
        entr_test = factory.make_entry(template)
        field = factory.make_field(template, "test1", "1")
        factory.make_content(entr_test, "data", field)
        course_test.author = user_test

        ass_test = factory.make_assignment(name='tcolloq', description='description')
        ass_test.courses.add(course_test)
        journ_test = factory.make_journal(user=user_test, assignment=ass_test)

        self.assertEquals(entr_test.template.pk, template.pk)
        self.assertEquals(journ_test.user.pk, user_test.pk)
        self.assertEquals(journ_test.assignment.pk, ass_test.pk)
        self.assertEquals(course_test.author.pk, user_test.pk)
예제 #10
0
    def test_assignment_journals(self):
        """Test the get assignment journals 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])
        students = test.set_up_users('student', 2)
        for student in students:
            test.set_up_participation(student, course, 'Student')
            test.set_up_journal(assignment, template, student, 4)

        login = test.logging_in(self, self.rein_user, self.rein_pass)
        response = test.api_get_call(self,
                                     '/journals/',
                                     login,
                                     params={
                                         'course_id': course.pk,
                                         'assignment_id': assignment.pk
                                     })
        result = response.json()
        self.assertEquals(len(result['journals']), 2)

        # 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,
                          '/journals/',
                          login,
                          status=403,
                          params={
                              'course_id': course.pk,
                              'assignment_id': assignment.pk
                          })
        test.api_get_call(self,
                          '/journals/',
                          login,
                          status=404,
                          params={
                              'course_id': course.pk,
                              'assignment_id': self.not_found_pk
                          })

        test.api_get_call(self, '/journals/', login, status=400, params={})
        test.test_unauthorized_api_get_call(self,
                                            '/journals/',
                                            params={
                                                'course_id': course.pk,
                                                'assignment_id':
                                                self.not_found_pk
                                            })
예제 #11
0
    def setUp(self):
        """Setup."""
        self.u_rick = factory.make_user("Rick", "pass", "*****@*****.**")
        self.u_lars = factory.make_user("Lars", "pass", "*****@*****.**")

        self.template = Template(name="some_template")
        self.template.save()

        f_colloq = factory.make_format()
        self.deadlineentry = factory.make_entrydeadline_node(
            f_colloq,
            datetime.datetime.now() - datetime.timedelta(days=10),
            self.template)
        self.progressnode = factory.make_progress_node(
            f_colloq,
            datetime.datetime.now() + datetime.timedelta(days=10), 10)
        f_log = factory.make_format()

        f_colloq.available_templates.add(self.template)

        course = factory.make_course("Some Course", "c")
        student_role = Role.objects.get(name='Student', course=course)
        factory.make_participation(self.u_rick, course, student_role)

        a_colloq = factory.make_assignment("Colloq",
                                           "In de opdracht...1",
                                           author=self.u_rick,
                                           format=f_colloq,
                                           courses=[course])
        a_log = factory.make_assignment("Logboek",
                                        "In de opdracht...2",
                                        author=self.u_rick,
                                        format=f_log,
                                        courses=[course])

        self.j_rick_colloq = factory.make_journal(a_colloq, self.u_rick)
        self.j_lars_colloq = factory.make_journal(a_colloq, self.u_lars)
        self.j_rick_log = factory.make_journal(a_log, self.u_rick)
예제 #12
0
    def test_get_nodes(self):
        """Test the get nodes 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 = test.set_up_journal(assignment, template, student, 4)

        login = test.logging_in(self, student_user, student_pass)
        response = test.api_get_call(self,
                                     '/nodes/',
                                     login,
                                     params={'journal_id': journal.pk})
        result = response.json()
        self.assertEquals(len(result['nodes']), 5)

        login = test.logging_in(self, self.rein_user, self.rein_pass)
        response = test.api_get_call(self,
                                     '/nodes/',
                                     login,
                                     params={'journal_id': journal.pk})
        result = response.json()
        self.assertEquals(len(result['nodes']), 4)

        # 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,
                          '/nodes/',
                          login,
                          status=403,
                          params={'journal_id': journal.pk})
        test.api_get_call(self,
                          '/nodes/',
                          login,
                          status=404,
                          params={'journal_id': self.not_found_pk})
        test.test_unauthorized_api_get_call(self,
                                            '/nodes/',
                                            params={'journal_id': journal.pk})
예제 #13
0
    def test_deadline_format(self):
        """Test if the deadline is correctly formatted."""
        deadline = datetime.date.today()

        format = factory.make_format()
        format.save()
        preset = factory.make_entrydeadline_node(format, deadline,
                                                 self.template)

        self.assertEquals(deadline, preset.deadline)

        assignment = factory.make_assignment("Portfolio",
                                             "Fixed deadlines",
                                             author=self.u_rick,
                                             format=format)
        journal = factory.make_journal(assignment, self.u_rick)

        self.assertTrue(journal.node_set.get(preset__deadline=deadline))
예제 #14
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})
예제 #15
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)