Skip to content

Commit

Permalink
renaming action
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikko Hellsing committed Oct 17, 2010
1 parent 0f3ef49 commit cee82ab
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 74 deletions.
6 changes: 5 additions & 1 deletion 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
Expand Down Expand Up @@ -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.
20 changes: 10 additions & 10 deletions README.rst
Expand Up @@ -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
Expand All @@ -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.

Expand All @@ -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
Expand All @@ -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']``)
Expand Down
12 changes: 6 additions & 6 deletions docs/registry.rst
Expand Up @@ -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`.
Expand All @@ -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__
14 changes: 7 additions & 7 deletions docs/usage.rst
Expand Up @@ -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
2 changes: 1 addition & 1 deletion 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

8 changes: 5 additions & 3 deletions mockups/base.py
Expand Up @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 5 additions & 5 deletions mockups/contrib/auth.py
Expand Up @@ -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


Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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)
10 changes: 5 additions & 5 deletions mockups/helpers.py
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
'''
Expand Down
2 changes: 1 addition & 1 deletion mockups/management/commands/mockups.py
Expand Up @@ -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):
Expand Down
Binary file modified mockups_tests/mockups_test/.tests.py.swn
Binary file not shown.

0 comments on commit cee82ab

Please sign in to comment.