def test_preference_order_match_register_call(self): expected = [ 'registration_allowed', 'max_users', 'items_per_page', 'featured_entry', ] self.assertEqual([p.name for p in global_preferences_registry.preferences()][:4], expected)
def test_preference_order_match_register_call(self): expected = [ 'registration_allowed', 'max_users', 'items_per_page', 'featured_entry', ] self.assertEqual([ p.name for p in global_preferences_registry.preferences() ][:4], expected)
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)
def test_can_list_preferences(self): manager = registry.manager() url = reverse('api:global-list') self.client.login(username='******', password="******") response = self.client.get(url) self.assertEqual(response.status_code, 200) payload = json.loads(response.content.decode('utf-8')) self.assertEqual(len(payload), len(registry.preferences())) for e in payload: pref = manager.get_db_pref(section=e['section'], name=e['name']) serializer = serializers.GlobalPreferenceSerializer(pref) self.assertEqual(pref.preference.identifier(), e['identifier'])