8000 Add tests for remaining rate limit of different resources · pythonthings/github3.py@e6246ef · GitHub
[go: up one dir, main page]

Skip to content

Commit e6246ef

Browse files
committed
Add tests for remaining rate limit of different resources
1 parent 89ac06d commit e6246ef

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"recorded_with": "betamax/0.8.0", "http_interactions": [{"response": {"body": {"base64_string": "H4sIAAAAAAAAA6tWKkotzi8tSk4tVrKqVkrOL0oF0TmZuZklSlZmBjpA+dzEzLzMvHQYtzgVKGNoamhmaWlibGhcq6NUnJpYlJyBpM8QVR+Ei6TPwNwcpC+9KLEgozAHSSOqPjAP3TqgvqLEEpJdWQsAyulOc+oAAAA=", "encoding": "utf-8", "string": ""}, "url": "https://api.github.com/rate_limit", "headers": {"Cache-Control": "no-cache", "Access-Control-Expose-Headers": "ETag, Link, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "Access-Control-Allow-Origin": "*", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Media-Type": "github.v3; param=full; format=json", "Content-Encoding": "gzip", "X-Content-Type-Options": "nosniff", "X-RateLimit-Limit": "60", "X-RateLimit-Reset": "1516994313", "Content-Type": "application/json; charset=utf-8", "X-XSS-Protection": "1; mode=block", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "Date": "Fri, 26 Jan 2018 18:18:33 GMT", "X-Runtime-rack": "0.008218", "Transfer-Encoding": "chunked", "X-GitHub-Request-Id": "D196:12414:2B7A313:507FFAA:5A6B70F9", "Status": "200 OK", "Server": "GitHub.com", "X-Frame-Options": "deny", "X-RateLimit-Remaining": "60"}, "status": {"message": "OK", "code": 200}}, "recorded_at": "2018-01-26T18:18:33", "request": {"body": {"encoding": "utf-8", "string": ""}, "method": "GET", "uri": "https://api.github.com/rate_limit", "headers": {"Connection": "keep-alive", "Content-Type": "application/json", "User-Agent": "github3.py/1.0.0a4", "Accept-Charset": "utf-8", "Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.v3.full+json"}}}, {"response": {"body": {"base64_string": "H4sIAAAAAAAAA6tWKkotzi8tSk4tVrKqVkrOL0oF0TmZuZklSlZmBjpA+dzEzLzMvHQYtzgVKGNoamhmaWlibGhcq6NUnJpYlJyBpM8QVR+Ei6TPwNwcpC+9KLEgozAHSSOqPjAP3TqgvqLEEpJdWQsAyulOc+oAAAA=", "encoding": "utf-8", "string": ""}, "url": "https://api.github.com/rate_limit", "headers": {"Cache-Control": "no-cache", "Access-Control-Expose-Headers": "ETag, Link, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "Access-Control-Allow-Origin": "*", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Media-Type": "github.v3; param=full; format=json", "Content-Encoding": "gzip", "X-Content-Type-Options": "nosniff", "X-RateLimit-Limit": "60", "X-RateLimit-Reset": "1516994313", "Content-Type": "application/json; charset=utf-8", "X-XSS-Protection": "1; mode=block", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "Date": "Fri, 26 Jan 2018 18:18:33 GMT", "X-Runtime-rack": "0.010151", "Transfer-Encoding": "chunked", "X-GitHub-Request-Id": "D196:12414:2B7A31F:507FFBB:5A6B70F9", "Status": "200 OK", "Server": "GitHub.com", "X-Frame-Options": "deny", "X-RateLimit-Remaining": "60"}, "status": {"message": "OK", "code": 200}}, "recorded_at": "2018-01-26T18:18:33", "request": {"body": {"encoding": "utf-8", "string": ""}, "method": "GET", "uri": "https://api.github.com/rate_limit", "headers": {"Connection": "keep-alive", "Content-Type": "application/json", "User-Agent": "github3.py/1.0.0a4", "Accept-Charset": "utf-8", "Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.v3.full+json"}}}]}

tests/integration/test_github_core.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,31 @@ def test_ratelimit_remaining(self):
66
cassette_name = self.cassette_name('ratelimit_remaining')
77
with self.recorder.use_cassette(cassette_name):
88
assert self.gh.ratelimit_remaining > 0
9+
10+
def test_ratelimit_remaining_search(self):
11+
"""Test if search iterators return search ratelimit"""
12+
13+
def _get_ratelimit(resource):
14+
resources = self.gh.rate_limit().get('resources', {})
15+
rate_limit = resources.get(resource, {})
16+
return rate_limit.get('remaining', -1)
17+
18+
cassette_name = self.cassette_name('ratelimit_remaining_search')
19+
20+
# Run cassette to get correct remaining rate limit from responses.
21+
with self.recorder.use_cassette(cassette_name):
22+
correct_ratelimit_search = _get_ratelimit('search')
23+
correct_ratelimit_core = _get_ratelimit('core')
24+
25+
# Re-run cassette to test functions under test.
26+
with self.recorder.use_cassette(cassette_name):
27+
result_iterator = self.gh.search_code(
28+
'HTTPAdapter in:file language:python'
29+
' repo:kennethreitz/requests'
30+
)
31+
ratelimit_remaining_search = result_iterator.ratelimit_remaining
32+
ratelimit_remaining_core = self.gh.ratelimit_remaining
33+
34+
assert ratelimit_remaining_search != ratelimit_remaining_core
35+
assert ratelimit_remaining_core == correct_ratelimit_core
36+
assert ratelimit_remaining_search == correct_ratelimit_search

0 commit comments

Comments
 (0)
0