-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathtest_ratelimit_properties.py
More file actions
45 lines (37 loc) · 1.26 KB
/
test_ratelimit_properties.py
File metadata and controls
45 lines (37 loc) · 1.26 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
41
42
43
44
45
# encoding: utf-8
from datetime import datetime
from pathlib import Path
import os
import httpretty
from httpretty import httprettified
from opencage.geocoder import OpenCageGeocode
# reduce maximum backoff retry time from 120s to 1s
os.environ['BACKOFF_MAX_TIME'] = '1'
geocoder = OpenCageGeocode('abcde')
@httprettified
def test_rate_limit_properties_no_headers():
httpretty.register_uri(
httpretty.GET,
geocoder.url,
body=Path('test/fixtures/uk_postcode.json').read_text(encoding="utf-8")
)
_ = geocoder.geocode("EC1M 5RF")
assert geocoder.ratelimit_limit is None
assert geocoder.ratelimit_remaining is None
assert geocoder.ratelimit_reset is None
@httprettified
def test_rate_limit_properties():
httpretty.register_uri(
httpretty.GET,
geocoder.url,
body=Path('test/fixtures/uk_postcode.json').read_text(encoding="utf-8"),
adding_headers={
'X-RateLimit-Limit': '2500',
'X-RateLimit-Remaining': '2487',
'X-RateLimit-Reset': '1402185600'
}
)
_ = geocoder.geocode("EC1M 5RF")
assert geocoder.ratelimit_limit == 2500
assert geocoder.ratelimit_remaining == 2487
assert geocoder.ratelimit_reset == datetime.fromtimestamp(1402185600)