-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathtest_error_ratelimit_exceeded.py
More file actions
40 lines (33 loc) · 1.09 KB
/
test_error_ratelimit_exceeded.py
File metadata and controls
40 lines (33 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from pathlib import Path
import pytest
import responses
from opencage.geocoder import OpenCageGeocode
from opencage.geocoder import RateLimitExceededError
geocoder = OpenCageGeocode('abcde')
@responses.activate
def test_no_rate_limit():
responses.add(
responses.GET,
geocoder.url,
body=Path('test/fixtures/no_ratelimit.json').read_text(encoding="utf-8"),
status=200
)
# shouldn't raise an exception
geocoder.geocode("whatever")
@responses.activate
def test_rate_limit_exceeded():
# 4372eff77b8343cebfc843eb4da4ddc4 will always return 402
responses.add(
responses.GET,
geocoder.url,
body=Path('test/fixtures/402_rate_limit_exceeded.json').read_text(encoding="utf-8"),
status=402,
headers={
'X-RateLimit-Limit': '2500',
'X-RateLimit-Remaining': '0',
'X-RateLimit-Reset': '1402185600'
}
)
with pytest.raises(RateLimitExceededError) as excinfo:
geocoder.geocode("whatever")
assert 'You have used the requests available on your plan.' in str(excinfo.value)