Comments (7)
Thanks a lot for the suggestion! However, I think that data creation is out of scope of this project.
Currently I don't have any problems creating it with a code like this:
@pytest.mark.django_db
def test_my_app_migration0031(migrator, fakery):
"""Ensures that the some fields are deleted correctly."""
old_state = migrator.before(
('my_app', '0030_pre'),
)
my_model = old_state.apps.get_model(
'my_app', 'MyModel',
)
kwargs_to_delete = [
{'a': None},
{'b': 'in_progress'},
{'c': None},
{'d': ''},
{'e': ''},
{'f': None},
]
for kwargs in kwargs_to_delete:
fakery.m(my_model)(**kwargs)
assert my_model.objects.count() == len(kwargs_to_delete)
new_state = migrator.after(('my_app', '0031_some'))
my_model = new_state.apps.get_model(
'my_app', 'MyModel',
)
assert not my_model.objects.count()
from django-test-migrations.
What's exactly fakery
fixtures?
Is it provided by some pytest
plugin or it's implemented by you?
from django-test-migrations.
Oh, sorry. It is a tool similar to factoryboy
: https://github.com/fcurella/django-fakery
I use it in all of my projects. It is just awesome!
from django-test-migrations.
Looks really good! I will give it a shot, even just for migrations tests.
I will also do some deeper research on possible ways to integrate factory-boy
with our project.
from django-test-migrations.
It seems like using factories would be pretty hard without either duplicating factories for each tested state, or getting a lot of strange errors because factories are always a mirror of the last database state. To me neither of those options seem worth it.
from django-test-migrations.
That's true, it's possible, but implementation and maintenance will be much more complicated than the benefits, so I am closing this issue
from django-test-migrations.
https://github.com/fcurella/django-fakery can be used, because it uses _meta
to inspect models in runtime.
You don't have to pre-define anything. So, that's quite useful.
from django-test-migrations.
Related Issues (20)
- Add `[email protected]` to the test matrix
- Python3.10 support
- Support `[email protected]`
- Can't handle squashed migrations HOT 1
- typing_extensions is still required in newer Python versions HOT 5
- Models from app state aren't compatible (Cannot assign "<A: A object (1)>": "B.a_fk" must be a "A" instance) HOT 5
- Migrations unrelated to the migration I want to test force the migration I want to test to run before I can test state differences HOT 1
- Migrations unrelated to the migration I want to test force the migration I want to test to run before I can test state differences HOT 2
- Checks failing on MariaDB HOT 1
- Inconsistent behaviour with data migration HOT 8
- Error when testing multiple schemas in django+postgres HOT 1
- Allow using shorthand names & __latest__ for MigrationTargets
- Deadlock when using pants, pytest and django-test-migrations HOT 1
- Cannot test migrations if there is a collation in the migrations HOT 8
- "Relation {table} does not exist" when creating using prototype model HOT 2
- django.db.utils.OperationalError: (1050, "Table 'bar' already exists") HOT 6
- truncate_plan should truncate each app separately HOT 3
- `through_fields` not reflected in test models
- Apply only specific app migrations HOT 2
- Keep initial data in database after migration test
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-test-migrations.