Exemplo n.º 1
0
    def clean_start_date(self):
        start_date = self.cleaned_data['start_date']

        # Prevent orders with a start_date before today
        if localdate(start_date) < today():
            raise ValidationError("You cannot create a backdated order")

        # Prevent orders with less than a day's notice
        if localdate(start_date) < today() + timedelta(days=1):
            raise ValidationError("Please allow 24 hours between now "
                                  "and the start of your order")
        return start_date
Exemplo n.º 2
0
    def test_is_closed(self):
        """
        order.is_closed()
        """
        # Ended 5 days ago - 100%
        self.assertTrue(OrderFactory(
            start_date=today()-timedelta(days=10),
            end_date=today()-timedelta(days=5),
        ).is_closed())

        # Started 5 days ago, ends in 5 days - 50%
        self.assertFalse(OrderFactory(
            start_date=today()-timedelta(days=5),
            end_date=today()+timedelta(days=5),
        ).is_closed())

        # Not yet started - 0%
        self.assertFalse(OrderFactory(
            start_date=today()+timedelta(days=5),
            end_date=today()+timedelta(days=10),
        ).is_closed())

        # Would be open, except it's canceled
        self.assertTrue(OrderFactory(
            start_date=today()-timedelta(days=5),
            end_date=today()+timedelta(days=5),
            canceled=True
        ).is_closed())
Exemplo n.º 3
0
    def test_inquirers(self):
        """ pick.inquirers() """
        picker = ActiveUserFactory()
        requester = ActiveUserFactory()
        gardeners = ActiveUserFactory.create_batch(2)
        garden = GardenFactory()
        plot = PlotFactory(garden=garden)
        plot.gardeners.add(gardeners[0])
        plot.gardeners.add(gardeners[1])
        Order.objects.create(
            plot=plot,
            start_date=today()-timedelta(days=5),
            end_date=today()+timedelta(days=5),
            requester=requester
        )
        pick = Pick.objects.create(picker=picker, plot=plot)

        self.assertIn(gardeners[0], list(pick.inquirers()))
        self.assertIn(gardeners[1], list(pick.inquirers()))
        self.assertIn(requester, list(pick.inquirers()))
Exemplo n.º 4
0
    def test_progress(self):
        """
        order.progress()
        """
        # Ended 5 days ago - 100%
        self.assertEqual(OrderFactory(
            start_date=today()-timedelta(days=10),
            end_date=today()-timedelta(days=5),
        ).progress(), 100)

        # Started 5 days ago, ends in 5 days - 50%
        # FIXME: Test this using freezegun instead of "close enough"
        self.assertTrue(abs(OrderFactory(
            start_date=today()-timedelta(days=5),
            end_date=today()+timedelta(days=5),
        ).progress() - 50) < 10)

        # Not yet started - 0%
        self.assertEqual(OrderFactory(
            start_date=today()+timedelta(days=5),
            end_date=today()+timedelta(days=10),
        ).progress(), 0)
Exemplo n.º 5
0
 def unpicked_today(self):
     """ Orders that have no Picks from today. """
     return self.exclude(plot__picks__timestamp__gte=today())
Exemplo n.º 6
0
 def picked_today(self):
     """ Orders that have at least one Pick from today. """
     return self.filter(plot__picks__timestamp__gte=today())
Exemplo n.º 7
0
 def inactive(self):
     """ All orders that aren't happening right now. """
     return self.filter(
         Q(end_date__lt=today()) | Q(start_date__gt=today())
         | Q(canceled=True))
Exemplo n.º 8
0
 def active(self):
     """ Orders that are happening right now. """
     return self.filter(
         Q(end_date__gte=today())
         & Q(start_date__lte=today())).exclude(canceled=True)
Exemplo n.º 9
0
 def upcoming(self):
     """ Orders that have not yet begun but are scheduled to happen. """
     return self.filter(start_date__gt=today()).exclude(canceled=True)
Exemplo n.º 10
0
 def closed(self):
     """ Orders that have finished or were canceled. """
     completed = self.filter(end_date__lt=today())
     canceled = self.filter(canceled=True)
     return completed.union(canceled).distinct()
Exemplo n.º 11
0
 def open(self):
     """ Orders that have not finished but also may not have begun. """
     return self.filter(end_date__gt=today()).exclude(canceled=True)
Exemplo n.º 12
0
    def test_picker_format(self):
        requester = get_user_model().objects.create_user(
            email=fake.email(), password=fake.password())

        garden = Garden.objects.create(
            title='Garden A', address='1000 Garden Rd, Philadelphia PA, 1776')
        plots = [
            Plot.objects.create(title='1', garden=garden),
            Plot.objects.create(title='2', garden=garden),
            Plot.objects.create(title='3', garden=garden),
            Plot.objects.create(title='4', garden=garden)
        ]
        orders = [
            Order.objects.create(
                plot=plots[0],
                start_date=today()+timedelta(days=5),
                end_date=today()+timedelta(days=10),
                requester=requester
            ),
            Order.objects.create(
                plot=plots[1],
                start_date=today()-timedelta(days=10),
                end_date=today()-timedelta(days=5),
                requester=requester
            ),
            Order.objects.create(
                plot=plots[3],
                start_date=today()-timedelta(days=5),
                end_date=today()+timedelta(days=5),
                requester=requester
            ),
            Order.objects.create(
                plot=plots[2],
                start_date=today()-timedelta(days=5),
                end_date=today()+timedelta(days=5),
                requester=requester
            ),
            Order.objects.create(
                plot=plots[0],
                start_date=today()-timedelta(days=5),
                end_date=today()+timedelta(days=5),
                requester=requester
            ),
        ]

        # Create picker
        picker = get_user_model().objects.create_user(
            email=fake.email(), password=fake.password())
        garden.pickers.add(picker)

        formatted = templatetags.picker_format(
            picker.get_picker_orders(),
            garden
        )

        self.assertNotIn(orders[0], formatted)
        self.assertNotIn(orders[1], formatted)
        self.assertIn(orders[2], formatted)
        self.assertIn(orders[3], formatted)
        self.assertIn(orders[4], formatted)

        self.assertEqual(len(formatted), 3)