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 | if('ELODIE_APPLICATION_DIRECTORY' in os.environ): |
||
30 | del os.environ['ELODIE_APPLICATION_DIRECTORY'] |
||
31 | reload(constants) |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
32 | expected_path = '{}/.elodie'.format(os.path.expanduser('~')) |
||
33 | assert constants.application_directory == expected_path, constants.application_directory |
||
34 | |||
35 | def test_application_directory_override_invalid(): |
||
36 | os.environ['ELODIE_APPLICATION_DIRECTORY'] = '/foo/bar' |
||
37 | reload(constants) |
||
38 | directory_to_check = constants.application_directory |
||
39 | |||
40 | # reset |
||
41 | if('ELODIE_APPLICATION_DIRECTORY' in os.environ): |
||
42 | del os.environ['ELODIE_APPLICATION_DIRECTORY'] |
||
43 | reload(constants) |
||
44 | |||
45 | expected_path = '{}/.elodie'.format(os.path.expanduser('~')) |
||
46 | assert directory_to_check == expected_path, constants.application_directory |
||
47 | |||
48 | def test_application_directory_override_valid(): |
||
49 | cwd = os.getcwd() |
||
50 | os.environ['ELODIE_APPLICATION_DIRECTORY'] = cwd |
||
51 | reload(constants) |
||
52 | directory_to_check = constants.application_directory |
||
53 | hash_db_to_check = constants.hash_db |
||
54 | |||
55 | # reset |
||
56 | if('ELODIE_APPLICATION_DIRECTORY' in os.environ): |
||
57 | del os.environ['ELODIE_APPLICATION_DIRECTORY'] |
||
58 | reload(constants) |
||
59 | |||
60 | assert directory_to_check == cwd, constants.application_directory |
||
61 | assert cwd in hash_db_to_check, constants.hash_db |
||
62 | |||
63 | def test_hash_db(): |
||
64 | assert constants.hash_db == '{}/hash.json'.format(constants.application_directory), constants.hash_db |
||
65 | |||
66 | def test_location_db(): |
||
67 | assert constants.location_db == '{}/location.json'.format(constants.application_directory), constants.location_db |
||
68 | |||
69 | def test_script_directory(): |
||
70 | path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) |
||
71 | assert path == constants.script_directory, constants.script_directory |
||
72 | |||
73 | def test_exiftool_config(): |
||
74 | path = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) |
||
75 | assert '{}/configs/ExifTool_config'.format(path) == constants.exiftool_config, constants.exiftool_config |
||
76 | |||
77 | def test_mapquest_base_url_default(): |
||
78 | assert constants.mapquest_base_url == 'https://open.mapquestapi.com', constants.mapquest_base_url |
||
79 | |||
80 | def test_mapquest_base_url_override(): |
||
81 | os.environ['ELODIE_MAPQUEST_BASE_URL'] = 'foobar' |
||
82 | reload(constants) |
||
83 | url_to_check = constants.mapquest_base_url |
||
84 | |||
85 | # reset |
||
86 | if('ELODIE_MAPQUEST_BASE_URL' in os.environ): |
||
87 | del os.environ['ELODIE_MAPQUEST_BASE_URL'] |
||
88 | reload(constants) |
||
89 | |||
90 | assert url_to_check == 'foobar', constants.mapquest_base_url |
||
91 | |||
92 | def test_mapquest_key_default(): |
||
93 | if('ELODIE_MAPQUEST_KEY' in os.environ): |
||
94 | os.environ['ELODIE_MAPQUEST_KEY'] = None |
||
95 | reload(constants) |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
96 | assert constants.mapquest_key == None, constants.mapquest_key |
||
97 | |||
98 | def test_mapquest_key_override(): |
||
99 | os.environ['ELODIE_MAPQUEST_KEY'] = 'foobar' |
||
100 | reload(constants) |
||
101 | key_to_check = constants.mapquest_key |
||
102 | |||
103 | # reset |
||
104 | if('ELODIE_MAPQUEST_KEY' in os.environ): |
||
105 | del os.environ['ELODIE_MAPQUEST_KEY'] |
||
106 | reload(constants) |
||
107 | |||
108 | assert key_to_check == 'foobar', key_to_check |
||
109 | |||
110 | def test_accepted_language(): |
||
111 | assert constants.accepted_language == 'en', constants.accepted_language |
||
112 | |||
113 | def test_python_version(): |
||
114 | assert constants.python_version == sys.version_info.major, constants.python_version |
||
115 |