Simple library for creating fake models in the unit tests.
This simple library allows to create fake models in your test without migrations, test apps and test tables in your base. All tables that you need will created/removed during the test.
Install
Install django-fake-model:
pip install django-fake-model
Quickstart
Just create a model in any file (Ex: in your test) and add decorator @YourModel.fake_me to test method or test class.
from django_fake_model import models as f
from django.db import models
from django.test import TestCase, TransactionTestCase
class MyFakeModel(f.FakeModel):
name = models.CharField(max_length=100)
@MyFakeModel.fake_me
class MyFakeModelTests(TestCase):
def test_create_model(self):
MyFakeModel.objects.create(name='123')
model = MyFakeModel.objects.get(name='123')
self.assertEqual(model.name, '123')
class MyFakeModelFunctionTest(TestCase):
@MyFakeModel.fake_me
def test_create_model(self):
MyFakeModel.objects.create(name='123')
model = MyFakeModel.objects.get(name='123')
self.assertEqual(model.name, '123')
class RelatedModel(f.FakeModel):
text = models.CharField(max_length=400)
class NyModel(f.FakeModel):
text = models.CharField(max_length=400)
related_model = models.ForeignKey(RelatedModel)
@NyModel.fake_me
@RelatedModel.fake_me
class TestRelatedModelsClassDecorator(TransactionTestCase):
def test_create_models(self):
related_model = RelatedModel()
related_model.text = 'qwerty'
related_model.save()
my_model = NyModel()
my_model.test = 'qwerty'
my_model.related_model = related_model
my_model.save()
self.assertIsNotNone(my_model)
self.assertIsNotNone(related_model)
Development:
To develop on this locally with Docker, install the Docker Engine and Docker Compose. Then you can build the Docker image and run the tests on all tox activities(this also uses a shared pip cache to reduce download times):
docker-compose up -d pg mysql docker-compose run --rm test
If you wanna run just one Tox activity you can specify that as well:
docker-compose run --rm test tox -e py35-dj19-mysql-unittest
If you add any dependencies or change the tox configuration, you have to rebuild the image:
docker-compose build
It will share this folder with the Docker containers, so that
History
0.1.4 (2016-02-08)
Fix class decorator fake_me for nose tests
0.1.3 (2015-12-23)
Fix issue #1 Multiple Fake Models. Thanks to Saul Shanabrook (@saulshanabrook)
Add support for developing with Docker. Thanks to Saul Shanabrook again
0.1.2 (2015-11-13)
Added Django 1.9 support
Added travis config generator
Added nose tests
Remove tests for Django master
0.1.1 (2015-09-28)
Added tests with different databases.
0.1.0 (2015-09-16)
First release on PyPI.
Metadata
Release files for django-fake-model 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-fake-model-0.1.4.tar.gz | 6.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_fake_model-0.1.4-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 13.2 kB
Release files / django-fake-model-0.1.4.tar.gz
| Download URL | django-fake-model-0.1.4.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
44940dea141be48ccffeab917c69de3a70c98cb45c3a2a224c2a800b57913965
|
|
BLAKE2b-256 checksum How to use checksums |
0fe18f330ca5dfb930850b1f232a0eaba6576befa890ac3e7e4ea950b54ad411
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / django_fake_model-0.1.4-py2.py3-none-any.whl
| Download URL | django_fake_model-0.1.4-py2.py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
5f5bd31a8825cb561f6df1dc2d8efbe1ba46f2082aa584d6438862b3e040e5f6
|
|
BLAKE2b-256 checksum How to use checksums |
27bd3e9132c29a5d805e7bfac37940072c2c1e1f5cac892707696863e3895fd4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |