Open davorrunje opened 1 year ago
For now user is able to access any message field via the Context
In the tests case, I am not sure that is required Will answer with examples in a few hours
it would be very useful to be able to check Context in the tests, how difficult would that be to implement?
We trigger mock here: https://github.com/airtai/fastkafka/blob/FastStream/faststream/broker/wrapper.py#L90 It is not a big problem to add something extra to it, but we need to create an API this extra information
This is not a priority right now, but I'll leave the issue for later.
I have an idea - we can just add assert_called_*
methods to the consumer itself
This way we can override any information before pass it to the inner mock object and add some extra checks
consumer.assert_called_once_with({"user": "John", "age": 25})
# instead
consumer.mock.assert_called_once_with({"user": "John", "age": 25})
This way we can make the following checks are equal:
consumer.assert_called_once_with({"user": "John", "age": 25})
consumer.assert_called_once_with(user="John", age=25)
consumer.assert_called_once_with(User(user="John", age=25))
And add any context check feature
consumer.assert_called_once_with(
body={"user": "John", "age": 25},
context={
"message.key": b"key"
}
)
not bad, I like it
Alternatively (and much easier) we can add assert_called_with_context
method to check just a context
consumer.mock.assert_called_once_with({"user": "John", "age": 25})
consumer.assert_called_with_context({"message.key": b"key"})
Please see the example and let me know what you think: