2
2
# Licensed under the MIT License.
3
3
import json
4
4
import time
5
- import pathlib
6
5
from datetime import datetime
7
6
from unittest import skipIf
8
7
@@ -37,14 +36,9 @@ def get_libraries_to_install(cls):
37
36
38
37
def test_eventhub_multiple (self ):
39
38
NUM_EVENTS = 3
40
- all_row_keys_seen = dict ([(str ( i ) , True ) for i in range (NUM_EVENTS )])
39
+ all_row_keys_seen = dict ([(i , True ) for i in range (NUM_EVENTS )])
41
40
partition_key = str (round (time .time ()))
42
41
43
- # Dynamically rewrite function.json to point to new partition key
44
- # for recording EventHub state
45
- old_partition_key = self ._get_table_partition_key ()
46
- self ._set_table_partition_key (partition_key )
47
-
48
42
# wait for host to restart after change
49
43
time .sleep (5 )
50
44
@@ -57,29 +51,26 @@ def test_eventhub_multiple(self):
57
51
data = json .dumps (docs ))
58
52
self .assertEqual (r .status_code , 200 )
59
53
60
- row_keys = [str ( i ) for i in range (NUM_EVENTS )]
54
+ row_keys = [i for i in range (NUM_EVENTS )]
61
55
seen = [False ] * NUM_EVENTS
62
56
row_keys_seen = dict (zip (row_keys , seen ))
63
57
64
58
# Allow trigger to fire.
65
59
time .sleep (5 )
66
60
67
- try :
68
- r = self .webhost .request ('GET' , 'get_eventhub_batch_triggered' )
61
+ r = self .webhost .request ('GET' , 'get_eventhub_batch_triggered' )
69
62
70
- # Waiting for the blob get updated with the latest data from the
71
- # eventhub output binding
72
- time .sleep (2 )
73
- self .assertEqual (r .status_code , 200 )
74
- entries = r .json ()
75
- for entry in entries :
76
- self .assertEqual (entry ['PartitionKey' ], partition_key )
77
- row_key = entry ['RowKey' ]
78
- row_keys_seen [row_key ] = True
63
+ # Waiting for the blob get updated with the latest data from the
64
+ # eventhub output binding
65
+ time .sleep (2 )
66
+ self .assertEqual (r .status_code , 200 )
67
+ entries = r .json ()
68
+ for entry in entries :
69
+ self .assertEqual (entry ['PartitionKey' ], partition_key )
70
+ row_key = entry ['RowKey' ]
71
+ row_keys_seen [row_key ] = True
79
72
80
- self .assertDictEqual (all_row_keys_seen , row_keys_seen )
81
- finally :
82
- self ._cleanup (old_partition_key )
73
+ self .assertDictEqual (all_row_keys_seen , row_keys_seen )
83
74
84
75
def test_eventhub_multiple_with_metadata (self ):
85
76
# Generate a unique event body for EventHub event
@@ -142,36 +133,6 @@ def test_eventhub_multiple_with_metadata(self):
142
133
self .assertGreaterEqual (sys_props ['SequenceNumber' ], 0 )
143
134
self .assertIsNotNone (sys_props ['Offset' ])
144
135
145
- def _cleanup (self , old_partition_key ):
146
- self ._set_table_partition_key (old_partition_key )
147
-
148
- def _get_table_partition_key (self ):
149
- func_dict = self ._get_table_function_json_dict ()
150
- partition_key = func_dict ['bindings' ][1 ]['partitionKey' ]
151
- return partition_key
152
-
153
- def _set_table_partition_key (self , partition_key ):
154
- full_json_path = self ._get_table_function_json_path ()
155
-
156
- func_dict = self ._get_table_function_json_dict ()
157
- func_dict ['bindings' ][1 ]['partitionKey' ] = partition_key
158
-
159
- with open (full_json_path , 'w' ) as f :
160
- json .dump (func_dict , f , indent = 2 )
161
-
162
- def _get_table_function_json_dict (self ):
163
- full_json_path = self ._get_table_function_json_path ()
164
-
165
- with open (full_json_path , 'r' ) as f :
166
- func_dict = json .load (f )
167
-
168
- return func_dict
169
-
170
- def _get_table_function_json_path (self ):
171
- script_dir = pathlib .Path (self .get_script_dir ())
172
- json_path = pathlib .Path ('get_eventhub_batch_triggered/function.json' )
173
- return testutils .TESTS_ROOT / script_dir / json_path
174
-
175
136
176
137
@skipIf (is_envvar_true (DEDICATED_DOCKER_TEST )
177
138
or is_envvar_true (CONSUMPTION_DOCKER_TEST ),
@@ -191,7 +152,7 @@ def get_libraries_to_install(cls):
191
152
192
153
def test_eventhub_multiple (self ):
193
154
NUM_EVENTS = 3
194
- all_row_keys_seen = dict ([(str ( i ) , True ) for i in range (NUM_EVENTS )])
155
+ all_row_keys_seen = dict ([(i , True ) for i in range (NUM_EVENTS )])
195
156
partition_key = str (round (time .time ()))
196
157
197
158
docs = []
@@ -203,7 +164,7 @@ def test_eventhub_multiple(self):
203
164
data = json .dumps (docs ))
204
165
self .assertEqual (r .status_code , 200 )
205
166
206
- row_keys = [str ( i ) for i in range (NUM_EVENTS )]
167
+ row_keys = [i for i in range (NUM_EVENTS )]
207
168
seen = [False ] * NUM_EVENTS
208
169
row_keys_seen = dict (zip (row_keys , seen ))
209
170
@@ -212,7 +173,7 @@ def test_eventhub_multiple(self):
212
173
213
174
r = self .webhost .request (
214
175
'GET' ,
215
- f 'get_eventhub_batch_triggered/ { partition_key } ' )
176
+ 'get_eventhub_batch_triggered' )
216
177
self .assertEqual (r .status_code , 200 )
217
178
entries = r .json ()
218
179
for entry in entries :
0 commit comments