gh-136 Skip geolocation lookup if no key is found
This commit is contained in:
		
							parent
							
								
									83b3e576ae
								
							
						
					
					
						commit
						051961db70
					
				| @ -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.') |               help='Import the file even if it\'s already been imported.') | ||||||
| @click.argument('paths', nargs=-1, type=click.Path()) | @click.argument('paths', nargs=-1, type=click.Path()) | ||||||
| def _import(destination, source, file, album_from_folder, trash, paths, allow_duplicates): | 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) |     destination = os.path.expanduser(destination) | ||||||
| 
 | 
 | ||||||
| @ -148,7 +148,7 @@ def update_time(media, file_path, time_string): | |||||||
| @click.argument('files', nargs=-1, type=click.Path(dir_okay=False), | @click.argument('files', nargs=-1, type=click.Path(dir_okay=False), | ||||||
|                 required=True) |                 required=True) | ||||||
| def _update(album, location, time, title, files): | 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: |     for file_path in files: | ||||||
|         if not os.path.exists(file_path): |         if not os.path.exists(file_path): | ||||||
|  | |||||||
| @ -153,6 +153,9 @@ def reverse_lookup(lat, lon): | |||||||
| 
 | 
 | ||||||
|     key = get_key() |     key = get_key() | ||||||
| 
 | 
 | ||||||
|  |     if(key is None): | ||||||
|  |         return None | ||||||
|  | 
 | ||||||
|     try: |     try: | ||||||
|         params = {'format': 'json', 'key': key, 'lat': lat, 'lon': lon} |         params = {'format': 'json', 'key': key, 'lat': lat, 'lon': lon} | ||||||
|         headers = {"Accept-Language": constants.accepted_language} |         headers = {"Accept-Language": constants.accepted_language} | ||||||
| @ -178,6 +181,9 @@ def lookup(name): | |||||||
| 
 | 
 | ||||||
|     key = get_key() |     key = get_key() | ||||||
| 
 | 
 | ||||||
|  |     if(key is None): | ||||||
|  |         return None | ||||||
|  | 
 | ||||||
|     try: |     try: | ||||||
|         params = {'format': 'json', 'key': key, 'location': name} |         params = {'format': 'json', 'key': key, 'location': name} | ||||||
|         if(constants.debug is True): |         if(constants.debug is True): | ||||||
|  | |||||||
| @ -7,6 +7,7 @@ import os | |||||||
| import random | import random | ||||||
| import re | import re | ||||||
| import sys | 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__)))))) | sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))) | ||||||
| 
 | 
 | ||||||
| @ -81,7 +82,19 @@ def test_reverse_lookup_with_invalid_key(): | |||||||
|     res = geolocation.reverse_lookup(123.45, 123.45) |     res = geolocation.reverse_lookup(123.45, 123.45) | ||||||
|     assert res is None, res |     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(): | def test_lookup_with_invalid_key(): | ||||||
|     geolocation.__KEY__ = 'invalid_key' |     geolocation.__KEY__ = 'invalid_key' | ||||||
|     res = geolocation.lookup('foo') |     res = geolocation.lookup('foo') | ||||||
|     assert res is None, res |     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 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Jaisen Mathai
						Jaisen Mathai