Skip to content

Commit

Permalink
Merge pull request #138 from jmathai/skip-location-gh-136
Browse files Browse the repository at this point in the history
gh-136 Skip geolocation lookup if no key is found
  • Loading branch information
jmathai committed Oct 8, 2016
2 parents 83b3e57 + 051961d commit a467ae9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions elodie.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def import_file(_file, destination, album_from_folder, trash, allow_duplicates):
help='Import the file even if it\'s already been imported.')
@click.argument('paths', nargs=-1, type=click.Path())
def _import(destination, source, file, album_from_folder, trash, paths, allow_duplicates):
"""Import files or directories.
"""Import files or directories by reading their EXIF and organizing them accordingly.
"""
destination = os.path.expanduser(destination)

Expand Down Expand Up @@ -148,7 +148,7 @@ def update_time(media, file_path, time_string):
@click.argument('files', nargs=-1, type=click.Path(dir_okay=False),
required=True)
def _update(album, location, time, title, files):
"""Update files.
"""Update a file's EXIF. Automatically modifies the file's location and file name accordingly.
"""
for file_path in files:
if not os.path.exists(file_path):
Expand Down
6 changes: 6 additions & 0 deletions elodie/geolocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ def reverse_lookup(lat, lon):

key = get_key()

if(key is None):
return None

try:
params = {'format': 'json', 'key': key, 'lat': lat, 'lon': lon}
headers = {"Accept-Language": constants.accepted_language}
Expand All @@ -178,6 +181,9 @@ def lookup(name):

key = get_key()

if(key is None):
return None

try:
params = {'format': 'json', 'key': key, 'location': name}
if(constants.debug is True):
Expand Down
13 changes: 13 additions & 0 deletions elodie/tests/geolocation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import random
import re
import sys
from mock import patch

sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))))

Expand Down Expand Up @@ -81,7 +82,19 @@ def test_reverse_lookup_with_invalid_key():
res = geolocation.reverse_lookup(123.45, 123.45)
assert res is None, res

@patch('elodie.geolocation.constants')
def test_reverse_lookup_with_no_key(mock_constants):
mock_constants.application_directory = 'invalid path'
res = geolocation.reverse_lookup(123.45, 123.45)
assert res is None, res

def test_lookup_with_invalid_key():
geolocation.__KEY__ = 'invalid_key'
res = geolocation.lookup('foo')
assert res is None, res

@patch('elodie.geolocation.constants')
def test_lookup_with_no_key(mock_constants):
mock_constants.application_directory = 'invalid path'
res = geolocation.lookup('foo')
assert res is None, res

0 comments on commit a467ae9

Please sign in to comment.