Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use Pytest on sending and receiving message on Topics. #732

Open
desharma12 opened this issue Aug 13, 2021 · 1 comment
Open

How to use Pytest on sending and receiving message on Topics. #732

desharma12 opened this issue Aug 13, 2021 · 1 comment

Comments

@desharma12
Copy link

desharma12 commented Aug 13, 2021

Hi Guys,
I have created a faust python app.

I am able to send and receive the message on topic. I want to write unit test case using pytest python. I am facing some problem to write the test_case for target topic(bar_topic)
I have two topics, foo_topic and bar_topic

Like:
Example.py

import faust

app = faust.App('example-test-agent-call1', broker='kafka://localhost')

class Order(faust.Record, serializer='json'):
account_id: str
product_id: str

foo_topic = app.topic('foo', value_type=Order)
bar_topic = app.topic('bar', value_type=Order)

#foo as an agent to receive the data, and send to bar_topic
@app.agent(foo_topic)
async def foo(foo_topic):
async for value in foo:
print(" value)
await bar_topic.send(value) // sending message to bar_topic (bar_topic as a variable here)

+++++++++++++++++++++++++++++++++++++++++++
Now added a new file test_example.py:
test_example.py
import faust
import pytest
from example import app, foo, foo_topic, bar_topic

@pytest.fixture()
def test_app(event_loop):
"""passing in event_loop helps avoid 'attached to a different loop' error"""
app.finalize()
app.conf.store = 'memory://'
app.flow_control.resume()
return app

@pytest.mark.asyncio()
async def test_foo_topic():
async with foo.test_context() as agent:
data = Order(account_id='1', product_id='2')
event = await agent.put(key="key1", value=data) // it is sending message to foo_topic

  //here I want to show the value of bar_topic
async with bar_topic.test_context() as agent:
    event = await agent.put(value = data) // don't want to use put(), just want to fetch the the data of bar_topic
    I want to apply assertion here on bar_topic receiving data
    event = await agent.put(key="key1", value=data)  // it is sending message to foo_topic
    assert value.key=='something'

in test_example.py I am able to send the data on foo_topic.
how to get/show the data on bar_topic and apply assertion on that. can you please looking forward to this.

Referring: https://faust.readthedocs.io/en/latest/userguide/testing.html(I am using the same scenario) , but don't want to use:

async def test_foo(test_app)
await agent.put('hey')

Thanks

@bobh66
Copy link
Contributor

bobh66 commented Aug 23, 2021

This project appears to have been abandoned.

You might want to check out the fork of this project - https://github.com/faust-streaming/faust

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants