forked from jazzband/django-model-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request jazzband#360 from marfyl/master
Add UUIDModel and UUIDField
- Loading branch information
Showing
9 changed files
with
212 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,4 +51,4 @@ | |
| Jack Cushman <[email protected]> | ||
| Zach Cheung <[email protected]> | ||
| Daniel Andrlik <[email protected]> | ||
| marfyl <github.com/marfyl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from __future__ import unicode_literals | ||
|
||
import uuid | ||
|
||
from django.core.exceptions import ValidationError | ||
from django.test import TestCase | ||
|
||
from model_utils.fields import UUIDField | ||
|
||
|
||
class UUIDFieldTests(TestCase): | ||
|
||
def test_uuid_version_default(self): | ||
instance = UUIDField() | ||
self.assertEqual(instance.default, uuid.uuid4) | ||
|
||
def test_uuid_version_1(self): | ||
instance = UUIDField(version=1) | ||
self.assertEqual(instance.default, uuid.uuid1) | ||
|
||
def test_uuid_version_2_error(self): | ||
self.assertRaises(ValidationError, UUIDField, 'version', 2) | ||
|
||
def test_uuid_version_3(self): | ||
instance = UUIDField(version=3) | ||
self.assertEqual(instance.default, uuid.uuid3) | ||
|
||
def test_uuid_version_4(self): | ||
instance = UUIDField(version=4) | ||
self.assertEqual(instance.default, uuid.uuid4) | ||
|
||
def test_uuid_version_5(self): | ||
instance = UUIDField(version=5) | ||
self.assertEqual(instance.default, uuid.uuid5) | ||
|
||
def test_uuid_version_bellow_min(self): | ||
self.assertRaises(ValidationError, UUIDField, 'version', 0) | ||
|
||
def test_uuid_version_above_max(self): | ||
self.assertRaises(ValidationError, UUIDField, 'version', 6) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from __future__ import unicode_literals | ||
|
||
from django.test import TestCase | ||
|
||
from tests.models import CustomUUIDModel, CustomNotPrimaryUUIDModel | ||
|
||
|
||
class UUIDFieldTests(TestCase): | ||
|
||
def test_uuid_model_with_uuid_field_as_primary_key(self): | ||
instance = CustomUUIDModel() | ||
instance.save() | ||
self.assertEqual(instance.id.__class__.__name__, 'UUID') | ||
self.assertEqual(instance.id, instance.pk) | ||
|
||
def test_uuid_model_with_uuid_field_as_not_primary_key(self): | ||
instance = CustomNotPrimaryUUIDModel() | ||
instance.save() | ||
self.assertEqual(instance.uuid.__class__.__name__, 'UUID') | ||
self.assertNotEqual(instance.uuid, instance.pk) |