Skip to content

Commit

Permalink
Merge pull request #9 from sirex/master
Browse files Browse the repository at this point in the history
Fixed failing tests.
  • Loading branch information
sorl committed May 12, 2011
2 parents a45e519 + f0276fa commit 5de0e44
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
9 changes: 7 additions & 2 deletions mockups/factory.py
Expand Up @@ -85,8 +85,13 @@ def get_generator(self, field, **kwargs):
return generators.ChoiceFieldGenerator(field)
elif field.default is not models.NOT_PROVIDED:
return None # bail out
elif field.__class__ in self.fieldclass_to_generator:
obj = self.fieldclass_to_generator.get(field.__class__)
# check if any of bases exests in self.fieldclass_to_generator
elif (set(field.__class__.__mro__).
intersection(self.fieldclass_to_generator)):
for cls in field.__class__.__mro__:
if cls in self.fieldclass_to_generator:
obj = self.fieldclass_to_generator.get(cls)
break
else:
return None # No matching generator found

Expand Down
8 changes: 8 additions & 0 deletions mockups/tests/mockups_test/models.py
Expand Up @@ -11,6 +11,12 @@ def y2k():
return datetime(2000, 1, 1)


class MyCustomField(models.CharField):
def __init__(self, *args, **kwargs):
kwargs.setdefault('max_length', 50)
super(MyCustomField, self).__init__(*args, **kwargs)


class SimpleModel(models.Model):
name = models.CharField(max_length=50)

Expand Down Expand Up @@ -69,6 +75,8 @@ class BasicModel(models.Model):
filepathfield = models.FilePathField(path=filepath)
mfilepathfield = models.FilePathField(path=filepath, match=r'^.+\.py$')

customfield = MyCustomField()


class UniqueTestModel(models.Model):
CHOICES = [(i,i) for i in range(10)]
Expand Down
2 changes: 2 additions & 0 deletions mockups/tests/mockups_test/tests.py
Expand Up @@ -54,6 +54,8 @@ def test_constraints(self):
self.assertTrue(' ' not in obj.emailfield)
self.assertTrue(obj.ipaddressfield.count('.'), 3)
self.assertTrue(len(obj.ipaddressfield) >= 7)
self.assertTrue(len(obj.customfield) > 0)
self.assertEqual(type(obj.customfield), unicode)
self.assertEqual(BasicModel.objects.count(), 100)

def test_factory(self):
Expand Down

0 comments on commit 5de0e44

Please sign in to comment.