Code Monkey home page Code Monkey logo

Comments (7)

sobolevn avatar sobolevn commented on May 24, 2024

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.

skarzi avatar skarzi commented on May 24, 2024

What's exactly fakery fixtures?
Is it provided by some pytest plugin or it's implemented by you?

from django-test-migrations.

sobolevn avatar sobolevn commented on May 24, 2024

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.

skarzi avatar skarzi commented on May 24, 2024

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.

antonagestam avatar antonagestam commented on May 24, 2024

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.

skarzi avatar skarzi commented on May 24, 2024

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.

sobolevn avatar sobolevn commented on May 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.