Skip to content

Commit

Permalink
Fix mocked lib tests not using real Inngest client
Browse files Browse the repository at this point in the history
  • Loading branch information
amh4r committed Oct 14, 2024
1 parent 607dbeb commit de70c6a
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions inngest/experimental/mocked/trigger_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import pytest

import inngest
from inngest.experimental.mocked import Inngest, Status, Timeout, trigger

from .client import Inngest
from .consts import Status, Timeout
from .errors import UnstubbedStepError
from .trigger import trigger

client = Inngest(app_id="test")
client = inngest.Inngest(app_id="my-app")
client_mock = Inngest(app_id="test")


class TestTriggerAsync(unittest.TestCase):
Expand All @@ -31,7 +30,7 @@ async def fn(
)
)

res = trigger(fn, inngest.Event(name="test"), client)
res = trigger(fn, inngest.Event(name="test"), client_mock)
assert res.status is Status.COMPLETED
assert res.output == ("a", "b")

Expand All @@ -48,7 +47,7 @@ def fn(
) -> str:
return "hi"

res = trigger(fn, inngest.Event(name="test"), client)
res = trigger(fn, inngest.Event(name="test"), client_mock)
assert res.status is Status.COMPLETED
assert res.output == "hi"

Expand All @@ -65,11 +64,17 @@ def fn(
step.run("b", lambda: None)
return "hi"

res = trigger(fn, inngest.Event(name="test"), client)
res = trigger(fn, inngest.Event(name="test"), client_mock)
assert res.status is Status.COMPLETED
assert res.output == "hi"

def test_client_send(self) -> None:
"""
TODO: Figure out how to support this use case. Since the client in the
Inngest function is real, it's trying to send the event to a real
Inngest server.
"""

@client.create_function(
fn_id="test",
trigger=inngest.TriggerEvent(event="test"),
Expand All @@ -85,12 +90,8 @@ def fn(
]
)

res = trigger(fn, inngest.Event(name="test"), client)
assert res.status is Status.COMPLETED
assert res.output == [
"00000000000000000000000000",
"00000000000000000000000000",
]
res = trigger(fn, inngest.Event(name="test"), client_mock)
assert res.status is Status.FAILED

def test_send_event(self) -> None:
@client.create_function(
Expand All @@ -109,7 +110,7 @@ def fn(
],
)

res = trigger(fn, inngest.Event(name="test"), client)
res = trigger(fn, inngest.Event(name="test"), client_mock)
assert res.status is Status.COMPLETED
assert res.output == [
"00000000000000000000000000",
Expand All @@ -134,7 +135,7 @@ def fn(
res = trigger(
fn,
inngest.Event(name="test"),
client,
client_mock,
step_stubs={"a": "hi"},
)
assert res.status is Status.COMPLETED
Expand All @@ -156,7 +157,7 @@ def fn(
)
)

res = trigger(fn, inngest.Event(name="test"), client)
res = trigger(fn, inngest.Event(name="test"), client_mock)
assert res.status is Status.COMPLETED
assert res.output == ("a", "b")

Expand All @@ -172,7 +173,7 @@ def fn(
step.sleep("a", datetime.timedelta(seconds=1))
return "hi"

res = trigger(fn, inngest.Event(name="test"), client)
res = trigger(fn, inngest.Event(name="test"), client_mock)
assert res.status is Status.COMPLETED
assert res.output == "hi"

Expand All @@ -196,7 +197,7 @@ def fn(
res = trigger(
fn,
inngest.Event(name="test"),
client,
client_mock,
step_stubs={
"a": inngest.Event(data={"foo": 1}, name="other-event")
},
Expand All @@ -223,7 +224,7 @@ def fn(
res = trigger(
fn,
inngest.Event(name="test"),
client,
client_mock,
step_stubs={"a": Timeout},
)
assert res.status is Status.COMPLETED
Expand All @@ -244,7 +245,7 @@ def fn(
)

with pytest.raises(UnstubbedStepError):
trigger(fn, inngest.Event(name="test"), client)
trigger(fn, inngest.Event(name="test"), client_mock)

def test_retry_step(self) -> None:
counter = 0
Expand All @@ -266,7 +267,7 @@ def a() -> str:

return step.run("a", a)

res = trigger(fn, inngest.Event(name="test"), client)
res = trigger(fn, inngest.Event(name="test"), client_mock)
assert res.status is Status.COMPLETED
assert res.output == "hi"

Expand All @@ -285,7 +286,7 @@ def a() -> None:

step.run("a", a)

res = trigger(fn, inngest.Event(name="test"), client)
res = trigger(fn, inngest.Event(name="test"), client_mock)
assert res.status is Status.FAILED
assert res.output is None
assert isinstance(res.error, Exception)
Expand All @@ -308,7 +309,7 @@ def fn(
raise Exception("oh no")
return "hi"

res = trigger(fn, inngest.Event(name="test"), client)
res = trigger(fn, inngest.Event(name="test"), client_mock)
assert res.status is Status.COMPLETED
assert res.output == "hi"

Expand All @@ -324,7 +325,7 @@ def fn(
) -> None:
raise Exception("oh no")

res = trigger(fn, inngest.Event(name="test"), client)
res = trigger(fn, inngest.Event(name="test"), client_mock)
assert res.status is Status.FAILED
assert res.output is None
assert isinstance(res.error, Exception)
Expand Down

0 comments on commit de70c6a

Please sign in to comment.