import pytest
from pipert.core.message_handlers import RedisHandler
from urllib.parse import urlparse

key = "test"


@pytest.fixture(scope="function")
def redis_handler():
    redis_handler = RedisHandler(urlparse("redis://127.0.0.1:6379"))
    yield redis_handler
    redis_handler.conn.delete(key)
    redis_handler.close()


# tests if the method read the last message if it didn't read before
def test_redis_read_next_msg_reads_last_message(redis_handler):
    redis_handler.send("AAA", key)
    redis_handler.send("BBB", key)
    msg = redis_handler.read_next_msg(key)

    assert msg.decode() == "BBB"


def test_redis_read_next_msg(redis_handler):
    redis_handler.send("AAA", key)
    assert redis_handler.read_next_msg(key).decode() == "AAA"
    redis_handler.send("BBB", key)
    redis_handler.send("CCC", key)
    assert redis_handler.read_next_msg(key).decode() == "BBB"


def test_redis_read_next_msg_cannot_read_the_same_message(redis_handler):
    redis_handler.send("AAA", key)
    assert redis_handler.read_next_msg(key).decode() == "AAA"

    assert redis_handler.read_next_msg(key) is None


def test_redis_read_most_recent_message(redis_handler):
    redis_handler.send("AAA", key)
    redis_handler.send("BBB", key)
    assert redis_handler.read_most_recent_msg(key).decode() == "BBB"


def test_redis_read_most_recent_message_cannot_read_the_same_message(redis_handler):
    redis_handler.send("AAA", key)
    assert redis_handler.read_most_recent_msg(key).decode() == "AAA"
    assert redis_handler.read_most_recent_msg(key) is None

d7d362a86ce51e8d847064dc90e6696bd92c9d0d
<mask token>


@pytest.fixture(scope='function')
def redis_handler():
    redis_handler = RedisHandler(urlparse('redis://127.0.0.1:6379'))
    yield redis_handler
    redis_handler.conn.delete(key)
    redis_handler.close()


<mask token>


def test_redis_read_next_msg_cannot_read_the_same_message(redis_handler):
    redis_handler.send('AAA', key)
    assert redis_handler.read_next_msg(key).decode() == 'AAA'
    assert redis_handler.read_next_msg(key) is None


def test_redis_read_most_recent_message(redis_handler):
    redis_handler.send('AAA', key)
    redis_handler.send('BBB', key)
    assert redis_handler.read_most_recent_msg(key).decode() == 'BBB'


def test_redis_read_most_recent_message_cannot_read_the_same_message(
    redis_handler):
    redis_handler.send('AAA', key)
    assert redis_handler.read_most_recent_msg(key).decode() == 'AAA'
    assert redis_handler.read_most_recent_msg(key) is None

<mask token>


@pytest.fixture(scope='function')
def redis_handler():
    redis_handler = RedisHandler(urlparse('redis://127.0.0.1:6379'))
    yield redis_handler
    redis_handler.conn.delete(key)
    redis_handler.close()


<mask token>


def test_redis_read_next_msg(redis_handler):
    redis_handler.send('AAA', key)
    assert redis_handler.read_next_msg(key).decode() == 'AAA'
    redis_handler.send('BBB', key)
    redis_handler.send('CCC', key)
    assert redis_handler.read_next_msg(key).decode() == 'BBB'


def test_redis_read_next_msg_cannot_read_the_same_message(redis_handler):
    redis_handler.send('AAA', key)
    assert redis_handler.read_next_msg(key).decode() == 'AAA'
    assert redis_handler.read_next_msg(key) is None


def test_redis_read_most_recent_message(redis_handler):
    redis_handler.send('AAA', key)
    redis_handler.send('BBB', key)
    assert redis_handler.read_most_recent_msg(key).decode() == 'BBB'


def test_redis_read_most_recent_message_cannot_read_the_same_message(
    redis_handler):
    redis_handler.send('AAA', key)
    assert redis_handler.read_most_recent_msg(key).decode() == 'AAA'
    assert redis_handler.read_most_recent_msg(key) is None

<mask token>
key = 'test'


@pytest.fixture(scope='function')
def redis_handler():
    redis_handler = RedisHandler(urlparse('redis://127.0.0.1:6379'))
    yield redis_handler
    redis_handler.conn.delete(key)
    redis_handler.close()


def test_redis_read_next_msg_reads_last_message(redis_handler):
    redis_handler.send('AAA', key)
    redis_handler.send('BBB', key)
    msg = redis_handler.read_next_msg(key)
    assert msg.decode() == 'BBB'


def test_redis_read_next_msg(redis_handler):
    redis_handler.send('AAA', key)
    assert redis_handler.read_next_msg(key).decode() == 'AAA'
    redis_handler.send('BBB', key)
    redis_handler.send('CCC', key)
    assert redis_handler.read_next_msg(key).decode() == 'BBB'


def test_redis_read_next_msg_cannot_read_the_same_message(redis_handler):
    redis_handler.send('AAA', key)
    assert redis_handler.read_next_msg(key).decode() == 'AAA'
    assert redis_handler.read_next_msg(key) is None


def test_redis_read_most_recent_message(redis_handler):
    redis_handler.send('AAA', key)
    redis_handler.send('BBB', key)
    assert redis_handler.read_most_recent_msg(key).decode() == 'BBB'


def test_redis_read_most_recent_message_cannot_read_the_same_message(
    redis_handler):
    redis_handler.send('AAA', key)
    assert redis_handler.read_most_recent_msg(key).decode() == 'AAA'
    assert redis_handler.read_most_recent_msg(key) is None

import pytest
from pipert.core.message_handlers import RedisHandler
from urllib.parse import urlparse
key = 'test'


@pytest.fixture(scope='function')
def redis_handler():
    redis_handler = RedisHandler(urlparse('redis://127.0.0.1:6379'))
    yield redis_handler
    redis_handler.conn.delete(key)
    redis_handler.close()


def test_redis_read_next_msg_reads_last_message(redis_handler):
    redis_handler.send('AAA', key)
    redis_handler.send('BBB', key)
    msg = redis_handler.read_next_msg(key)
    assert msg.decode() == 'BBB'


def test_redis_read_next_msg(redis_handler):
    redis_handler.send('AAA', key)
    assert redis_handler.read_next_msg(key).decode() == 'AAA'
    redis_handler.send('BBB', key)
    redis_handler.send('CCC', key)
    assert redis_handler.read_next_msg(key).decode() == 'BBB'


def test_redis_read_next_msg_cannot_read_the_same_message(redis_handler):
    redis_handler.send('AAA', key)
    assert redis_handler.read_next_msg(key).decode() == 'AAA'
    assert redis_handler.read_next_msg(key) is None


def test_redis_read_most_recent_message(redis_handler):
    redis_handler.send('AAA', key)
    redis_handler.send('BBB', key)
    assert redis_handler.read_most_recent_msg(key).decode() == 'BBB'


def test_redis_read_most_recent_message_cannot_read_the_same_message(
    redis_handler):
    redis_handler.send('AAA', key)
    assert redis_handler.read_most_recent_msg(key).decode() == 'AAA'
    assert redis_handler.read_most_recent_msg(key) is None

import pytest
from pipert.core.message_handlers import RedisHandler
from urllib.parse import urlparse

key = "test"


@pytest.fixture(scope="function")
def redis_handler():
    redis_handler = RedisHandler(urlparse("redis://127.0.0.1:6379"))
    yield redis_handler
    redis_handler.conn.delete(key)
    redis_handler.close()


# tests if the method read the last message if it didn't read before
def test_redis_read_next_msg_reads_last_message(redis_handler):
    redis_handler.send("AAA", key)
    redis_handler.send("BBB", key)
    msg = redis_handler.read_next_msg(key)

    assert msg.decode() == "BBB"


def test_redis_read_next_msg(redis_handler):
    redis_handler.send("AAA", key)
    assert redis_handler.read_next_msg(key).decode() == "AAA"
    redis_handler.send("BBB", key)
    redis_handler.send("CCC", key)
    assert redis_handler.read_next_msg(key).decode() == "BBB"


def test_redis_read_next_msg_cannot_read_the_same_message(redis_handler):
    redis_handler.send("AAA", key)
    assert redis_handler.read_next_msg(key).decode() == "AAA"

    assert redis_handler.read_next_msg(key) is None


def test_redis_read_most_recent_message(redis_handler):
    redis_handler.send("AAA", key)
    redis_handler.send("BBB", key)
    assert redis_handler.read_most_recent_msg(key).decode() == "BBB"


def test_redis_read_most_recent_message_cannot_read_the_same_message(redis_handler):
    redis_handler.send("AAA", key)
    assert redis_handler.read_most_recent_msg(key).decode() == "AAA"
    assert redis_handler.read_most_recent_msg(key) is None
