diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..edca474 --- /dev/null +++ b/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. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..728f6f3 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,5 @@ +include LICENSE +include README +include MANIFEST.in +include django_hudson/management/commands/pylint.rc +recursive-include docs * diff --git a/README b/README index 6b5dbe5..d621a58 100644 --- a/README +++ b/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 diff --git a/docs/quickstart.txt b/docs/quickstart.txt new file mode 100644 index 0000000..4feacd1 --- /dev/null +++ b/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. diff --git a/setup.py b/setup.py index 7dea58b..584b86f 100644 --- a/setup.py +++ b/setup.py @@ -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',