def test_connection(self): self.logger.info('Running test: %s', get_function_name(__name__)) config = get_config() self.logger.info('REDIS_HOST: {}'.format(config.REDIS_HOST)) self.logger.info('REDIS_PORT: {}'.format(config.REDIS_PORT)) connection = get_connection() self.assertIsNotNone(connection)
def test_connection_error(self): self.logger.info('Running test: %s', get_function_name(__name__)) config = get_config() # forca os parametros config.REDIS_HOST = 'localhost' config.REDIS_PORT = '1111' self.logger.info('REDIS_HOST: {}'.format(config.REDIS_HOST)) self.logger.info('REDIS_PORT: {}'.format(config.REDIS_PORT)) connection = get_connection(config) self.assertIsNone(connection)
def test_list(self, request:ApiRequest): self.logger.info('Running test: %s', get_function_name(__name__)) event_type = EventType.SALE_EVENT where = "{}:*".format(event_type) config = get_config() connection = get_connection(config) repository = EventRepository(redis_connection=connection) result = repository.list(where=where, offset=request.offset, limit=request.limit) self.assertIsNotNone(result) self.assertTrue(len(result) > 0)
def test_create(self, event: EventVO): self.logger.info('Running test: %s', get_function_name(__name__)) event_type = event.type key = '%s:%s' % (event_type, event.hash) config = get_config() connection = get_connection(config) repository = EventRepository(redis_connection=connection) result = repository.create(key, event.to_json()) self.assertTrue(result) with self.assertRaises(DatabaseException): repository.create(key, event.to_json())
def test_get(self, event: EventVO): self.logger.info('Running test: %s', get_function_name(__name__)) event_type = event.type key = '%s:%s' % (event_type, event.hash) config = get_config() connection = get_connection(config) repository = EventRepository(redis_connection=connection) result = repository.create(key, event.to_json()) response = repository.get(key) self.assertTrue(result) self.assertIsNotNone(response)
def __init__(self, logger=None, redis_connection=None): # logger self.logger = logger if logger is not None else get_logger() # database connection self.redis_connection = redis_connection if redis_connection is not None else get_connection() self.total = 0 self.where = None