Skip to content

Commit

Permalink
Add basic documentation, update setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kmmbvnr committed Dec 15, 2010
1 parent f1493e2 commit 98ec831
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 1 deletion.
19 changes: 19 additions & 0 deletions LICENSE
@@ -0,0 +1,19 @@
copyright (c) 2010 Mikhail Podgurskiy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,5 @@
include LICENSE
include README
include MANIFEST.in
include django_hudson/management/commands/pylint.rc
recursive-include docs *
26 changes: 26 additions & 0 deletions README
@@ -1 +1,27 @@
Unobtrusive test models creation for django
===========================================

django-any the explicit replacement for old-style, big and error-prone
implicit fixture files.

django-any allows to specify only fields important for test,
and fill rest by random with acceptable values.

It makes tests clean and easy to undestood, without reading fixture files.


from django_any import any_model, WithTestDataSeed

class TestMyShop(TestCase):
def test_order_updates_user_account(self):
account = any_model(Account, amount=25, user__is_active=True)
order = any_model(Order, user=account.user, amount=10)
order.proceed()

account = Account.objects.get(pk=account.pk)
self.assertEquals(15, account.amount)


The same approach available for forms also (django_any.any_form)

See docs/quickstart.txt for more details
71 changes: 71 additions & 0 deletions docs/quickstart.txt
@@ -0,0 +1,71 @@
Quickstart
==========

django-any the explicit replacement for old-style, big and error-prone
implicit fixture files.

django-any allows to specify only fields important for test,
and fill rest by random with acceptable values.


Basic features
--------------

You could get saved in db model instance without specify
any model fields

from django_any import any_model
user = any_model(User)

django-any will preserve all field constrants, such as max_length,
and choices when filling models with random data.

django-any supports the same `double-underscore` syntax as django orm,
for setting subfields values

order = any_model(Order, user__is_active = True)

You could use Q objects, for selection values for fields from fixtures

order = any_model(Order, customer__location=Q(country='US'))


Debugging
---------

It is recomended to specify django_any.WithTestDataSeed as metaclass
for your TestCase

from django_any import any_model, WithTestDataSeed

class SiteTests(TestCase):
__metaclass__ = WithTestDataSeed

def test_something(self):
....

If you test sometimes fails, in error log, you could found used
random seed


======================================================================
FAIL: test__something (mysite.SiteTests) With seed 1434556623


You could use this seed, to reapeat and debug you tests, with exactly
the same random data


from django_any import any_model, WithTestDataSeed, with_seed, without_random_seed

class SiteTests(TestCase):
__metaclass__ = WithTestDataSeed

@without_random_seed
@with_seed(1434556623)
def test_something(self):
....


`without_random_seed` decorator disables test run with random seed, and
`with_seed` runs test with selected seed.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -2,7 +2,7 @@

setup(
name='django-any',
version='0.0.1',
version='0.1.0',
description='Unobtrusive test models creation for django.',
author='Mikhail Podgurskiy',
author_email='kmmbvnr@gmail.com',
Expand Down

0 comments on commit 98ec831

Please sign in to comment.