Skip to content

Commit

Permalink
Fixing small bug with CharFields.max_length < 15
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmuellegger committed Jun 9, 2010
1 parent 8a4387d commit fe85e28
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/autofixture/base.py
Expand Up @@ -307,6 +307,7 @@ def get_generator(self, field):
return generators.LoremSentenceGenerator(
common=False,
max_length=field.max_length)
else:
generator = generators.StringGenerator
return generator(max_length=field.max_length)
if isinstance(field, fields.DecimalField):
Expand Down
3 changes: 3 additions & 0 deletions src/autofixture/tests.py
Expand Up @@ -47,6 +47,7 @@ class NullableFKModel(models.Model):

class BasicModel(models.Model):
chars = models.CharField(max_length=50)
shortchars = models.CharField(max_length=2)
blankchars = models.CharField(max_length=100, blank=True)
nullchars = models.CharField(max_length=100, blank=True, null=True)
slugfield = models.SlugField()
Expand Down Expand Up @@ -138,6 +139,8 @@ def test_constraints(self):
for obj in filler.create(100):
self.assertTrue(len(obj.chars) > 0)
self.assertEqual(type(obj.chars), unicode)
self.assertTrue(len(obj.shortchars) <= 2)
self.assertEqual(type(obj.shortchars), unicode)
self.assertTrue(type(obj.blankchars), unicode)
self.assertEqualOr(type(obj.nullchars), unicode, None)
self.assertEqual(type(obj.slugfield), unicode)
Expand Down

0 comments on commit fe85e28

Please sign in to comment.