-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add producer.suppress for global message suppression, refs #27
- Loading branch information
1 parent
3a075b8
commit 44bb778
Showing
9 changed files
with
229 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
django_kafka/tests/test_models.py → django_kafka/tests/connect/test_models.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from unittest import mock | ||
|
||
from django.test import TestCase | ||
|
||
from django_kafka.producer import Producer, suppress | ||
|
||
|
||
@mock.patch("django_kafka.producer.ConfluentProducer") | ||
class ProducerSuppressTestCase(TestCase): | ||
def test_suppress_all(self, mock_confluent_producer): | ||
producer = Producer() | ||
|
||
with suppress(): | ||
producer.produce("topicA") | ||
|
||
mock_confluent_producer.return_value.produce.assert_not_called() | ||
|
||
def test_suppress_topic_list(self, mock_confluent_producer): | ||
producer = Producer() | ||
|
||
with suppress(["topicA"]): | ||
producer.produce("topicA") | ||
producer.produce("topicB") | ||
|
||
mock_confluent_producer.return_value.produce.assert_called_once_with("topicB") | ||
|
||
def test_suppress_nested_usage(self, mock_confluent_producer): | ||
"""tests that message suppression lists are combined with later contexts""" | ||
producer = Producer() | ||
|
||
with suppress(["topicA"]): | ||
with suppress(["topicB"]): | ||
producer.produce("topicA") | ||
producer.produce("topicB") | ||
producer.produce("topicC") | ||
|
||
mock_confluent_producer.return_value.produce.assert_called_once_with("topicC") | ||
|
||
def test_suppress_nested_usage_all(self, mock_confluent_producer): | ||
"""test that global message suppression is maintained by later contexts""" | ||
producer = Producer() | ||
|
||
with suppress(): | ||
with suppress(["topicA"]): | ||
producer.produce("topicB") | ||
|
||
mock_confluent_producer.return_value.produce.assert_not_called() | ||
|
||
def test_suppress_nested_usage_deactivate(self, mock_confluent_producer): | ||
producer = Producer() | ||
|
||
with suppress(["topicA"]): | ||
with suppress(deactivate=True): | ||
producer.produce("topicA") | ||
|
||
mock_confluent_producer.return_value.produce.assert_called_once_with("topicA") | ||
|
||
def test_suppress_resets(self, mock_confluent_producer): | ||
producer = Producer() | ||
|
||
with suppress(["topicA", "topicB"]): | ||
producer.produce("topicA") | ||
producer.produce("topicB") | ||
|
||
mock_confluent_producer.return_value.produce.assert_called_once_with("topicB") | ||
|
||
def test_suppress_usable_as_decorator(self, mock_confluent_producer): | ||
producer = Producer() | ||
|
||
@suppress(["topicA"]) | ||
def _produce_args(): | ||
producer.produce("topicA") | ||
|
||
@suppress() | ||
def _produce_empty_args(): | ||
producer.produce("topicA") | ||
|
||
@suppress | ||
def _produce_no_args(): | ||
producer.produce("topicA") | ||
|
||
_produce_args() | ||
_produce_empty_args() | ||
_produce_no_args() | ||
|
||
mock_confluent_producer.return_value.produce.assert_not_called() |
Oops, something went wrong.