def __init__(self, request): self.request = request # *** replace with actual requesting client self.client = db.query(Client).filter_by(name=settings.TEST_CLIENT).one()
def load_client(cls, fields): if isinstance(fields.get('client'), basestring): fields['client'] = db.query(Client).filter_by( name=fields['client']).one()
def _get_active_limits(self): if not hasattr(self, '_limits'): self._limits = db.query(AccountLimits).filter_by( account=self.data_obj, is_active=True).first() return self._limits
def test_exchange(self): addresses = [{u'address': u'my_address', 'owner': 'guy'}, {u'address': u'other_address', 'owner': 'girl'}] accounts = [{u'name': u'acct1_girl', u'owner': u'girl', u'balance': D(u'0.00'), u'unit': u'CAD', u'upper_limit': D(u'100.00'), u'lower_limit': D(u'-100.00'), u'limits_expiry_time': None, # the rest are for account request u'address': u'other_address', u'partner': u'my_address', u'note': u'Hey.'}, {u'name': u'acct2_girl', u'owner': u'girl', u'balance': D(u'0.00'), u'unit': u'USD', u'upper_limit': D(u'100.00'), u'lower_limit': D(u'-100.00'), u'limits_expiry_time': None, # the rest are for account request u'address': u'other_address', u'partner': u'my_address', u'note': u'Heya.'}] rate1 = {'name': u'CADUSD', 'value': D('1.0232'), 'expiry_time': None} rate2 = {'name': u'gAuhrs', 'value': D('0.003943'), 'expiry_time': None} exchange = {'from': u'acct1_girl', 'to': u'acct2_girl', 'rate': rate1['name']} in_exchange = {'from': u'acct1_girl', 'to': u'USD', 'rate': rate1['name']} out_exchange = {'from': u'CAD', 'to': u'acct2_girl', 'rate': rate1['name']} for address in addresses: urlopen('/addresses/', address) for account in accounts: urlopen('/accounts', account) for rate in (rate1, rate2): urlopen('/rates', rate) urlopen('/exchanges', exchange) self.check_data('/exchanges/', [exchange]) self.check_data('/exchanges/%s/%s' % (exchange['from'], exchange['to']), exchange) # alter rate, check history is stored time.sleep(1) # make sure time is different self.update_and_check('/exchanges/%s/%s' % (exchange['from'], exchange['to']), {'rate': rate2['name']}) eers = list(db.query(ExchangeExchangeRate).order_by('effective_time')) self.assertEquals(eers[0].rate.name, rate1['name']) self.assertEquals(eers[1].rate.name, rate2['name']) self.failUnless(eers[0].effective_time < eers[1].effective_time) # try some in & out exchanges urlopen('/inexchanges', in_exchange) self.check_data('/inexchanges/', [in_exchange]) self.check_data('/inexchanges/%s/%s' % (in_exchange['from'], in_exchange['to']), in_exchange) urlopen('/outexchanges', out_exchange) self.check_data('/outexchanges/', [out_exchange]) self.check_data('/outexchanges/%s/%s' % (out_exchange['from'], out_exchange['to']), out_exchange)
def _get_active_exchange_exchange_rate(self): return db.query(ExchangeExchangeRate).filter_by( exchange=self.data_obj, is_active=True).first()
def _get_active_value_obj(self): if not hasattr(self, '_value_obj'): self._value_obj = db.query(ExchangeRateValue).filter_by( rate=self.data_obj, is_active=True).first() return self._value_obj
def __init__(self, request): self.request = request # *** replace with actual requesting client self.client = db.query(Client).filter_by( name=settings.TEST_CLIENT).one()