def test_customers_get(self): """Check getting customer from db""" data = { 'id': str(uuid.uuid4()), 'login': str(uuid.uuid4()), 'name_short': str(uuid.uuid4()), 'name_full': str(uuid.uuid4()), 'comment': str(uuid.uuid4()), 'contract_client': str(uuid.uuid4()), 'contract_service': str(uuid.uuid4()), 'tariff_id': str(uuid.uuid4()), 'contact_person': str(uuid.uuid4()), 'contact_email': str(uuid.uuid4()), 'contact_phone': str(uuid.uuid4())[:10], 'state': customers.constants.STATE_ENABLED, 'time_create': int(time.time()), 'time_destroy': 0, 'wallet': 10, 'wallet_mode': customers.constants.WALLET_MODE_LIMITED } cus = customers.Customer(data) with database.DBConnect() as db: db.insert('customers', data) with self.assertRaises(ValueError): customers.get('', random.choice(list(set(data.keys())-set(['login', 'id'])))) self.assertEquals(customers.get(cus.id, 'id'), cus) self.assertEquals(customers.get(cus.login, 'login'), cus)
def customerGet(params): try: ret = customers.get(params['id'], 'id') if not ret: srv = zones.write_zone(params['id']) if not srv['local']: return jsonrpc.result({ 'status':'redirect', 'server': srv['server'] }) return jsonrpc.result_error('InvalidRequest', { 'status': 'error', 'message': 'Customer not found' }) except Exception, e: LOG.error(e) return jsonrpc.result_error('ServerError', { 'status': 'error', 'message': 'Unable to obtain customer' })
def taskAdd(request): """ Open new billing task """ if request['time-create'] == 0: request['time-create'] = int(time.time()) try: rid, rate = ('', 0) customer = customers.get(request['customer'], typ='id') if customer: rid, rate = rates.resolve(request['type'], customer.tariff_id) if not rid: LOG.error("task(%s): Unable to find rate for metric", request['uuid']) else: LOG.error("task(%s): Unknown customer (%s)", request['uuid'], request['customer']) t = tasks.Task({ 'group_id': GROUPID.next(), 'base_id': request['uuid'], 'customer': request['customer'], 'metric_id': request['type'], 'rate_id': rid, 'rate': rate, 'value': request['value'], 'time_create': request['time-create'], 'time_check': request['time-create'], 'time_destroy': request['time-destroy'], 'target_user': request['user'], 'target_uuid': request['uuid'], 'target_descr': request['descr'], }) tasks.add(t) except Exception, e: LOG.exception("Unable to add new task: %s", e) return jsonrpc.result_error('ServerError', { 'status': 'error', 'message': 'Unable to add new task' })