-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added RandomCharField - Prepopulates random character string.
- Factored out query logic to ensure uniqueness to BaseUniqueField. - The field value factories have been moved to generators.
- Loading branch information
Derrick Petzold
committed
May 17, 2015
1 parent
78b52d1
commit c508e66
Showing
6 changed files
with
323 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import mock | ||
import string | ||
import pytest | ||
|
||
import django | ||
from django.test import TestCase | ||
|
||
from .testapp.models import ( | ||
RandomCharTestModel, | ||
RandomCharTestModelLower, | ||
RandomCharTestModelAlpha, | ||
RandomCharTestModelDigits, | ||
RandomCharTestModelPunctuation, | ||
RandomCharTestModelLowerAlphaDigits, | ||
) | ||
|
||
if django.VERSION >= (1, 7): | ||
from django.db import migrations # NOQA | ||
from django.db.migrations.writer import MigrationWriter # NOQA | ||
from django.utils import six # NOQA | ||
import django_extensions # NOQA | ||
|
||
|
||
class RandomCharFieldTest(TestCase): | ||
|
||
def testRandomCharField(self): | ||
m = RandomCharTestModel() | ||
m.save() | ||
assert len(m.random_char_field) == 8, m.random_char_field | ||
|
||
def testRandomCharFieldLower(self): | ||
m = RandomCharTestModelLower() | ||
m.save() | ||
for c in m.random_char_field: | ||
assert c.islower(), m.random_char_field | ||
|
||
def testRandomCharFieldAlpha(self): | ||
m = RandomCharTestModelAlpha() | ||
m.save() | ||
for c in m.random_char_field: | ||
assert c.isalpha(), m.random_char_field | ||
|
||
def testRandomCharFieldDigits(self): | ||
m = RandomCharTestModelDigits() | ||
m.save() | ||
for c in m.random_char_field: | ||
assert c.isdigit(), m.random_char_field | ||
|
||
def testRandomCharFieldPunctuation(self): | ||
m = RandomCharTestModelPunctuation() | ||
m.save() | ||
for c in m.random_char_field: | ||
assert c in string.punctuation, m.random_char_field | ||
|
||
def testRandomCharTestModelLowerAlphaDigits(self): | ||
m = RandomCharTestModelLowerAlphaDigits() | ||
m.save() | ||
for c in m.random_char_field: | ||
assert c.isdigit() or (c.isalpha() and c.islower()), m.random_char_field | ||
|
||
def testRandomCharTestModelDuplicate(self): | ||
m = RandomCharTestModel() | ||
m.save() | ||
with mock.patch('django_extensions.db.fields.RandomCharField.random_char_generator') as func: | ||
func.return_value = iter([m.random_char_field, 'aaa']) | ||
m = RandomCharTestModel() | ||
m.save() | ||
assert m.random_char_field == 'aaa' | ||
|
||
def testRandomCharTestModelAsserts(self): | ||
with mock.patch('django_extensions.db.fields.random_sample') as mock_sample: | ||
mock_sample.return_value = 'aaa' | ||
m = RandomCharTestModel() | ||
m.save() | ||
|
||
m = RandomCharTestModel() | ||
with pytest.raises(RuntimeError): | ||
m.save() |
Oops, something went wrong.