<s> from preggy import expect <EOL> from cyclops . storage import InMemoryStorage , RedisStorage <EOL> from tests . helpers import App , get_config <EOL> def get_app ( ) : <EOL> cfg = get_config ( REDIS_HOST = '<STR_LIT:localhost>' , REDIS_PORT = <NUM_LIT> , REDIS_DB_COUNT = <NUM_LIT:0> , REDIS_PASSWORD = None ) <EOL> return App ( config = cfg ) <EOL> def test_in_memory_storage_putting_item ( ) : <EOL> app = get_app ( ) <EOL> storage = InMemoryStorage ( app ) <EOL> storage . put ( project_id = <NUM_LIT:10> , message = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" <EOL> } ) <EOL> storage . put ( project_id = <NUM_LIT:20> , message = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" <EOL> } ) <EOL> expect ( storage . get_size ( <NUM_LIT:10> ) ) . to_equal ( <NUM_LIT:1> ) <EOL> expect ( storage . get_size ( <NUM_LIT:20> ) ) . to_equal ( <NUM_LIT:1> ) <EOL> expect ( storage . total_size ) . to_equal ( <NUM_LIT:2> ) <EOL> def test_in_memory_storage_get_next_when_no_projects ( ) : <EOL> app = get_app ( ) <EOL> storage = InMemoryStorage ( app ) <EOL> retrieved = storage . get_next_message ( ) <EOL> expect ( retrieved ) . to_be_null ( ) <EOL> def test_in_memory_storage_get_next_when_empty ( ) : <EOL> app = get_app ( ) <EOL> storage = InMemoryStorage ( app ) <EOL> storage . put ( project_id = <NUM_LIT:20> , message = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" <EOL> } ) <EOL> storage . get_next_message ( ) <EOL> retrieved = storage . get_next_message ( ) <EOL> expect ( retrieved ) . to_be_null ( ) <EOL> def test_in_memory_storage_get_next ( ) : <EOL> app = get_app ( ) <EOL> storage = InMemoryStorage ( app ) <EOL> msg = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" <EOL> } <EOL> storage . put ( project_id = <NUM_LIT:10> , message = msg ) <EOL> retrieved = storage . get_next_message ( ) <EOL> expect ( retrieved ) . to_be_like ( msg ) <EOL> def test_in_memory_storage_mark_as_done ( ) : <EOL> app = get_app ( ) <EOL> storage = InMemoryStorage ( app ) <EOL> msg = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" <EOL> } <EOL> storage . put ( project_id = <NUM_LIT:10> , message = msg ) <EOL> retrieved = storage . get_next_message ( ) <EOL> expect ( retrieved ) . to_be_like ( msg ) <EOL> storage . mark_as_done ( <NUM_LIT:10> ) <EOL> def test_redis_storage_putting_item ( ) : <EOL> app = get_app ( ) <EOL> storage = RedisStorage ( app ) <EOL> storage . clear ( ) <EOL> storage . put ( project_id = <NUM_LIT:10> , message = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" <EOL> } ) <EOL> storage . put ( project_id = <NUM_LIT:20> , message = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" <EOL> } ) <EOL> expect ( storage . get_size ( <NUM_LIT:10> ) ) . to_equal ( <NUM_LIT:1> ) <EOL> expect ( storage . get_size ( <NUM_LIT:20> ) ) . to_equal ( <NUM_LIT:1> ) <EOL> expect ( storage . total_size ) . to_equal ( <NUM_LIT:2> ) <EOL> def test_redis_storage_get_next_when_no_projects ( ) : <EOL> app = get_app ( ) <EOL> storage = RedisStorage ( app ) <EOL> storage . clear ( ) <EOL> retrieved = storage . get_next_message ( ) <EOL> expect ( retrieved ) . to_be_null ( ) <EOL> def test_redis_storage_get_next_when_empty ( ) : <EOL> app = get_app ( ) <EOL> storage = RedisStorage ( app ) <EOL> storage . clear ( ) <EOL> storage . put ( project_id = <NUM_LIT:20> , message = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" <EOL> } ) <EOL> storage . get_next_message ( ) <EOL> retrieved = storage . get_next_message ( ) <EOL> expect ( retrieved ) . to_be_null ( ) <EOL> def test_redis_storage_get_next ( ) : <EOL> app = get_app ( ) <EOL> storage = RedisStorage ( app ) <EOL> storage . clear ( ) <EOL> msg = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" <EOL> } <EOL> storage . put ( project_id = <NUM_LIT:10> , message = msg ) <EOL> retrieved = storage . get_next_message ( ) <EOL> expect ( retrieved ) . to_be_like ( msg ) <EOL> def test_redis_storage_mark_as_done ( ) : <EOL> app = get_app ( ) <EOL> storage = RedisStorage ( app ) <EOL> storage . clear ( ) <EOL> msg = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" <EOL> } <EOL> storage . put ( project_id = <NUM_LIT:10> , message = msg ) <EOL> retrieved = storage . get_next_message ( ) <EOL> expect ( retrieved ) . to_be_like ( msg ) <EOL> storage . mark_as_done ( <NUM_LIT:10> ) <EOL> def test_redis_storage_available_queues ( ) : <EOL> app = get_app ( ) <EOL> storage = RedisStorage ( app ) <EOL> storage . clear ( ) <EOL> msg = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" <EOL> } <EOL> storage . put ( project_id = <NUM_LIT:10> , message = msg ) <EOL> storage . put ( project_id = <NUM_LIT:20> , message = msg ) <EOL> expect ( storage . available_queues ) . to_be_like ( [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def test_redis_storage_fails_if_not_configured_properly ( ) : <EOL> cfg = get_config ( REDIS_HOST = None , REDIS_PORT = <NUM_LIT> , REDIS_DB_COUNT = <NUM_LIT:0> , REDIS_PASSWORD = None ) <EOL> app = App ( config = cfg ) <EOL> try : <EOL> RedisStorage ( app ) <EOL> except RuntimeError , err : <EOL> msg = "<STR_LIT>" "<STR_LIT>" <EOL> expect ( err ) . to_have_an_error_message_of ( msg ) <EOL> return <EOL> assert False , "<STR_LIT>" </s>
