Permalink
Browse files

Merge pull request #9 from sirex/master

Fixed failing tests.
  • Loading branch information...
2 parents a45e519 + f0276fa commit 5de0e4465d6c9683d7a1f74e4ba69d805aaf1a6d @sorl committed May 12, 2011
Showing with 17 additions and 2 deletions.
  1. +7 −2 mockups/factory.py
  2. +8 −0 mockups/tests/mockups_test/models.py
  3. +2 −0 mockups/tests/mockups_test/tests.py
View
9 mockups/factory.py
@@ -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
View
8 mockups/tests/mockups_test/models.py
@@ -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)
@@ -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)]
View
2 mockups/tests/mockups_test/tests.py
@@ -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):

0 comments on commit 5de0e44

Please sign in to comment.