Example #1
0
    def test_post_createmode_specific_groups(self):
        self.assertEquals(self.testhelper.sub_p1_a1_g1.deadlines.count(), 1)
        self.assertEquals(self.testhelper.sub_p1_a1_g2.deadlines.count(), 1)

        new_deadline = datetime(2004, 12, 24, 20, 30)
        self.assertEquals(Deadline.objects.filter(deadline=new_deadline).count(), 0)
        content, response = self._postas('adm', {'deadline': format_datetime(new_deadline),
                                                 'text': 'Created',
                                                 'group_ids': [self.testhelper.sub_p1_a1_g1.id,
                                                               self.testhelper.sub_p1_a1_g2.id],
                                                 'createmode': 'specific-groups'})

        # Check response
        self.assertEquals(response.status_code, 201)
        self.assertEquals(decode_bulkdeadline_id(content['bulkdeadline_id'])[0],
                          new_deadline)
        self.assertEquals(len(content['groups']), 2)
        self.assertEquals(content['text'], 'Created')
        self.assertEquals(content['deadline'], format_datetime(new_deadline))

        # Check actual data
        self.assertEquals(Deadline.objects.filter(deadline=new_deadline).count(), 2)
        g1 = self.testhelper.reload_from_db(self.testhelper.sub_p1_a1_g1)
        deadlines = g1.deadlines.all()
        self.assertEquals(len(deadlines), 2)
        self.assertEquals(deadlines[0].deadline, new_deadline)
        self.assertEquals(deadlines[0].text, 'Created')
Example #2
0
    def test_post_createmode_failed(self):
        self.testhelper.add_delivery('sub.p1.a1.g1', {'bad.py': ['print ', 'bah']})
        self.testhelper.add_feedback('sub.p1.a1.g1', verdict={'grade': 'F', 'points': 30, 'is_passing_grade': False})
        g1 = AssignmentGroup.objects.get(id=self.testhelper.sub_p1_a1_g1.id)
        self.assertFalse(g1.is_open)


        new_deadline = datetime(2004, 12, 24, 20, 30)
        self.assertEquals(Deadline.objects.filter(deadline=new_deadline).count(), 0)
        content, response = self._postas('adm', {'deadline': format_datetime(new_deadline),
                                                 'text': 'Created',
                                                 'createmode': 'failed'})

        # Check response
        self.assertEquals(response.status_code, 201)
        self.assertEquals(decode_bulkdeadline_id(content['bulkdeadline_id'])[0],
                          new_deadline)
        self.assertEquals(len(content['groups']), 1)
        self.assertEquals(content['text'], 'Created')
        self.assertEquals(content['deadline'], format_datetime(new_deadline))

        # Check actual data
        self.assertEquals(Deadline.objects.filter(deadline=new_deadline).count(), 1)
        g1 = AssignmentGroup.objects.get(id=self.testhelper.sub_p1_a1_g1.id)
        deadlines = g1.deadlines.all().order_by('-deadline')
        self.assertEquals(len(deadlines), 2)
        self.assertEquals(deadlines[0].deadline, new_deadline)
        self.assertEquals(deadlines[0].text, 'Created')
        self.assertTrue(g1.is_open) # Group was automatically opened in devilry.apps.core.models.Deadline.save()
Example #3
0
    def test_post_createmode_no_deadlines(self):
        self.assertEquals(self.testhelper.sub_p1_a1_g1.deadlines.count(), 1)
        self.testhelper.add_to_path('uni;sub.p1.a1.extragroup')
        self.assertEquals(self.testhelper.sub_p1_a1_extragroup.deadlines.count(), 0)

        new_deadline = datetime(2004, 12, 24, 20, 30)
        self.assertEquals(Deadline.objects.filter(deadline=new_deadline).count(), 0)
        content, response = self._postas('adm', {'deadline': format_datetime(new_deadline),
                                                 'text': 'Created',
                                                 'createmode': 'no-deadlines'})

        # Check response
        self.assertEquals(response.status_code, 201)
        self.assertEquals(decode_bulkdeadline_id(content['bulkdeadline_id'])[0],
                          new_deadline)
        self.assertEquals(len(content['groups']), 1)
        self.assertEquals(content['text'], 'Created')
        self.assertEquals(content['deadline'], format_datetime(new_deadline))

        # Check actual data
        self.assertEquals(Deadline.objects.filter(deadline=new_deadline).count(), 1)
        extragroup = AssignmentGroup.objects.get(id=self.testhelper.sub_p1_a1_extragroup.id)
        deadlines = extragroup.deadlines.all()
        self.assertEquals(len(deadlines), 1)
        self.assertEquals(deadlines[0].deadline, new_deadline)
        self.assertEquals(deadlines[0].text, 'Created')
        self.assertTrue(extragroup.is_open) # Group was automatically opened in devilry.apps.core.models.Deadline.save()
Example #4
0
    def test_post_createmode_failed_or_no_feedback(self):
        # Fail g0
        self.testhelper.add_delivery('sub.p1.a1.g0', {'bad.py': ['print ', 'bah']})
        self.testhelper.add_feedback('sub.p1.a1.g0', verdict={'grade': 'F', 'points': 30, 'is_passing_grade': False})
        # Pass g1
        self.testhelper.add_delivery('sub.p1.a1.g1', {'good.py': ['print ', 'bah']})
        self.testhelper.add_feedback('sub.p1.a1.g1', verdict={'grade': 'A', 'points': 100, 'is_passing_grade': True})
        # g2 has no feedback
        self.assertEquals(self.testhelper.sub_p1_a1_g2.feedback, None)

        new_deadline = datetime(2004, 12, 24, 20, 30)
        self.assertEquals(Deadline.objects.filter(deadline=new_deadline).count(), 0)
        content, response = self._postas('adm', {'deadline': format_datetime(new_deadline),
                                                 'text': 'Created',
                                                 'createmode': 'failed-or-no-feedback'})

        # Check response
        self.assertEquals(response.status_code, 201)
        self.assertEquals(len(content['groups']), 2)

        # Check actual data
        self.assertEquals(Deadline.objects.filter(deadline=new_deadline).count(), 2)
        g0 = self.testhelper.sub_p1_a1_g0
        g2 = self.testhelper.sub_p1_a1_g2
        for group in (g0, g2):
            deadlines = group.deadlines.all().order_by('-deadline')
            self.assertEquals(len(deadlines), 2)
            self.assertEquals(deadlines[0].deadline, new_deadline)
            self.assertEquals(deadlines[0].text, 'Created')
        g1 = self.testhelper.sub_p1_a1_g1
        self.assertEquals(g1.deadlines.count(), 1) # We did not a deadline to g1 because they have passing grade
Example #5
0
 def test_get(self):
     content, response = self._getas('adm')
     self.assertEquals(response.status_code, 200)
     self.assertEquals(decode_bulkdeadline_id(content['bulkdeadline_id'])[0],
                       self.testhelper.sub_p1_a1_g1_d1.deadline)
     self.assertEquals(content['deadline'],
                       format_datetime(self.testhelper.sub_p1_a1_g1_d1.deadline))
     self.assertEquals(content['text'], None)
     self.assertEquals(len(content['groups']), 3)
Example #6
0
 def test_post_createmode_specific_groups_nogroups(self):
     new_deadline = datetime(2004, 12, 24, 20, 30)
     self.assertEquals(Deadline.objects.filter(deadline=new_deadline).count(), 0)
     content, response = self._postas('adm', {'deadline': format_datetime(new_deadline),
                                              'text': 'Created',
                                              'createmode': 'specific-groups'})
     self.assertEquals(response.status_code, 400)
     self.assertEquals(content['field_errors']['group_ids'][0],
                       '``group_ids`` is required when ``createmode=="specific-groups"``.')
Example #7
0
 def test_post_no_matching_groups(self):
     for group in self._itergroups():
         deadlines = group.deadlines.all().order_by('-deadline')
         self.assertEquals(group.feedback, None)
     new_deadline = datetime(2004, 12, 24, 20, 30)
     content, response = self._postas('adm', {'deadline': format_datetime(new_deadline),
                                              'text': 'Created',
                                              'createmode': 'failed'})
     self.assertEquals(response.status_code, 400)
     self.assertEquals(content['field_errors']['createmode'], ['The given option did not match any groups.'])
Example #8
0
    def test_put(self):
        self.assertEquals(self.testhelper.sub_p1_a1.publishing_time, datetime(2000, 1, 1, 22, 30, 51))
        self.assertEquals(self.testhelper.sub_p1_a1_g1_d1.deadline,
                          datetime(2000, 1, 1, 22, 30) + timedelta(days=5))

        new_deadline = datetime(2004, 12, 24, 20, 30)
        content, response = self._putas('adm', {'deadline': format_datetime(new_deadline),
                                                'text': 'Hello'})
        self.assertEquals(response.status_code, 200)
        self.assertEquals(decode_bulkdeadline_id(content['bulkdeadline_id'])[0],
                          new_deadline)
        self.assertEquals(len(content['groups']), 3)
        self.assertEquals(content['text'], 'Hello')
        self.assertEquals(content['deadline'], format_datetime(new_deadline))
        for groupnum in xrange(3):
            deadline_id = getattr(self.testhelper, 'sub_p1_a1_g{0}_d1'.format(groupnum)).id
            deadline = Deadline.objects.get(id=deadline_id)
            self.assertEquals(deadline.deadline, new_deadline)
            self.assertEquals(deadline.text, 'Hello')
Example #9
0
    def test_put_nonetext(self):
        self.assertEquals(self.testhelper.sub_p1_a1.publishing_time, datetime(2000, 1, 1, 22, 30, 51))
        self.assertEquals(self.testhelper.sub_p1_a1_g1_d1.deadline,
                          datetime(2000, 1, 1, 22, 30) + timedelta(days=5))

        new_deadline = datetime(2004, 12, 24, 20, 30)
        content, response = self._putas('adm', {'deadline': format_datetime(new_deadline),
                                                'text': None})
        self.assertEquals(response.status_code, 200)
        for groupnum in xrange(3):
            deadline_id = getattr(self.testhelper, 'sub_p1_a1_g{0}_d1'.format(groupnum)).id
            deadline = Deadline.objects.get(id=deadline_id)
            self.assertEquals(deadline.deadline, new_deadline)
            self.assertEquals(deadline.text, '')
Example #10
0
def create_deadlinedict(assignment_id, deadlines, now=None, autoserialize_groups=True):
    now = now or datetime.now()
    deadline = deadlines[0]
    groups = []
    if autoserialize_groups:
        groups = GroupsListResource().serialize(deadlines)
    bulkdeadline_id = encode_bulkdeadline_id(deadline)
    return {'bulkdeadline_id': bulkdeadline_id,
            'deadline': format_datetime(deadline.deadline),
            'in_the_future': deadline.deadline > now,
            'offset_from_now': format_timedelta(now - deadline.deadline),
            'url': reverse('devilry_subjectadmin_rest_deadlinesbulkinstance',
                           kwargs={'id': assignment_id,
                                   'bulkdeadline_id': bulkdeadline_id}),
            'text': deadline.text,
            'groups': groups} # Only provided on instance, not in list
Example #11
0
    def test_put_group_ids(self):
        new_deadline = datetime(2004, 12, 24, 20, 30)
        g1 = self.testhelper.sub_p1_a1_g1
        g2 = self.testhelper.sub_p1_a1_g2
        self.assertEquals(g1.deadlines.count(), 1)

        content, response = self._putas('adm', {'deadline': format_datetime(new_deadline),
                                                'text': 'Updated',
                                                'group_ids': [g1.id, g2.id]})
        self.assertEquals(response.status_code, 200)
        self.assertEquals(len(content['groups']), 2)
        group_ids = set([g['id'] for g in content['groups']])
        self.assertEquals(group_ids, set([g1.id, g2.id]))

        for group in g1, g2:
            group = self.testhelper.reload_from_db(group)
            self.assertEquals(group.deadlines.count(), 1)
            deadline = group.deadlines.all()[0]
            self.assertEquals(deadline.deadline, new_deadline)
            self.assertEquals(deadline.text, 'Updated')
Example #12
0
 def first_deadline(self, instance):
     if isinstance(instance, self.model) and instance.first_deadline:
         return format_datetime(instance.first_deadline)
Example #13
0
 def publishing_time(self, instance):
     if isinstance(instance, self.model):
         return format_datetime(instance.publishing_time)
Example #14
0
 def end_time(self, instance):
     if isinstance(instance, self.model):
         return format_datetime(instance.end_time)
Example #15
0
 def test_put_with_bulkdeadline_id(self):
     new_deadline = datetime(2004, 12, 24, 20, 30)
     content, response = self._putas('adm', {'deadline': format_datetime(new_deadline),
                                             'bulkdeadline_id': 'ignored'})
     self.assertEquals(response.status_code, 200)
Example #16
0
 def test_put_before_publishingtime(self):
     new_deadline = datetime(1990, 1, 1, 20, 30, 40)
     content, response = self._putas('adm', {'deadline': format_datetime(new_deadline),
                                             'text': None})
     self.assertEquals(response.status_code, 400)
     self.assertEquals(content['errors'], ['Deadline cannot be before publishing time.'])
 def format_feedback(self, staticfeedback):
     feedbackdict = super(AdministratorGroupResource, self).format_feedback(staticfeedback)
     feedbackdict["saved_by"] = self._serialize_user(staticfeedback.saved_by)
     feedbackdict["save_timestamp"] = format_datetime(staticfeedback.save_timestamp)
     feedbackdict["points"] = staticfeedback.points
     return feedbackdict