diff --git a/runtests_sqlite.py b/runtests_sqlite.py index 4ba8245..26c7405 100755 --- a/runtests_sqlite.py +++ b/runtests_sqlite.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -import sys from django.conf import settings from optparse import OptionParser @@ -25,6 +24,14 @@ from django_nose import NoseTestSuiteRunner +try: + # django 1.7 standalone app setup + import django + django.setup() +except AttributeError: + pass + + from runtests import runtests if __name__ == '__main__': diff --git a/tox.ini b/tox.ini index 204e08e..7be25eb 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,19 @@ -[testenv] +[tox] +envlist = + py2, + py3 + +[base] downloadcache = {toxworkdir}/_download/ deps = - Django==1.3.1 - psycopg2==2.4.1 + Django>=1.3.1 + psycopg2>=2.4.1 django-nose commands = - {envbindir}/python setup.py test + {envpython} setup.py test + +[testenv:py2] +basepython=python2 + +[testenv:py3] +basepython=python3 diff --git a/uuidfield/fields.py b/uuidfield/fields.py index b49d76a..249850e 100644 --- a/uuidfield/fields.py +++ b/uuidfield/fields.py @@ -6,6 +6,11 @@ from django.utils.encoding import smart_unicode except ImportError: from django.utils.encoding import smart_text as smart_unicode +try: + from django.utils import six +except ImportError: + import six +from django.utils.encoding import python_2_unicode_compatible try: # psycopg2 needs us to register the uuid type @@ -15,6 +20,7 @@ pass +@python_2_unicode_compatible class StringUUID(uuid.UUID): def __init__(self, *args, **kwargs): # get around UUID's immutable setter @@ -32,7 +38,7 @@ def __len__(self): return len(self.__str__()) -class UUIDField(Field): +class UUIDField(six.with_metaclass(SubfieldBase, Field)): """ A field which stores a UUID value in hex format. This may also have the Boolean attribute 'auto' which will set the value on initial save to a new @@ -40,7 +46,7 @@ class UUIDField(Field): this with a DB constraint. """ # TODO: support binary storage types - __metaclass__ = SubfieldBase + # __metaclass__ = SubfieldBase def __init__(self, version=4, node=None, clock_seq=None, namespace=None, name=None, auto=False, hyphenate=False, diff --git a/uuidfield/tests/__init__.py b/uuidfield/tests/__init__.py index 1d2c605..1d10cd5 100644 --- a/uuidfield/tests/__init__.py +++ b/uuidfield/tests/__init__.py @@ -1,2 +1,2 @@ -from tests import * -from models import * \ No newline at end of file +from .tests import * +from .models import * diff --git a/uuidfield/tests/tests.py b/uuidfield/tests/tests.py index 40992da..7462997 100644 --- a/uuidfield/tests/tests.py +++ b/uuidfield/tests/tests.py @@ -1,10 +1,16 @@ import uuid -from django.db import connection, IntegrityError +from django.db import IntegrityError from django.test import TestCase +try: + from django.utils.encoding import smart_unicode +except ImportError: + from django.utils.encoding import smart_text as smart_unicode -from uuidfield.tests.models import (AutoUUIDField, ManualUUIDField, - NamespaceUUIDField, BrokenNamespaceUUIDField, HyphenatedUUIDField) +from uuidfield.tests.models import ( + AutoUUIDField, ManualUUIDField, + NamespaceUUIDField, BrokenNamespaceUUIDField, HyphenatedUUIDField +) class UUIDFieldTestCase(TestCase): @@ -40,8 +46,7 @@ def test_hyphenated(self): obj = HyphenatedUUIDField.objects.create(name='test') uuid = obj.uuid - self.assertTrue('-' in unicode(uuid)) - self.assertTrue('-' in str(uuid)) + self.assertTrue('-' in smart_unicode(uuid)) self.assertEquals(len(uuid), 36) @@ -56,9 +61,8 @@ def test_hyphenated(self): def test_can_use_hyphenated_uuids_in_filter_and_get(self): obj = AutoUUIDField.objects.create() - obj_uuid = uuid.UUID(str(obj.uuid)) - self.assertTrue('-' in unicode(obj_uuid)) - self.assertTrue('-' in str(obj_uuid)) + obj_uuid = uuid.UUID(smart_unicode(obj.uuid)) + self.assertTrue('-' in smart_unicode(obj_uuid)) inserted_obj = AutoUUIDField.objects.get(uuid=obj_uuid) filtered_obj = AutoUUIDField.objects.filter(uuid=obj_uuid)[0] self.assertEqual(inserted_obj.uuid, obj_uuid)