Skip to content

Commit

Permalink
Create and test UserSettingsHolder
Browse files Browse the repository at this point in the history
  • Loading branch information
rougeth committed Sep 12, 2018
1 parent 40a9760 commit 0cfd99d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions bottery/conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,12 @@ def __getattr__(self, name):
return getattr(self._wrapped, name)


class UserSettingsHolder:
def __init__(self, defaut_settings):
for key in dir(defaut_settings):
if key.isupper():
value = getattr(defaut_settings, key)
setattr(self, key, deepcopy(value))


settings = LazySettings()
15 changes: 14 additions & 1 deletion tests/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from bottery.conf import Settings, lazy_obj_method
from bottery.conf import Settings, UserSettingsHolder, lazy_obj_method


@pytest.mark.parametrize('wrapped,expected_result', (
Expand Down Expand Up @@ -74,3 +74,16 @@ def test_settings_import_settings(mock_import_module):
settings.import_settings()

assert settings.DEBUG


def test_usersettingsholder():
templates = []
default_settings = type('Settings', (), {
'TEMPLATES': templates,
'anotherconf': True,
})

settings = UserSettingsHolder(default_settings)
assert settings.TEMPLATES == templates
assert id(settings.TEMPLATES) != id(templates)
assert not hasattr(settings, 'anotherconf')

0 comments on commit 0cfd99d

Please sign in to comment.