def test_account_balance_constructor(self): ab = AccountBalance(institution="Test Bank", balance=500.59, last_update=self.now) self.assertEqual(ab.institution, "Test Bank") self.assertEqual(ab.balance, 50059) self.assertEqual(ab.last_update, self.now) self.assertEqual("500.59", ab.get_balance_string()) ab = AccountBalance(institution="Test Bank", balance=1500, last_update=self.now) self.assertEqual(150000, ab.balance) ab = AccountBalance(institution="Test Bank", pennies=150045, last_update=self.now) self.assertEqual(150045, ab.balance)
def test_account_balance_str(self): ab = AccountBalance(_id=1, institution="Test Bank", balance=1500.59, last_update=self.now) self.assertEqual( "<AccountBalance: id=1, institution=Test Bank, balance=1,500.59, last_update=2002/12/31,23:59:59>", str(ab))
def post(self): logger.debug("------ %s\n%s" % (self.request.headers, self.request.body)) params = self.json_args institution = None balance = None for field in params: logger.info("Field = %s" % field) if field[u'name'] == u'institution': institution = field[u'value'] elif field[u'name'] == u'current_balance': balance = field[u'value'] ab = AccountBalance(institution=institution, balance=balance, last_update=datetime.datetime.utcnow()) logger.debug(">>>>>>>>> %s" % ab) db = self.settings['db'] result = yield db.account_balances.insert(ab.to_motor_create_json()) logger.debug("XXXXXXXX result = %s" % result) self.finish()
def get(self): logger.debug("--json=%s-- %s\n%s" % (self.produce_json, self.request.headers, self.request.body)) db = self.settings['db'] cursor = db.account_balances.find() balances = [] while (yield cursor.fetch_next): document = cursor.next_object() balances.append(AccountBalance.from_db_rep(document).to_json()) if self.produce_json: self.write(dict(result=balances)) else: self.render("templ_balance.html")
def get(self): logger.debug( "--json=%s-- %s\n%s" % (self.produce_json, self.request.headers, self.request.body)) db = self.settings['db'] cursor = db.account_balances.find() balances = [] while (yield cursor.fetch_next): document = cursor.next_object() balances.append(AccountBalance.from_db_rep(document).to_json()) if self.produce_json: self.write(dict(result=balances)) else: self.render("templ_balance.html")
def test_account_balance_balance_string(self): ab = AccountBalance(institution="Test Bank", balance=1500.59, last_update=self.now) self.assertEqual("1,500.59", ab.get_balance_string())