コード例 #1
0
ファイル: test_utils.py プロジェクト: Canelaguil/eJournal
def set_up_assignments(name, desc, n, course, lti_id=False, is_published=True):
    """Set up some assignments.

    Arguments:
    name -- the base for the incremental names for the assignments
    desc -- the base for the incremental description for the assignments
    n -- number of assignments to be made.
    lti_id -- a boolean to determine if to give lti ids

    Returns a list of assignments.
    """
    assignments = []
    if lti_id:
        for i in range(n):
            assignments.append(
                factory.make_assignment(name + str(i),
                                        desc + str(i),
                                        lti_id=str(i),
                                        courses=[course],
                                        is_published=is_published))
    else:
        for i in range(n):
            assignments.append(
                factory.make_assignment(name + str(i),
                                        desc + str(i),
                                        courses=[course],
                                        is_published=is_published))
    return assignments
コード例 #2
0
    def setUp(self):
        self.user = factory.make_user('Username', DEFAULT_PASSWORD, email='*****@*****.**', full_name='Test User')

        self.course1 = factory.make_course('Course', 'crs', startdate=datetime.date.today())
        self.course2 = factory.make_course('Course2', 'crs2', startdate=datetime.date.today())
        self.course_independent = factory.make_course('Independent Course', 'crs3', startdate=datetime.date.today())

        self.assignment = factory.make_assignment('Assignment', 'Assignment linked to multiple courses.',
                                                  courses=[self.course1, self.course2])
        self.assignment_independent = factory.make_assignment('Assignment2', 'Assignment linked to separate course.',
                                                              courses=[self.course_independent])
コード例 #3
0
ファイル: test_get_apis.py プロジェクト: Canelaguil/eJournal
    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) + '/')
コード例 #4
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!')
コード例 #5
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())
コード例 #6
0
ファイル: test_get_apis.py プロジェクト: Canelaguil/eJournal
    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)
コード例 #7
0
ファイル: preset_db.py プロジェクト: Canelaguil/eJournal
    def gen_assignments(self):
        """Generate assignments."""
        assign_examples = [
            {
                "name": "Logboek",
                "description": "This is a logboek for all your logging purposes",
                "courses": [0, 1],
                "format": 0,
                "author": 4,
            },
            {
                "name": "Colloquium",
                "description": "This is the best colloquium logbook in the world",
                "courses": [0],
                "format": 1,
                "author": 4,
            }
        ]

        self.assignments = []
        for a in assign_examples:
            author = self.users[a["author"]]
            format = self.formats[a["format"]]
            faker.date_time_between(start_date="now", end_date="+1y", tzinfo=None)
            assignment = factory.make_assignment(a["name"], a["description"], author, format, is_published=True)

            for course in a["courses"]:
                assignment.courses.add(self.courses[course])
            self.assignments.append(assignment)
コード例 #8
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")
コード例 #9
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)
コード例 #10
0
    def test_delete_assignment(self):
        """Test delete_assignment."""
        login = test.logging_in(self, self.username, self.password)

        course1 = factory.make_course("Portfolio Academische Vaardigheden",
                                      "PAV")
        course2 = factory.make_course("BeeldBewerken", "BB")

        assign1 = factory.make_assignment("Colloq", "In de opdracht...1",
                                          self.user)
        assign2 = factory.make_assignment("Logboek", "In de opdracht...2",
                                          self.user)

        role = factory.make_role_default_no_perms("teacher",
                                                  self.course,
                                                  can_delete_assignment=True)
        factory.make_participation(user=self.user,
                                   course=self.course,
                                   role=role)

        role = factory.make_role_default_no_perms("teacher",
                                                  course1,
                                                  can_delete_assignment=True)
        factory.make_participation(user=self.user, course=course1, role=role)

        role = factory.make_role_default_no_perms("teacher",
                                                  course2,
                                                  can_delete_assignment=True)
        factory.make_participation(user=self.user, course=course2, role=role)

        assign1.courses.add(course1)
        assign1.courses.add(course2)
        assign2.courses.add(course1)

        # Stupid test to begin with, glad this is replaced soon
        test.api_del_call(
            self,
            '/assignments/{}/?course_id={}'.format(str(assign1.pk),
                                                   self.course.pk), login)
        assignment = Assignment.objects.get(pk=assign1.pk)
        self.assertEquals(assignment.courses.count(), 2)

        test.api_del_call(
            self,
            '/assignments/{}/?course_id={}'.format(self.course.pk,
                                                   self.course.pk), login)
        self.assertEquals(Assignment.objects.filter(pk=assign1.pk).count(), 1)
コード例 #11
0
 def test_check_if_need_VLE_publish_no_journals(self):
     """Hopefully doesnt crash."""
     course = factory.make_course('TestCourse', 'aaaa', lti_id='qqsa')
     assign = factory.make_assignment("TestAss",
                                      "TestDescr",
                                      lti_id='aasas',
                                      courses=[course])
     lti_grade.check_if_need_VLE_publish(assign)
コード例 #12
0
ファイル: test_get_apis.py プロジェクト: Canelaguil/eJournal
    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))
コード例 #13
0
 def test_get_lti_params_from_jwt_journal_teacher(self):
     """Hopefully returns the LTI assignment and course."""
     course = factory.make_course('TestCourse', 'aaaa', lti_id='asdf')
     factory.make_assignment("TestAss",
                             "TestDescr",
                             lti_id='bughh',
                             courses=[course])
     login = test.logging_in(self, self.username, self.password)
     self.request["user_id"] = "awefd"
     jwt_params = jwt.encode(self.request,
                             settings.SECRET_KEY,
                             algorithm='HS256').decode('utf-8')
     response = test.api_get_call(
         self,
         '/get_lti_params_from_jwt/{0}/'.format(jwt_params),
         login=login,
         status=200)
     self.assertIn(
         '"state": "{0}"'.format(lti_view.LTI_STATES.FINISH_T.value),
         response.content.decode('utf-8'))
コード例 #14
0
    def setUp(self):
        """Setup."""
        self.u_rick = factory.make_user("Rick",
                                        DEFAULT_PASSWORD,
                                        "*****@*****.**",
                                        full_name='Test User')
        self.u_lars = factory.make_user("Lars",
                                        DEFAULT_PASSWORD,
                                        "*****@*****.**",
                                        full_name='Test User')

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

        self.template = f_colloq.template_set.first()

        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)
コード例 #15
0
 def test_get_lti_params_from_jwt_unknown_role(self):
     """Test case for when a unknown role is given ."""
     course = factory.make_course('TestCourse', 'aaaa', lti_id='asdf')
     factory.make_assignment("TestAss",
                             "TestDescr",
                             lti_id='bughh',
                             courses=[course])
     login = test.logging_in(self, self.username, self.password)
     self.request["user_id"] = "awefd"
     self.request["roles"] = 'urn:lti:instrole:ims/lis/Administrator'
     jwt_params = jwt.encode(self.request,
                             settings.SECRET_KEY,
                             algorithm='HS256').decode('utf-8')
     response = test.api_get_call(
         self,
         '/get_lti_params_from_jwt/{0}/'.format(jwt_params),
         login=login,
         status=200)
     self.assertIn(
         '"state": "{0}"'.format(lti_view.LTI_STATES.FINISH_S.value),
         response.content.decode('utf-8'))
コード例 #16
0
ファイル: test_get_apis.py プロジェクト: Canelaguil/eJournal
    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
                                            })
コード例 #17
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)
コード例 #18
0
 def setUp(self):
     """Setup."""
     self.course = factory.make_course('TestCourse', 'aaaa', lti_id='asdf')
     self.user = factory.make_user('TestUser', 'Pass', '*****@*****.**')
     factory.make_participation(
         self.user, self.course,
         Role.objects.get(name='Student', course=self.course))
     self.assignment = factory.make_assignment("TestAss",
                                               "TestDescr",
                                               points_possible=100,
                                               courses=[self.course])
     self.journal = factory.make_journal(self.assignment, self.user)
     self.journal.sourcedid = 'f6d552'
     self.journal.grade_url = 'http://127.0.0.1:8000/grade_passback'
コード例 #19
0
ファイル: test_get_apis.py プロジェクト: Canelaguil/eJournal
    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})
コード例 #20
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))
コード例 #21
0
ファイル: assignment.py プロジェクト: Canelaguil/eJournal
    def create(self, request):
        """Create a new assignment.

        Arguments:
        request -- request data
            name -- name of the assignment
            description -- description of the assignment
            course_id -- id of the course the assignment belongs to
            points_possible -- the possible amount of points for the assignment
            unlock_date -- (optional) date the assignment becomes available on
            due_date -- (optional) date the assignment is due for
            lock_date -- (optional) date the assignment becomes unavailable on
            lti_id -- id labeled link to LTI instance

        Returns:
        On failure:
            unauthorized -- when the user is not logged in
            not_found -- could not find the course with the given id
            key_error -- missing keys
            forbidden -- the user is not allowed to create assignments in this course

        On success:
            succes -- with the assignment data

        """
        name, description, course_id = utils.required_params(request.data, "name", "description", "course_id")
        points_possible, unlock_date, due_date, lock_date, lti_id, is_published = \
            utils.optional_params(request.data, "points_possible", "unlock_date", "due_date", "lock_date", "lti_id",
                                  "is_published")
        course = Course.objects.get(pk=course_id)

        request.user.check_permission('can_add_assignment', course)

        assignment = factory.make_assignment(name, description, courses=[course],
                                             author=request.user, lti_id=lti_id,
                                             points_possible=points_possible,
                                             unlock_date=unlock_date, due_date=due_date,
                                             lock_date=lock_date, is_published=is_published)

        for user in course.users.all():
            factory.make_journal(assignment, user)

        serializer = AssignmentSerializer(assignment, context={'user': request.user, 'course': course})
        return response.created({'assignment': serializer.data})
コード例 #22
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)
コード例 #23
0
    def setUp(self):
        """Setup."""
        self.factory = RequestFactory()

        self.request = {
            "oauth_consumer_key": settings.LTI_KEY,
            "oauth_signature_method": "HMAC-SHA1",
            "oauth_version": "1.0",
            "custom_assignment_due": "2018-11-10 23:59:00 +0100",
            "custom_assignment_id": "bughh",
            "custom_assignment_lock": "2018-12-15 23:59:59 +0100",
            "custom_assignment_title": "TestAss",
            "custom_assignment_unlock": "2018-08-16 00:00:00 +0200",
            "custom_assignment_points": "10",
            "custom_assignment_publish": "true",
            "custom_course_id": "asdf",
            "custom_course_name": "TestCourse",
            "custom_course_start": "2018-06-15 14:41:00 +0200",
            "context_label": "aaaa",
            "lti_message_type": "basic-lti-launch-request",
            "lti_version": "LTI-1p0",
            'custom_username': '******',
            "roles": "Instructor",
            "custom_user_image":
            "https://uvadlo-tes.instructure.com/images/thumbnails/11601/\
6ivT7povCYWoXPCVOSnfPqWADsLktcGXTXkAUYDv",
            "user_id": "0000"
        }

        self.oauth_consumer = oauth2.Consumer(settings.LTI_KEY,
                                              settings.LTI_SECRET)

        self.username, self.password, self.user = test.set_up_user_and_auth(
            'TestUser', 'Pass', '*****@*****.**')
        self.user.lti_id = 'awefd'
        self.user.verified_email = True
        self.user.save()

        self.created_assignment = factory.make_assignment(
            "TestAss", "TestDescr")
        self.created_journal = factory.make_journal(self.created_assignment,
                                                    self.user)
コード例 #24
0
ファイル: test_get_apis.py プロジェクト: Canelaguil/eJournal
    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})
コード例 #25
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)