Esempio 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))
Esempio n. 2
0
    def setUp(self):
        self.province = utils.create_province('test province')
        self.district = utils.create_district('test district', self.province)
        self.ward = utils.create_ward('test ward', self.district)
        self.market = utils.create_market('test market', self.district)

        self.officer = utils.create_extension_officer()
        self.client.login(username=self.officer.actor.user.username, password=utils.PASSWORD)
Esempio n. 3
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')
Esempio n. 4
0
    def setUp(self):
        self.province = utils.create_province('test province')
        self.district = utils.create_district('test district', self.province)
        self.ward = utils.create_ward('test ward', self.district)
        self.market = utils.create_market('test market', self.district)

        self.agent = utils.create_agent()

        self.farmers = list(create_random_farmers(10, self.agent, self.market))
        self.farmer = self.farmers[0]

        self.officer = utils.create_extension_officer()
        self.client.login(username=self.officer.actor.user.username, password=utils.PASSWORD)
Esempio n. 5
0
    def test_farmer_districts(self):
        province = utils.create_province("province")
        district1 = utils.create_district("district 1", province)
        market1 = utils.create_market("market 1", district1)

        district2 = utils.create_district("district 2", province)
        market2 = utils.create_market("market 2", district2)

        farmer = utils.create_farmer()
        agent1 = utils.create_agent("agent 1")
        agent2 = utils.create_agent("agent 2")

        farmer.operates_at(market1, agent1)
        farmer.operates_at(market2, agent2)

        self.assertEquals(farmer.market_districts().count(), 2)
        self.assertIn(district1, farmer.market_districts())
        self.assertIn(district2, farmer.market_districts())
Esempio n. 6
0
    def setUp(self):
        self.client = Client()
        self.pin = '1234'
        self.province = utils.create_province('test province')
        self.district = utils.create_district('test district', self.province)
        self.ward = utils.create_ward('test ward', self.district)
        self.market = utils.create_market('test market', self.district)

        self.agent = utils.create_agent()
        self.msisdn = self.agent.actor.user.username

        identity = self.agent.actor.get_identity(self.msisdn)
        identity.set_pin(self.pin)
        identity.save()

        self.login_url = '%s?next=%s' % (reverse('login'), reverse('fncs:home'))
        self.farmers = list(create_random_farmers(10, self.agent, self.market))
        self.farmer = self.farmers[0]
 def handle_row(self, row):
     username = row['Mobile_Number_1']
     password = username[-4:]
     
     if User.objects.filter(username=username).exists():
         print 'User with username %s already exists' % username
         return
     
     user = User.objects.create_user(username, '*****@*****.**' % username,
         password)
     user.first_name = row['Agent_F_Name']
     user.last_name = row['Agent_S_Name']
     user.save()
     
     actor = user.get_profile()
     agent, _ = Agent.objects.get_or_create(actor=actor)
     province = utils.create_province("Unspecified Province")
     district = utils.create_district("Unspecified District", province)
     market = utils.create_market(row['Market1'], district)
     agent.markets.add(market)
    def setUp(self):
        self.user_1, _ = User.objects.get_or_create(username="******",
                                                    first_name="user_first_1",
                                                    last_name="user_last_1")

        self.user_2, _ = User.objects.get_or_create(username="******",
                                                    first_name="user_first_2",
                                                    last_name="user_last_2")

        self.province = utils.create_province("province_name")
        self.district_1 = utils.create_district("district_1_name", self.province)
        self.district_2 = utils.create_district("district_2_name", self.province)
        self.market_1 = utils.create_market("market_1_name", self.district_1)
        self.market_2 = utils.create_market("market_1_name", self.district_2)
        self.farmer_1, _ = Farmer.objects.get_or_create(actor=self.user_1.get_profile())
        self.farmer_1.markets.add(self.market_1)
        self.farmer_1.markets.add(self.market_2)

        self.farmer_2, _ = Farmer.objects.get_or_create(actor=self.user_2.get_profile())
        self.farmer_2.markets.add(self.market_1)
        self.farmer_2.markets.add(self.market_2)
        self.farmer_2.districts.add(self.district_2)