1
|
|
|
from __future__ import absolute_import |
2
|
|
|
# Project imports |
3
|
|
|
|
4
|
|
|
import os |
5
|
|
|
import sys |
6
|
|
|
import unittest |
7
|
|
|
|
8
|
|
|
try: |
9
|
|
|
reload # Python 2.7 |
|
|
|
|
10
|
|
|
except NameError: |
11
|
|
|
try: |
12
|
|
|
from importlib import reload # Python 3.4+ |
13
|
|
|
except ImportError: |
14
|
|
|
from imp import reload # Python 3.0 - 3.3 |
15
|
|
|
|
16
|
|
|
from mock import patch |
17
|
|
|
|
18
|
|
|
sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))) |
19
|
|
|
|
20
|
|
|
from elodie import constants |
21
|
|
|
|
22
|
|
|
BASE_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) |
23
|
|
|
|
24
|
|
|
def test_debug(): |
25
|
|
|
# This seems pointless but on Travis we explicitly modify the file to be True |
26
|
|
|
assert constants.debug == constants.debug, constants.debug |
27
|
|
|
|
28
|
|
|
def test_application_directory_default(): |
29
|
|
|
expected_path = '{}/.elodie'.format(os.path.expanduser('~')) |
30
|
|
|
assert constants.application_directory == expected_path, constants.application_directory |
31
|
|
|
|
32
|
|
|
def test_application_directory_override_invalid(): |
33
|
|
|
os.environ['ELODIE_APPLICATION_DIRECTORY'] = '/foo/bar' |
34
|
|
|
reload(constants) |
|
|
|
|
35
|
|
|
directory_to_check = constants.application_directory |
36
|
|
|
|
37
|
|
|
# reset |
38
|
|
|
os.environ['ELODIE_APPLICATION_DIRECTORY'] = '' |
39
|
|
|
reload(constants) |
40
|
|
|
|
41
|
|
|
expected_path = '{}/.elodie'.format(os.path.expanduser('~')) |
42
|
|
|
assert directory_to_check == expected_path, constants.application_directory |
43
|
|
|
|
44
|
|
|
def test_application_directory_override_valid(): |
45
|
|
|
cwd = os.getcwd() |
46
|
|
|
os.environ['ELODIE_APPLICATION_DIRECTORY'] = cwd |
47
|
|
|
reload(constants) |
|
|
|
|
48
|
|
|
directory_to_check = constants.application_directory |
49
|
|
|
hash_db_to_check = constants.hash_db |
50
|
|
|
|
51
|
|
|
# reset |
52
|
|
|
os.environ['ELODIE_APPLICATION_DIRECTORY'] = '' |
53
|
|
|
reload(constants) |
54
|
|
|
|
55
|
|
|
assert directory_to_check == cwd, constants.application_directory |
56
|
|
|
assert cwd in hash_db_to_check, constants.hash_db |
57
|
|
|
|
58
|
|
|
def test_hash_db(): |
59
|
|
|
assert constants.hash_db == '{}/hash.json'.format(constants.application_directory), constants.hash_db |
60
|
|
|
|
61
|
|
|
def test_location_db(): |
62
|
|
|
assert constants.location_db == '{}/location.json'.format(constants.application_directory), constants.location_db |
63
|
|
|
|
64
|
|
|
def test_script_directory(): |
65
|
|
|
path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) |
66
|
|
|
assert path == constants.script_directory, constants.script_directory |
67
|
|
|
|
68
|
|
|
def test_exiftool_config(): |
69
|
|
|
path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) |
70
|
|
|
assert '{}/configs/ExifTool_config'.format(path) == constants.exiftool_config, constants.exiftool_config |
71
|
|
|
|
72
|
|
|
def test_mapquest_base_url_default(): |
73
|
|
|
assert constants.mapquest_base_url == 'https://open.mapquestapi.com', constants.mapquest_base_url |
74
|
|
|
|
75
|
|
|
def test_mapquest_base_url_override(): |
76
|
|
|
os.environ['ELODIE_MAPQUEST_BASE_URL'] = 'foobar' |
77
|
|
|
reload(constants) |
|
|
|
|
78
|
|
|
url_to_check = constants.mapquest_base_url |
79
|
|
|
|
80
|
|
|
# reset |
81
|
|
|
os.environ['ELODIE_MAPQUEST_BASE_URL'] = '' |
82
|
|
|
reload(constants) |
83
|
|
|
|
84
|
|
|
assert url_to_check == 'foobar', constants.mapquest_base_url |
85
|
|
|
|
86
|
|
|
def test_mapquest_Key(): |
87
|
|
|
assert constants.mapquest_key == None, constants.mapquest_key |
88
|
|
|
|
89
|
|
|
def test_mapquest_key_override(): |
90
|
|
|
os.environ['ELODIE_MAPQUEST_KEY'] = 'foobar' |
91
|
|
|
reload(constants) |
|
|
|
|
92
|
|
|
key_to_check = constants.mapquest_key |
93
|
|
|
|
94
|
|
|
# reset |
95
|
|
|
os.environ['ELODIE_MAPQUEST_KEY'] = '' |
96
|
|
|
reload(constants) |
97
|
|
|
|
98
|
|
|
assert key_to_check == 'foobar', constants.mapquest_key |
99
|
|
|
|
100
|
|
|
def test_accepted_language(): |
101
|
|
|
assert constants.accepted_language == 'en', constants.accepted_language |
102
|
|
|
|
103
|
|
|
def test_python_version(): |
104
|
|
|
assert constants.python_version == sys.version_info.major, constants.python_version |
105
|
|
|
|