def test_set_number_first(self): deadline = PeriodBuilder.quickadd_ducku_duck1010_active()\ .add_assignment('week1').add_group()\ .add_deadline_x_weeks_ago(weeks=1).deadline delivery = Delivery(deadline=deadline) delivery.set_number() self.assertEqual(delivery.number, 1)
def __init__(self, **kwargs): if 'time_of_delivery' not in kwargs: kwargs['time_of_delivery'] = timezone.now() self.delivery = Delivery(**kwargs) if 'number' not in kwargs: self.delivery.set_number() self.delivery.save()
def _create_deliveries(self): from devilry.apps.core.models import Delivery for assignmentgroup in self.assignment.assignmentgroups.all().prefetch_related('candidates'): number_of_deliveries = random.randint(self.mindeliveries, self.maxdeliveries) self._print_message('Adding {} deliveries to {}'.format(number_of_deliveries, assignmentgroup)) try: first_canididate = assignmentgroup.candidates.all()[0] except IndexError: continue for deliverynumber in xrange(number_of_deliveries): files = self._choose_random_files(random.randint(self.minfiles, self.maxfiles)) delivery = Delivery( deadline=assignmentgroup.last_deadline, delivered_by=first_canididate, successful=True, # NOTE: Set time_of_delivery to ensure sorting is correct (can create multiple deliveries during # a single second) time_of_delivery=datetime.now() + timedelta(seconds=deliverynumber)) delivery.save(autoset_time_of_delivery=False) self._print_message('Adding {} files to {}'.format(len(files), delivery)) for filepath in files: filename = os.path.relpath(filepath, self.directory) delivery.add_file( filename=filename, iterable_data=open(filepath, 'rb') )
def test_where_is_admin(self): self._create_testdata() teacher1 = User.objects.get(username='******') self.assertEquals(Delivery.where_is_admin(teacher1).count(), 3) delivery0 = self.inf1100_period1_assignment1_g1_d1.deliveries.all()[0] delivery0.successful = False delivery0.save() self.assertEquals(Delivery.where_is_admin(teacher1).count(), 2)
def test_published_where_is_examiner(self): self._create_testdata() examiner1 = User.objects.get(username='******') deliveries = Delivery.published_where_is_examiner(examiner1) self.assertEquals(deliveries.count(), 2) delivery0 = deliveries.all()[0] delivery0.successful = False delivery0.save() self.assertEquals(Delivery.published_where_is_examiner(examiner1).count(), 1)
def test_do_not_autoset_last_delivery_on_group_when_false(self): groupbuilder = PeriodBuilder.quickadd_ducku_duck1010_active()\ .add_assignment('week1')\ .add_group() deadline = groupbuilder\ .add_deadline_in_x_weeks(weeks=1).deadline delivery = Delivery( deadline=deadline, successful=False) delivery.save(autoset_last_delivery_on_group=False) groupbuilder.reload_from_db() self.assertEquals(groupbuilder.group.last_delivery_id, None)
def __init__(self, **kwargs): if 'time_of_delivery' not in kwargs: kwargs['time_of_delivery'] = datetime.now() self.delivery = Delivery(**kwargs) if 'number' not in kwargs: self.delivery.set_number() self.delivery.save()
def get_queryset(self): qry = Delivery.where_is_candidate(self.request.user) qry = qry.order_by('-time_of_delivery') qry = qry.select_related('deadline', 'deadline__assignment_group', 'deadline__assignment_group__parentnode', 'deadline__assignment_group__parentnode__parentnode', 'deadline__assignment_group__parentnode__parentnode__parentnode') return qry[:6]
def _create_copydata(self): self.add(nodes="uni", subjects=["sub"], periods=["p1"], assignments=['a1']) self.add_to_path('uni;sub.p1.a1.g1:candidate(student1):examiner(examiner1).d1') # Create delivery for alias_delivery self.add_to_path('uni;sub.p_old.a1.g1:candidate(student1):examiner(examiner1).d1') old_delivery = self.add_delivery("sub.p_old.a1.g1", {"secondtry.py": "print second"}) # Make a delivery without any of the default/generated values, so when # we check that they are copied, we get no generate stuff g1 = self.sub_p1_a1_g1 d1 = self.sub_p1_a1_g1_d1 time_of_delivery = datetime(2005, 1, 1, 0, 0, 0) delivery = Delivery(deadline=d1, number=10, successful=False, delivery_type=1, delivered_by=g1.candidates.all()[0], alias_delivery=old_delivery, time_of_delivery=time_of_delivery) delivery.full_clean() delivery.save() delivery.add_file('test.txt', ['Hello', ' world']) return delivery, old_delivery
def mark_as_delivered_in_previous(self, group, oldgroup=None, feedback=None): if oldgroup: oldfeedback = oldgroup.feedback alias_delivery = oldfeedback.delivery if not feedback: feedback = {'grade': oldfeedback.grade, 'is_passing_grade': oldfeedback.is_passing_grade, 'points': oldfeedback.points, 'rendered_view': oldfeedback.rendered_view, 'saved_by': oldfeedback.saved_by} elif feedback: alias_delivery = None else: raise ValueError('oldgroup or feedback is required arguments.') latest_deadline = group.deadlines.order_by('-deadline')[0] latest_deadline.deadline = datetime.now() + timedelta(seconds=60) delivery = Delivery( deadline=latest_deadline, delivery_type=deliverytypes.ALIAS, alias_delivery=alias_delivery) delivery.set_number() delivery.save() if isinstance(feedback, dict): feedback = delivery.feedbacks.create(**feedback) else: delivery.feedbacks.add(feedback) delivery.full_clean() # NOTE: We have to validate after adding feedback, or the delivery will fail to validate feedback.full_clean() return feedback
def test_override_autoset(self): self.add(nodes="uni", subjects=["sub"], periods=["p1"], assignments=['a1']) self.add_to_path('uni;sub.p1.a1.g1:candidate(student1):examiner(examiner1).d1') d1 = self.sub_p1_a1_g1_d1 time_of_delivery = datetime(2005, 1, 1, 0, 0, 0) delivery = Delivery(deadline=d1, number=10, successful=False, time_of_delivery=time_of_delivery) delivery.full_clean() delivery.save() self.assertEquals(delivery.number, 10) self.assertEquals(delivery.successful, False) self.assertEquals(delivery.time_of_delivery, time_of_delivery)
def get_queryset(self): qry = Delivery.where_is_candidate(self.request.user) qry = qry.annotate(number_of_feedbacks=Count('feedbacks')) qry = qry.annotate(last_feedback_timestamp=Max('feedbacks__save_timestamp')) qry = qry.filter(number_of_feedbacks__gt=0) qry = qry.select_related('deadline', 'deadline__assignment_group', 'deadline__assignment_group__parentnode', 'deadline__assignment_group__parentnode__parentnode', 'deadline__assignment_group__parentnode__parentnode__parentnode') qry = qry.order_by('-last_feedback_timestamp') return qry[:6]
def __create_delivery(self): delivery = Delivery( deadline_id=self.group.last_deadline_id, successful=True, delivered_by=self.__get_canidate(), time_of_delivery=datetime.now()) delivery.set_number() delivery.full_clean() delivery.save() return delivery
def _create_deliveries(self): from devilry.apps.core.models import Delivery for assignmentgroup in self.assignment.assignmentgroups.all().prefetch_related('candidates'): number_of_deliveries = random.randint(self.mindeliveries, self.maxdeliveries) self._print_message('Adding {} deliveries to {}'.format(number_of_deliveries, assignmentgroup)) try: first_canididate = assignmentgroup.candidates.all()[0] except IndexError: continue for deliverynumber in xrange(number_of_deliveries): files = self._choose_random_files(random.randint(self.minfiles, self.maxfiles)) delivery = Delivery( deadline=assignmentgroup.last_deadline, delivered_by=first_canididate, successful=True, # NOTE: Set time_of_delivery to ensure sorting is correct (can create multiple deliveries during # a single second) time_of_delivery=timezone.now() + timedelta(seconds=deliverynumber)) delivery.save(autoset_time_of_delivery=False) self._print_message('Adding {} files to {}'.format(len(files), delivery)) for filepath in files: filename = os.path.relpath(filepath, self.directory) delivery.add_file( filename=filename, iterable_data=open(filepath, 'rb') )
def convert_to_delivery(self, deadline, user): """ Convert all the UploadedDeliveryFile objects mathing the given deadline and user to a Delivery. Typical usage:: from django.db import transaction with transaction.commit_on_success(): delivery, files = UploadedDeliveryFile.objects.convert_to_delivery(mydeadline, myuser) with transaction.commit_on_success(): files.delete_objects_and_files() :return: A (delivery, queryset) tuple where the ``delivery`` is the created Delivery, the ``queryset` is a :class:`.UploadedDeliveryFileQuerySet` with the files that was made into a delivery. """ queryset = self.filter_for_deadline(deadline, user) if not queryset.exists(): raise UploadedDeliveryFile.DoesNotExist('No UploadedDeliveryFile with the given deadline and user exists.') candidate = deadline.assignment_group.candidates.filter(relatedstudent__user=user).get() delivery = Delivery( deadline=deadline, delivered_by=candidate, successful=False ) delivery.set_number() delivery.save() for uploaded_deliveryfile in queryset: delivery.add_file(uploaded_deliveryfile.filename, uploaded_deliveryfile.uploaded_file) delivery.successful = True delivery.save() return delivery, queryset
def add_nonelectronic_delivery(self): from devilry.apps.core.models import Delivery for group in self.all(): deadline = group.last_deadline delivery = Delivery( deadline=deadline, delivery_type=deliverytypes.NON_ELECTRONIC, time_of_delivery=datetime.now()) delivery.set_number() delivery.full_clean() delivery.save()
class DeliveryBuilder(CoreBuilderBase): object_attribute_name = "delivery" @classmethod def set_memory_deliverystore(cls): FileMeta.deliverystore = MemoryDeliveryStore() def __init__(self, **kwargs): if not "time_of_delivery" in kwargs: kwargs["time_of_delivery"] = datetime.now() self.delivery = Delivery(**kwargs) self.delivery.save(autoset_time_of_delivery=False) def _save(self): self.delivery.save(autoset_time_of_delivery=False) def add_filemeta(self, **kwargs): kwargs["delivery"] = self.delivery return FileMetaBuilder(**kwargs) def add_feedback(self, **kwargs): kwargs["delivery"] = self.delivery return StaticFeedbackBuilder(**kwargs) def add_passed_feedback(self, **kwargs): kwargs["points"] = 1 kwargs["grade"] = "Passed" kwargs["is_passing_grade"] = True kwargs["delivery"] = self.delivery return StaticFeedbackBuilder(**kwargs) def add_failed_feedback(self, **kwargs): kwargs["points"] = 0 kwargs["grade"] = "Failed" kwargs["is_passing_grade"] = False kwargs["delivery"] = self.delivery return StaticFeedbackBuilder(**kwargs)
class DeliveryBuilder(CoreBuilderBase): object_attribute_name = 'delivery' @classmethod def set_memory_deliverystore(cls): FileMeta.deliverystore = MemoryDeliveryStore() def __init__(self, **kwargs): if 'time_of_delivery' not in kwargs: kwargs['time_of_delivery'] = datetime.now() self.delivery = Delivery(**kwargs) if 'number' not in kwargs: self.delivery.set_number() self.delivery.save() def _save(self): self.delivery.save() def add_filemeta(self, **kwargs): kwargs['delivery'] = self.delivery return FileMetaBuilder(**kwargs) def add_feedback(self, **kwargs): kwargs['delivery'] = self.delivery return StaticFeedbackBuilder(**kwargs) def add_passed_feedback(self, **kwargs): kwargs['points'] = 1 kwargs['grade'] = 'Passed' kwargs['is_passing_grade'] = True kwargs['delivery'] = self.delivery return StaticFeedbackBuilder(**kwargs) def add_failed_feedback(self, **kwargs): kwargs['points'] = 0 kwargs['grade'] = 'Failed' kwargs['is_passing_grade'] = False kwargs['delivery'] = self.delivery return StaticFeedbackBuilder(**kwargs) def add_passed_A_feedback(self, **kwargs): kwargs['points'] = 100 kwargs['grade'] = 'A' kwargs['is_passing_grade'] = True kwargs['delivery'] = self.delivery return StaticFeedbackBuilder(**kwargs) def add_failed_F_feedback(self, **kwargs): kwargs['points'] = 0 kwargs['grade'] = 'F' kwargs['is_passing_grade'] = False kwargs['delivery'] = self.delivery return StaticFeedbackBuilder(**kwargs)
class DeliveryBuilder(CoreBuilderBase): object_attribute_name = 'delivery' @classmethod def set_memory_deliverystore(cls): FileMeta.deliverystore = MemoryDeliveryStore() def __init__(self, **kwargs): if 'time_of_delivery' not in kwargs: kwargs['time_of_delivery'] = timezone.now() self.delivery = Delivery(**kwargs) if 'number' not in kwargs: self.delivery.set_number() self.delivery.save() def _save(self): self.delivery.save() def add_filemeta(self, **kwargs): kwargs['delivery'] = self.delivery return FileMetaBuilder(**kwargs) def add_feedback(self, **kwargs): kwargs['delivery'] = self.delivery return StaticFeedbackBuilder(**kwargs) def add_passed_feedback(self, **kwargs): kwargs['points'] = 1 kwargs['grade'] = 'Passed' kwargs['is_passing_grade'] = True kwargs['delivery'] = self.delivery return StaticFeedbackBuilder(**kwargs) def add_failed_feedback(self, **kwargs): kwargs['points'] = 0 kwargs['grade'] = 'Failed' kwargs['is_passing_grade'] = False kwargs['delivery'] = self.delivery return StaticFeedbackBuilder(**kwargs) def add_passed_A_feedback(self, **kwargs): kwargs['points'] = 100 kwargs['grade'] = 'A' kwargs['is_passing_grade'] = True kwargs['delivery'] = self.delivery return StaticFeedbackBuilder(**kwargs) def add_failed_F_feedback(self, **kwargs): kwargs['points'] = 0 kwargs['grade'] = 'F' kwargs['is_passing_grade'] = False kwargs['delivery'] = self.delivery return StaticFeedbackBuilder(**kwargs)
def test_published_where_is_candidate(self): self._create_testdata() # Add 2 on g1 d = self.add_delivery("inf1100.period1.assignment1.g1", self.goodFile) d = self.add_delivery("inf1100.period1.assignment1.g1", self.goodFile) # Add 3 on g2 d = self.add_delivery("inf1100.period1.assignment1.g2", self.goodFile) d = self.add_delivery("inf1100.period1.assignment1.g2", self.goodFile) d = self.add_delivery("inf1100.period1.assignment1.g2", self.goodFile) # Add 2 on g3 d = self.add_delivery("inf1100.period1.assignment1.g3", self.goodFile) d = self.add_delivery("inf1100.period1.assignment1.g3", self.goodFile) self.assertEquals(Delivery.published_where_is_candidate(self.student1).count(), 3) self.assertEquals(Delivery.published_where_is_candidate(self.student2).count(), 7) self.assertEquals(Delivery.published_where_is_candidate(self.student3).count(), 3) self.assertEquals(Delivery.published_where_is_candidate(self.student4).count(), 0) delivery = Delivery.published_where_is_candidate(self.student3)[0] delivery.successful = False delivery.save() self.assertEquals(Delivery.published_where_is_candidate(self.student3).count(), 2)
def convert_to_delivery(self, deadline, user): """ Convert all the UploadedDeliveryFile objects mathing the given deadline and user to a Delivery. Typical usage:: from django.db import transaction with transaction.commit_on_success(): delivery, files = UploadedDeliveryFile.objects.convert_to_delivery(mydeadline, myuser) with transaction.commit_on_success(): files.delete_objects_and_files() :return: A (delivery, queryset) tuple where the ``delivery`` is the created Delivery, the ``queryset` is a :class:`.UploadedDeliveryFileQuerySet` with the files that was made into a delivery. """ queryset = self.filter_for_deadline(deadline, user) if not queryset.exists(): raise UploadedDeliveryFile.DoesNotExist( 'No UploadedDeliveryFile with the given deadline and user exists.' ) candidate = deadline.assignment_group.candidates.filter( relatedstudent__user=user).get() delivery = Delivery(deadline=deadline, delivered_by=candidate, successful=False) delivery.set_number() delivery.save() for uploaded_deliveryfile in queryset: delivery.add_file(uploaded_deliveryfile.filename, uploaded_deliveryfile.uploaded_file) delivery.successful = True delivery.save() return delivery, queryset
def test_delivery_numbering(self): self._create_testdata() deadline = self.inf1100_period1_assignment1_g1_d1 self.assertEquals(deadline.deliveries.count(), 1) self.assertEquals(deadline.deliveries.all()[0].number, 1) d2 = Delivery(deadline=deadline, delivered_by=deadline.assignment_group.candidates.all()[0]) d2.save() d3 = Delivery(deadline=deadline, delivered_by=deadline.assignment_group.candidates.all()[0]) d3.save() self.assertEquals(d2.number, 0) self.assertEquals(d3.number, 0) d3.successful = True d3.save() self.assertEquals(d3.number, 2) d2.successful = True d2.save() self.assertEquals(d2.number, 3)
def __init__(self, **kwargs): if not "time_of_delivery" in kwargs: kwargs["time_of_delivery"] = datetime.now() self.delivery = Delivery(**kwargs) self.delivery.save(autoset_time_of_delivery=False)