-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #312 from maykinmedia/feature/conf-env
Environment config for Sentry
- Loading branch information
Showing
8 changed files
with
90 additions
and
137 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
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
Empty file.
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,15 @@ | ||
from django.test import SimpleTestCase | ||
|
||
from ..utils import config | ||
|
||
|
||
class ConfigHelperTests(SimpleTestCase): | ||
def test_empty_list_as_default(self): | ||
value = config("SOME_TEST_ENVVAR", split=True, default=[]) | ||
|
||
self.assertEqual(value, []) | ||
|
||
def test_non_empty_list_as_default(self): | ||
value = config("SOME_TEST_ENVVAR", split=True, default=["foo"]) | ||
|
||
self.assertEqual(value, ["foo"]) |
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 @@ | ||
import logging | ||
|
||
from decouple import Csv, config as _config, undefined | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def config(option: str, default=undefined, *args, **kwargs): | ||
""" | ||
Pull a config parameter from the environment. | ||
Read the config variable ``option``. If it's optional, use the ``default`` value. | ||
Input is automatically cast to the correct type, where the type is derived from the | ||
default value if possible. | ||
Pass ``split=True`` to split the comma-separated input into a list. | ||
""" | ||
if "split" in kwargs: | ||
kwargs.pop("split") | ||
kwargs["cast"] = Csv() | ||
if isinstance(default, list): | ||
default = ",".join(default) | ||
|
||
if default is not undefined and default is not None: | ||
kwargs.setdefault("cast", type(default)) | ||
return _config(option, default=default, *args, **kwargs) |