Skip to content

Commit

Permalink
Fix bug when retrieving/setting default settings values
Browse files Browse the repository at this point in the history
  • Loading branch information
shacker committed Jun 4, 2019
1 parent caed3b3 commit 21e0c6d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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 = "/"
Expand Down
2 changes: 1 addition & 1 deletion todo/__init__.py
Original file line number Diff line number Diff line change
@@ -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__ = "[email protected]"
Expand Down
8 changes: 6 additions & 2 deletions todo/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"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
Expand All @@ -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
28 changes: 24 additions & 4 deletions todo/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -56,5 +55,26 @@ def test_send_email_to_thread_participants(todo_setup, django_user_model, email_
assert "[email protected]" 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

0 comments on commit 21e0c6d

Please sign in to comment.