Skip to content

Commit 50ea83c

Browse files
committed
Passing the expected_dates as a parameter
1 parent 375a280 commit 50ea83c

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

tests/test_audit.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,27 +134,32 @@ async def test_get_audit_parameterized(
134134

135135
@freeze_time("2025-08-01")
136136
@pytest.mark.parametrize(
137-
("lookback_period", "expected_path"),
137+
("lookback_period", "expected_path", "expected_dates"),
138138
[
139139
(
140140
{"days": 7},
141141
"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"],
142143
),
143144
(
144145
{"months": 2},
145146
"action:protected_branch.create created:2025-06-01",
147+
["2025-06-01", "2025-06-02", "2025-06-03"],
146148
),
147149
(
148150
{"years": 1},
149151
"action:protected_branch.create created:2024-08-01",
152+
["2024-08-01", "2024-08-02", "2024-08-03"],
150153
),
151154
(
152155
{"days": 15, "months": 1},
153156
"action:protected_branch.create created:2025-06-16",
157+
["2025-06-16", "2025-06-17", "2025-06-18"],
154158
),
155159
(
156160
{"days": 10, "months": 1, "years": 1},
157161
"action:protected_branch.create created:2024-06-21",
162+
["2024-06-21", "2024-06-22", "2024-06-23"],
158163
),
159164
],
160165
)
@@ -163,9 +168,8 @@ async def test_get_audit_lookback_periods(
163168
gh_rest_mock: GithubHttpxMock,
164169
lookback_period: dict[str, int] | None,
165170
expected_path: str,
171+
expected_dates: list[str],
166172
):
167-
from nodestream_github.audit import generate_date_range
168-
169173
extractor = GithubAuditLogExtractor(
170174
auth_token="test-token",
171175
github_hostname=DEFAULT_HOSTNAME,
@@ -177,19 +181,14 @@ async def test_get_audit_lookback_periods(
177181
lookback_period=lookback_period,
178182
)
179183

180-
expected_dates = generate_date_range(lookback_period)
181-
182-
# Mock the first date call with the expected_path
183184
gh_rest_mock.get_enterprise_audit_logs(
184185
status_code=200,
185186
search_phrase=expected_path,
186187
json=GITHUB_AUDIT,
187188
)
188189

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:]:
193192
search_phrase = f"action:protected_branch.create created:{date}"
194193
gh_rest_mock.get_enterprise_audit_logs(
195194
status_code=200,
@@ -202,11 +201,11 @@ async def test_get_audit_lookback_periods(
202201
import nodestream_github.audit as client_module
203202

204203
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
206205

207206
try:
208207
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)
210209
assert all_records == expected_output
211210
finally:
212211
client_module.generate_date_range = original_generate

0 commit comments

Comments
 (0)