Commits

ollyc  committed 1d1df50

Updated README

  • Participants
  • Parent commits a3edb43

Comments (0)

Files changed (1)

 
         fixture.teardown()
 
+Toffee is similar in scope to `factory_boy <https://github.com/dnerdy/factory_boy>`_.
+The differences that prompted me to write a new library are:
 
-If you're using Django, you need to use DjangoFactory, which knows how to
-create and delete DjangoFactory model objects correctly. 
+- It promotes working with on fixtures of groups of objects to be created and
+  destroyed as a unit
+- Explicit support for setup/teardown of fixtures
 
-Example for Django::
+Use with Django
+---------------
+
+To use this with Django's ORM, import DjangoFactory, which knows how to create
+and delete Django model objects correctly::
 
     from toffee import DjangoFactory as Factory
     from myapp.models import Product
     class MyFixture(Fixture):
         product_2 = Factory(Product, desc='toy tractor')
 
-There is currently no support for other ORMs (although it is planned).
 
-Toffee is similar in scope to `factory_boy <https://github.com/dnerdy/factory_boy>`_.
-The differences that prompted me to write a new library are:
+Use with Storm
+--------------
 
-- It promotes working with on fixtures of groups of objects to be created and
-  destroyed as a unit
-- Explicit support for setup/teardown of fixtures
+To use this with the `Storm ORM <http://storm.canonical.com/>`,
+import StormFactory, which knows how to create
+and delete objects with Storm::
+
+    from toffee import StormFactory
+    from myapp.models import Product
+
+    from storm.database import create_database
+    from storm.store import Store
+
+    database = create_database('sqlite:')
+    Factory = StormFactory.configure(lamdba: Store(database))
+
+    class MyFixture(Fixture):
+        product_2 = Factory(Product, desc='toy tractor')
+
+
+Other ORMs
+----------
+
+There is currently no support for other ORMs. Contributions are welcome!
 
 Setup and teardown
 ------------------
 
         def test_wotsit(self):
             assert self.fixtures.user.username == 'fred'
-            assert self.fixtures.user.get_profile().address == '10 Downing Street'
+            assert self.fixtures.user.get_profile().address == \
+              '10 Downing Street'
 
 
 You can also use fixtures as context managers,
         fred = Factory(User, username='fred', is_admin=False)
         albert = Factory(User, username='albert', is_admin=True)
 
-You can avoid repeating code by predefine factories for commonly used model classes::
+You can avoid repeating code by predefine factories for commonly used model
+classes::
 
     user_factory = Factory(User, is_admin=False, is_active=True)
 
 ---------
 
 When creating multiple objects of the same type you can use the
-:class:`~toffee.Seq` class to avoid manually specifying unique values for fields::
+:class:`~toffee.Seq` class to avoid manually specifying unique values for
+fields::
 
     product_factory = Factory(Product, sku=Seq('%04d', 0))
 
     class BugFixture(Fixture):
 
         product = Factory(Product, name='my amazing software')
-        bug1 = Factory(Bug, description="it doesnt work", product=product)
-        bug2 = Factory(Bug, description="it still doesnt work", product=product)
+        bug1 = Factory(Bug, comment="it doesnt work", product=product)
+        bug2 = Factory(Bug, comment="it still doesnt work", product=product)
 
 Now when we setup the fixture, toffee will figure out the relationships we need
 to create the object graph - a single Product instance, linked to two bugs::
         assert f.bug1.product is f.bug2.product
 
 
-Suppose we write a lot of tests, and we need a lot of fixtures. To avoid having to repeat a lot of code we can predefine the factories::
+Suppose we write a lot of tests, and we need a lot of fixtures. To avoid having
+to repeat a lot of code we can predefine the factories::
 
     product_factory = Factory(Product, name=Seq('Product-%d'))
-    bug_factory = Factory(Bug, description=Seq('Bug #%d'), product=product_factory)
+    bug_factory = Factory(Bug, comment=Seq('Bug #%d'), product=product_factory)
 
 
 Notice the ``product=product_factory`` bit. Using this ``bug_factory``