Example #1
0
    def test_post(self):
        """ Test that the form submits """
        client = Client()

        gardener = GardenerFactory()
        plot = gardener.get_plots().first()
        client.force_login(gardener)

        # Add user to multiple gardens
        # https://github.com/HarvestHub/GardenHub/issues/88
        plot.garden.managers.add(gardener)
        GardenFactory(managers=[gardener])

        response = client.post(
            reverse('plot-update', args=[plot.id]), {
                'garden': plot.garden.id,
                'title': "New title",
                'gardener_emails': gardener.email,
                'crops': CropFactory().id
            }
        )

        # Ensure the correct response
        self.assertRedirects(response, reverse('plot-list'))

        # Check that the model updated
        plot.refresh_from_db()
        self.assertEqual(plot.title, "New title")
Example #2
0
    def test_can_edit_garden(self):
        """ user.can_edit_garden() """

        # Garden manager can edit the garden
        manager = GardenManagerFactory()
        garden = manager.get_gardens().first()
        self.assertTrue(manager.can_edit_garden(garden))

        # Gardener can't edit the garden
        gardener = GardenerFactory()
        garden = gardener.get_plots().first().garden
        self.assertFalse(gardener.can_edit_garden(garden))

        # Normal user can't edit the garden
        self.assertFalse(ActiveUserFactory().can_edit_garden(GardenFactory()))
Example #3
0
    def test_can_edit_plot(self):
        """ user.can_edit_plot() """

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

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

        # Normal user can't edit the plot
        self.assertFalse(ActiveUserFactory().can_edit_plot(PlotFactory()))
Example #4
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 #5
0
 def test_no_plots(self):
     """ Make sure we can set no plots """
     gardener = GardenerFactory(plots=[])
     self.assertTrue(gardener.get_plots().count(), 0)