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())
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()))
def test_get(self): """ Ensure that the page can be accessed """ client = Client() # Only GM's can access the page client.force_login(GardenManagerFactory()) response = client.get(reverse('plot-create')) self.assertEqual(response.status_code, 200)
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()))
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())
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())
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()))
def test_post(self): """ Test submit under ideal conditions """ client = Client() manager = GardenManagerFactory() garden = manager.get_gardens().first() client.force_login(manager) response = client.post( reverse('plot-create'), { 'garden': garden.id, 'title': '0', 'gardener_emails': manager.email, 'crops': CropFactory().id }) # Test status code self.assertRedirects(response, reverse('plot-list')) # Test that object was created self.assertTrue(Plot.objects.get(title=0))
def test_garden_manager_only(self): """ By default, they're not a Gardener or Picker """ self.assertFalse(GardenManagerFactory().is_gardener()) self.assertFalse(GardenManagerFactory().is_picker())
def test_no_gardens(self): """ Make sure we can set no gardens """ manager = GardenManagerFactory(gardens=[]) self.assertTrue(manager.get_gardens().count(), 0)
def test_set_gardens(self): """ Make sure we can set gardens """ gardens = GardenFactory.create_batch(5) manager = GardenManagerFactory(gardens=gardens) for garden in gardens: self.assertIn(manager, garden.managers.all())
def test_is_garden_manager(self): """ The generated user should be a GM """ self.assertTrue(GardenManagerFactory().is_garden_manager())
def test_create(self): """ Test creation """ self.assertTrue(GardenManagerFactory())