11import unittest
22
3- from conductor .client .workflow .task .kafka_publish_input import KafkaPublishInput
43from conductor .client .http .api_client import ApiClient
4+ from conductor .client .workflow .task .kafka_publish_input import \
5+ KafkaPublishInput
56
67
78class TestKafkaPublishInput (unittest .TestCase ):
@@ -11,115 +12,134 @@ def setUp(self):
1112 """Set up test fixtures."""
1213 self .api_client = ApiClient ()
1314 self .sample_kafka_input = KafkaPublishInput (
14- bootstrap_servers = ' kafka-broker:29092' ,
15- key = ' test-key' ,
16- key_serializer = ' org.apache.kafka.common.serialization.StringSerializer' ,
15+ bootstrap_servers = " kafka-broker:29092" ,
16+ key = " test-key" ,
17+ key_serializer = " org.apache.kafka.common.serialization.StringSerializer" ,
1718 value = '{"test": "data"}' ,
18- request_timeout_ms = ' 30000' ,
19- max_block_ms = ' 60000' ,
20- headers = {' content-type' : ' application/json' },
21- topic = ' test-topic'
19+ request_timeout_ms = " 30000" ,
20+ max_block_ms = " 60000" ,
21+ headers = {" content-type" : " application/json" },
22+ topic = " test-topic" ,
2223 )
2324
2425 def test_kafka_publish_input_serialization_structure (self ):
2526 """Test that serialized KafkaPublishInput has the correct structure."""
2627 serialized = self .api_client .sanitize_for_serialization (self .sample_kafka_input )
27-
28+
2829 expected_keys = [
29- 'bootStrapServers' , 'key' , 'keySerializer' , 'value' ,
30- 'requestTimeoutMs' , 'maxBlockMs' , 'headers' , 'topic'
30+ "bootStrapServers" ,
31+ "key" ,
32+ "keySerializer" ,
33+ "value" ,
34+ "requestTimeoutMs" ,
35+ "maxBlockMs" ,
36+ "headers" ,
37+ "topic" ,
3138 ]
32-
39+
3340 for key in expected_keys :
3441 self .assertIn (key , serialized , f"Missing key '{ key } ' in serialized output" )
35-
36- self .assertEqual (serialized ['bootStrapServers' ], 'kafka-broker:29092' )
37- self .assertEqual (serialized ['key' ], 'test-key' )
38- self .assertEqual (serialized ['keySerializer' ], 'org.apache.kafka.common.serialization.StringSerializer' )
39- self .assertEqual (serialized ['value' ], '{"test": "data"}' )
40- self .assertEqual (serialized ['requestTimeoutMs' ], '30000' )
41- self .assertEqual (serialized ['maxBlockMs' ], '60000' )
42- self .assertEqual (serialized ['headers' ], {'content-type' : 'application/json' })
43- self .assertEqual (serialized ['topic' ], 'test-topic' )
42+
43+ self .assertEqual (serialized ["bootStrapServers" ], "kafka-broker:29092" )
44+ self .assertEqual (serialized ["key" ], "test-key" )
45+ self .assertEqual (
46+ serialized ["keySerializer" ],
47+ "org.apache.kafka.common.serialization.StringSerializer" ,
48+ )
49+ self .assertEqual (serialized ["value" ], '{"test": "data"}' )
50+ self .assertEqual (serialized ["requestTimeoutMs" ], "30000" )
51+ self .assertEqual (serialized ["maxBlockMs" ], "60000" )
52+ self .assertEqual (serialized ["headers" ], {"content-type" : "application/json" })
53+ self .assertEqual (serialized ["topic" ], "test-topic" )
4454
4555 def test_kafka_publish_input_with_none_values_serialization (self ):
4656 """Test that KafkaPublishInput with None values serializes correctly."""
4757 kafka_input = KafkaPublishInput (
48- bootstrap_servers = 'kafka:9092' ,
49- topic = 'test-topic'
58+ bootstrap_servers = "kafka:9092" , topic = "test-topic"
5059 )
51-
60+
5261 serialized = self .api_client .sanitize_for_serialization (kafka_input )
53-
54- self .assertEqual (serialized ['bootStrapServers' ], 'kafka:9092' )
55- self .assertEqual (serialized ['topic' ], 'test-topic' )
5662
57- self .assertNotIn ('key' , serialized )
58- self .assertNotIn ('keySerializer' , serialized )
59- self .assertNotIn ('value' , serialized )
60- self .assertNotIn ('requestTimeoutMs' , serialized )
61- self .assertNotIn ('maxBlockMs' , serialized )
62- self .assertNotIn ('headers' , serialized )
63+ self .assertEqual (serialized ["bootStrapServers" ], "kafka:9092" )
64+ self .assertEqual (serialized ["topic" ], "test-topic" )
65+
66+ self .assertNotIn ("key" , serialized )
67+ self .assertNotIn ("keySerializer" , serialized )
68+ self .assertNotIn ("value" , serialized )
69+ self .assertNotIn ("requestTimeoutMs" , serialized )
70+ self .assertNotIn ("maxBlockMs" , serialized )
71+ self .assertNotIn ("headers" , serialized )
6372
6473 def test_kafka_publish_input_complex_headers_serialization (self ):
6574 """Test that KafkaPublishInput with complex headers serializes correctly."""
6675 complex_headers = {
67- ' content-type' : ' application/json' ,
68- ' correlation-id' : ' test-123' ,
69- ' user-agent' : ' conductor-python-sdk' ,
70- ' custom-header' : ' custom-value'
76+ " content-type" : " application/json" ,
77+ " correlation-id" : " test-123" ,
78+ " user-agent" : " conductor-python-sdk" ,
79+ " custom-header" : " custom-value" ,
7180 }
72-
81+
7382 kafka_input = KafkaPublishInput (
74- bootstrap_servers = ' kafka:9092' ,
83+ bootstrap_servers = " kafka:9092" ,
7584 headers = complex_headers ,
76- topic = ' complex-topic' ,
77- value = '{"complex": "data"}'
85+ topic = " complex-topic" ,
86+ value = '{"complex": "data"}' ,
7887 )
79-
88+
8089 serialized = self .api_client .sanitize_for_serialization (kafka_input )
81-
82- self .assertEqual (serialized [' headers' ], complex_headers )
83- self .assertEqual (serialized [' bootStrapServers' ], ' kafka:9092' )
84- self .assertEqual (serialized [' topic' ], ' complex-topic' )
85- self .assertEqual (serialized [' value' ], '{"complex": "data"}' )
90+
91+ self .assertEqual (serialized [" headers" ], complex_headers )
92+ self .assertEqual (serialized [" bootStrapServers" ], " kafka:9092" )
93+ self .assertEqual (serialized [" topic" ], " complex-topic" )
94+ self .assertEqual (serialized [" value" ], '{"complex": "data"}' )
8695
8796 def test_kafka_publish_input_swagger_types_consistency (self ):
8897 """Test that swagger_types are consistent with actual serialization."""
8998 swagger_types = KafkaPublishInput .swagger_types
90-
99+
91100 kafka_input = KafkaPublishInput (
92- bootstrap_servers = ' test' ,
93- key = ' test' ,
94- key_serializer = ' test' ,
95- value = ' test' ,
96- request_timeout_ms = ' test' ,
97- max_block_ms = ' test' ,
98- headers = {' test' : ' test' },
99- topic = ' test'
101+ bootstrap_servers = " test" ,
102+ key = " test" ,
103+ key_serializer = " test" ,
104+ value = " test" ,
105+ request_timeout_ms = " test" ,
106+ max_block_ms = " test" ,
107+ headers = {" test" : " test" },
108+ topic = " test" ,
100109 )
101-
110+
102111 serialized = self .api_client .sanitize_for_serialization (kafka_input )
103-
112+
104113 for internal_attr , expected_type in swagger_types .items ():
105114 external_attr = KafkaPublishInput .attribute_map [internal_attr ]
106- self .assertIn (external_attr , serialized ,
107- f"Swagger type '{ internal_attr } ' not found in serialized output" )
115+ self .assertIn (
116+ external_attr ,
117+ serialized ,
118+ f"Swagger type '{ internal_attr } ' not found in serialized output" ,
119+ )
108120
109121 def test_kafka_publish_input_attribute_map_consistency (self ):
110122 """Test that attribute_map correctly maps all internal attributes."""
111123 kafka_input = self .sample_kafka_input
112- internal_attrs = [attr for attr in dir (kafka_input )
113- if attr .startswith ('_' ) and not attr .startswith ('__' )]
114-
124+ internal_attrs = [
125+ attr
126+ for attr in dir (kafka_input )
127+ if attr .startswith ("_" ) and not attr .startswith ("__" )
128+ ]
129+
115130 for attr in internal_attrs :
116- self .assertIn (attr , KafkaPublishInput .attribute_map ,
117- f"Internal attribute '{ attr } ' not found in attribute_map" )
118-
131+ self .assertIn (
132+ attr ,
133+ KafkaPublishInput .attribute_map ,
134+ f"Internal attribute '{ attr } ' not found in attribute_map" ,
135+ )
136+
119137 for internal_attr in KafkaPublishInput .attribute_map .keys ():
120- self .assertTrue (hasattr (kafka_input , internal_attr ),
121- f"Attribute_map key '{ internal_attr } ' not found in instance" )
138+ self .assertTrue (
139+ hasattr (kafka_input , internal_attr ),
140+ f"Attribute_map key '{ internal_attr } ' not found in instance" ,
141+ )
122142
123143
124- if __name__ == ' __main__' :
125- unittest .main ()
144+ if __name__ == " __main__" :
145+ unittest .main ()
0 commit comments