-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add useragent with library/python/http client versions
- Loading branch information
Showing
4 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
""" Base module for OpenCage stuff. """ | ||
|
||
from .version import __version__ | ||
|
||
__author__ = "OpenCage GmbH" | ||
__email__ = '[email protected]' | ||
__version__ = '2.3.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = '2.3.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# encoding: utf-8 | ||
|
||
from pathlib import Path | ||
|
||
import os | ||
import re | ||
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') | ||
|
||
user_agent_format = re.compile(r'^opencage-python/[\d\.]+ Python/[\d\.]+ (requests|aiohttp)/[\d\.]+$') | ||
|
||
@httprettified | ||
def test_sync(): | ||
httpretty.register_uri( | ||
httpretty.GET, | ||
geocoder.url, | ||
body=Path('test/fixtures/uk_postcode.json').read_text(encoding="utf-8") | ||
) | ||
|
||
geocoder.geocode("EC1M 5RF") | ||
user_agent = httpretty.last_request().headers['User-Agent'] | ||
|
||
assert user_agent_format.match(user_agent) is not None |