parent
7fc5b5ffe0
commit
19be12b0bb
|
@ -9,13 +9,12 @@ from sys import version_info
|
||||||
debug = False
|
debug = False
|
||||||
|
|
||||||
#: Directory in which to store Elodie settings.
|
#: Directory in which to store Elodie settings.
|
||||||
|
application_directory = '{}/.elodie'.format(path.expanduser('~'))
|
||||||
if (
|
if (
|
||||||
'ELODIE_APPLICATION_DIRECTORY' in environ and
|
'ELODIE_APPLICATION_DIRECTORY' in environ and
|
||||||
path.isdir(environ['ELODIE_APPLICATION_DIRECTORY'])
|
path.isdir(environ['ELODIE_APPLICATION_DIRECTORY'])
|
||||||
):
|
):
|
||||||
application_directory = environ['ELODIE_APPLICATION_DIRECTORY']
|
application_directory = environ['ELODIE_APPLICATION_DIRECTORY']
|
||||||
else:
|
|
||||||
application_directory = '{}/.elodie'.format(path.expanduser('~'))
|
|
||||||
|
|
||||||
#: File in which to store details about media Elodie has seen.
|
#: File in which to store details about media Elodie has seen.
|
||||||
hash_db = '{}/hash.json'.format(application_directory)
|
hash_db = '{}/hash.json'.format(application_directory)
|
||||||
|
@ -29,6 +28,22 @@ script_directory = path.dirname(path.dirname(path.abspath(__file__)))
|
||||||
#: Path to Elodie's ExifTool config file.
|
#: Path to Elodie's ExifTool config file.
|
||||||
exiftool_config = path.join(script_directory, 'configs', 'ExifTool_config')
|
exiftool_config = path.join(script_directory, 'configs', 'ExifTool_config')
|
||||||
|
|
||||||
|
#: Path to MapQuest base URL
|
||||||
|
mapquest_base_url = 'https://open.mapquestapi.com'
|
||||||
|
if (
|
||||||
|
'ELODIE_MAPQUEST_BASE_URL' in environ and
|
||||||
|
environ['ELODIE_MAPQUEST_BASE_URL'] != ''
|
||||||
|
):
|
||||||
|
mapquest_base_url = environ['ELODIE_MAPQUEST_BASE_URL']
|
||||||
|
|
||||||
|
#: MapQuest key from environment
|
||||||
|
mapquest_key = None
|
||||||
|
if (
|
||||||
|
'ELODIE_MAPQUEST_KEY' in environ and
|
||||||
|
environ['ELODIE_MAPQUEST_KEY'] != ''
|
||||||
|
):
|
||||||
|
mapquest_key = environ['ELODIE_MAPQUEST_KEY']
|
||||||
|
|
||||||
#: Accepted language in responses from MapQuest
|
#: Accepted language in responses from MapQuest
|
||||||
accepted_language = 'en'
|
accepted_language = 'en'
|
||||||
|
|
||||||
|
|
|
@ -104,6 +104,10 @@ def get_key():
|
||||||
if __KEY__ is not None:
|
if __KEY__ is not None:
|
||||||
return __KEY__
|
return __KEY__
|
||||||
|
|
||||||
|
if constants.mapquest_key is not None:
|
||||||
|
__KEY__ = constants.mapquest_key
|
||||||
|
return __KEY__
|
||||||
|
|
||||||
config_file = '%s/config.ini' % constants.application_directory
|
config_file = '%s/config.ini' % constants.application_directory
|
||||||
if not path.exists(config_file):
|
if not path.exists(config_file):
|
||||||
return None
|
return None
|
||||||
|
@ -197,7 +201,8 @@ def lookup(**kwargs):
|
||||||
path = '/geocoding/v1/address'
|
path = '/geocoding/v1/address'
|
||||||
if('lat' in kwargs and 'lon' in kwargs):
|
if('lat' in kwargs and 'lon' in kwargs):
|
||||||
path = '/nominatim/v1/reverse.php'
|
path = '/nominatim/v1/reverse.php'
|
||||||
url = 'https://open.mapquestapi.com%s?%s' % (
|
url = '%s%s?%s' % (
|
||||||
|
constants.mapquest_base_url,
|
||||||
path,
|
path,
|
||||||
urllib.parse.urlencode(params)
|
urllib.parse.urlencode(params)
|
||||||
)
|
)
|
||||||
|
|
|
@ -26,28 +26,36 @@ def test_debug():
|
||||||
assert constants.debug == constants.debug, constants.debug
|
assert constants.debug == constants.debug, constants.debug
|
||||||
|
|
||||||
def test_application_directory_default():
|
def test_application_directory_default():
|
||||||
reload(constants)
|
|
||||||
expected_path = '{}/.elodie'.format(os.path.expanduser('~'))
|
expected_path = '{}/.elodie'.format(os.path.expanduser('~'))
|
||||||
assert constants.application_directory == expected_path, constants.application_directory
|
assert constants.application_directory == expected_path, constants.application_directory
|
||||||
|
|
||||||
def test_application_directory_override_invalid():
|
def test_application_directory_override_invalid():
|
||||||
os.environ['ELODIE_APPLICATION_DIRECTORY'] = '/foo/bar'
|
os.environ['ELODIE_APPLICATION_DIRECTORY'] = '/foo/bar'
|
||||||
reload(constants)
|
reload(constants)
|
||||||
|
directory_to_check = constants.application_directory
|
||||||
|
|
||||||
|
# reset
|
||||||
|
os.environ['ELODIE_APPLICATION_DIRECTORY'] = ''
|
||||||
|
reload(constants)
|
||||||
|
|
||||||
expected_path = '{}/.elodie'.format(os.path.expanduser('~'))
|
expected_path = '{}/.elodie'.format(os.path.expanduser('~'))
|
||||||
assert constants.application_directory == expected_path, constants.application_directory
|
assert directory_to_check == expected_path, constants.application_directory
|
||||||
|
|
||||||
def test_application_directory_override_valid():
|
def test_application_directory_override_valid():
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
os.environ['ELODIE_APPLICATION_DIRECTORY'] = cwd
|
os.environ['ELODIE_APPLICATION_DIRECTORY'] = cwd
|
||||||
reload(constants)
|
reload(constants)
|
||||||
|
directory_to_check = constants.application_directory
|
||||||
|
hash_db_to_check = constants.hash_db
|
||||||
|
|
||||||
assert constants.application_directory == cwd, constants.application_directory
|
# reset
|
||||||
assert cwd in constants.hash_db, constants.hash_db
|
|
||||||
|
|
||||||
# must come after test_application_directory_override_valid due to env var reset
|
|
||||||
def test_hash_db():
|
|
||||||
os.environ['ELODIE_APPLICATION_DIRECTORY'] = ''
|
os.environ['ELODIE_APPLICATION_DIRECTORY'] = ''
|
||||||
reload(constants)
|
reload(constants)
|
||||||
|
|
||||||
|
assert directory_to_check == cwd, constants.application_directory
|
||||||
|
assert cwd in hash_db_to_check, constants.hash_db
|
||||||
|
|
||||||
|
def test_hash_db():
|
||||||
assert constants.hash_db == '{}/hash.json'.format(constants.application_directory), constants.hash_db
|
assert constants.hash_db == '{}/hash.json'.format(constants.application_directory), constants.hash_db
|
||||||
|
|
||||||
def test_location_db():
|
def test_location_db():
|
||||||
|
@ -61,6 +69,34 @@ def test_exiftool_config():
|
||||||
path = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
|
path = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
|
||||||
assert '{}/configs/ExifTool_config'.format(path) == constants.exiftool_config, constants.exiftool_config
|
assert '{}/configs/ExifTool_config'.format(path) == constants.exiftool_config, constants.exiftool_config
|
||||||
|
|
||||||
|
def test_mapquest_base_url_default():
|
||||||
|
assert constants.mapquest_base_url == 'https://open.mapquestapi.com', constants.mapquest_base_url
|
||||||
|
|
||||||
|
def test_mapquest_base_url_override():
|
||||||
|
os.environ['ELODIE_MAPQUEST_BASE_URL'] = 'foobar'
|
||||||
|
reload(constants)
|
||||||
|
url_to_check = constants.mapquest_base_url
|
||||||
|
|
||||||
|
# reset
|
||||||
|
os.environ['ELODIE_MAPQUEST_BASE_URL'] = ''
|
||||||
|
reload(constants)
|
||||||
|
|
||||||
|
assert url_to_check == 'foobar', constants.mapquest_base_url
|
||||||
|
|
||||||
|
def test_mapquest_Key():
|
||||||
|
assert constants.mapquest_key == None, constants.mapquest_key
|
||||||
|
|
||||||
|
def test_mapquest_key_override():
|
||||||
|
os.environ['ELODIE_MAPQUEST_KEY'] = 'foobar'
|
||||||
|
reload(constants)
|
||||||
|
key_to_check = constants.mapquest_key
|
||||||
|
|
||||||
|
# reset
|
||||||
|
os.environ['ELODIE_MAPQUEST_KEY'] = ''
|
||||||
|
reload(constants)
|
||||||
|
|
||||||
|
assert key_to_check == 'foobar', constants.mapquest_key
|
||||||
|
|
||||||
def test_accepted_language():
|
def test_accepted_language():
|
||||||
assert constants.accepted_language == 'en', constants.accepted_language
|
assert constants.accepted_language == 'en', constants.accepted_language
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue