Ejemplo n.º 1
0
 def test_can_autodiscover_multiple_times(self):
     autodiscover()
     self.assertEqual(len(global_preferences_registry.preferences()), 7)
     self.assertEqual(len(user_preferences_registry.preferences()), 7)
     autodiscover()
     self.assertEqual(len(global_preferences_registry.preferences()), 7)
     self.assertEqual(len(user_preferences_registry.preferences()), 7)
Ejemplo n.º 2
0
    def test_can_autodiscover_site_preferences(self):
        clear()
        with self.assertRaises(KeyError):
            site_preferences_registry.preferences(section='test')
        autodiscover(force_reload=True)

        self.assertEqual(len(site_preferences_registry.preferences(section='test')), 4)
Ejemplo n.º 3
0
 def test_can_autodiscover_multiple_times(self):
     autodiscover()
     self.assertEqual(len(global_preferences_registry.preferences()), 8)
     self.assertEqual(len(user_preferences_registry.preferences()), 6)
     autodiscover()
     self.assertEqual(len(global_preferences_registry.preferences()), 8)
     self.assertEqual(len(user_preferences_registry.preferences()), 6)
Ejemplo n.º 4
0
    def test_can_autodiscover_user_preferences(self):

        clear()
        with self.assertRaises(KeyError):
            user_preferences_registry.preferences(section="test")

        autodiscover(force_reload=True)

        self.assertEqual(len(user_preferences_registry.preferences(section="test")), 4)
    def handle(self, *args, **options):
        autodiscover()
        deleted = delete_preferences(GlobalPreferenceModel.objects.all())
        print "Deleted %s global preference models : %s" % \
            (len(deleted), ", ".join(['Section: %s - Name: %s' % (p.section, p.name) for p in deleted]))

        deleted = delete_preferences(UserPreferenceModel.objects.all())
        print "Deleted %s user preference models : %s" % \
            (len(deleted), ", ".join(['Section: %s - Name: %s' % (p.section, p.name) for p in deleted]))

        deleted = delete_preferences(SitePreferenceModel.objects.all())
        print "Deleted %s site preference models : %s" % \
            (len(deleted), ", ".join(['Section: %s - Name: %s' % (p.section, p.name) for p in deleted]))

        # Create needed preferences
        # Global
        preferences = global_preferences_registry.preferences()
        for p in preferences:
            p.to_model(**{"help": p.help})
        print 'Created/updated %s default global preferences' % len(
            preferences)

        # User
        preferences = user_preferences_registry.preferences()
        try:
            from django.contrib.auth import get_user_model
        except ImportError:  # django < 1.5
            from django.contrib.auth.models import User
        else:
            User = get_user_model()
        users = list(User.objects.all())
        for user in users:
            for p in preferences:
                p.to_model(user=user, **{"help": p.help})
        print 'Created/updated default preferences for %s users' % len(users)

        # Site
        preferences = site_preferences_registry.preferences()
        try:
            site = Site.objects.get(pk=1)
        except Site.DoesNotExist:
            print 'Cannot create default preference for first site. Please create add at least one site in your ' \
                  'database.'
            site = None
        if site is not None:
            for p in preferences:
                p.to_model(site=site, **{"help": p.help})
            print 'Created/updated %s default preferences for first site' % len(
                preferences)
Ejemplo n.º 6
0
                'level': 'DEBUG',
                'class': 'logging.StreamHandler',
                'formatter': 'simple'
            },
        },
        'loggers': {
            'django.request': {
                'handlers': ['console'],
                'propagate': True,
                'level': 'DEBUG',
            },
        },
    },
    TESTING=True,
    TEST_RUNNER='django_nose.NoseTestSuiteRunner',
)

django.setup()
call_command('syncdb', verbosity=1, interactive=False)
autodiscover()

# ---- app start
verbosity = 2 if '-v' in sys.argv else 1

TestRunner = get_runner(settings)  # DjangoTestSuiteRunner
runner = TestRunner(verbosity=verbosity, interactive=True, failfast=False)
failures = runner.run_tests(['tests'])

if failures:
    sys.exit(bool(failures))
Ejemplo n.º 7
0
# !/usr/bin/env python
# encoding:UTF-8

from django.conf.urls import include, url
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.conf import settings
from dynamic_preferences.registries import autodiscover

admin.autodiscover()

urlpatterns = i18n_patterns(
    '',
    url(r'^$', 'example.views.home', name='home'),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^preferences/', include('dynamic_preferences.urls')),
    url(r'^(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
)

autodiscover(True)