示例#1
0
    def testCollectFromAssignment_NoneAssigned(self):
        c, d, v, a, fix_to_date = self.setup_sendable_test()

        f.TriggerByAssignmentFactory.create(campaign=c)

        result = Sendable.collect_from_assignment(fix_to_date)

        self.assertEqual(0, result)
        all_qs = Sendable.objects.all()
        self.assertQuerysetEqual(all_qs, [])
示例#2
0
    def testSendable_EventCollectSendablesAssignable_ButEventNotVisible(self):
        c, d, v, a, fix_to_date = self.setup_sendable_test()

        f.TriggerByEventFactory.create_batch(
            3, assignment_state=TriggerBase.ASSIGNED, campaign=c)

        result = Sendable.collect_from_event_only_assigned_triggers(
            fix_to_date)
        self.assertEqual(0, result)
        all_qs = Sendable.objects.all()
        self.assertQuerysetEqual(all_qs, [])
示例#3
0
    def testSendable_DateCollectSendablesAssigned(self):
        c, d, v, a, fix_to_date = self.setup_sendable_test()

        f.TriggerByDateFactory.create_batch(
            3, fixed_date=fix_to_date,
            assignment_state=TriggerBase.ASSIGNED,
            campaign=c)

        result = Sendable.collect_from_fixed_triggers(fix_to_date)
        self.assertEqual(0, result)
        all_qs = Sendable.objects.all()
        self.assertQuerysetEqual(all_qs, [])
示例#4
0
    def testCollectFromAssignment_OneAssigned(self):
        c, d, v, a, fix_to_date = self.setup_sendable_test()
        when = datetime.combine(fix_to_date, time(1, 0, 0, 0, pytz.utc))
        f.AssignmentFactory(volunteer=v, duty=d, created=when)
        f.TriggerByAssignmentFactory.create(campaign=c)

        result = Sendable.collect_from_assignment(fix_to_date)

        self.assertEqual(1, result)
        all_qs = Sendable.objects.all()
        self.assertQuerysetEqual(all_qs, [v],
                                 transform=lambda s: s.volunteer)
示例#5
0
    def testSendable_DateCollectSendablesAssignable(self):
        c, d, v, a, fix_to_date = self.setup_sendable_test()

        f.TriggerByDateFactory.create_batch(
            3, fixed_date=fix_to_date,
            assignment_state=TriggerBase.ASSIGNABLE, campaign=c)

        result = Sendable.collect_from_fixed_triggers(fix_to_date)
        self.assertEqual(3, result)
        all_qs = Sendable.objects.all().order_by('id')
        self.assertQuerysetEqual(all_qs, [v, v, v],
                                 transform=lambda s: s.volunteer)
示例#6
0
    def testSendable_DateCollectSendablesAssignableButEventNotVisible(self):
        c, d, v, a, fix_to_date = self.setup_sendable_test()

        d.event.is_visible_to_volunteers = False
        d.event.save()

        f.TriggerByDateFactory.create_batch(
            3, fixed_date=fix_to_date,
            assignment_state=TriggerBase.ASSIGNABLE, campaign=c)

        result = Sendable.collect_from_fixed_triggers(fix_to_date)
        self.assertEqual(0, result)
        all_qs = Sendable.objects.all()
        self.assertQuerysetEqual(all_qs, [])
示例#7
0
    def testCollectFromAssignment_OneAssignedButEventInPast(self):
        c, d, v, a, fix_to_date = self.setup_sendable_test()
        when = datetime.combine(fix_to_date, time(1, 0, 0, 0, pytz.utc))
        f.AssignmentFactory(volunteer=v, duty=d, created=when)
        f.TriggerByAssignmentFactory.create(campaign=c)

        d.event.date = fix_to_date - timedelta(days=1)
        d.event.save()

        result = Sendable.collect_from_assignment(fix_to_date)

        self.assertEqual(0, result)
        all_qs = Sendable.objects.all()
        self.assertQuerysetEqual(all_qs, [])
示例#8
0
    def testSendable_DateCollectSendablesAssignableButAlreadyAssigned(self):
        c, d, v, a, fix_to_date = self.setup_sendable_test()

        f.AssignmentFactory(volunteer=v, duty=d)

        f.TriggerByDateFactory.create(
            fixed_date=fix_to_date,
            assignment_state=TriggerBase.ASSIGNABLE,
            campaign=c)

        result = Sendable.collect_from_fixed_triggers(fix_to_date)
        self.assertEqual(0, result)
        all_qs = Sendable.objects.all()
        self.assertQuerysetEqual(all_qs, [])
示例#9
0
    def testSendable_EventCollectSendablesAssignedDifferentActivity(self):
        c, d, v, a, fix_to_date = self.setup_sendable_test()

        f.AssignmentFactory(volunteer=v, duty=d)

        f.TriggerByEventFactory.create_batch(
            3, assignment_state=TriggerBase.ASSIGNED, campaign=c,
            activities=[])

        TriggerByEvent.objects.first().activities.add(d.activity)

        result = Sendable.collect_from_event_only_assigned_triggers(
            fix_to_date)

        self.assertEqual(1, result)
示例#10
0
    def testSendable_EventCollectSendablesAssignable(self):
        c, d, v, a, fix_to_date = self.setup_sendable_test()

        f.AssignmentFactory(volunteer=v, duty=d)

        f.TriggerByEventFactory.create_batch(
            3, assignment_state=TriggerBase.ASSIGNED, campaign=c,
            activities=[d.activity])

        result = Sendable.collect_from_event_only_assigned_triggers(
            fix_to_date)
        self.assertEqual(3, result)
        all_qs = Sendable.objects.all().order_by('id')
        self.assertQuerysetEqual(all_qs, [v, v, v],
                                 transform=lambda s: s.volunteer)
 def testSendable_EventCollectSendablesAssignable(self):
     fix_to_date = date(2225, 5, 5)  # This must be in the future.
     e = f.EventFactory(date=fix_to_date)
     c = f.CampaignFactory()
     d = f.FullDutyFactory(event=e)
     c.events.add(e)
     v = f.VolunteerFactory()
     f.AssignmentFactory(volunteer=v, duty=d)
     f.TriggerByEventFactory.create_batch(
         3, assignment_state=TriggerBase.ASSIGNED, campaign=c)
     result = Sendable.collect_from_event_only_assigned_triggers(
         fix_to_date)
     self.assertEqual(3, result)
     all_qs = Sendable.objects.all().order_by('id')
     self.assertQuerysetEqual(all_qs, [v, v, v],
                              transform=lambda s: s.volunteer)
示例#12
0
    def testSendable_EventCollectSendablesAssigned_ButEventInPast(self):
        c, d, v, a, fix_to_date = self.setup_sendable_test()

        f.AssignmentFactory(volunteer=v, duty=d)

        d.event.date = fix_to_date - timedelta(days=1)
        d.event.save()

        f.TriggerByEventFactory.create_batch(
            3, assignment_state=TriggerBase.ASSIGNED,
            campaign=c)
        result = Sendable.collect_from_event_only_assigned_triggers(
            fix_to_date)
        self.assertEqual(0, result)
        all_qs = Sendable.objects.all()
        self.assertQuerysetEqual(all_qs, [])
示例#13
0
    def testCollectFromAssignment_OnlyAssignedOnRightDayNoOffset(self):
        c, d, v, a, fix_to_date = self.setup_sendable_test()
        v2, v3, v4 = f.VolunteerFactory.create_batch(3)
        when = datetime.combine(fix_to_date, time(1, 0, 0, 0, pytz.utc))
        f.AssignmentFactory(volunteer=v, duty=d, created=when - timedelta(1))
        f.AssignmentFactory(volunteer=v2, duty=d, created=when)
        f.AssignmentFactory(volunteer=v3, duty=d, created=when)
        f.AssignmentFactory(volunteer=v4, duty=d, created=when + timedelta(1))
        f.TriggerByAssignmentFactory.create(campaign=c)

        result = Sendable.collect_from_assignment(fix_to_date)

        self.assertEqual(2, result)
        all_qs = Sendable.objects.all().order_by('id')
        self.assertQuerysetEqual(all_qs, [v3, v2],
                                 transform=lambda s: s.volunteer)
 def testSendable_DateCollectSendablesAssigned(self):
     fix_to_date = date(2005, 5, 5)
     c = f.CampaignFactory()
     d = f.FullDutyFactory()
     c.events.add(d.event)
     v = f.VolunteerFactory()
     a = f.AttributeFactory()
     v.attributes.add(a)
     d.activity.attributes.add(a)
     f.TriggerByDateFactory.create_batch(
         3, fixed_date=fix_to_date,
         assignment_state=TriggerBase.ASSIGNED,
         campaign=c)
     result = Sendable.collect_from_fixed_triggers(fix_to_date)
     self.assertEqual(0, result)
     all_qs = Sendable.objects.all()
     self.assertQuerysetEqual(all_qs, [])
示例#15
0
    def testCollectAll_OneToCollectFromEachTrigger(self):
        c, d, v, a, fix_to_date = self.setup_sendable_test()
        fix_to_datetime = datetime.combine(
            fix_to_date, time(1, 0, 0, 0, pytz.utc))

        f.TriggerByAssignmentFactory.create(campaign=c, days_after=0)
        f.TriggerByEventFactory.create(assignment_state=TriggerBase.ASSIGNED,
                                       campaign=c, activities=[d.activity])
        f.TriggerByDateFactory.create(fixed_date=fix_to_date,
                                      assignment_state=TriggerBase.ASSIGNED,
                                      campaign=c)

        f.AssignmentFactory(volunteer=v, duty=d, created=fix_to_datetime)

        result = Sendable.collect_all(fix_to_date, stdout)

        self.assertEqual(3, result)
        all_qs = Sendable.objects.all().order_by('id')
        self.assertQuerysetEqual(all_qs, [v, v, v],
                                 transform=lambda s: s.volunteer)
示例#16
0
    def testSendable_DateCollectSndblesUnassignedButAssignedOnce(self):
        c, d, v, a, fix_to_date = self.setup_sendable_test()

        d2 = f.FullDutyFactory.create()
        c.events.add(d2.event)
        v2, _ = f.VolunteerFactory.create_batch(2)
        v2.attributes.add(a)
        d2.activity.attributes.add(a)

        f.AssignmentFactory(volunteer=v, duty=d)

        f.TriggerByDateFactory.create(
            fixed_date=fix_to_date,
            assignment_state=TriggerBase.UNASSIGNED,
            campaign=c)

        result = Sendable.collect_from_fixed_triggers(fix_to_date)
        self.assertEqual(1, result)
        all_qs = Sendable.objects.all()
        self.assertQuerysetEqual(all_qs, [v2],
                                 transform=lambda s: s.volunteer)
示例#17
0
    def testCollectFromAssignment_MultipleCampaignsDifferentActivites(self):
        c, d, v, a, fix_to_date = self.setup_sendable_test()
        c.locations.add(d.location)
        when = datetime.combine(fix_to_date, time(1, 0, 0, 0, pytz.utc))
        f.AssignmentFactory(volunteer=v, duty=d, created=when)

        # Create and assign event at different location
        d2 = f.FullDutyFactory()
        a2 = f.ActivityFactory()
        d2.event = d.event
        d2.activity = a2
        d2.save()
        f.AssignmentFactory(volunteer=v, duty=d2, created=when)

        f.TriggerByAssignmentFactory.create(campaign=c)

        result = Sendable.collect_from_assignment(fix_to_date)

        self.assertEqual(1, result)
        all_qs = Sendable.objects.all()
        self.assertQuerysetEqual(all_qs, [v],
                                 transform=lambda s: s.volunteer)