def generate_farmers(self, msisdns, agent):
        for msisdn in msisdns:
            # create a district
            district = utils.random_district()
            farmergroup_name = "%s Farmer Group" % (district.name,)

            # create the farmer
            farmer = utils.create_farmer(msisdn=str(msisdn),
                                         name=utils.random_name(),
                                         surname=utils.random_surname(),
                                         )

            # cultivates two types of crops
            farmer.grows_crop(utils.random_crop())
            farmer.grows_crop(utils.random_crop())

            # create a market in the district
            market_name = '%s Market' % district.name
            market = utils.create_market(market_name, district)

            # have the farmer sells crops at that market through the agent
            farmer.operates_at(market, agent)
    def handle(self, *args, **options):
        total = options['total']

        farmers = Farmer.objects.all()
        username = options['agent']
        if not username:
            raise Exception, 'please provide --agent'

        agent = Agent.objects.get(actor__user__username=username)
        farmers = farmers.filter(agent=agent)

        for farmer in farmers.iterator():
            for i in range(total):
                crop = utils.random_crop()
                unit = crop.units.order_by('?')[0]
                market = farmer.markets.order_by('?')[0]
                amount = random.randint(10,50)
                receipt = agent.take_in_crop(market, farmer, amount, unit, crop)
                print receipt
Beispiel #3
0
 def test_farmer_grows_crops(self):
     farmer = utils.create_farmer()
     crop = utils.random_crop()
     farmer.grows_crop(crop)
     self.assertIn(crop, farmer.crops.all())