def test_customers_get_all(self): """Check getting customers from db""" cus = [] for i in range(25): 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': random.choice([customers.constants.STATE_ENABLED, customers.constants.STATE_DELETED, customers.constants.STATE_DISABLED]), 'time_create': int(time.time()), 'time_destroy': 0, 'wallet': 10, 'wallet_mode': customers.constants.WALLET_MODE_LIMITED } cus.append( customers.Customer(data) ) with database.DBConnect() as db: db.insert('customers', data) self.assertEquals(set(list(customers.get_all())), set(filter(lambda x: x.state==customers.constants.STATE_ENABLED, cus)))
def customerList(request): """ Returns a list of all registered customers """ try: ret = map(lambda c: c.values, customers.get_all()) except Exception, e: LOG.error(e) return jsonrpc.result_error('ServerError', { 'status': 'error', 'message': 'Unable to obtain customer list' })