Example #1
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())
Example #2
0
    def test_inactive(self):
        """ Order.objects.inactive() """

        # Active orders
        active_orders = OrderFactory.create_batch(
            3,
            start_date=self.past_date,
            end_date=self.future_date,
        )

        # Inactive orders
        inactive_orders = [
            # Start date is greater than today
            OrderFactory(
                start_date=self.future_date,
                end_date=self.extra_future_date,
            ),
            # End date is greater than today
            OrderFactory(
                start_date=self.extra_past_date,
                end_date=self.past_date,
            ),
        ]

        # Test it
        result = Order.objects.inactive()
        for order in inactive_orders:
            self.assertIn(order, result)
        for order in active_orders:
            self.assertNotIn(order, result)
Example #3
0
 def test_was_picked_today(self):
     """
     order.was_picked_today()
     """
     order = OrderFactory()
     PickFactory(plot=order.plot)
     self.assertTrue(order.was_picked_today())
     self.assertFalse(OrderFactory().was_picked_today())
Example #4
0
    def test_closed(self):
        """ Order.objects.closed() """

        # Completed orders
        completed_orders = OrderFactory.create_batch(
            3,
            start_date=self.extra_past_date,
            end_date=self.past_date,
        )

        # Canceled orders
        canceled_orders = [
            # Would be upcoming, but canceled
            OrderFactory(
                start_date=self.future_date,
                end_date=self.extra_future_date,
                canceled=True
            ),
            # Would be active, but canceled
            OrderFactory(
                start_date=self.past_date,
                end_date=self.future_date,
                canceled=True
            ),
        ]

        # Open orders
        open_orders = [
            # Upcoming
            OrderFactory(
                start_date=self.future_date,
                end_date=self.extra_future_date,
            ),
            # Active
            OrderFactory(
                start_date=self.past_date,
                end_date=self.future_date,
            ),
        ]

        # Test it
        result = Order.objects.closed()
        for order in completed_orders:
            self.assertIn(order, result)
        for order in canceled_orders:
            self.assertIn(order, result)
        for order in open_orders:
            self.assertNotIn(order, result)
Example #5
0
 def test_is_order_picker(self):
     """ user.is_order_picker() """
     picker = PickerFactory()
     plot = PlotFactory(garden=Garden.objects.get(pickers__id=picker.id))
     order = OrderFactory(plot=plot)
     self.assertTrue(picker.is_order_picker(order))
     self.assertFalse(ActiveUserFactory().is_order_picker(order))
Example #6
0
    def test_can_edit_order(self):
        """ user.can_edit_order() """

        # Gardener can edit the order
        gardener = GardenerFactory()
        order = OrderFactory(plot=gardener.get_plots().first())
        self.assertTrue(gardener.can_edit_order(order))

        # Garden manager can edit the order
        manager = GardenManagerFactory()
        garden = manager.get_gardens().first()
        plot = PlotFactory(garden=garden)
        order = OrderFactory(plot=plot)
        self.assertTrue(manager.can_edit_order(order))

        # Normal user can't edit the order
        self.assertFalse(ActiveUserFactory().can_edit_order(OrderFactory()))
Example #7
0
 def test_get_orders(self):
     """ user.get_orders() """
     user = ActiveUserFactory()
     orders = OrderFactory.create_batch(
         5,
         start_date=localdate(2017, 1, 1),
         end_date=localdate(2017, 1, 5),
         plot__gardeners=[user]
     )
     self.assertEqual(set(user.get_orders()), set(orders))
Example #8
0
    def test_has_orders(self):
        """ user.has_orders() """

        # Create plot
        garden = GardenFactory()
        plot = PlotFactory(garden=garden)

        # Create orders
        requester = ActiveUserFactory()
        OrderFactory.create_batch(
            5,
            plot=plot,
            requester=requester
        )

        # Create user and assign it to the plot
        user = ActiveUserFactory()
        plot.gardeners.add(user)

        # Test orders
        self.assertTrue(user.has_orders())
        self.assertFalse(ActiveUserFactory().has_orders())
Example #9
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)
Example #10
0
    def test_upcoming(self):
        """ Order.objects.upcoming() """

        # Active orders
        active_orders = OrderFactory.create_batch(
            3,
            start_date=self.past_date,
            end_date=self.future_date,
        )

        # Past orders
        past_orders = [
            # End date is greater than today
            OrderFactory(
                start_date=self.extra_past_date,
                end_date=self.past_date,
            ),
        ]

        # Upcoming orders
        upcoming_orders = [
            # Start date is greater than today
            OrderFactory(
                start_date=self.future_date,
                end_date=self.extra_future_date,
            ),
        ]

        # Test it
        result = Order.objects.upcoming()
        for order in upcoming_orders:
            self.assertIn(order, result)
        for order in active_orders:
            self.assertNotIn(order, result)
        for order in past_orders:
            self.assertNotIn(order, result)
Example #11
0
    def test_get_picker_orders(self):
        """ user.get_picker_orders() """
        picker = PickerFactory()
        plot = PlotFactory(garden=picker.get_picker_gardens().first())

        # Create orders
        orders = OrderFactory.create_batch(
            3,
            plot=plot,
            start_date=localdate(2017, 1, 1),
            end_date=localdate(2017, 1, 5),
            requester=ActiveUserFactory()
        )

        self.assertEqual(set(picker.get_picker_orders()), set(orders))
        self.assertEqual(picker.get_picker_orders().count(), 3)
Example #12
0
 def test_create(self):
     """ Test creation """
     order = OrderFactory(start_date=Faker("past_date"),
                          end_date=Faker("future_date"))
     self.assertTrue(order)
Example #13
0
 def test_create_order(self):
     """
     Ensure that an Order can be created and retrieved.
     """
     order = OrderFactory()
     self.assertIn(order, Order.objects.all())
Example #14
0
 def test_unpicked_today(self):
     """ Order.objects.unpicked_today() """
     order = OrderFactory()
     self.assertIn(order, Order.objects.unpicked_today())
Example #15
0
 def test_picked_today(self):
     """ Order.objects.picked_today() """
     order = OrderFactory()
     PickFactory(plot=order.plot)
     self.assertIn(order, Order.objects.picked_today())