Пример #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")
Пример #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()))
Пример #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()))
Пример #4
0
 def test_is_anything(self):
     """ user.is_anything() """
     # Test a normal user
     self.assertFalse(ActiveUserFactory().is_anything())
     # Test a gardener and garden manager
     self.assertTrue(GardenerFactory().is_anything())
     self.assertTrue(GardenManagerFactory().is_anything())
Пример #5
0
 def test_is_garden_manager(self):
     """ user.is_garden_manager() """
     # Test a garden manager
     self.assertTrue(GardenManagerFactory().is_garden_manager())
     # Test *not* garden managers
     self.assertFalse(GardenerFactory().is_garden_manager())
     self.assertFalse(ActiveUserFactory().is_garden_manager())
Пример #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()))
Пример #7
0
 def test_is_gardener(self):
     """ user.is_gardener() """
     # Test a gardener of a single plot
     self.assertTrue(GardenerFactory().is_gardener())
     # Test that a garden manager is also considered a gardener
     # if the garden has plots
     manager = GardenManagerFactory()
     garden = manager.get_gardens().first()
     PlotFactory.create_batch(3, garden=garden)
     self.assertTrue(manager.is_gardener())
     # Create and test a *not* gardener
     self.assertFalse(ActiveUserFactory().is_gardener())
Пример #8
0
 def test_set_plots(self):
     """ Make sure we can set plots """
     plots = PlotFactory.create_batch(5)
     gardener = GardenerFactory(plots=plots)
     for plot in plots:
         self.assertIn(gardener, plot.gardeners.all())
Пример #9
0
 def test_is_gardener(self):
     """ The generated user should be a gardener """
     self.assertTrue(GardenerFactory().is_gardener())
Пример #10
0
 def test_create(self):
     """ Test creation """
     self.assertTrue(GardenerFactory())
Пример #11
0
 def test_gardener_only(self):
     """ By default, they're not a GM or Picker """
     self.assertFalse(GardenerFactory().is_garden_manager())
     self.assertFalse(GardenerFactory().is_picker())
Пример #12
0
 def test_no_plots(self):
     """ Make sure we can set no plots """
     gardener = GardenerFactory(plots=[])
     self.assertTrue(gardener.get_plots().count(), 0)