|
26 | 26 |
|
27 | 27 | class TestMessageSerializer(unittest.TestCase):
|
28 | 28 | def test_topic_name(self):
|
29 |
| - strategy = strategies.TopicNameStrategy() |
| 29 | + strategy = strategies.topic_name_strategy |
30 | 30 | topic = "some_legal_topic_name"
|
31 | 31 | expected = topic + "-key"
|
32 |
| - actual = strategy.get_subject_name(topic, True, None) |
| 32 | + actual = strategy(topic, True, None) |
33 | 33 | assert expected == actual
|
34 | 34 | expected = topic + "-value"
|
35 |
| - actual = strategy.get_subject_name(topic, False, None) |
| 35 | + actual = strategy(topic, False, None) |
36 | 36 | assert expected == actual
|
37 | 37 |
|
38 | 38 | def test_record_name(self):
|
39 |
| - strategy = strategies.RecordNameStrategy() |
| 39 | + strategy = strategies.record_name_strategy |
40 | 40 | schema = RecordSchema("MyRecordType", "my.namespace", fields=[], names=Names())
|
41 | 41 | expected = "my.namespace.MyRecordType"
|
42 |
| - actual = strategy.get_subject_name(None, None, schema) |
| 42 | + actual = strategy(None, None, schema) |
43 | 43 | assert expected == actual
|
44 | 44 |
|
45 | 45 | def test_topic_record_name(self):
|
46 |
| - strategy = strategies.TopicRecordNameStrategy() |
| 46 | + strategy = strategies.topic_record_name_strategy |
47 | 47 | topic = "some_legal_topic_name"
|
48 | 48 | schema = RecordSchema("MyRecordType", "my.namespace", fields=[], names=Names())
|
49 | 49 | expected = "some_legal_topic_name-my.namespace.MyRecordType"
|
50 |
| - actual = strategy.get_subject_name(topic, None, schema) |
| 50 | + actual = strategy(topic, None, schema) |
51 | 51 | assert expected == actual
|
52 | 52 |
|
53 | 53 | def test_default_subject_name_strategy(self):
|
54 | 54 | schema_registry = MockSchemaRegistryClient()
|
55 | 55 | producer = AvroProducer(config={}, schema_registry=schema_registry)
|
56 | 56 | serializer = producer._serializer
|
57 |
| - assert isinstance(serializer.key_subject_name_strategy, strategies.TopicNameStrategy) |
58 |
| - assert isinstance(serializer.value_subject_name_strategy, strategies.TopicNameStrategy) |
| 57 | + assert serializer.key_subject_name_strategy is strategies.topic_name_strategy |
| 58 | + assert serializer.value_subject_name_strategy is strategies.topic_name_strategy |
59 | 59 |
|
60 | 60 | def test_explicit_topic_subject_name_strategy(self):
|
61 | 61 | schema_registry = MockSchemaRegistryClient()
|
62 |
| - config = { |
63 |
| - 'value.subject.name.strategy': 'TopicName', |
64 |
| - 'key.subject.name.strategy': 'TopicName' |
65 |
| - } |
66 |
| - producer = AvroProducer(config=config, schema_registry=schema_registry) |
| 62 | + producer = AvroProducer(config={}, schema_registry=schema_registry, |
| 63 | + key_subject_name_strategy=strategies.topic_name_strategy, |
| 64 | + value_subject_name_strategy=strategies.topic_name_strategy) |
67 | 65 | serializer = producer._serializer
|
68 |
| - assert isinstance(serializer.key_subject_name_strategy, strategies.TopicNameStrategy) |
69 |
| - assert isinstance(serializer.value_subject_name_strategy, strategies.TopicNameStrategy) |
| 66 | + assert serializer.key_subject_name_strategy is strategies.topic_name_strategy |
| 67 | + assert serializer.value_subject_name_strategy is strategies.topic_name_strategy |
70 | 68 |
|
71 | 69 | def test_explicit_record_subject_name_strategy(self):
|
72 | 70 | schema_registry = MockSchemaRegistryClient()
|
73 |
| - config = { |
74 |
| - 'value.subject.name.strategy': 'RecordName', |
75 |
| - 'key.subject.name.strategy': 'RecordName' |
76 |
| - } |
77 |
| - producer = AvroProducer(config=config, schema_registry=schema_registry) |
| 71 | + producer = AvroProducer(config={}, schema_registry=schema_registry, |
| 72 | + key_subject_name_strategy=strategies.record_name_strategy, |
| 73 | + value_subject_name_strategy=strategies.record_name_strategy) |
78 | 74 | serializer = producer._serializer
|
79 |
| - assert isinstance(serializer.key_subject_name_strategy, strategies.RecordNameStrategy) |
80 |
| - assert isinstance(serializer.value_subject_name_strategy, strategies.RecordNameStrategy) |
| 75 | + assert serializer.key_subject_name_strategy is strategies.record_name_strategy |
| 76 | + assert serializer.value_subject_name_strategy is strategies.record_name_strategy |
81 | 77 |
|
82 | 78 | def test_explicit_topic_record_subject_name_strategy(self):
|
83 | 79 | schema_registry = MockSchemaRegistryClient()
|
84 |
| - config = { |
85 |
| - 'value.subject.name.strategy': 'TopicRecordName', |
86 |
| - 'key.subject.name.strategy': 'TopicRecordName' |
87 |
| - } |
88 |
| - producer = AvroProducer(config=config, schema_registry=schema_registry) |
| 80 | + producer = AvroProducer(config={}, schema_registry=schema_registry, |
| 81 | + key_subject_name_strategy=strategies.topic_record_name_strategy, |
| 82 | + value_subject_name_strategy=strategies.topic_record_name_strategy) |
89 | 83 | serializer = producer._serializer
|
90 |
| - assert isinstance(serializer.key_subject_name_strategy, strategies.TopicRecordNameStrategy) |
91 |
| - assert isinstance(serializer.value_subject_name_strategy, strategies.TopicRecordNameStrategy) |
| 84 | + assert serializer.key_subject_name_strategy is strategies.topic_record_name_strategy |
| 85 | + assert serializer.value_subject_name_strategy is strategies.topic_record_name_strategy |
92 | 86 |
|
93 | 87 | def test_differing_key_and_value_subject_name_strategies(self):
|
94 | 88 | schema_registry = MockSchemaRegistryClient()
|
95 |
| - config = { |
96 |
| - 'value.subject.name.strategy': 'RecordName', |
97 |
| - 'key.subject.name.strategy': 'TopicRecordName' |
98 |
| - } |
99 |
| - producer = AvroProducer(config=config, schema_registry=schema_registry) |
| 89 | + producer = AvroProducer(config={}, schema_registry=schema_registry, |
| 90 | + key_subject_name_strategy=strategies.record_name_strategy, |
| 91 | + value_subject_name_strategy=strategies.topic_record_name_strategy) |
100 | 92 | serializer = producer._serializer
|
101 |
| - assert isinstance(serializer.key_subject_name_strategy, strategies.RecordNameStrategy) |
102 |
| - assert isinstance(serializer.value_subject_name_strategy, strategies.TopicRecordNameStrategy) |
| 93 | + assert serializer.key_subject_name_strategy is strategies.record_name_strategy |
| 94 | + assert serializer.value_subject_name_strategy is strategies.topic_record_name_strategy |
0 commit comments