def test_get_peers(self): """ user.get_peers() """ # Create test Gardens gardens = GardenFactory.create_batch(4) # Create test Plots plots = [ PlotFactory(garden=gardens[0]), PlotFactory(garden=gardens[2]), PlotFactory(garden=gardens[3]), PlotFactory(garden=gardens[3]) ] # Create test Users users = ActiveUserFactory.create_batch(10) # Garden with 2 managers and 1 plot with 1 gardener gardens[0].managers.add(users[0], users[1]) plots[0].gardeners.add(users[2]) self.assertEqual(set(users[0].get_peers()), set([users[1], users[2]])) self.assertEqual(set(users[1].get_peers()), set([users[0], users[2]])) self.assertEqual(set(users[2].get_peers()), set([])) # Garden with 2 managers and no plots gardens[1].managers.add(users[3], users[4]) self.assertEqual(set(users[3].get_peers()), set([users[4]])) self.assertEqual(set(users[4].get_peers()), set([users[3]])) # Garden with 0 managers and 1 plot with 2 gardeners gardens[2].managers.add(users[5], users[6]) self.assertEqual(set(users[5].get_peers()), set([users[6]])) self.assertEqual(set(users[6].get_peers()), set([users[5]])) # Garden with 1 manager and 2 plots, each with 1 gardener gardens[3].managers.add(users[7]) plots[2].gardeners.add(users[8]) plots[3].gardeners.add(users[9]) self.assertEqual(set(users[7].get_peers()), set([users[8], users[9]])) self.assertEqual(set(users[8].get_peers()), set([])) self.assertEqual(set(users[9].get_peers()), set([]))
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_get_picker_gardens(self): """ user.get_picker_gardens() """ picker = ActiveUserFactory() gardens = GardenFactory.create_batch(4, pickers=[picker]) GardenFactory.create_batch(3) self.assertEqual(set(picker.get_picker_gardens()), set(gardens))
def test_get_gardens(self): """ user.get_gardens() """ user = ActiveUserFactory() gardens = GardenFactory.create_batch(4, managers=[user]) self.assertEqual(set(user.get_gardens()), set(gardens))