def test_inquirers(self): """ pick.inquirers() """ picker = ActiveUserFactory() requester = ActiveUserFactory() gardeners = ActiveUserFactory.create_batch(2) garden = GardenFactory() plot = PlotFactory(garden=garden) plot.gardeners.add(gardeners[0]) plot.gardeners.add(gardeners[1]) Order.objects.create( plot=plot, start_date=today()-timedelta(days=5), end_date=today()+timedelta(days=5), requester=requester ) pick = Pick.objects.create(picker=picker, plot=plot) self.assertIn(gardeners[0], list(pick.inquirers())) self.assertIn(gardeners[1], list(pick.inquirers())) self.assertIn(requester, list(pick.inquirers()))
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([]))