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")
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_create(self): """ Test creation """ self.assertTrue(CropFactory())
def test_set_crops(self): """ Test setting crops """ crops = CropFactory.create_batch(5) plot = PlotFactory(crops=crops) self.assertEqual(set(crops), set(plot.crops.all()))
def test_crop_str(self): """ Test the __str__ method of Crop. """ crop = CropFactory(title="tomato") self.assertEqual(str(crop), "tomato")
def test_create_crop(self): """ Ensure that a Crop can be created and retrieved. """ crop = CropFactory() self.assertIn(crop, Crop.objects.all())