Beispiel #1
0
def import_sites(input_csv="../2012_ROOMS_site_info_sample.csv"):
    """Change input_csv to actual input file - the default is test data."""
    reader = csv.DictReader(open(input_csv))
    for s in reader:
        number = s["Site ID"]
        site = models.NewSite.all().filter('number =', number).get()
        if site:
            logging.info('site %s exists, skipping', number)
            continue
        else:
            site = models.NewSite(number=number)
        site.program = PROGRAM
        site.budget = int(s["Budgeted Cost in Campaign"]
                          ) if s["Budgeted Cost in Campaign"] else 0

        # Because Python 2.x csv module only reads ascii.
        def clean_s(k):
            return s[k].replace('\n', ' ').replace('\xe2', "'").replace(
                '\x80', "'").replace('\x99', '').replace('\xc3', '').replace(
                    '\x95', '').replace('\xb1', '').encode('ascii', 'replace')

        site.name = clean_s("Repair Application: Applicant's Name")
        site.street_number = clean_s("Street Address")
        site.city_state_zip = "%s CA, %s" % (
            clean_s("Repair Application: Recipient's City"),
            clean_s("Repair Application: Recipient's Zip Code"))
        site.applicant = clean_s("Repair Application: Applicant's Name")
        site.applicant_home_phone = clean_s(
            "Repair Application: Applicant Home Phone")
        site.applicant_work_phone = clean_s(
            "Repair Application: Applicant Work Phone")
        site.applicant_mobile_phone = clean_s(
            "Repair Application: Applicant Mobile Phone")
        site.sponsor = clean_s("(Sponsor) Campaign Description")
        site.rrp_test = clean_s("Repair Application: RRP Test Results")
        site.rrp_level = clean_s("Repair Application: RRP Result Notes")
        # site.roof = clean_s("Roof?")
        site.jurisdiction = clean_s("Jurisdiction")
        site.announcement_subject = clean_s("Announcement Subject")
        site.announcement_body = clean_s("Announcement Body")
        site.put()
        logging.info('put site %s', number)
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.os = models.OrderSheet()
     self.os.delivery_options = 'Yes'
     self.os.put()
     self.os_id = self.os.key().id()
     self.s = models.Supplier(email='*****@*****.**')
     self.s.put()
     self.i = models.Item(name='test item',
                          supplier=self.s,
                          unit_cost=50.,
                          appears_on_order_form=self.os)
     self.i.put()
     self.i_id = self.i.key().id()
     self.site = models.NewSite(number='1234')
     self.site.put()
     self.site_id = self.site.key().id()
     self.order = models.Order(order_sheet=self.os, site=self.site)
     self.order.put()
     self.order_id = self.order.key().id()
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.captain = models.Captain(email='1234')
     self.captain.put()
     self.os = models.OrderSheet()
     self.os.put()
     self.site = models.NewSite(number='1234')
     self.site.put()
     self.order = models.Order(order_sheet=self.os, site=self.site)
     self.order.put()
     self.item = models.Item(name='foo', unit_cost=2.4)
     self.item.put()
     self.oi = models.OrderItem(order=self.order,
                                item=self.item,
                                quantity=2)
     self.oi.put()
     self.item2 = models.Item(name='foo2', unit_cost=0.3)
     self.item2.put()
     self.oi2 = models.OrderItem(order=self.order,
                                 item=self.item2,
                                 quantity=0)
     self.oi2.put()
 def testNewSite(self):
     site = models.NewSite(number='1234',
                           name='Belle Haven',
                           street='Main Street',
                           street_number='100 Main Street',
                           city_state_zip='Menlo Park CA 94025',
                           budget=1000)
     self.assertTrue(site)
     self.assertTrue(site.put())
     cr = models.CheckRequest(site=site, labor_amount=450.)
     cr.put()
     try:
         self.assertEquals('Site #%d | Belle Haven' % site.key().id(),
                           site.__unicode__())
         self.assertEquals('100 Main Street, Menlo Park CA 94025',
                           site.StreetAddress())
         self.assertEquals(250, site.StandardKitCost())
         self.assertEquals(250, site.OrderTotal())
         self.assertEquals(450, site.CheckRequestTotal())
         self.assertEquals(300, site.BudgetRemaining())
         self.assertEquals([], list(site.VisibleOrders()))
     finally:
         site.delete()
         cr.delete()