Ejemplo n.º 1
0
    def test_market_monitor_registration(self):
        monitor = utils.create_market_monitor()
        province = utils.create_province("province")
        rpiarea = utils.create_rpiarea("rpiarea")
        rpiarea.provinces.add(province)
        district = utils.create_district("district", province)
        market = utils.create_market("market", district)

        crop = utils.create_crop("potatoes")
        unit = utils.create_crop_unit("boxes")
        price_floor = 150
        price_ceiling = 200

        offer = monitor.register_offer(market, crop, unit, price_floor,
                                       price_ceiling)
        self.assertTrue(monitor.is_monitoring(market))
        self.assertIn(market, monitor.markets.all())
        for rpiarea in market.rpiareas():
            self.assertIn(rpiarea, monitor.rpiareas.all())
        self.assertEquals(offer.price_floor, 150.0)
        self.assertEquals(offer.price_ceiling, 200.0)
        self.assertEquals(offer.crop, crop)
        self.assertEquals(offer.unit, unit)
        self.assertEquals(offer.market, market)
        self.assertAlmostEqual(offer.created_at, datetime.now(),
                               delta=timedelta(seconds=2))
Ejemplo n.º 2
0
 def test_farmer_create_helper(self):
     rpiarea = utils.create_rpiarea("rpiarea")
     zone = utils.create_zone("zone", rpiarea)
     province = utils.create_province("province")
     district = utils.create_district("district", province)
     ward = utils.create_ward("ward", district)
     self.assertFalse(Farmer.objects.exists())
     farmer1 = Farmer.create("0761234567", "name", "surname")
     self.assertTrue(Farmer.objects.count(), 1)
     self.assertEqual(farmer1.actor.name, 'name surname')
     farmer2 = Farmer.create("0761234567", "new name", "new surname")
     self.assertTrue(Farmer.objects.count(), 1)
     self.assertEqual(farmer2.actor.name, 'new name new surname')