Skip to content

Commit

Permalink
👌 [#310] fix config util
Browse files Browse the repository at this point in the history
  • Loading branch information
annashamray committed Nov 22, 2022
1 parent 771ed91 commit c8ccd3d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Empty file.
15 changes: 15 additions & 0 deletions src/objects/conf/tests/test_config_helper.py
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"])
2 changes: 2 additions & 0 deletions src/objects/conf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def config(option: str, default=undefined, *args, **kwargs):
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))
Expand Down

0 comments on commit c8ccd3d

Please sign in to comment.