# 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 itertools
import uuid
import pytest
from collections import namedtuple
from pgshovel.interfaces.streams_pb2 import (
    Message,
    RollbackOperation,
)
from pgshovel.replication.validation.transactions import (
    Committed,
    InTransaction,
    InvalidBatch,
    InvalidEventError,
    InvalidPublisher,
    RolledBack,
    StatefulStreamValidator,
    get_operation,
    require_batch_id_advanced_if_same_node,
    require_batch_id_not_advanced_if_same_node,
    require_different_publisher,
    require_same_batch,
    require_same_publisher,
    validate_transaction_state,
)
from pgshovel.utilities.protobuf import get_oneof_value
from tests.pgshovel.streams.fixtures import (
    batch_identifier,
    begin,
    commit,
    copy,
    make_batch_messages,
    message,
    mutation,
    reserialize,
)
        0,
        message,
    )

    with pytest.raises(InvalidBatch):
        require_batch_id_advanced_if_same_node(
            Committed(
                publisher=message.header.publisher,
                batch_identifier=batch_identifier,
            ),
            0,
            message,
        )


def test_require_batch_id_not_advanced_if_same_node(message):
    batch_identifier = get_operation(message).batch_identifier

    require_batch_id_not_advanced_if_same_node(
        RolledBack(
            publisher=message.header.publisher,
            batch_identifier=batch_identifier,
        ),
        0,
        message,
    )

    require_batch_id_not_advanced_if_same_node(
        RolledBack(
            publisher=message.header.publisher,

# 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/states.py
import itertools
import uuid
import pytest
from collections import namedtuple
from pgshovel.interfaces.streams_pb2 import (
    Message,
    RollbackOperation,
)
from pgshovel.replication.validation.transactions import (
    Committed,
    InTransaction,
    InvalidBatch,
    InvalidEventError,
    InvalidPublisher,
    RolledBack,
    StatefulStreamValidator,
    get_operation,
    require_batch_id_advanced_if_same_node,
    require_batch_id_not_advanced_if_same_node,
    require_different_publisher,
    require_same_batch,
    require_same_publisher,
    validate_transaction_state,
)
from pgshovel.utilities.protobuf import get_oneof_value
from tests.pgshovel.streams.fixtures import (
    batch_identifier,
    begin,
    commit,
    copy,
    make_batch_messages,
    message,
    mutation,
    reserialize,
)

        0,
        message,
    )

    with pytest.raises(InvalidBatch):
        require_batch_id_advanced_if_same_node(
            Committed(
                publisher=message.header.publisher,
                batch_identifier=batch_identifier,
            ),
            0,
            message,
        )


def test_require_batch_id_not_advanced_if_same_node(message):
    batch_identifier = get_operation(message).batch_identifier

    require_batch_id_not_advanced_if_same_node(
        RolledBack(
            publisher=message.header.publisher,
            batch_identifier=batch_identifier,
        ),
        0,
        message,
    )

    require_batch_id_not_advanced_if_same_node(
        RolledBack(
            publisher=message.header.publisher,

            batch_identifier=copy(batch_identifier, node=uuid.uuid1().bytes),