Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixed failing tests. #9

Merged
merged 5 commits into from

2 participants

@sirex

No description provided.

@sorl sorl merged commit 5de0e44 into sorl:master
@sorl
Owner

Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 10, 2011
  1. @sirex

    Fixes search for generator by field class. Now search is performed no…

    sirex authored
    …t only in
    
    field class, but also in all bases of field class.
  2. @sirex

    Fixes search for generator by field class. Now search is performed no…

    sirex authored
    …t only in
    
    field class, but also in all bases of field class.
  3. @sirex

    Fixed failing tests.

    sirex authored
  4. @sirex

    Merge branch 'master' of https://github.com/sirex/django-mockups

    sirex authored
    Conflicts:
    	mockups/factory.py
  5. @sirex
This page is out of date. Refresh to see the latest.
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):
Something went wrong with that request. Please try again.