def _create_new_for_customer(self): # create the appointment and ensure he's editable. cust = self.get_customer() R = self.get("/crm/appointment/new_for_customer/%s" % cust.customer_id) assert R.status_int == 200 R.mustcontain("New Appointment") f = R.forms["frm_appointment"] self.assertEqual(f["appointment_id"].value, "") self.assertEqual(f["customer_id"].value, str(cust.customer_id)) f.set("title", "Test Customer Appointment") f.set("phone", "9041234567") f.set("description", "Test Description") f.set("start_dt", util.format_date(TOMORROW)) f.set("start_time", "09:00") f.set("end_time", "10:00") R = f.submit("submit") self.assertEqual(R.status_int, 302) R = R.follow() assert R.status_int == 200 f = R.forms["frm_appointment"] R.mustcontain("Edit Customer Appointment") appointment_id = f["appointment_id"].value self.assertNotEqual(f["appointment_id"].value, "") self.assertEqual(f["customer_id"].value, str(cust.customer_id)) return appointment_id
def _create_subscription(self, prod, order_item, customer, billing): try: xml = render('/crm/billing/authnet_arb_create_subscription.xml.mako', {'auth_login' : self.authnet_login_id, 'auth_key' : self.authnet_transaction_key, 'amount' : order_item.total(), 'card_number' : billing.get_cc_num(), 'exp_date' : billing.cc_exp, 'start_date' : util.format_date(order_item.start_dt) if order_item.start_dt else util.str_today(), 'total_occurrences' : 9999, 'interval_length' : 1, 'interval_unit' : 'months', 'sub_name' : '', 'first_name' : customer.fname, 'last_name' : customer.lname }) headers = {'content-type': 'text/xml'} conn = urllib2.Request(url=self._arb_url, data=xml, headers=headers) try: open_conn = urllib2.urlopen(conn) xml_response = open_conn.read() except urllib2.URLError: #pragma: no cover return (5, '1', 'Could not talk to payment gateway.') response = util.xml_str_to_dict(xml_response)['ARBCreateSubscriptionResponse'] if response['messages']['resultCode'].lower() != 'ok': message = response['messages']['message'] message = message[0] if type(message) == list else message self.last_status = message['code'] self.last_note = message['text'] return False order_item.third_party_id = response['subscriptionId'] order_item.save() return True except Exception as exc2: #pragma: no cover self.last_status = -1 self.last_note = exc2.message return False #pragma: no cover
def test_util(self): d8e = util.today_date() dtime = util.today() assert util.format_rss_date(d8e) == d8e.strftime("%a, %d %b %Y %H:%M:%S EST") assert util.words_date(dtime) == dtime.strftime("%B %d, %Y") assert util.is_empty(" ") == True assert util.float_("8") == None assert util.page_list([1, 2, 3, 4, 5, 6, 7, 8, 9], 2, 2) == [3, 4] assert util.page_list([1, 2, 3, 4, 5, 6, 7, 8, 9], None, None) == [1, 2, 3, 4, 5, 6, 7, 8, 9] assert util.parse_date("2012-05-06") == datetime.datetime.strptime("2012-05-06", "%Y-%m-%d") today_ = datetime.date.today() assert [today_.year + 10, today_.year + 10] in util.year_list() assert util.month_list()[0] == ["1", "January"] assert util.this_year() == datetime.date.today().year assert util.get_first_day(today_) == util.get_first_day( today_ ) # this is pretty dumb. it works, just get it covered. assert util.get_last_day(today_) == util.get_last_day(today_) assert util.to_uuid("ken") == None assert int(util.average([1, 2, 3])) == 2 assert util.format_date(util.truncate_datetime(dtime)) == util.str_today() assert util.is_today(d8e) == True
def is_today(dat): return util.format_date(dat) == util.str_today()
def google_y_labels(self): return "|%s|" % "|".join([util.format_date(res.create_dt)[5:] for res in self.results])