Permalink
Browse files

ModelMockupModel, just Mockup

  • Loading branch information...
1 parent 949a274 commit 8836eccd293d0b2d3cfea187badfbc9d2e730cd2 @sorl sorl committed Feb 6, 2011
View
@@ -64,14 +64,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...
-ModelMockups to the rescue! It lets you automatically generate models and all
+Mockups 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 ``ModelMockup`` instance for the
+Lets start with the very basics. We create a ``Mockup`` instance for the
``Entry`` model and tell it to create ten model instances::
- from mockups import ModelMockup
- mockup = ModelMockup(Entry)
+ from mockups import Mockup
+ mockup = Mockup(Entry)
entries = mockup.create(10)
Now you can play around and test your blog entries. By default dependecies of
@@ -80,18 +80,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 = ModelMockup(Entry, generate_fk=True)
+ mockup = Mockup(Entry, generate_fk=True)
This generates new instance for *all* foreignkey fields of ``Entry``. Its
possible to limit this behaviour to single fields::
- mockup = ModelMockup(Entry, generate_fk=['author'])
+ mockup = Mockup(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 = ModelMockup(Entry, generate_m2m={'categories': (1,3)})
+ mockup = Mockup(Entry, generate_m2m={'categories': (1,3)})
All created entry models get one to three new categories assigned.
@@ -103,18 +103,18 @@ specific value. This is easily achieved with the use of ``Factory``::
class PonyFactory(Factory):
pub_date = generators.StaticGenerator(datetime(2010, 2, 1))
- class PonyModelMockup(ModelMockup):
+ class PonyMockup(Mockup):
factory = PonyFactory
- mockup = PonyModelMockup(Entry)
+ mockup = PonyMockup(Entry)
More
====
There is so much more to explore which might be useful for you and your
projects:
-* There are ways to register custom ``ModelMockup`` subclasses with models
+* There are ways to register custom ``Mockup`` 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
@@ -2,11 +2,11 @@ The mockup registry
===================
.. _registry:
-Since :class:`ModelMockup` is designed to fit for almost all models, its very
+Since :class:`Mockup` 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:`ModelMockup` subclasses with
+So there is a registry to register custom :class:`Mockup` 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,11 +16,11 @@ command or with one of the :ref:`shortcuts <shortcuts>` in :mod:`mockups`.
.. autofunction:: mockups.unregister
-Included ModelMockup subclasses
+Included Mockup subclasses
-------------------------------
-There are some :class:`ModelMockup` subclasses that are shipped by default
+There are some :class:`Mockup` subclasses that are shipped by default
with ``django-mockups``. These are listed below.
-.. _UserModelMockup:
-.. autoclass:: mockups.contrib.auth.UserModelMockup
+.. _UserMockup:
+.. autoclass:: mockups.contrib.auth.UserMockup
:members: __init__
View
@@ -20,21 +20,21 @@ test data as fast as possible.
.. autofunction:: mockups.create_one
-.. _ModelMockup:
+.. _Mockup:
-Using the ModelMockup class
+Using the Mockup class
---------------------------
-.. autoclass:: mockups.base.ModelMockup
+.. autoclass:: mockups.base.Mockup
:members: __init__, update_fieldname_generator, add_constraint, check_constrains,
create, create_one
-Subclassing :class:`ModelMockup`
+Subclassing :class:`Mockup`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The following methods may be overwritten by subclasses:
-.. automethod:: mockups.base.ModelMockup.prepare_class
+.. automethod:: mockups.base.Mockup.prepare_class
-.. automethod:: mockups.base.ModelMockup.post_process_instance
+.. automethod:: mockups.base.Mockup.post_process_instance
-.. automethod:: mockups.base.ModelMockup.get_generator
+.. automethod:: mockups.base.Mockup.get_generator
View
@@ -1,5 +1,6 @@
from mockups.helpers import *
from mockups.factory import Factory
-from mockups.base import ModelMockup
+from mockups.base import Mockup
+from mockups.base import Mockup as MockupModel # compat
from mockups.constraints import InvalidConstraint
View
@@ -61,7 +61,7 @@ def get_deep_links(self, field):
return Link(fields, default=self.default)
-class ModelMockup(object):
+class Mockup(object):
'''
.. We don't support the following fields yet:
@@ -114,7 +114,7 @@ def __init__(self, model, constraints=None, follow_fk=None,
will be ignored if this parameter is set.
``factory``: A Factory *instance*, overriding the one defined in the
- ModelMockup class.
+ Mockup class.
'''
self.model = model
self.constraints = constraints or []
@@ -2,7 +2,7 @@
import mockups
from datetime import datetime
from django.contrib.auth.models import User, UNUSABLE_PASSWORD
-from mockups import ModelMockup, Factory
+from mockups import Mockup, Factory
from mockups import generators
@@ -19,9 +19,9 @@ class UserFactory(Factory):
last_login = generators.DateTimeGenerator(max_date=datetime.now())
-class UserModelMockup(ModelMockup):
+class UserMockup(Mockup):
'''
- :class:`UserModelMockup` is automatically used by default to create new
+ :class:`UserMockup` 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(UserModelMockup, self).__init__(*args, **kwargs)
+ super(UserMockup, 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, UserModelMockup, fail_silently=True)
+mockups.register(User, UserMockup, fail_silently=True)
View
@@ -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 ModelMockup
+ from mockups.base import Mockup
warnings.warn('Model `%s` not in registry' % model.__name__)
- cls = ModelMockup
+ cls = Mockup
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:`ModelMockup` subclass that shall be used to
+ *mockup_cls* is the :mod:`Mockup` 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 <registry>` or fall back to the
- default:class:`ModelMockup` class. *model* can be a model class or its
+ default:class:`Mockup` 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:`ModelMockup` for more information.
+ .. note:: See :ref:`Mockup` for more information.
:func:`create` will return a list of the created objects.
'''
@@ -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.MyModelMockup'),
+ u'test data. E.g. myapp.mockup.MyMockup'),
)
def format_output(self, obj):
Oops, something went wrong.

0 comments on commit 8836ecc

Please sign in to comment.