@@ -97,7 +97,9 @@ def test_read_records_all(self, mocker, api, some_config):
97
97
if read slice 2, 3, 1 state changed to 3
98
98
"""
99
99
job = mocker .Mock (spec = InsightAsyncJob )
100
- job .get_result .return_value = [mocker .Mock (), mocker .Mock (), mocker .Mock ()]
100
+ rec = mocker .Mock ()
101
+ rec .export_all_data .return_value = {}
102
+ job .get_result .return_value = [rec , rec , rec ]
101
103
job .interval = pendulum .Period (pendulum .date (2010 , 1 , 1 ), pendulum .date (2010 , 1 , 1 ))
102
104
stream = AdsInsights (
103
105
api = api ,
@@ -124,8 +126,11 @@ def test_read_records_random_order(self, mocker, api, some_config):
124
126
2. if read slice 2, 3 state not changed
125
127
if read slice 2, 3, 1 state changed to 3
126
128
"""
129
+ rec = mocker .Mock ()
130
+ rec .export_all_data .return_value = {}
131
+
127
132
job = mocker .Mock (spec = AsyncJob )
128
- job .get_result .return_value = [mocker . Mock (), mocker . Mock (), mocker . Mock () ]
133
+ job .get_result .return_value = [rec , rec , rec ]
129
134
job .interval = pendulum .Period (pendulum .date (2010 , 1 , 1 ), pendulum .date (2010 , 1 , 1 ))
130
135
stream = AdsInsights (
131
136
api = api ,
@@ -147,6 +152,38 @@ def test_read_records_random_order(self, mocker, api, some_config):
147
152
148
153
assert len (records ) == 3
149
154
155
+ def test_read_records_add_account_id (self , mocker , api , some_config ):
156
+ rec_without_account = mocker .Mock ()
157
+ rec_without_account .export_all_data .return_value = {}
158
+
159
+ rec_with_account = mocker .Mock ()
160
+ rec_with_account .export_all_data .return_value = {"account_id" : "some_account_id" }
161
+
162
+ job = mocker .Mock (spec = AsyncJob )
163
+ job .get_result .return_value = [rec_without_account , rec_with_account ]
164
+ job .interval = pendulum .Period (pendulum .date (2010 , 1 , 1 ), pendulum .date (2010 , 1 , 1 ))
165
+ stream = AdsInsights (
166
+ api = api ,
167
+ account_ids = some_config ["account_ids" ],
168
+ start_date = datetime (2010 , 1 , 1 ),
169
+ end_date = datetime (2011 , 1 , 1 ),
170
+ insights_lookback_window = 28 ,
171
+ )
172
+
173
+ records = list (
174
+ stream .read_records (
175
+ sync_mode = SyncMode .incremental ,
176
+ stream_slice = {
177
+ "insight_job" : job ,
178
+ "account_id" : some_config ["account_ids" ][0 ],
179
+ },
180
+ )
181
+ )
182
+
183
+ assert len (records ) == 2
184
+ for record in records :
185
+ assert record .get ("account_id" )
186
+
150
187
@pytest .mark .parametrize (
151
188
"state,result_state" ,
152
189
[
0 commit comments