import pytest

from eventualpy import connect, NotFound
from ..factory import make_events


@pytest.mark.asyncio
async def test_get_single_event(factory):
    events = make_events(7, "invoice_created")
    await factory.publish(events)

    async with connect(factory.eventstore) as c:
        e = await c.get_event(factory.stream, 3)

    assert e.id == events[3].id
    assert e.stream == factory.stream
    assert e.event_number == 3
    assert e.type == events[3].type
    assert e.data == events[3].data
    assert e.metadata == events[3].metadata


@pytest.mark.asyncio
async def test_when_no_stream(factory):
    async with connect(factory.eventstore) as c:
        with pytest.raises(NotFound):
            await c.get_event(factory.stream, 13)


@pytest.mark.asyncio
async def test_when_incorrect_event_number(factory):
    events = make_events(7, "invoice_created")
    await factory.publish(events)

    async with connect(factory.eventstore) as c:
        with pytest.raises(NotFound):
            await c.get_event(factory.stream, 13)

import pytest

from eventualpy import connect, NotFound
from ..factory import make_events


@pytest.mark.asyncio
async def test_get_single_event(factory):
    events = make_events(7, "invoice_created")
    await factory.publish(events)

    async with connect(factory.eventstore) as c:
        e = await c.get_event(factory.stream, 3)

    assert e.id == events[3].id
    assert e.stream == factory.stream
    assert e.event_number == 3
    assert e.type == events[3].type
    assert e.data == events[3].data
    assert e.metadata == events[3].metadata


@pytest.mark.asyncio
async def test_when_no_stream(factory):
    async with connect(factory.eventstore) as c:
        with pytest.raises(NotFound):
            await c.get_event(factory.stream, 13)


@pytest.mark.asyncio
async def test_when_incorrect_event_number(factory):
    events = make_events(7, "invoice_created")
    await factory.publish(events)

    async with connect(factory.eventstore) as c:
        with pytest.raises(NotFound):
            await c.get_event(factory.stream, 13)
