Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'no-pil'

Conflicts:
	MANIFEST.in
	README.md
	setup.py
  • Loading branch information...
commit bc6e3e318390cbddd356c9ec571e0d473a9662b2 2 parents 27500c3 + 6fa7e2e
@vandersonmota authored
View
1  MANIFEST.in
@@ -1,3 +1,4 @@
include model_mommy/mock_file.txt
include model_mommy/mock-img.jpeg
+include README.rst
include requirements.txt
View
6 model_mommy/mommy.py
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
-from django.conf import settings
from django.utils import importlib
from django.db.models.fields import AutoField, CharField, TextField, SlugField
@@ -27,6 +26,11 @@
recipes = None
+from os.path import dirname, join
+mock_file_jpeg = join(dirname(__file__), 'mock-img.jpeg')
+mock_file_txt = join(dirname(__file__), 'mock_file.txt')
+
+
#TODO: improve related models handling
foreign_key_required = [lambda field: ('model', field.related.parent_model)]
View
2  requirements.txt
@@ -1,3 +1 @@
Django<1.5
-PIL==1.1.7
-tox==1.4.2
View
27 runtests.py
@@ -9,15 +9,7 @@
def parse_args():
parser = OptionParser()
parser.add_option('--use-tz', dest='USE_TZ', action='store_true')
- options, args = parser.parse_args()
-
- # Build labels
- if args:
- labels = ["model_mommy.%s" % label for label in args]
- else:
- labels = ['model_mommy']
-
- return options, labels
+ return parser.parse_args()
def configure_settings(options):
@@ -35,15 +27,15 @@ def configure_settings(options):
},
INSTALLED_APPS = (
'django.contrib.contenttypes',
- 'model_mommy',
+ 'test.generic',
),
SITE_ID=1,
- TEST_ROOT=join(dirname(__file__), 'model_mommy', 'tests'),
+ TEST_ROOT=join(dirname(__file__), 'test', 'generic', 'tests'),
)
# Force the use of timezone aware datetime and change Django's warning to
# be treated as errors.
- if options.USE_TZ:
+ if getattr(options, 'USE_TZ', False):
params.update(USE_TZ=True)
warnings.filterwarnings('error', r"DateTimeField received a naive datetime",
RuntimeWarning, r'django\.db\.models\.fields')
@@ -63,12 +55,15 @@ def get_runner(settings):
return TestRunner(verbosity=1, interactive=True, failfast=False)
-def runtests():
- options, test_labels = parse_args()
+def runtests(options=None, labels=None):
+ if not labels:
+ labels = ['generic']
+
settings = configure_settings(options)
runner = get_runner(settings)
- sys.exit(runner.run_tests(test_labels))
+ sys.exit(runner.run_tests(labels))
if __name__ == '__main__':
- runtests()
+ options, labels = parse_args()
+ runtests(options, labels)
View
14 setup.py
@@ -5,15 +5,21 @@
setuptools.setup(
name="model_mommy",
version="0.8.1",
- author="Vanderson Mota",
+ packages=["model_mommy"],
+ include_package_data=True, # declarations in MANIFEST.in
+ install_requires=open(join(dirname(__file__), 'requirements.txt')).readlines(),
+ tests_require=[
+ 'django<1.5',
+ 'pil',
+ 'tox',
+ ],
+ test_suite='runtests.runtests',
+ author="vandersonmota",
author_email="vandersonmota@gmail.com",
url="http://github.com/vandersonmota/model_mommy",
license="Apache 2.0",
description="Smart object creation facility for Django.",
long_description=open(join(dirname(__file__), "README.rst")).read(),
- packages=["model_mommy"],
- include_package_data=True, # declarations in MANIFEST.in
- install_requires=open(join(dirname(__file__), "requirements.txt")).readlines(),
keywords="django testing factory python",
classifiers=[
'Framework :: Django',
View
0  model_mommy/tests/sub_package/__init__.py → test/__init__.py
File renamed without changes
View
0  test/generic/__init__.py
No changes.
View
10 model_mommy/models.py → test/generic/models.py
@@ -140,10 +140,6 @@ class DummyFileFieldModel(models.Model):
file_field = models.FileField(upload_to="%Y/%m/%d", storage=fs)
-try:
- import PIL
- class DummyImageFieldModel(models.Model):
- fs = FileSystemStorage(location='/tmp/')
- image_field = models.ImageField(upload_to="%Y/%m/%d", storage=fs)
-except ImportError:
- pass
+class DummyImageFieldModel(models.Model):
+ fs = FileSystemStorage(location='/tmp/')
+ image_field = models.ImageField(upload_to="%Y/%m/%d", storage=fs)
View
2  model_mommy/mommy_recipes.py → test/generic/mommy_recipes.py
@@ -2,8 +2,8 @@
#ATTENTION: Recipes defined for testing purposes only
from model_mommy.recipe import Recipe, foreign_key
-from model_mommy.models import Person, Dog
from model_mommy.timezone import now
+from test.generic.models import Person, Dog
person = Recipe(Person,
View
0  model_mommy/tests/__init__.py → test/generic/tests/__init__.py
File renamed without changes
View
0  test/generic/tests/sub_package/__init__.py
No changes.
View
2  model_mommy/tests/sub_package/mommy_recipes.py → test/generic/tests/sub_package/mommy_recipes.py
@@ -1,6 +1,6 @@
#coding: utf-8
-from model_mommy.models import Person
from model_mommy.recipe import Recipe, foreign_key
+from test.generic.models import Person
from datetime import date, datetime
View
2  model_mommy/tests/test_extending_mommy.py → test/generic/tests/test_extending_mommy.py
@@ -2,8 +2,8 @@
from django.test import TestCase
from model_mommy import mommy
-from model_mommy.models import Person
from model_mommy.generators import gen_from_list
+from test.generic.models import Person
__all__ = ['SimpleExtendMommy', 'LessSimpleExtendMommy']
View
68 model_mommy/tests/test_filling_fields.py → test/generic/tests/test_filling_fields.py
@@ -1,9 +1,6 @@
from datetime import date, datetime, time
from decimal import Decimal
-import os
-from os.path import abspath, join, dirname
-
from django.test import TestCase
from django.contrib.contenttypes.models import ContentType
from django.db.models.fields import CharField, TextField, SlugField
@@ -24,12 +21,13 @@
#BigIntegerField = IntegerField
from model_mommy import mommy
-from model_mommy.models import Person
-from model_mommy.models import DummyIntModel, DummyPositiveIntModel
-from model_mommy.models import DummyNumbersModel
-from model_mommy.models import DummyDecimalModel, DummyEmailModel
-from model_mommy.models import DummyGenericForeignKeyModel
-from model_mommy.models import DummyFileFieldModel
+from test.generic.models import Person
+from test.generic.models import DummyIntModel, DummyPositiveIntModel
+from test.generic.models import DummyNumbersModel
+from test.generic.models import DummyDecimalModel, DummyEmailModel
+from test.generic.models import DummyGenericForeignKeyModel
+from test.generic.models import DummyFileFieldModel
+from test.generic.models import DummyImageFieldModel
__all__ = [
'StringFieldsFilling', 'BooleanFieldsFilling', 'DateTimeFieldsFilling',
@@ -57,7 +55,7 @@ def setUp(self):
class FillingFromChoice(FieldFillingTestCase):
def test_if_gender_is_populated_from_choices(self):
- from model_mommy.models import GENDER_CH
+ from test.generic.models import GENDER_CH
self.assertTrue(self.person.gender in map(lambda x: x[0], GENDER_CH))
@@ -208,7 +206,7 @@ def test_filling_content_type_field(self):
class FillingFileField(TestCase):
def setUp(self):
- path = abspath(join(dirname(__file__),'..','mock_file.txt'))
+ path = mommy.mock_file_txt
self.fixture_txt_file = File(open(path))
def test_filling_file_field(self):
@@ -225,30 +223,24 @@ def test_filling_file_field(self):
def tearDown(self):
self.dummy.file_field.delete()
-try:
- from model_mommy.models import DummyImageFieldModel
- __all__ += ['FillingImageFileField']
-
- class FillingImageFileField(TestCase):
-
- def setUp(self):
- path = abspath(join(dirname(__file__),'..','mock-img.jpeg'))
- self.fixture_img_file = ImageFile(open(path))
-
- def test_filling_image_file_field(self):
- self.dummy = mommy.make_one(DummyImageFieldModel)
- field = DummyImageFieldModel._meta.get_field('image_field')
- self.assertIsInstance(field, ImageField)
- import time
- path = "/tmp/%s/mock-img.jpeg" % time.strftime('%Y/%m/%d')
-
- from django import VERSION
- if VERSION[1] >= 4:
- self.assertEqual(self.dummy.image_field.path, path)
- self.assertTrue(self.dummy.image_field.width)
- self.assertTrue(self.dummy.image_field.height)
-
- def tearDown(self):
- self.dummy.image_field.delete()
-except ImportError:
- pass
+class FillingImageFileField(TestCase):
+
+ def setUp(self):
+ path = mommy.mock_file_jpeg
+ self.fixture_img_file = ImageFile(open(path))
+
+ def test_filling_image_file_field(self):
+ self.dummy = mommy.make_one(DummyImageFieldModel)
+ field = DummyImageFieldModel._meta.get_field('image_field')
+ self.assertIsInstance(field, ImageField)
+ import time
+ path = "/tmp/%s/mock-img.jpeg" % time.strftime('%Y/%m/%d')
+
+ from django import VERSION
+ if VERSION[1] >= 4:
+ self.assertEqual(self.dummy.image_field.path, path)
+ self.assertTrue(self.dummy.image_field.width)
+ self.assertTrue(self.dummy.image_field.height)
+
+ def tearDown(self):
+ self.dummy.image_field.delete()
View
18 model_mommy/tests/test_mommy.py → test/generic/tests/test_mommy.py
@@ -5,13 +5,13 @@
from model_mommy import mommy
from model_mommy.mommy import ModelNotFound
-from model_mommy.models import Person, Dog, Store, LonelyPerson
-from model_mommy.models import User, PaymentBill
-from model_mommy.models import UnsupportedModel, DummyGenericRelationModel
-from model_mommy.models import DummyNullFieldsModel, DummyBlankFieldsModel
-from model_mommy.models import DummyDefaultFieldsModel
-from model_mommy.models import DummyGenericForeignKeyModel
from model_mommy.timezone import smart_datetime as datetime
+from test.generic.models import Person, Dog, Store, LonelyPerson
+from test.generic.models import User, PaymentBill
+from test.generic.models import UnsupportedModel, DummyGenericRelationModel
+from test.generic.models import DummyNullFieldsModel, DummyBlankFieldsModel
+from test.generic.models import DummyDefaultFieldsModel
+from test.generic.models import DummyGenericForeignKeyModel
class MommyCreatesSimpleModel(TestCase):
@@ -40,11 +40,11 @@ def test_make_many(self):
self.assertTrue(all(p.name == "George Washington" for p in people))
def test_accept_model_as_string(self):
- person = mommy.make_one('model_mommy.person')
+ person = mommy.make_one('generic.person')
self.assertIsInstance(person, Person)
- person = mommy.prepare_one('model_mommy.Person')
+ person = mommy.prepare_one('generic.Person')
self.assertIsInstance(person, Person)
- people = mommy.make_many('model_mommy.person')
+ people = mommy.make_many('generic.person')
[self.assertIsInstance(person, Person) for person in people]
def test_raise_pretty_excpetion_if_model_not_found(self):
View
26 model_mommy/tests/test_recipes.py → test/generic/tests/test_recipes.py
@@ -2,9 +2,9 @@
from django.test import TestCase
from model_mommy import mommy
-from model_mommy.models import Person, DummyNumbersModel, DummyBlankFieldsModel
from model_mommy.recipe import Recipe, foreign_key
from model_mommy.timezone import now
+from test.generic.models import Person, DummyNumbersModel, DummyBlankFieldsModel
class TestDefiningRecipes(TestCase):
@@ -103,54 +103,54 @@ class TestExecutingRecipes(TestCase):
Tests for calling recipes defined in mommy_recipes.py
"""
def test_model_with_foreign_key(self):
- dog = mommy.make_recipe('model_mommy.dog')
+ dog = mommy.make_recipe('test.generic.dog')
self.assertEqual(dog.breed, 'Pug')
self.assertIsInstance(dog.owner, Person)
self.assertNotEqual(dog.owner.id, None)
- dog = mommy.prepare_recipe('model_mommy.dog')
+ dog = mommy.prepare_recipe('test.generic.dog')
self.assertEqual(dog.breed, 'Pug')
self.assertIsInstance(dog.owner, Person)
self.assertNotEqual(dog.owner.id, None)
def test_model_with_foreign_key_as_str(self):
- dog = mommy.make_recipe('model_mommy.other_dog')
+ dog = mommy.make_recipe('test.generic.other_dog')
self.assertEqual(dog.breed, 'Basset')
self.assertIsInstance(dog.owner, Person)
self.assertNotEqual(dog.owner.id, None)
- dog = mommy.prepare_recipe('model_mommy.other_dog')
+ dog = mommy.prepare_recipe('test.generic.other_dog')
self.assertEqual(dog.breed, 'Basset')
self.assertIsInstance(dog.owner, Person)
self.assertNotEqual(dog.owner.id, None)
def test_make_recipe(self):
- person = mommy.make_recipe('model_mommy.person')
+ person = mommy.make_recipe('test.generic.person')
self.assertIsInstance(person, Person)
self.assertNotEqual(person.id, None)
def test_prepare_recipe(self):
- person = mommy.prepare_recipe('model_mommy.person')
+ person = mommy.prepare_recipe('test.generic.person')
self.assertIsInstance(person, Person)
self.assertEqual(person.id, None)
def test_make_recipe_with_args(self):
- person = mommy.make_recipe('model_mommy.person', name='Dennis Ritchie', age=70)
+ person = mommy.make_recipe('test.generic.person', name='Dennis Ritchie', age=70)
self.assertEqual(person.name, 'Dennis Ritchie')
self.assertEqual(person.age, 70)
def test_prepare_recipe_with_args(self):
- person = mommy.prepare_recipe('model_mommy.person', name='Dennis Ritchie', age=70)
+ person = mommy.prepare_recipe('test.generic.person', name='Dennis Ritchie', age=70)
self.assertEqual(person.name, 'Dennis Ritchie')
self.assertEqual(person.age, 70)
def test_import_recipe_inside_deeper_modules(self):
- recipe_name = 'model_mommy.tests.sub_package.person'
+ recipe_name = 'test.generic.tests.sub_package.person'
person = mommy.prepare_recipe(recipe_name)
self.assertEqual(person.name, 'John Deeper')
def test_make_many_from_recipe(self):
- persons = mommy.make_many_from_recipe('model_mommy.person')
+ persons = mommy.make_many_from_recipe('test.generic.person')
self.assertIsInstance(persons, list)
self.assertEqual(len(persons), mommy.MAX_MANY_QUANTITY)
for person in persons:
@@ -159,12 +159,12 @@ def test_make_many_from_recipe(self):
def test_make_many_from_recipe_with_specified_quantity(self):
quantity = 2
- persons = mommy.make_many_from_recipe('model_mommy.person', quantity=quantity)
+ persons = mommy.make_many_from_recipe('test.generic.person', quantity=quantity)
self.assertIsInstance(persons, list)
self.assertEqual(len(persons), quantity)
def test_make_many_with_model_args(self):
- persons = mommy.make_many_from_recipe('model_mommy.person', name='Dennis Ritchie', age=70)
+ persons = mommy.make_many_from_recipe('test.generic.person', name='Dennis Ritchie', age=70)
for person in persons:
self.assertEqual(person.name, 'Dennis Ritchie')
self.assertEqual(person.age, 70)
Please sign in to comment.
Something went wrong with that request. Please try again.