@@ -134,27 +134,32 @@ async def test_get_audit_parameterized(
134
134
135
135
@freeze_time ("2025-08-01" )
136
136
@pytest .mark .parametrize (
137
- ("lookback_period" , "expected_path" ),
137
+ ("lookback_period" , "expected_path" , "expected_dates" ),
138
138
[
139
139
(
140
140
{"days" : 7 },
141
141
"action:protected_branch.create created:2025-07-25" ,
142
+ ["2025-07-25" , "2025-07-26" , "2025-07-27" , "2025-07-28" , "2025-07-29" , "2025-07-30" , "2025-07-31" , "2025-08-01" ],
142
143
),
143
144
(
144
145
{"months" : 2 },
145
146
"action:protected_branch.create created:2025-06-01" ,
147
+ ["2025-06-01" , "2025-06-02" , "2025-06-03" ],
146
148
),
147
149
(
148
150
{"years" : 1 },
149
151
"action:protected_branch.create created:2024-08-01" ,
152
+ ["2024-08-01" , "2024-08-02" , "2024-08-03" ],
150
153
),
151
154
(
152
155
{"days" : 15 , "months" : 1 },
153
156
"action:protected_branch.create created:2025-06-16" ,
157
+ ["2025-06-16" , "2025-06-17" , "2025-06-18" ],
154
158
),
155
159
(
156
160
{"days" : 10 , "months" : 1 , "years" : 1 },
157
161
"action:protected_branch.create created:2024-06-21" ,
162
+ ["2024-06-21" , "2024-06-22" , "2024-06-23" ],
158
163
),
159
164
],
160
165
)
@@ -163,9 +168,8 @@ async def test_get_audit_lookback_periods(
163
168
gh_rest_mock : GithubHttpxMock ,
164
169
lookback_period : dict [str , int ] | None ,
165
170
expected_path : str ,
171
+ expected_dates : list [str ],
166
172
):
167
- from nodestream_github .audit import generate_date_range
168
-
169
173
extractor = GithubAuditLogExtractor (
170
174
auth_token = "test-token" ,
171
175
github_hostname = DEFAULT_HOSTNAME ,
@@ -177,19 +181,14 @@ async def test_get_audit_lookback_periods(
177
181
lookback_period = lookback_period ,
178
182
)
179
183
180
- expected_dates = generate_date_range (lookback_period )
181
-
182
- # Mock the first date call with the expected_path
183
184
gh_rest_mock .get_enterprise_audit_logs (
184
185
status_code = 200 ,
185
186
search_phrase = expected_path ,
186
187
json = GITHUB_AUDIT ,
187
188
)
188
189
189
- # Mock additional dates if there are more than one
190
- test_dates = expected_dates [:3 ] if len (expected_dates ) > 3 else expected_dates
191
- if len (test_dates ) > 1 :
192
- for date in test_dates [1 :]:
190
+ if len (expected_dates ) > 1 :
191
+ for date in expected_dates [1 :]:
193
192
search_phrase = f"action:protected_branch.create created:{ date } "
194
193
gh_rest_mock .get_enterprise_audit_logs (
195
194
status_code = 200 ,
@@ -202,11 +201,11 @@ async def test_get_audit_lookback_periods(
202
201
import nodestream_github .audit as client_module
203
202
204
203
original_generate = client_module .generate_date_range
205
- client_module .generate_date_range = lambda x : test_dates
204
+ client_module .generate_date_range = lambda x : expected_dates
206
205
207
206
try :
208
207
all_records = [record async for record in extractor .extract_records ()]
209
- expected_output = GITHUB_EXPECTED_OUTPUT * len (test_dates )
208
+ expected_output = GITHUB_EXPECTED_OUTPUT * len (expected_dates )
210
209
assert all_records == expected_output
211
210
finally :
212
211
client_module .generate_date_range = original_generate
0 commit comments