mirror of
https://github.com/jazzband/django-constance.git
synced 2026-03-16 22:40:24 +00:00
Merge pull request #645 from jazzband/fix/tests
This commit is contained in:
commit
6931c45c7b
2 changed files with 10 additions and 9 deletions
|
|
@ -70,8 +70,8 @@ class Command(BaseCommand):
|
|||
for k, v in get_values().items():
|
||||
self.stdout.write(f"{k}\t{v}", ending="\n")
|
||||
elif command == self.REMOVE_STALE_KEYS:
|
||||
prefix = getattr(settings, 'CONSTANCE_DATABASE_PREFIX', '')
|
||||
actual_keys = [f'{prefix}{key}' for key in settings.CONSTANCE_CONFIG]
|
||||
prefix = getattr(settings, "CONSTANCE_DATABASE_PREFIX", "")
|
||||
actual_keys = [f"{prefix}{key}" for key in settings.CONSTANCE_CONFIG]
|
||||
stale_records = Constance.objects.exclude(key__in=actual_keys)
|
||||
if stale_records:
|
||||
self.stdout.write("The following record will be deleted:", ending="\n")
|
||||
|
|
|
|||
|
|
@ -6,12 +6,13 @@ from textwrap import dedent
|
|||
from django.conf import settings
|
||||
from django.core.management import CommandError
|
||||
from django.core.management import call_command
|
||||
from django.test import TransactionTestCase, override_settings
|
||||
from django.test import TransactionTestCase
|
||||
from django.test import override_settings
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import smart_str
|
||||
|
||||
from constance.models import Constance
|
||||
from constance import config
|
||||
from constance.models import Constance
|
||||
|
||||
|
||||
class CliTestCase(TransactionTestCase):
|
||||
|
|
@ -51,12 +52,12 @@ class CliTestCase(TransactionTestCase):
|
|||
)
|
||||
|
||||
def test_get(self):
|
||||
call_command("constance", *("get EMAIL_VALUE".split()), stdout=self.out)
|
||||
call_command("constance", *(["get", "EMAIL_VALUE"]), stdout=self.out)
|
||||
|
||||
self.assertEqual(self.out.getvalue().strip(), "test@example.com")
|
||||
|
||||
def test_set(self):
|
||||
call_command("constance", *("set EMAIL_VALUE blah@example.com".split()), stdout=self.out)
|
||||
call_command("constance", *(["set", "EMAIL_VALUE", "blah@example.com"]), stdout=self.out)
|
||||
|
||||
self.assertEqual(config.EMAIL_VALUE, "blah@example.com")
|
||||
|
||||
|
|
@ -120,13 +121,13 @@ class CliTestCase(TransactionTestCase):
|
|||
self.assertEqual(Constance.objects.count(), initial_count, msg=self.out)
|
||||
|
||||
@override_settings(
|
||||
CONSTANCE_DATABASE_PREFIX='constance:',
|
||||
CONSTANCE_DATABASE_PREFIX="constance:",
|
||||
)
|
||||
def test_delete_stale_records_respects_prefix(self):
|
||||
self._populate_database_with_default_values()
|
||||
initial_count = Constance.objects.count()
|
||||
|
||||
call_command('constance', 'remove_stale_keys', stdout=self.out)
|
||||
call_command("constance", "remove_stale_keys", stdout=self.out)
|
||||
|
||||
self.assertEqual(Constance.objects.count(), initial_count, msg=self.out)
|
||||
|
||||
|
|
@ -136,4 +137,4 @@ class CliTestCase(TransactionTestCase):
|
|||
in settings since that's not done automatically at startup
|
||||
"""
|
||||
for key, (value, *_) in settings.CONSTANCE_CONFIG.items():
|
||||
Constance.objects.create(key=f'{getattr(settings, "CONSTANCE_DATABASE_PREFIX", "")}{key}', value=value)
|
||||
Constance.objects.create(key=f"{getattr(settings, 'CONSTANCE_DATABASE_PREFIX', '')}{key}", value=value)
|
||||
|
|
|
|||
Loading…
Reference in a new issue