Exemplo n.º 1
0
 def test_autocreate_delivery_if_nonelectronic_false(self):
     groupbuilder = PeriodBuilder.quickadd_ducku_duck1010_active()\
         .add_assignment('assignment1',
             delivery_types=deliverytypes.NON_ELECTRONIC)\
         .add_group()
     deadline = Deadline(
         assignment_group=groupbuilder.group,
         deadline=DateTimeBuilder.now().plus(days=10))
     deadline.save(autocreate_delivery_if_nonelectronic=False)
     self.assertEquals(deadline.deliveries.count(), 0)
Exemplo n.º 2
0
 def test_encode_unique_bulkdeadline_id(self):
     d = Deadline(deadline=datetime(2000, 12, 24, 22, 30, 49))
     self.assertEquals(encode_bulkdeadline_id(d),
                       '2000-12-24T22_30_49--')
     d.text = 'Hello world'
     self.assertEquals(encode_bulkdeadline_id(d),
                       '2000-12-24T22_30_49--{0}'.format(sha1hash('Hello world')))
     # Ensure unicode works
     d.text = u'\u00e5ello world'
     self.assertEquals(encode_bulkdeadline_id(d),
                       '2000-12-24T22_30_49--{0}'.format(sha1hash(u'\u00e5ello world')))
Exemplo n.º 3
0
    def test_smart_create_non_electronic(self):
        assignment = PeriodBuilder.quickadd_ducku_duck1010_active()\
            .add_assignment('assignment1', delivery_types=deliverytypes.NON_ELECTRONIC).assignment
        group1 = AssignmentGroup(parentnode=assignment)
        group2 = AssignmentGroup(parentnode=assignment)
        for group in group1, group2:
            group.save(autocreate_first_deadline_for_nonelectronic=False)
        deadline_datetime = Deadline.reduce_datetime_precision(DateTimeBuilder.now().plus(days=10))
        result = Deadline.objects.smart_create(
            assignment.assignmentgroups.all(),
            deadline_datetime=deadline_datetime,
            text='Hello world')
        self.assertIsNone(result)
        self.assertEquals(group1.deadlines.count(), 1)

        group1 = AssignmentGroup.objects.get(id=group1.id) # Reload from db
        created_deadline = group1.deadlines.all()[0]
        self.assertEquals(created_deadline.deadline, deadline_datetime)
        self.assertEquals(created_deadline.text, 'Hello world')
        self.assertEquals(group1.last_deadline, created_deadline)
        self.assertEquals(group1.last_deadline.deliveries.count(), 1)
        self.assertEquals(group1.last_deadline.deliveries.all()[0], group1.last_delivery)
        self.assertTrue(group1.last_delivery.successful)
        self.assertEquals(group1.last_delivery.number, 1)

        group2 = AssignmentGroup.objects.get(id=group2.id) # Reload from db
        self.assertEquals(group2.deadlines.all()[0].deadline, deadline_datetime)
        self.assertEquals(group2.last_deadline, group2.deadlines.all()[0])
        self.assertEquals(group2.last_deadline.deliveries.count(), 1)
        self.assertEquals(group2.last_deadline.deliveries.all()[0], group2.last_delivery)
        self.assertTrue(group2.last_delivery.successful)
        self.assertEquals(group2.last_delivery.number, 1)
            def create_old_delivery_structure():
                deadlinebuilder = groupbuilder \
                    .add_deadline(
                        deadline=Deadline.reduce_datetime_precision(
                            assignmentbuilder.assignment.first_deadline))

                deliverybuilder = deadlinebuilder.add_delivery_x_hours_before_deadline(
                    hours=random.randint(1, 30))
                used_filenames = set()
                for number in xrange(filecount):
                    while True:
                        deliveryfile = random.choice(programs)
                        filename = deliveryfile['filename']
                        if filename not in used_filenames:
                            used_filenames.add(filename)
                            break
                    deliverybuilder.add_filemeta(
                        filename=deliveryfile['filename'],
                        data=deliveryfile['data'])

                if random.randint(0, 100) <= feedback_percent:
                    feedback = StaticFeedback.from_points(
                        assignment=assignmentbuilder.assignment,
                        saved_by=examiner,
                        delivery=deliverybuilder.delivery,
                        rendered_view=self._lorem_paras(random.randint(1, 5)),
                        points=random.randint(minpoints, maxpoints))
                    feedback.save()
Exemplo n.º 5
0
    def test_deadline_notunique(self):
        self.add_to_path('uni;sub.p1:begins(-2).a1.g1.d1:ends(5)')
        self.add_to_path('uni;sub.p1.a1.g2.d1:ends(5)')

        g1 = self.sub_p1_a1_g1
        d1 = self.sub_p1_a1_g1_d1
        g2_d1 = self.sub_p1_a1_g2_d1

        # Ensure that we are not checking outside the group (the tests below would fail if this fails)
        self.assertEquals(d1.deadline, g2_d1.deadline)

        # Will not fail because id matches in the validator
        d1.full_clean()

        d2 = Deadline(assignment_group=g1, deadline=d1.deadline)
        with self.assertRaises(ValidationError):
            d2.full_clean()
 def _add_deadlines(self):
     new_deadline = self.CONTENT['deadline']
     text = self.CONTENT['text']
     deadlines = []
     with transaction.commit_manually():
         try:
             groups = self._query_creategroups()
             if len(groups) == 0:
                 raise BadRequestFieldError('createmode',
                                            _('The given option did not match any groups.'))
             for group in groups:
                 deadline = Deadline(assignment_group=group)
                 deadline.deadline = new_deadline
                 deadline.text = text
                 deadline.full_clean()
                 deadline.save()
                 deadlines.append(deadline)
                 logger.info('User=%s created Deadline id=%s (%s)', self.user, deadline.id, deadline.deadline)
         except ValidationError as e:
             transaction.rollback()
             raise ValidationErrorResponse(e)
         except Exception as e:
             transaction.rollback()
             raise
         else:
             transaction.commit()
     return deadlines
Exemplo n.º 7
0
 def test_smart_create_no_text(self):
     assignmentbuilder = PeriodBuilder.quickadd_ducku_duck1010_active()\
         .add_assignment('assignment1')
     group1builder = assignmentbuilder.add_group()
     deadline_datetime = Deadline.reduce_datetime_precision(DateTimeBuilder.now().plus(days=10))
     Deadline.objects.smart_create(
         assignmentbuilder.assignment.assignmentgroups.all(),
         deadline_datetime=deadline_datetime)
     group1builder.reload_from_db()
     self.assertEquals(group1builder.group.last_deadline.deadline, deadline_datetime)
     self.assertEquals(group1builder.group.last_deadline.text, None)
 def test_custom_success_url(self):
     group1builder = self.assignment1builder\
         .add_group(examiners=[self.examiner1])
     deadline_datetime = Deadline.reduce_datetime_precision(DateTimeBuilder.now().plus(days=10))
     response = self._postas(self.examiner1, {
         'group_ids': [group1builder.group.id],
         'deadline': isoformat_datetime(deadline_datetime),
         'text': 'Hello world',
         'success_url': '/my/test',
         'add_deadline_form': 'i18nlabel'
     })
     self.assertEquals(response.status_code, 302)
     self.assertTrue(response['Location'].endswith('/my/test'))
 def test_default_success_url(self):
     group1builder = self.assignment1builder\
         .add_group(examiners=[self.examiner1])
     deadline_datetime = Deadline.reduce_datetime_precision(DateTimeBuilder.now().plus(days=10))
     response = self._postas(self.examiner1, {
         'group_ids': [group1builder.group.id],
         'deadline': isoformat_datetime(deadline_datetime),
         'text': 'Hello world',
         'add_deadline_form': 'i18nlabel'
     })
     self.assertEquals(response.status_code, 302)
     self.assertTrue(response['Location'].endswith(
         reverse('devilry_examiner_allgroupsoverview', kwargs={'assignmentid': self.assignment1builder.assignment.id})))
 def test_post_no_text(self):
     group1builder = self.assignment1builder\
         .add_group(examiners=[self.examiner1])
     deadline_datetime = Deadline.reduce_datetime_precision(DateTimeBuilder.now().plus(days=10))
     response = self._postas(self.examiner1, {
         'group_ids': [group1builder.group.id],
         'deadline': isoformat_datetime(deadline_datetime),
         'add_deadline_form': 'i18nlabel',
         'no_text': 'on'
     })
     self.assertEquals(response.status_code, 302)
     group1builder.reload_from_db()
     self.assertEquals(group1builder.group.last_deadline.deadline, deadline_datetime)
     self.assertEquals(group1builder.group.last_deadline.text, '')
 def test_post_why_created(self):
     group1builder = self.assignment1builder\
         .add_group(examiners=[self.examiner1])
     deadline_datetime = Deadline.reduce_datetime_precision(DateTimeBuilder.now().plus(days=10))
     response = self._postas(self.examiner1, {
         'group_ids': [group1builder.group.id],
         'deadline': isoformat_datetime(deadline_datetime),
         'text': 'Hello world',
         'why_created': 'examiner-gave-another-chance',
         'add_deadline_form': 'i18nlabel'
     })
     self.assertEquals(response.status_code, 302)
     group1builder.reload_from_db()
     self.assertEquals(group1builder.group.last_deadline.why_created, 'examiner-gave-another-chance')
 def test_post_no_text_checkbox_required(self):
     group1builder = self.assignment1builder\
         .add_group(examiners=[self.examiner1])
     deadline_datetime = Deadline.reduce_datetime_precision(DateTimeBuilder.now().plus(days=10))
     response = self._postas(self.examiner1, {
         'group_ids': [group1builder.group.id],
         'deadline': isoformat_datetime(deadline_datetime),
         'add_deadline_form': 'i18nlabel'
     })
     self.assertEquals(response.status_code, 200)
     group1builder.reload_from_db()
     self.assertEquals(group1builder.group.last_deadline, None)
     self.assertIn('You must specify an &quot;About this deadline&quot; message, or select that you do not want to specify a message.',
         response.content)
Exemplo n.º 13
0
def create_default_deadline(update_db, ag):
    # Create the default deadline, with deadline at the beginning of the period
    default_d = Deadline()
    default_d.deadline = ag.parentnode.parentnode.start_time
    default_d.assignment_group = ag
    default_d.is_head = True

    deadlines = ag.deadlines.all().order_by('deadline')
    # If script is run multiple times, avoid adding a new head deadline
    if len(deadlines) == 0 or deadlines[0].is_head:
        print "Created new head deadline with time %s", default_d.deadline
        if update_db:
            default_d.save()
 def test_post_no_text_checked_and_text_provided(self):
     group1builder = self.assignment1builder\
         .add_group(examiners=[self.examiner1])
     deadline_datetime = Deadline.reduce_datetime_precision(DateTimeBuilder.now().plus(days=10))
     response = self._postas(self.examiner1, {
         'group_ids': [group1builder.group.id],
         'deadline': isoformat_datetime(deadline_datetime),
         'add_deadline_form': 'i18nlabel',
         'no_text': 'on',
         'text': 'Test'
     })
     self.assertEquals(response.status_code, 200)
     group1builder.reload_from_db()
     self.assertEquals(group1builder.group.last_deadline, None)
     self.assertIn('If you do not want to provide an &quot;About this deadline&quot; message, you have to clear the text field.',
         response.content)
    def handle_noargs(self, **options):
        from devilry.apps.core.models import Deadline
        verbosity = int(options.get('verbosity', '1'))

        updates = 0
        with transaction.commit_manually():
            for deadline in Deadline.objects.all():
                if deadline.deadline.microsecond != 0 and deadline.deadline.seconds != 0 and deadline.deadline.tzinfo != None:
                    deadline.deadline = Deadline.reduce_datetime_precision(deadline.deadline)
                    deadline.save()
                    if verbosity > 1:
                        print 'Updated deadline {0}'.format(deadline.id)
                elif verbosity > 1:
                    print 'Deadline {0} is already correctly formatted: {1}'.format(deadline.id, deadline.deadline)
                updates += 1
            transaction.commit()
        if verbosity > 0:
            print 'Successfully updated {0} deadlines.'.format(updates)
Exemplo n.º 16
0
def create_default_deadline(update_db, ag):
    # Create the default deadline, with deadline at the beginning of the period
    default_d = Deadline()
    default_d.deadline = ag.parentnode.parentnode.start_time
    default_d.assignment_group = ag
    default_d.is_head = True
    
    deadlines = ag.deadlines.all().order_by('deadline')
    # If script is run multiple times, avoid adding a new head deadline
    if len(deadlines) == 0 or deadlines[0].is_head:
        print "Created new head deadline with time %s", default_d.deadline
        if update_db:
            default_d.save()
Exemplo n.º 17
0
    def test_smart_create_electronic(self):
        assignmentbuilder = PeriodBuilder.quickadd_ducku_duck1010_active()\
            .add_assignment('assignment1')
        group1builder = assignmentbuilder.add_group()
        group2builder = assignmentbuilder.add_group()
        deadline_datetime = Deadline.reduce_datetime_precision(DateTimeBuilder.now().plus(days=10))
        result = Deadline.objects.smart_create(
            assignmentbuilder.assignment.assignmentgroups.all(),
            deadline_datetime=deadline_datetime,
            text='Hello world')
        self.assertIsNone(result)

        group1builder.reload_from_db()
        self.assertEquals(group1builder.group.deadlines.count(), 1)
        created_deadline = group1builder.group.deadlines.all()[0]
        self.assertEquals(created_deadline.deadline, deadline_datetime)
        self.assertEquals(created_deadline.text, 'Hello world')
        self.assertEquals(group1builder.group.last_deadline, created_deadline)
        self.assertEquals(group1builder.group.last_deadline.deliveries.count(), 0)

        group2builder.reload_from_db()
        self.assertEquals(group2builder.group.deadlines.all()[0].deadline, deadline_datetime)
        self.assertEquals(group2builder.group.last_deadline, group2builder.group.deadlines.all()[0])
    def add_duck1100(self):
        duck1100 = self.duckburgh.add_subject(
            short_name='duck1100',
            long_name='DUCK1100 - Programming for the natural sciences')
        duck1100.add_admins(self.thor)

        relatedstudents = [
            RelatedStudent(user=self.april, tags='group1'),
        ]
        relatedstudents.extend(self._as_relatedstudents(self.good_students.values(), 'group1'))
        relatedstudents.extend(self._as_relatedstudents(self.bad_students.values(), 'group2'))
        testsemester = duck1100.add_6month_active_period(
            short_name='testsemester', long_name='Testsemester',
            relatedstudents=relatedstudents,
            relatedexaminers=[
                RelatedExaminer(user=self.thor, tags=''),
                RelatedExaminer(user=self.donald, tags='group1'),
                RelatedExaminer(user=self.scrooge, tags='group2')
            ])

        # old_relatedstudentusers = [
        #     self.thor,
        #     self.april, self.bad_students['dewey'],
        #     self.bad_students['louie'], self.bad_students['june'],
        #     self.good_students['loki'], self.good_students['kvasir']]
        # old_relatedstudents = self._as_relatedstudents(old_relatedstudentusers, tags='')
        oldtestsemester = duck1100.add_6month_lastyear_period(
            short_name='oldtestsemester', long_name='Old testsemester',
            relatedstudents=relatedstudents,
            relatedexaminers=[
                RelatedExaminer(user=self.thor, tags=''),
                RelatedExaminer(user=self.donald, tags='group1'),
                RelatedExaminer(user=self.scrooge, tags='group2')
            ])

        for periodbuilder, weekoffset in [
                (oldtestsemester, 52),
                (testsemester, 0)]:
            self.build_random_pointassignmentdata(
                periodbuilder=periodbuilder,
                weeks_ago=weekoffset + 6, filecount=4,
                short_name='week1', long_name='Week 1')
            self.build_random_pointassignmentdata(
                periodbuilder=periodbuilder,
                weeks_ago=weekoffset + 5, filecount=2,
                short_name='week2', long_name='Week 2')
            self.build_random_pointassignmentdata(
                periodbuilder=periodbuilder,
                weeks_ago=weekoffset + 4, filecount=4,
                short_name='week3', long_name='Week 3')
            self.build_random_pointassignmentdata(
                periodbuilder=periodbuilder,
                weeks_ago=weekoffset + 3, filecount=8,
                short_name='week4', long_name='Week 4')

            if weekoffset == 0:
                self.build_random_pointassignmentdata(
                    periodbuilder=periodbuilder,
                    weeks_ago=weekoffset + 1, filecount=6,
                    short_name='week5', long_name='Week 5',
                    feedback_percent=50)

                week6 = periodbuilder.add_assignment_x_weeks_ago(
                    weeks=weekoffset, short_name='week6', long_name='Week 6',
                    passing_grade_min_points=1,
                    grading_system_plugin_id='devilry_gradingsystemplugin_points',
                    points_to_grade_mapper='raw-points',
                    max_points=6
                )
                for user in self.allstudentslist + [self.april]:
                    examiner = random.choice(self.examiners)
                    week6 \
                        .add_group(students=[user], examiners=[examiner]) \
                        .add_deadline(deadline=Deadline.reduce_datetime_precision(DateTimeBuilder.now().plus(days=7)))
            else:
                self.build_random_pointassignmentdata(
                    periodbuilder=periodbuilder,
                    weeks_ago=weekoffset + 1, filecount=1,
                    short_name='week5', long_name='Week 5')
                self.build_random_pointassignmentdata(
                    periodbuilder=periodbuilder,
                    weeks_ago=weekoffset, filecount=2,
                    short_name='week6', long_name='Week 6')

        print
        print("*" * 70)
        print
        print('duck1100 added')
        print
        print("*" * 70)
        print
Exemplo n.º 19
0
 def _addFirstDeadline(self, group):
     from devilry.apps.core.models import Deadline
     deadline = Deadline(assignment_group=group, deadline=group.parentnode.first_deadline)
     deadline.full_clean()
     deadline.save()