-
Notifications
You must be signed in to change notification settings - Fork 660
added a timezone parameter to geonames #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2dd9c6b
added a timezone parameter to geonames
14fcb96
removed comments
ceff683
added a new method timezone which returns a timezone and added a bool…
9dbff31
flake fix
a4b9c36
added tests for reverse timezone, use geopy timezone object instead o…
9754fcc
change naming of tz_api to api_tz
c386ba0
removed unnecesary imports
a158d28
added more tests, docs, style code fix
47547f1
removed credentials C:
8d7efa0
sort imports
df70ba5
split tests, fix docs
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,6 +1,9 @@ | ||
| # -*- coding: UTF-8 -*- | ||
| import unittest | ||
|
|
||
| from pytz import timezone | ||
|
|
||
| from geopy import Point | ||
| from geopy.compat import u | ||
| from geopy.geocoders import GeoNames | ||
| from test.geocoders.util import GeocoderTestBase, env | ||
|
|
@@ -23,11 +26,18 @@ def test_user_agent_custom(self): | |
| class GeoNamesTestCase(GeocoderTestBase): | ||
|
|
||
| delta = 0.04 | ||
| new_york_point = Point(40.75376406311989, -73.98489005863667) | ||
| america_new_york = timezone("America/New_York") | ||
|
|
||
| @classmethod | ||
| def setUpClass(cls): | ||
| cls.geocoder = GeoNames(username=env['GEONAMES_USERNAME']) | ||
|
|
||
| def reverse_timezone_run(self, payload, expected): | ||
| timezone = self._make_request(self.geocoder.reverse_timezone, **payload) | ||
| self.assertEqual(timezone.pytz_timezone, expected) | ||
| return timezone | ||
|
|
||
| def test_unicode_name(self): | ||
| self.geocode_run( | ||
| {"query": "Mount Everest, Nepal"}, | ||
|
|
@@ -45,6 +55,77 @@ def test_query_urlencoding(self): | |
|
|
||
| def test_reverse(self): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test contains too many checks. Could you please split it to multiple distinct test methods? |
||
| self.reverse_run( | ||
| {"query": "40.75376406311989, -73.98489005863667", "exactly_one": True}, | ||
| {"latitude": 40.75376406311989, "longitude": -73.98489005863667}, | ||
| { | ||
| "query": "40.75376406311989, -73.98489005863667", | ||
| "exactly_one": True, | ||
| }, | ||
| { | ||
| "latitude": 40.75376406311989, | ||
| "longitude": -73.98489005863667, | ||
| "address": "Times Square, NY, US", | ||
| }, | ||
| ) | ||
|
|
||
| with self.assertRaises(ValueError): | ||
| self.reverse_run( | ||
| { | ||
| "query": "40.75376406311989, -73.98489005863667", | ||
| "exactly_one": True, | ||
| "feature_code": 'ADM1' | ||
| }, | ||
| {}, | ||
| ) | ||
|
|
||
| loc = self._make_request( | ||
| self.geocoder.reverse, | ||
| **{ | ||
| "query": "40.75376406311989, -73.98489005863667", | ||
| "exactly_one": True, | ||
| "lang": 'ru' | ||
| } | ||
| ) | ||
| self.assertEqual(loc.raw['adminName1'], 'Нью-Йорк') | ||
|
|
||
| def test_find_nearby_json(self): | ||
| with self.assertRaises(ValueError): | ||
| self.reverse_run( | ||
| { | ||
| "query": "40.75376406311989, -73.98489005863667", | ||
| "exactly_one": True, | ||
| "find_nearby_type": 'findNearbyJSON', | ||
| "lang": 'en', | ||
| }, | ||
| {}, | ||
| ) | ||
|
|
||
| self.reverse_run( | ||
| { | ||
| "query": "40.75376406311989, -73.98489005863667", | ||
| "exactly_one": True, | ||
| "find_nearby_type": 'findNearbyJSON', | ||
| }, | ||
| { | ||
| "latitude": 40.75376406311989, | ||
| "longitude": -73.98489005863667, | ||
| "address": "Bryant Park Studios, NY, US", | ||
| }, | ||
| ) | ||
|
|
||
| self.reverse_run( | ||
| { | ||
| "query": "40.75376406311989, -73.98489005863667", | ||
| "exactly_one": True, | ||
| "find_nearby_type": 'findNearbyJSON', | ||
| "feature_code": "ADM1" | ||
| }, | ||
| { | ||
| "latitude": 40.16706, | ||
| "longitude": -74.49987, | ||
| }, | ||
| ) | ||
|
|
||
| def test_reverse_timezone(self): | ||
| self.reverse_timezone_run( | ||
| {"query": self.new_york_point}, | ||
| self.america_new_york, | ||
| ) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.