示例#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_templates(self):
        """Generate templates.

        One with title, summary, experience, requested points and proof.
        One with only a title.
        One with only an image.
        One with only a file.
        """
        template_examples = [
            {
                "name": "Colloquium",
                "fields": [
                    {"title": "Title", "location": 0, "type": Field.TEXT},
                    {"title": "Summary", "location": 1, "type": Field.RICH_TEXT},
                    {"title": "Experience", "location": 2, "type": Field.RICH_TEXT},
                    {"title": "Requested Points", "location": 3, "type": Field.TEXT},
                ]
            },
            {
                "name": "Default Text",
                "fields": [
                    {"title": "Text", "location": 0, "type": Field.TEXT},
                ]
            }
        ]

        self.templates = []
        for t in template_examples:
            template = factory.make_entry_template(t["name"])
            for f in t["fields"]:
                factory.make_field(template, f["title"], f["location"], f["type"])

            self.templates.append(template)
示例#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 gen_templates(self, format):
        """Generate templates.

        One with title, summary, experience, requested points and proof.
        One with only text.
        """
        template_examples = [
            {
                "name": "Colloquium",
                "fields": [
                    {"title": "Title", "location": 0, "type": Field.TEXT},
                    {"title": "Summary", "location": 1, "type": Field.RICH_TEXT},
                    {"title": "Experience", "location": 2, "type": Field.RICH_TEXT},
                    {"title": "Requested Points", "location": 3, "type": Field.TEXT},
                    {"title": "Proof", "location": 4, "type": Field.IMG},
                ]
            },
            {
                "name": "Mentorgesprek",
                "fields": [
                    {"title": "Text", "location": 0, "type": Field.TEXT},
                ]
            }
        ]

        templates = []
        for t in template_examples:
            template = factory.make_entry_template(t["name"], format)
            templates.append(template)
            for f in t["fields"]:
                factory.make_field(template, f["title"], f["location"], f["type"])

        return templates
示例#9
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
                                            })
示例#10
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})
示例#11
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))
示例#12
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)
示例#13
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})
示例#14
0
def parse_template(template_dict):
    """Parse a new template according to the passed JSON-serialized template."""
    name = template_dict['name']
    fields = template_dict['field_set']

    template = factory.make_entry_template(name)

    for field in fields:
        type = field['type']
        title = field['title']
        location = field['location']
        required = field['required']
        description = field['description']
        options = field['options']

        factory.make_field(template, title, location, type, required,
                           description, options)

    template.save()
    return template
示例#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)