Пример #1
0
    def test_matches_first_when_distance_is_equal(self):
        now = timezone.now()

        # shift pickups
        every_minute = [now + relativedelta(minutes=n) for n in range(1, 5)]
        pickups = [
            PickupDate(date=to_range(d +
                                     relativedelta(seconds=30), minutes=30))
            for d in every_minute
        ]

        self.assertIteratorEqual(
            match_pickups_with_dates(pickups, every_minute),
            zip(pickups, every_minute),
        )

        # shift dates
        pickups = [
            PickupDate(date=to_range(d, minutes=30)) for d in every_minute
        ]
        every_minute = [n + relativedelta(seconds=30) for n in every_minute]

        self.assertIteratorEqual(
            match_pickups_with_dates(pickups, every_minute),
            zip(pickups, every_minute),
        )
Пример #2
0
    def test_matches_empty(self):
        now = timezone.now()
        every_day = [now + relativedelta(days=n) for n in range(1, 3)]
        pickups = [PickupDate(date=to_range(d, minutes=30)) for d in every_day]

        self.assertIteratorEqual(
            match_pickups_with_dates([], every_day),
            zip((None, None), every_day),
        )
        self.assertIteratorEqual(
            match_pickups_with_dates(pickups, []),
            zip(pickups, (None, None)),
        )
        self.assertIteratorEqual(
            match_pickups_with_dates([], []),
            [],
        )
Пример #3
0
    def test_matches_identical_pickups(self):
        now = timezone.now()
        every_day = [now + relativedelta(days=n) for n in range(1, 5)]
        pickups = [PickupDate(date=to_range(d, minutes=30)) for d in every_day]

        self.assertIteratorEqual(
            match_pickups_with_dates(pickups, every_day),
            zip(pickups, every_day),
        )
Пример #4
0
    def test_matches_partially(self):
        now = timezone.now()
        every_day = [now + relativedelta(days=n) for n in range(1, 5)]
        pickups = [PickupDate(date=to_range(d, minutes=30)) for d in every_day]

        self.assertIteratorEqual(
            match_pickups_with_dates(pickups[::2], every_day),
            zip((pickups[0], None, pickups[2], None), every_day),
        )
        self.assertIteratorEqual(
            match_pickups_with_dates(pickups[1::2], every_day),
            zip((None, pickups[1], None, pickups[3]), every_day),
        )
        self.assertIteratorEqual(
            match_pickups_with_dates(pickups, every_day[::2]),
            zip(pickups, (every_day[0], None, every_day[2], None)),
        )
        self.assertIteratorEqual(
            match_pickups_with_dates(pickups, every_day[1::2]),
            zip(pickups, (None, every_day[1], None, every_day[3])),
        )
Пример #5
0
    def test_matches_shifted_pickups_within_few_seconds(self):
        now = timezone.now()
        every_day = [now + relativedelta(days=n) for n in range(1, 5)]
        pickups = [
            PickupDate(date=to_range(d +
                                     relativedelta(seconds=20), minutes=30))
            for d in every_day
        ]

        self.assertIteratorEqual(
            match_pickups_with_dates(pickups, every_day),
            zip(pickups, every_day),
        )
Пример #6
0
    def test_not_matches_shifted_pickups_with_more_difference(self):
        now = timezone.now()
        every_day = [now + relativedelta(days=n) for n in range(1, 3)]
        pickups = [
            PickupDate(date=to_range(d +
                                     relativedelta(minutes=10), minutes=30))
            for d in every_day
        ]

        self.assertIteratorEqual(
            match_pickups_with_dates(pickups, every_day),
            [
                (None, every_day[0]),
                (pickups[0], None),
                (None, every_day[1]),
                (pickups[1], None),
            ],
        )
Пример #7
0
 def get_matched_pickups(self):
     return match_pickups_with_dates(
         pickups=self.pickup_dates.order_by('date').filter(
             date__startswith__gt=self.period_start()),
         new_dates=self.dates(),
     )