-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
98 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
[MapQuest] | ||
key=your-api-key-goes-here | ||
[Directory] | ||
dir=%Y-%m-%b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"""Load config file as a singleton.""" | ||
from configparser import RawConfigParser | ||
from os import path | ||
|
||
from elodie import constants | ||
|
||
config_file = '%s/config.ini' % constants.application_directory | ||
|
||
|
||
def load_config(): | ||
if hasattr(load_config, "config"): | ||
return load_config.config | ||
|
||
if not path.exists(config_file): | ||
return None | ||
|
||
load_config.config = RawConfigParser() | ||
load_config.config.read(config_file) | ||
return load_config.config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from __future__ import absolute_import | ||
# Project imports | ||
|
||
import os | ||
import sys | ||
import unittest | ||
|
||
from mock import patch | ||
|
||
sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))) | ||
|
||
from elodie import constants | ||
from elodie.config import load_config | ||
|
||
BASE_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) | ||
|
||
@patch('elodie.config.config_file', '%s/config.ini-sample' % BASE_PATH) | ||
def test_load_config_singleton_success(): | ||
config = load_config() | ||
assert config['MapQuest']['key'] == 'your-api-key-goes-here', config.get('MapQuest', 'key') | ||
config.set('MapQuest', 'key', 'new-value') | ||
|
||
config = load_config() | ||
assert config['MapQuest']['key'] == 'new-value', config.get('MapQuest', 'key') | ||
|
||
del load_config.config |