diff --git a/README.md b/README.md index 3f89792..10b6536 100644 --- a/README.md +++ b/README.md @@ -300,6 +300,10 @@ django-todo uses pytest exclusively for testing. The best way to run the suite i ## Version History +**2.4.8** Fix bug when setting default values for unspecified settings + +**2.4.7** Support custom user model in external_add + **2.4.6** Use `defaults` hash for default settings, update perms and tests **2.4.5** Re-enable "notify" feature during task edit diff --git a/test_settings.py b/test_settings.py index 4cb22ce..9180bdb 100644 --- a/test_settings.py +++ b/test_settings.py @@ -7,7 +7,6 @@ DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3"}} EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" # Document -TODO_STAFF_ONLY = False TODO_DEFAULT_LIST_SLUG = "tickets" TODO_DEFAULT_ASSIGNEE = None TODO_PUBLIC_SUBMIT_REDIRECT = "/" diff --git a/todo/__init__.py b/todo/__init__.py index 7139c3b..9a57202 100644 --- a/todo/__init__.py +++ b/todo/__init__.py @@ -1,7 +1,7 @@ """ A multi-user, multi-group task management and assignment system for Django. """ -__version__ = "2.4.6" +__version__ = "2.4.8" __author__ = "Scot Hacker" __email__ = "shacker@birdhouse.org" diff --git a/todo/defaults.py b/todo/defaults.py index bc1a385..898fd5d 100644 --- a/todo/defaults.py +++ b/todo/defaults.py @@ -11,7 +11,7 @@ hash = { "TODO_STAFF_ONLY": True, } -# These intentionally have no defaults (user MUST set a value): +# These intentionally have no defaults (user MUST set a value if their features are used): # TODO_DEFAULT_LIST_SLUG # TODO_MAIL_BACKENDS # TODO_MAIL_TRACKERS @@ -21,4 +21,8 @@ def defaults(key: str): """Try to get a setting from project settings. If empty or doesn't exist, fall back to a value from defaults hash.""" - return getattr(settings, key, False) or hash.get(key) + if hasattr(settings, key): + val = getattr(settings, key) + else: + val = hash.get(key) + return val diff --git a/todo/tests/test_utils.py b/todo/tests/test_utils.py index cf26a38..80a79aa 100644 --- a/todo/tests/test_utils.py +++ b/todo/tests/test_utils.py @@ -1,9 +1,8 @@ -import pytest - from django.core import mail -from todo.models import Task, Comment -from todo.utils import send_notify_mail, send_email_to_thread_participants +from todo.defaults import defaults +from todo.models import Comment, Task +from todo.utils import send_email_to_thread_participants, send_notify_mail def test_send_notify_mail_not_me(todo_setup, django_user_model, email_backend_setup): @@ -56,5 +55,26 @@ def test_send_email_to_thread_participants(todo_setup, django_user_model, email_ assert "u4@example.com" in mail.outbox[0].recipients() +def test_defaults(settings): + """todo's `defaults` module provides reasonable default values for unspecified settings. + If a value is NOT set, it should be pulled from the hash in defaults.py. + If a value IS set, it should be respected. + n.b. TODO_STAFF_ONLY which defaults to True in the `defaults` module.""" + + key = "TODO_STAFF_ONLY" + + # Setting is not set, and should default to True (the value in defaults.py) + assert not hasattr(settings, key) + assert defaults(key) + + # Setting is already set to True and should be respected. + settings.TODO_STAFF_ONLY = True + assert defaults(key) + + # Setting is already set to False and should be respected. + settings.TODO_STAFF_ONLY = False + assert not defaults(key) + + # FIXME: Add tests for: # Attachments: Test whether allowed, test multiple, test extensions