Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

renaming action

  • Loading branch information...
commit cee82abc53dd1c0b6725c54cab9d61efdf718f9c 1 parent 0f3ef49
Mikko Hellsing authored
View
6 CHANGES.rst
@@ -1,6 +1,10 @@
Changelog
=========
+0.4.1
+-----
+* Just a rename of Mockup to ModelMockup
+
0.4.0
-----
* Major rewrite to use Factory
@@ -34,4 +38,4 @@ Changelog
* Fixing bug when a ``CharField`` with ``max_length`` smaller than 15 is used.
-* ``Mockup.field_generators`` accepts callables as values.
+* ``ModelMockup.field_generators`` accepts callables as values.
View
20 README.rst
@@ -69,14 +69,14 @@ dumped from your production database. But while in development when database
schemes are changing frequently, its hard to maintain all fixtures and to know
exactly which objects are contained in the dumps etc...
-Mockups to the rescue! It lets you automatically generate models and all
+ModelMockups to the rescue! It lets you automatically generate models and all
of their dependecies on the fly. Have a look at the following examples.
-Lets start with the very basics. We create a ``Mockup`` instance for the
+Lets start with the very basics. We create a ``ModelMockup`` instance for the
``Entry`` model and tell it to create ten model instances::
- from mockups import Mockup
- mockup = Mockup(Entry)
+ from mockups import ModelMockup
+ mockup = ModelMockup(Entry)
entries = mockup.create(10)
Now you can play around and test your blog entries. By default dependecies of
@@ -85,18 +85,18 @@ already existing object of the related model. What if you don't have one yet?
You can provide the ``generate_fk`` attribute which allows the mockup
instance to follow foreignkeys by generating new related models::
- mockup = Mockup(Entry, generate_fk=True)
+ mockup = ModelMockup(Entry, generate_fk=True)
This generates new instance for *all* foreignkey fields of ``Entry``. Its
possible to limit this behaviour to single fields::
- mockup = Mockup(Entry, generate_fk=['author'])
+ mockup = ModelMockup(Entry, generate_fk=['author'])
This will only create new authors automatically and doesn't touch other
tables. The same is possible with many to many fields. But you need
additionally specify how many objects should be created for the m2m relation::
- mockup = Mockup(Entry, generate_m2m={'categories': (1,3)})
+ mockup = ModelMockup(Entry, generate_m2m={'categories': (1,3)})
All created entry models get one to three new categories assigned.
@@ -109,10 +109,10 @@ specific value. This is easily achieved with the use of ``Factory``::
class PonyFactory(Factory):
pub_date = generators.StaticGenerator(datetime(2010, 2, 1))
- class PonyMockup(Mockup):
+ class PonyModelMockup(ModelMockup):
factory = PonyFactory
- mockup = PonyMockup(Entry)
+ mockup = PonyModelMockup(Entry)
More
@@ -121,7 +121,7 @@ More
There is so much more to explore which might be useful for you and your
projects:
-* There are ways to register custom ``Mockup`` subclasses with models
+* There are ways to register custom ``ModelMockup`` subclasses with models
that are automatically used when calling ``mockups`` on the model.
* More control for related models, even with relations of related models...
(e.g. by using ``generate_fk=['author', 'author__user']``)
View
12 docs/registry.rst
@@ -3,11 +3,11 @@ The mockup registry
.. _registry:
-Since :class:`Mockup` is designed to fit for almost all models, its very
+Since :class:`ModelMockup` is designed to fit for almost all models, its very
generic and doesn't know anything about the actual logic and meanings of
relations or the purpose of your model fields.
-So there is a registry to register custom :class:`Mockup` subclasses with
+So there is a registry to register custom :class:`ModelMockup` subclasses with
specific models. These subclasses are then used by default if you generated
test data either with the :ref:`mockups <mockups>` management
command or with one of the :ref:`shortcuts <shortcuts>` in :mod:`mockups`.
@@ -16,12 +16,12 @@ command or with one of the :ref:`shortcuts <shortcuts>` in :mod:`mockups`.
.. autofunction:: mockups.unregister
-Included Mockup subclasses
+Included ModelMockup subclasses
--------------------------
-There are some :class:`Mockup` subclasses that are shipped by default
+There are some :class:`ModelMockup` subclasses that are shipped by default
with ``django-mockups``. These are listed below.
-.. _UserMockup:
-.. autoclass:: mockups.contrib.auth.UserMockup
+.. _UserModelMockup:
+.. autoclass:: mockups.contrib.auth.UserModelMockup
:members: __init__
View
14 docs/usage.rst
@@ -21,22 +21,22 @@ test data as fast as possible.
.. autofunction:: mockups.create_one
-.. _Mockup:
+.. _ModelMockup:
-Using the Mockup class
+Using the ModelMockup class
----------------------
-.. autoclass:: mockups.base.Mockup
+.. autoclass:: mockups.base.ModelMockup
:members: __init__, add_field_generator, add_constraint, check_constrains,
create, create_one
-Subclassing :class:`Mockup`
+Subclassing :class:`ModelMockup`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The following methods may be overwritten by subclasses:
-.. automethod:: mockups.base.Mockup.prepare_class
+.. automethod:: mockups.base.ModelMockup.prepare_class
-.. automethod:: mockups.base.Mockup.post_process_instance
+.. automethod:: mockups.base.ModelMockup.post_process_instance
-.. automethod:: mockups.base.Mockup.get_generator
+.. automethod:: mockups.base.ModelMockup.get_generator
View
2  mockups/__init__.py
@@ -1,5 +1,5 @@
from mockups.helpers import *
from mockups.factory import Factory
-from mockups.base import Mockup
+from mockups.base import ModelMockup
from mockups.constraints import InvalidConstraint
View
8 mockups/base.py
@@ -59,7 +59,7 @@ def get_deep_links(self, field):
return Link(fields, default=self.default)
-class Mockup(object):
+class ModelMockup(object):
'''
.. We don't support the following fields yet:
@@ -80,7 +80,8 @@ class Mockup(object):
factory = factory.Factory
def __init__(self, model, constraints=None, follow_fk=None,
- generate_fk=None, follow_m2m=None, generate_m2m=None):
+ generate_fk=None, follow_m2m=None, generate_m2m=None,
+ factory=None):
'''
Parameters:
``model``: A model class which is used to create the test data.
@@ -114,6 +115,8 @@ def __init__(self, model, constraints=None, follow_fk=None,
self.constraints = constraints or []
# create a factory instance
+ if factory is not None:
+ self.factory = factory
self._factory = self.factory()
if follow_fk is not None:
@@ -150,7 +153,6 @@ def __init__(self, model, constraints=None, follow_fk=None,
self.add_constraint(constraint)
self._fieldname_to_generator = {}
-
self.prepare_class()
def prepare_class(self):
View
10 mockups/contrib/auth.py
@@ -2,7 +2,7 @@
import mockups
from datetime import datetime
from django.contrib.auth.models import User, UNUSABLE_PASSWORD
-from mockups import Mockup, Factory
+from mockups import ModelMockup, Factory
from mockups import generators
@@ -19,9 +19,9 @@ class UserFactory(Factory):
last_login = generators.DateTimeGenerator(max_date=datetime.now())
-class UserMockup(Mockup):
+class UserModelMockup(ModelMockup):
'''
- :class:`UserMockup` is automatically used by default to create new
+ :class:`UserModelMockup` is automatically used by default to create new
``User`` instances. It uses the following values to assure that you can
use the generated instances without any modification:
@@ -53,7 +53,7 @@ def __init__(self, *args, **kwargs):
'''
self.username = kwargs.pop('username', None)
self.password = kwargs.pop('password', None)
- super(UserMockup, self).__init__(*args, **kwargs)
+ super(UserModelMockup, self).__init__(*args, **kwargs)
if self.username:
self.update_fieldname_generator(
username = generators.StaticGenerator(self.username)
@@ -75,4 +75,4 @@ def post_process_instance(self, instance):
return instance
-mockups.register(User, UserMockup, fail_silently=True)
+mockups.register(User, UserModelMockup, fail_silently=True)
View
10 mockups/helpers.py
@@ -17,9 +17,9 @@ def get_mockup(model, *args, **kwargs):
Gets an mockup instance for a model
'''
if model not in _registry:
- from mockups.base import Mockup
+ from mockups.base import ModelMockup
warnings.warn('Model `%s` not in registry' % model.__name__)
- cls = Mockup
+ cls = ModelMockup
else:
cls = _registry[model]
return cls(model, *args, **kwargs)
@@ -34,7 +34,7 @@ def register(model, mockup_cls, overwrite=False, fail_silently=False):
*model* can be either a model class or a string that contains the model's
app label and class name seperated by a dot, e.g. ``"app.ModelClass"``.
- *mockup_cls* is the :mod:`Mockup` subclass that shall be used to
+ *mockup_cls* is the :mod:`ModelMockup` subclass that shall be used to
generated instances of *model*.
By default :func:`register` will raise :exc:`ValueError` if the given
@@ -86,7 +86,7 @@ def create(model, count, *args, **kwargs):
'''
Create *count* instances of *model* using the either an appropiate
mockup that was :ref:`registry <registered>` or fall back to the
- default:class:`Mockup` class. *model* can be a model class or its
+ default:class:`ModelMockup` class. *model* can be a model class or its
string representation (e.g. ``"app.ModelClass"``).
All positional and keyword arguments are passed to the mockup
@@ -96,7 +96,7 @@ def create(model, count, *args, **kwargs):
import mockups
mockup = mockups.create('auth.User', 10)
- .. note:: See :ref:`Mockup` for more information.
+ .. note:: See :ref:`ModelMockup` for more information.
:func:`create` will return a list of the created objects.
'''
View
2  mockups/management/commands/mockups.py
@@ -73,7 +73,7 @@ class Command(BaseCommand):
make_option('-u', '--use', action='store', dest='use',
default='', help=
u'Specify a mockup subclass that is used to create the '
- u'test data. E.g. myapp.mockup.MyMockup'),
+ u'test data. E.g. myapp.mockup.MyModelMockup'),
)
def format_output(self, obj):
View
BIN  mockups_tests/mockups_test/.tests.py.swn
Binary file not shown
View
70 mockups_tests/mockups_test/tests.py
@@ -5,7 +5,7 @@
from django.test import TestCase
from mockups import generators
from mockups import Factory
-from mockups.base import Mockup, CreateInstanceError, Link
+from mockups.base import ModelMockup, CreateInstanceError, Link
from mockups_tests.mockups_test.models import y2k
from mockups_tests.mockups_test.models import (
SimpleModel, OtherSimpleModel, DeepLinkModel1, DeepLinkModel2,
@@ -16,7 +16,7 @@
class SimpleFactory(Factory):
name = generators.StaticGenerator('foo')
-class SimpleMockup(Mockup):
+class SimpleModelMockup(ModelMockup):
factory = SimpleFactory
@@ -26,12 +26,12 @@ def assertEqualOr(self, first, second, fallback):
self.fail()
def test_create(self):
- filler = Mockup(BasicModel)
+ filler = ModelMockup(BasicModel)
filler.create(10)
self.assertEqual(BasicModel.objects.count(), 10)
def test_constraints(self):
- filler = Mockup(BasicModel)
+ filler = ModelMockup(BasicModel)
for obj in filler.create(100):
self.assertTrue(len(obj.chars) > 0)
self.assertEqual(type(obj.chars), unicode)
@@ -65,7 +65,7 @@ class GF(Factory):
intfield = generators.StaticGenerator(1)
chars = generators.ChoicesGenerator(values=char_values)
shortchars = generators.CallableGenerator(lambda: u'ab')
- class M(Mockup):
+ class M(ModelMockup):
factory = GF
filler = M(BasicModel)
@@ -77,7 +77,7 @@ class M(Mockup):
class TestRelations(TestCase):
def test_generate_foreignkeys(self):
- filler = Mockup(
+ filler = ModelMockup(
RelatedModel,
generate_fk=True)
for obj in filler.create(100):
@@ -85,7 +85,7 @@ def test_generate_foreignkeys(self):
self.assertEqual(obj.limitedfk.name, 'foo')
def test_deep_generate_foreignkeys(self):
- filler = Mockup(
+ filler = ModelMockup(
DeepLinkModel2,
generate_fk=True)
for obj in filler.create(10):
@@ -94,7 +94,7 @@ def test_deep_generate_foreignkeys(self):
self.assertEqual(obj.related.related2.__class__, SimpleModel)
def test_deep_generate_foreignkeys2(self):
- filler = Mockup(
+ filler = ModelMockup(
DeepLinkModel2,
follow_fk=False,
generate_fk=('related', 'related__related'))
@@ -104,7 +104,7 @@ def test_deep_generate_foreignkeys2(self):
self.assertEqual(obj.related.related2, None)
def test_generate_only_some_foreignkeys(self):
- filler = Mockup(
+ filler = ModelMockup(
RelatedModel,
generate_fk=('related',))
for obj in filler.create(100):
@@ -112,13 +112,13 @@ def test_generate_only_some_foreignkeys(self):
self.assertEqual(obj.limitedfk, None)
def test_follow_foreignkeys(self):
- related = Mockup(BasicModel).create()[0]
+ related = ModelMockup(BasicModel).create()[0]
self.assertEqual(BasicModel.objects.count(), 1)
simple = SimpleModel.objects.create(name='foo')
simple2 = SimpleModel.objects.create(name='bar')
- filler = Mockup(
+ filler = ModelMockup(
RelatedModel,
follow_fk=True)
for obj in filler.create(100):
@@ -126,13 +126,13 @@ def test_follow_foreignkeys(self):
self.assertEqual(obj.limitedfk, simple)
def test_follow_only_some_foreignkeys(self):
- related = Mockup(BasicModel).create()[0]
+ related = ModelMockup(BasicModel).create()[0]
self.assertEqual(BasicModel.objects.count(), 1)
simple = SimpleModel.objects.create(name='foo')
simple2 = SimpleModel.objects.create(name='bar')
- filler = Mockup(
+ filler = ModelMockup(
RelatedModel,
follow_fk=('related',))
for obj in filler.create(100):
@@ -141,7 +141,7 @@ def test_follow_only_some_foreignkeys(self):
def test_follow_fk_for_o2o(self):
# OneToOneField is the same as a ForeignKey with unique=True
- filler = Mockup(O2OModel, follow_fk=True)
+ filler = ModelMockup(O2OModel, follow_fk=True)
simple = SimpleModel.objects.create()
obj = filler.create()[0]
@@ -151,7 +151,7 @@ def test_follow_fk_for_o2o(self):
def test_generate_fk_for_o2o(self):
# OneToOneField is the same as a ForeignKey with unique=True
- filler = Mockup(O2OModel, generate_fk=True)
+ filler = ModelMockup(O2OModel, generate_fk=True)
all_o2o = set()
for obj in filler.create(10):
@@ -160,22 +160,22 @@ def test_generate_fk_for_o2o(self):
self.assertEqual(set(SimpleModel.objects.all()), all_o2o)
def test_follow_m2m(self):
- related = Mockup(SimpleModel).create()[0]
+ related = ModelMockup(SimpleModel).create()[0]
self.assertEqual(SimpleModel.objects.count(), 1)
- filler = Mockup(
+ filler = ModelMockup(
M2MModel,
follow_m2m=(2, 10))
for obj in filler.create(10):
self.assertEqual(list(obj.m2m.all()), [related])
def test_follow_only_some_m2m(self):
- related = Mockup(SimpleModel).create()[0]
+ related = ModelMockup(SimpleModel).create()[0]
self.assertEqual(SimpleModel.objects.count(), 1)
- other_related = Mockup(OtherSimpleModel).create()[0]
+ other_related = ModelMockup(OtherSimpleModel).create()[0]
self.assertEqual(OtherSimpleModel.objects.count(), 1)
- filler = Mockup(
+ filler = ModelMockup(
M2MModel,
follow_m2m={
'm2m': (2, 10),
@@ -185,7 +185,7 @@ def test_follow_only_some_m2m(self):
self.assertEqual(list(obj.secondm2m.all()), [])
def test_generate_m2m(self):
- filler = Mockup(
+ filler = ModelMockup(
M2MModel,
generate_m2m=(1, 5))
all_m2m = set()
@@ -199,7 +199,7 @@ def test_generate_m2m(self):
self.assertEqual(OtherSimpleModel.objects.count(), len(all_secondm2m))
def test_generate_only_some_m2m(self):
- filler = Mockup(
+ filler = ModelMockup(
M2MModel,
generate_m2m={
'm2m': (1, 5),
@@ -215,7 +215,7 @@ def test_generate_only_some_m2m(self):
self.assertEqual(OtherSimpleModel.objects.count(), len(all_secondm2m))
def test_generate_m2m_with_intermediary_model(self):
- filler = Mockup(
+ filler = ModelMockup(
M2MModelThrough,
generate_m2m=(1, 5))
all_m2m = set()
@@ -227,14 +227,14 @@ def test_generate_m2m_with_intermediary_model(self):
class TestUniqueConstraints(TestCase):
def test_unique_field(self):
- filler = Mockup(UniqueTestModel)
+ filler = ModelMockup(UniqueTestModel)
count = len(filler.model._meta.
get_field_by_name('choice1')[0].choices)
for obj in filler.create(count):
pass
def test_unique_together(self):
- filler = Mockup(UniqueTogetherTestModel)
+ filler = ModelMockup(UniqueTogetherTestModel)
count1 = len(filler.model._meta.
get_field_by_name('choice1')[0].choices)
count2 = len(filler.model._meta.
@@ -245,7 +245,7 @@ def test_unique_together(self):
class TestGenerators(TestCase):
def test_instance_selector(self):
- Mockup(SimpleModel).create(10)
+ ModelMockup(SimpleModel).create(10)
result = generators.InstanceSelector(SimpleModel).generate()
self.assertEqual(result.__class__, SimpleModel)
@@ -345,12 +345,12 @@ def tearDown(self):
mockups.helpers._registry = self.original_registry
def test_registration(self):
- mockups.register(SimpleModel, SimpleMockup)
+ mockups.register(SimpleModel, SimpleModelMockup)
self.assertTrue(SimpleModel in mockups.helpers._registry)
- self.assertEqual(mockups.helpers._registry[SimpleModel], SimpleMockup)
+ self.assertEqual(mockups.helpers._registry[SimpleModel], SimpleModelMockup)
def test_create(self):
- mockups.register(SimpleModel, SimpleMockup)
+ mockups.register(SimpleModel, SimpleModelMockup)
for obj in mockups.create(SimpleModel, 10):
self.assertEqual(obj.name, 'foo')
obj = mockups.create_one(SimpleModel)
@@ -368,7 +368,7 @@ class B(A):
def test_overwrite_attributes(self):
class GF(Factory):
name = generators.StaticGenerator('bar')
- class M(SimpleMockup):
+ class M(SimpleModelMockup):
factory = GF
mockups.register(SimpleModel, M)
for obj in mockups.create(SimpleModel, 10):
@@ -377,7 +377,7 @@ class M(SimpleMockup):
self.assertEqual(obj.name, 'bar')
-class TestMockupAPI(TestCase):
+class TestModelMockupAPI(TestCase):
def setUp(self):
self.original_registry = mockups.helpers._registry
mockups.helpers._registry = {}
@@ -449,7 +449,7 @@ def test_generate_fk_with_ALL(self):
self.assertTrue(obj.related.related != obj.related.related2)
def test_no_follow_m2m(self):
- Mockup(SimpleModel).create(1)
+ ModelMockup(SimpleModel).create(1)
models = ('mockups_test.NullableFKModel:1',)
self.options['no_follow_m2m'] = True
@@ -458,8 +458,8 @@ def test_no_follow_m2m(self):
self.assertEqual(obj.m2m.count(), 0)
def test_follow_m2m(self):
- Mockup(SimpleModel).create(10)
- Mockup(OtherSimpleModel).create(10)
+ ModelMockup(SimpleModel).create(10)
+ ModelMockup(OtherSimpleModel).create(10)
models = ('mockups_test.M2MModel:25',)
self.options['follow_m2m'] = 'm2m:3:3,secondm2m:0:10'
@@ -486,7 +486,7 @@ def test_generate_m2m(self):
self.assertEqual(all_secondm2m, set(OtherSimpleModel.objects.all()))
def test_using_registry(self):
- mockups.register(SimpleModel, SimpleMockup)
+ mockups.register(SimpleModel, SimpleModelMockup)
models = ('mockups_test.SimpleModel:10',)
self.command.handle(*models, **self.options)
for obj in SimpleModel.objects.all():
Please sign in to comment.
Something went wrong with that request. Please try again.