1
1
import httpx
2
2
import pytest
3
+ from freezegun import freeze_time
3
4
from pytest_httpx import HTTPXMock
4
5
5
- from nodestream_github .client .githubclient import GithubRestApiClient , RateLimitedError
6
+ from nodestream_github .client .githubclient import (
7
+ GithubRestApiClient ,
8
+ RateLimitedError ,
9
+ build_search_phrase ,
10
+ generate_date_range ,
11
+ validate_lookback_period ,
12
+ )
6
13
from tests .mocks .githubrest import DEFAULT_BASE_URL , DEFAULT_HOSTNAME
7
14
8
15
@@ -127,3 +134,114 @@ async def test_pagination_truncate_warning(
127
134
def test_all_null_args ():
128
135
# noinspection PyTypeChecker
129
136
assert GithubRestApiClient (auth_token = None , github_hostname = None )
137
+
138
+ # Test generate_date_range
139
+
140
+ def test_generate_date_range_empty_lookback_period ():
141
+ result = generate_date_range ({})
142
+ assert result == []
143
+
144
+ @freeze_time ("2025-08-01" )
145
+ def test_generate_date_range_days_only ():
146
+ result = generate_date_range ({"days" : 3 })
147
+ expected = ["2025-07-29" , "2025-07-30" , "2025-07-31" , "2025-08-01" ]
148
+ assert result == expected
149
+
150
+ @freeze_time ("2025-08-01" )
151
+ def test_generate_date_range_zero_days ():
152
+ """Test with zero days (same day only)."""
153
+ result = generate_date_range ({"days" : 0 })
154
+ expected = ["2025-08-01" ]
155
+ assert result == expected
156
+
157
+ @freeze_time ("2025-08-01" )
158
+ def test_generate_date_range_months_only ():
159
+ result = generate_date_range ({"months" : 1 })
160
+ # July 1 to August 1 = 32 days
161
+ assert len (result ) == 32
162
+ assert result [0 ] == "2025-07-01"
163
+ assert result [- 1 ] == "2025-08-01"
164
+
165
+ @freeze_time ("2025-08-01" )
166
+ def test_generate_date_range_years_only ():
167
+ result = generate_date_range ({"years" : 1 })
168
+ assert len (result ) == 366
169
+ assert result [0 ] == "2024-08-01"
170
+ assert result [- 1 ] == "2025-08-01"
171
+
172
+ @freeze_time ("2025-08-01" )
173
+ def test_generate_date_range_combined_periods ():
174
+ """Test with combined periods."""
175
+ result = generate_date_range ({"months" : 1 , "days" : 5 })
176
+ assert result [0 ] == "2025-06-26"
177
+ assert result [- 1 ] == "2025-08-01"
178
+
179
+ @freeze_time ("2025-08-01" )
180
+ def test_generate_date_range_complex_combination ():
181
+ """Test with years, months, and days."""
182
+ result = generate_date_range ({"years" : 1 , "months" : 2 , "days" : 10 })
183
+ assert result [0 ] == "2024-05-22"
184
+ assert result [- 1 ] == "2025-08-01"
185
+
186
+
187
+ # Test validate_lookback_period
188
+
189
+ def test_validate_lookback_period_valid_input ():
190
+ result = validate_lookback_period ({"days" : 7 , "months" : 2 , "years" : 1 })
191
+ expected = {"days" : 7 , "months" : 2 , "years" : 1 }
192
+ assert result == expected
193
+
194
+
195
+ def test_validate_lookback_period_empty_dict ():
196
+ result = validate_lookback_period ({})
197
+ assert result == {}
198
+
199
+
200
+ def test_validate_lookback_period_single_value ():
201
+ result = validate_lookback_period ({"days" : 30 })
202
+ assert result == {"days" : 30 }
203
+
204
+
205
+ def test_validate_lookback_period_string_to_int_conversion ():
206
+ result = validate_lookback_period ({"days" : "7" , "months" : "2" })
207
+ expected = {"days" : 7 , "months" : 2 }
208
+ assert result == expected
209
+
210
+ def test_validate_lookback_period_zero_value ():
211
+ with pytest .raises (ValueError , match = "Formatting lookback period failed" ):
212
+ validate_lookback_period ({"days" : 0 })
213
+
214
+
215
+ def test_validate_lookback_period_negative_value ():
216
+ with pytest .raises (ValueError , match = "Formatting lookback period failed" ):
217
+ validate_lookback_period ({"days" : - 5 })
218
+
219
+
220
+ def test_validate_lookback_period_multiple_negative_values ():
221
+ with pytest .raises (ValueError , match = "Formatting lookback period failed" ):
222
+ validate_lookback_period ({"days" : 7 , "months" : - 1 , "years" : 2 })
223
+
224
+
225
+ def test_validate_lookback_period_zero_string ():
226
+ with pytest .raises (ValueError , match = "Formatting lookback period failed" ):
227
+ validate_lookback_period ({"days" : "0" })
228
+
229
+
230
+ def test_validate_lookback_period_negative_string ():
231
+ with pytest .raises (ValueError , match = "Formatting lookback period failed" ):
232
+ validate_lookback_period ({"months" : "-10" })
233
+
234
+
235
+ def test_validate_lookback_period_invalid_string ():
236
+ with pytest .raises (ValueError , match = "Formatting lookback period failed" ):
237
+ validate_lookback_period ({"days" : "invalid" })
238
+
239
+
240
+ def test_validate_lookback_period_invalid_type ():
241
+ with pytest .raises (ValueError , match = "Formatting lookback period failed" ):
242
+ validate_lookback_period ({"days" : []})
243
+
244
+
245
+ def test_validate_lookback_period_none_value ():
246
+ with pytest .raises (ValueError , match = "Formatting lookback period failed" ):
247
+ validate_lookback_period ({"days" : None })
0 commit comments