Fix bug when retrieving/setting default settings values

This commit is contained in:
Scot Hacker 2019-06-04 00:31:00 -07:00
parent caed3b384d
commit 21e0c6d656
5 changed files with 35 additions and 8 deletions

View file

@ -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

View file

@ -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 = "/"

View file

@ -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"

View file

@ -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

View file

@ -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