Skip to content

Instantly share code, notes, and snippets.

@felipecruz
Created February 20, 2013 20:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipecruz/4998966 to your computer and use it in GitHub Desktop.
Save felipecruz/4998966 to your computer and use it in GitHub Desktop.
Generate models tests boilerplate code
from django.conf import settings
from django.db.models import get_apps, get_app, get_models
app = get_app('realestate')
source = '''
class %sTest(TestCase):
def test_import(self):
from %s import %s
'''
app_full_name = app.__name__
for model in get_models(app):
model_name = model._meta.object_name
print(source % (model_name, app_full_name, model_name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment