# Path: tests/pgshovel/streams/fixtures.py
# DEFAULT_PUBLISHER = uuid.uuid1().bytes
# def reserialize(message):
# def copy(message, **replacements):
# def make_message(payload, sequence=1, publisher=DEFAULT_PUBLISHER):
# def make_messages(payloads, publisher=DEFAULT_PUBLISHER):
# def make_batch_messages(batch_identifier, payloads, **kwargs):
# def transactions():
# def message():


import pytest
from pgshovel.interfaces.common_pb2 import Snapshot
from pgshovel.interfaces.replication_pb2 import (
    BootstrapState,
    ConsumerState,
    State,
    StreamState,
    TransactionState,
)
from pgshovel.replication.validation import validate_state
from pgshovel.streams.publisher import Publisher
from pgshovel.utilities.protobuf import get_oneof_value
from tests.pgshovel.streams.fixtures import (
    batch_identifier,
    begin,
    commit,
    mutation,
    reserialize,
    rollback,
)

    # Ensure it actually generates valid data.
    state = None
    for offset, message in enumerate(published_messages):
        state = reserialize(validate_state(state, offset, message))


def test_publisher_failure():
    messages = []
    publisher = Publisher(messages.extend)

    with pytest.raises(NotImplementedError):
        with publisher.batch(batch_identifier, begin):
            raise NotImplementedError

    published_messages = map(reserialize, messages)

    assert get_oneof_value(
        get_oneof_value(published_messages[0], 'operation'),
        'operation'
    ) == begin
    assert get_oneof_value(
        get_oneof_value(published_messages[1], 'operation'),
        'operation'
    ) == rollback


    # Ensure it actually generates valid data.
    state = None
    for offset, message in enumerate(published_messages):

# Path: tests/pgshovel/streams/fixtures.py
# DEFAULT_PUBLISHER = uuid.uuid1().bytes
# def reserialize(message):
# def copy(message, **replacements):
# def make_message(payload, sequence=1, publisher=DEFAULT_PUBLISHER):
# def make_messages(payloads, publisher=DEFAULT_PUBLISHER):
# def make_batch_messages(batch_identifier, payloads, **kwargs):
# def transactions():
# def message():


# Path: tests/pgshovel/streams/publisher.py
import pytest
from pgshovel.interfaces.common_pb2 import Snapshot
from pgshovel.interfaces.replication_pb2 import (
    BootstrapState,
    ConsumerState,
    State,
    StreamState,
    TransactionState,
)
from pgshovel.replication.validation import validate_state
from pgshovel.streams.publisher import Publisher
from pgshovel.utilities.protobuf import get_oneof_value
from tests.pgshovel.streams.fixtures import (
    batch_identifier,
    begin,
    commit,
    mutation,
    reserialize,
    rollback,
)


    # Ensure it actually generates valid data.
    state = None
    for offset, message in enumerate(published_messages):
        state = reserialize(validate_state(state, offset, message))


def test_publisher_failure():
    messages = []
    publisher = Publisher(messages.extend)

    with pytest.raises(NotImplementedError):
        with publisher.batch(batch_identifier, begin):
            raise NotImplementedError

    published_messages = map(reserialize, messages)

    assert get_oneof_value(
        get_oneof_value(published_messages[0], 'operation'),
        'operation'
    ) == begin
    assert get_oneof_value(
        get_oneof_value(published_messages[1], 'operation'),
        'operation'
    ) == rollback


    # Ensure it actually generates valid data.
    state = None
    for offset, message in enumerate(published_messages):

        state = reserialize(validate_state(state, offset, message))