mirror of
https://github.com/jazzband/django-constance.git
synced 2026-03-16 22:40:24 +00:00
More py3k changes.
This commit is contained in:
parent
89b423fa65
commit
36a9c23500
7 changed files with 48 additions and 46 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import itertools
|
||||
from six.moves import zip
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ class RedisBackend(Backend):
|
|||
if not keys:
|
||||
return
|
||||
prefixed_keys = [self.add_prefix(key) for key in keys]
|
||||
for key, value in itertools.izip(keys, self._rd.mget(prefixed_keys)):
|
||||
for key, value in zip(keys, self._rd.mget(prefixed_keys)):
|
||||
if value:
|
||||
yield key, loads(value)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
import os
|
||||
import six
|
||||
from datetime import datetime, date, time
|
||||
from decimal import Decimal
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
import sys
|
||||
import six
|
||||
from datetime import datetime, date, time
|
||||
from decimal import Decimal
|
||||
|
||||
if six.PY3:
|
||||
def long(value):
|
||||
return value
|
||||
|
||||
|
||||
class StorageTestsMixin(object):
|
||||
|
||||
|
|
@ -10,23 +15,23 @@ class StorageTestsMixin(object):
|
|||
# read defaults
|
||||
del sys.modules['constance']
|
||||
from constance import config
|
||||
self.assertEquals(config.INT_VALUE, 1)
|
||||
self.assertEquals(config.LONG_VALUE, 123456L)
|
||||
self.assertEquals(config.BOOL_VALUE, True)
|
||||
self.assertEquals(config.STRING_VALUE, 'Hello world')
|
||||
self.assertEquals(config.UNICODE_VALUE, u'Rivi\xe8re-Bonjour')
|
||||
self.assertEquals(config.DECIMAL_VALUE, Decimal('0.1'))
|
||||
self.assertEquals(config.DATETIME_VALUE, datetime(2010, 8, 23, 11, 29, 24))
|
||||
self.assertEquals(config.FLOAT_VALUE, 3.1415926536)
|
||||
self.assertEquals(config.DATE_VALUE, date(2010, 12, 24))
|
||||
self.assertEquals(config.TIME_VALUE, time(23, 59, 59))
|
||||
self.assertEqual(config.INT_VALUE, 1)
|
||||
self.assertEqual(config.LONG_VALUE, long(123456))
|
||||
self.assertEqual(config.BOOL_VALUE, True)
|
||||
self.assertEqual(config.STRING_VALUE, 'Hello world')
|
||||
self.assertEqual(config.UNICODE_VALUE, u'Rivi\xe8re-Bonjour')
|
||||
self.assertEqual(config.DECIMAL_VALUE, Decimal('0.1'))
|
||||
self.assertEqual(config.DATETIME_VALUE, datetime(2010, 8, 23, 11, 29, 24))
|
||||
self.assertEqual(config.FLOAT_VALUE, 3.1415926536)
|
||||
self.assertEqual(config.DATE_VALUE, date(2010, 12, 24))
|
||||
self.assertEqual(config.TIME_VALUE, time(23, 59, 59))
|
||||
|
||||
# set values
|
||||
config.INT_VALUE = 100
|
||||
config.LONG_VALUE = 654321L
|
||||
config.LONG_VALUE = long(654321)
|
||||
config.BOOL_VALUE = False
|
||||
config.STRING_VALUE = 'Beware the weeping angel'
|
||||
config.UNICODE_VALUE = 'Québec'.decode('utf-8')
|
||||
config.UNICODE_VALUE = six.u('Québec')
|
||||
config.DECIMAL_VALUE = Decimal('1.2')
|
||||
config.DATETIME_VALUE = datetime(1977, 10, 2)
|
||||
config.FLOAT_VALUE = 2.718281845905
|
||||
|
|
@ -34,50 +39,48 @@ class StorageTestsMixin(object):
|
|||
config.TIME_VALUE = time(1, 59, 0)
|
||||
|
||||
# read again
|
||||
self.assertEquals(config.INT_VALUE, 100)
|
||||
self.assertEquals(config.LONG_VALUE, 654321L)
|
||||
self.assertEquals(config.BOOL_VALUE, False)
|
||||
self.assertEquals(config.STRING_VALUE, 'Beware the weeping angel')
|
||||
self.assertEquals(config.UNICODE_VALUE, 'Québec'.decode('utf-8'))
|
||||
self.assertEquals(config.DECIMAL_VALUE, Decimal('1.2'))
|
||||
self.assertEquals(config.DATETIME_VALUE, datetime(1977, 10, 2))
|
||||
self.assertEquals(config.FLOAT_VALUE, 2.718281845905)
|
||||
self.assertEquals(config.DATE_VALUE, date(2001, 12, 20))
|
||||
self.assertEquals(config.TIME_VALUE, time(1, 59, 0))
|
||||
self.assertEqual(config.INT_VALUE, 100)
|
||||
self.assertEqual(config.LONG_VALUE, long(654321))
|
||||
self.assertEqual(config.BOOL_VALUE, False)
|
||||
self.assertEqual(config.STRING_VALUE, 'Beware the weeping angel')
|
||||
self.assertEqual(config.UNICODE_VALUE, six.u('Québec'))
|
||||
self.assertEqual(config.DECIMAL_VALUE, Decimal('1.2'))
|
||||
self.assertEqual(config.DATETIME_VALUE, datetime(1977, 10, 2))
|
||||
self.assertEqual(config.FLOAT_VALUE, 2.718281845905)
|
||||
self.assertEqual(config.DATE_VALUE, date(2001, 12, 20))
|
||||
self.assertEqual(config.TIME_VALUE, time(1, 59, 0))
|
||||
|
||||
def test_nonexistent(self):
|
||||
from constance import config
|
||||
try:
|
||||
config.NON_EXISTENT
|
||||
except Exception as e:
|
||||
pass
|
||||
self.assertEquals(type(e), AttributeError)
|
||||
self.assertEqual(type(e), AttributeError)
|
||||
|
||||
try:
|
||||
config.NON_EXISTENT = 1
|
||||
except Exception as e:
|
||||
pass
|
||||
self.assertEquals(type(e), AttributeError)
|
||||
self.assertEqual(type(e), AttributeError)
|
||||
|
||||
def test_missing_values(self):
|
||||
from constance import config
|
||||
|
||||
# set some values and leave out others
|
||||
config.LONG_VALUE = 654321L
|
||||
config.LONG_VALUE = long(654321)
|
||||
config.BOOL_VALUE = False
|
||||
config.UNICODE_VALUE = 'Québec'.decode('utf-8')
|
||||
config.UNICODE_VALUE = six.u('Québec')
|
||||
config.DECIMAL_VALUE = Decimal('1.2')
|
||||
config.DATETIME_VALUE = datetime(1977, 10, 2)
|
||||
config.DATE_VALUE = date(2001, 12, 20)
|
||||
config.TIME_VALUE = time(1, 59, 0)
|
||||
|
||||
self.assertEquals(config.INT_VALUE, 1) # this should be the default value
|
||||
self.assertEquals(config.LONG_VALUE, 654321L)
|
||||
self.assertEquals(config.BOOL_VALUE, False)
|
||||
self.assertEquals(config.STRING_VALUE, 'Hello world') # this should be the default value
|
||||
self.assertEquals(config.UNICODE_VALUE, 'Québec'.decode('utf-8'))
|
||||
self.assertEquals(config.DECIMAL_VALUE, Decimal('1.2'))
|
||||
self.assertEquals(config.DATETIME_VALUE, datetime(1977, 10, 2))
|
||||
self.assertEquals(config.FLOAT_VALUE, 3.1415926536) # this should be the default value
|
||||
self.assertEquals(config.DATE_VALUE, date(2001, 12, 20))
|
||||
self.assertEquals(config.TIME_VALUE, time(1, 59, 0))
|
||||
self.assertEqual(config.INT_VALUE, 1) # this should be the default value
|
||||
self.assertEqual(config.LONG_VALUE, long(654321))
|
||||
self.assertEqual(config.BOOL_VALUE, False)
|
||||
self.assertEqual(config.STRING_VALUE, 'Hello world') # this should be the default value
|
||||
self.assertEqual(config.UNICODE_VALUE, six.u('Québec'))
|
||||
self.assertEqual(config.DECIMAL_VALUE, Decimal('1.2'))
|
||||
self.assertEqual(config.DATETIME_VALUE, datetime(1977, 10, 2))
|
||||
self.assertEqual(config.FLOAT_VALUE, 3.1415926536) # this should be the default value
|
||||
self.assertEqual(config.DATE_VALUE, date(2001, 12, 20))
|
||||
self.assertEqual(config.TIME_VALUE, time(1, 59, 0))
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class TestAdmin(TestCase):
|
|||
request = self.rf.get('/admin/constance/config/')
|
||||
request.user = self.superuser
|
||||
response = self.options.changelist_view(request, {})
|
||||
self.assertEquals(response.status_code, 200)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_custom_auth(self):
|
||||
settings.SUPERUSER_ONLY = False
|
||||
|
|
@ -42,4 +42,4 @@ class TestAdmin(TestCase):
|
|||
self.assertTrue(request.user.has_perm('constance.change_config'))
|
||||
|
||||
response = self.options.changelist_view(request, {})
|
||||
self.assertEquals(response.status_code, 200)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from django.test import TestCase
|
|||
from constance import settings
|
||||
from constance.config import Config
|
||||
|
||||
from .storage import StorageTestsMixin
|
||||
from tests.storage import StorageTestsMixin
|
||||
|
||||
|
||||
class TestDatabase(TestCase, StorageTestsMixin):
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from django.test import TestCase
|
|||
from constance import settings
|
||||
from constance.config import Config
|
||||
|
||||
from .storage import StorageTestsMixin
|
||||
from tests.storage import StorageTestsMixin
|
||||
|
||||
|
||||
class TestRedis(TestCase, StorageTestsMixin):
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from django.contrib import admin
|
||||
from django.conf.urls.defaults import patterns, include
|
||||
from django.conf.urls import patterns, include
|
||||
|
||||
urlpatterns = patterns('',
|
||||
(r'^admin/', include(admin.site.urls)),
|
||||
|
|
|
|||
Loading…
Reference in a new issue