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.
- Loading branch information
1 parent
57d26ee
commit a56d07c
Showing
5 changed files
with
141 additions
and
0 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
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,55 @@ | ||
from unittest.mock import Mock | ||
|
||
from django.db.models import NOT_PROVIDED | ||
from django.test import TestCase | ||
|
||
from model_utils.fields import UrlsafeTokenField | ||
|
||
|
||
class UrlsaftTokenFieldTests(TestCase): | ||
def test_editable_default(self): | ||
field = UrlsafeTokenField() | ||
self.assertFalse(field.editable) | ||
|
||
def test_editable(self): | ||
field = UrlsafeTokenField(editable=True) | ||
self.assertTrue(field.editable) | ||
|
||
def test_max_length_default(self): | ||
field = UrlsafeTokenField() | ||
self.assertEqual(field.max_length, 128) | ||
|
||
def test_max_length(self): | ||
field = UrlsafeTokenField(max_length=256) | ||
self.assertEqual(field.max_length, 256) | ||
|
||
def test_factory_default(self): | ||
field = UrlsafeTokenField() | ||
self.assertIsNone(field._factory) | ||
|
||
def test_factory_not_callable(self): | ||
with self.assertRaises(TypeError): | ||
UrlsafeTokenField(factory='INVALID') | ||
|
||
def test_get_default(self): | ||
field = UrlsafeTokenField() | ||
value = field.get_default() | ||
self.assertEqual(len(value), field.max_length) | ||
|
||
def test_get_default_with_non_default_max_length(self): | ||
field = UrlsafeTokenField(max_length=64) | ||
value = field.get_default() | ||
self.assertEqual(len(value), 64) | ||
|
||
def test_get_default_with_factory(self): | ||
token = 'SAMPLE_TOKEN' | ||
factory = Mock(return_value=token) | ||
field = UrlsafeTokenField(factory=factory) | ||
value = field.get_default() | ||
|
||
self.assertEqual(value, token) | ||
factory.assert_called_once_with(field.max_length) | ||
|
||
def test_no_default_param(self): | ||
field = UrlsafeTokenField(default='DEFAULT') | ||
self.assertIs(field.default, NOT_PROVIDED) |