Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions uuidfield/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import absolute_import

try:
VERSION = __import__('pkg_resources') \
.get_distribution('django-uuidfield').version
except Exception as e:
VERSION = 'unknown'
from .fields import UUIDField

from .fields import UUIDField
5 changes: 1 addition & 4 deletions uuidfield/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

from django import forms
from django.db.models import Field
try:
from django.utils.encoding import smart_unicode
except ImportError:
from django.utils.encoding import smart_text as smart_unicode
from django.utils.encoding import smart_str as smart_unicode

try:
# psycopg2 needs us to register the uuid type
Expand Down
4 changes: 2 additions & 2 deletions uuidfield/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from tests import *
from models import *
from .tests import *
from .models import *
18 changes: 9 additions & 9 deletions uuidfield/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ class UUIDFieldTestCase(TestCase):
def test_auto_uuid4(self):
obj = AutoUUIDField.objects.create()
self.assertTrue(obj.uuid)
self.assertEquals(len(obj.uuid), 32)
self.assertEqual(len(obj.uuid), 32)
self.assertTrue(isinstance(obj.uuid, uuid.UUID))
self.assertEquals(obj.uuid.version, 4)
self.assertEqual(obj.uuid.version, 4)

def test_raises_exception(self):
self.assertRaises(IntegrityError, ManualUUIDField.objects.create)

def test_manual(self):
obj = ManualUUIDField.objects.create(uuid=uuid.uuid4())
self.assertTrue(obj)
self.assertEquals(len(obj.uuid), 32)
self.assertEqual(len(obj.uuid), 32)
self.assertTrue(isinstance(obj.uuid, uuid.UUID))
self.assertEquals(obj.uuid.version, 4)
self.assertEqual(obj.uuid.version, 4)

def test_namespace(self):
obj = NamespaceUUIDField.objects.create()
self.assertTrue(obj)
self.assertEquals(len(obj.uuid), 32)
self.assertEqual(len(obj.uuid), 32)
self.assertTrue(isinstance(obj.uuid, uuid.UUID))
self.assertEquals(obj.uuid.version, 5)
self.assertEqual(obj.uuid.version, 5)

def test_long_uuid(self):
invalid_uuid = "1" * 33
Expand All @@ -58,10 +58,10 @@ 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 str(uuid))

self.assertEquals(len(uuid), 36)
self.assertEqual(len(uuid), 36)

# ensure the hyphens don't affect re-saving object
obj.name = 'shoe'
Expand All @@ -75,7 +75,7 @@ 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))
self.assertTrue('-' in str(obj_uuid))
inserted_obj = AutoUUIDField.objects.get(uuid=obj_uuid)
filtered_obj = AutoUUIDField.objects.filter(uuid=obj_uuid)[0]
Expand Down