croach / Flask-Fixtures

A simple library for adding database fixtures for unit tests using nothing but JSON or YAML.
MIT License
63 stars 30 forks source link

add load_fixtures_from_files #16

Closed elvismacak closed 5 years ago

elvismacak commented 9 years ago

I think this is a really good idea and project.

I prefered to use load_fixture in manage.py, like django.

./manage.py load_fixtures

but, i got no direct method to do this.

before this commit, i use:

import json
...
...
@manager.command
def load_fixtures():
    json_files = ['user.json', 'category.json', 'book.json']
    for json_file in json_files:
        fixtures = json.load(open('fixtures/' + json_file))
        fixtures_loader(db, fixtures)

it's a bit complex and hard-code, so i add a method, and then:

@manager.command
def load_fixtures():
    json_files = ['user.json', 'category.json', 'book.json']
    load_fixtures_from_files(db, json_files)

hope it's helpful and meets your orignal desgin

thx

croach commented 8 years ago

Hi @elvis-macak, I looked over the pull request, and it looks like the change you're proposing would add a new function that copies code from the setup function. I don't think I would have a problem with accepting the pull request if instead it refactored the code in the setup function into a new function.