I have test script:
#!/usr/bin/env python
# coding: utf-8
import os, sys, subprocess, time, re
from django.conf import settings
from django.apps import apps
import django
django.setup()
"""
http://stackoverflow.com/questions/24027901/dynamically-loading-django-apps-at-runtime
"""
MAIN_IMPORTS = """\
from django.test import TestCase
from model_mommy import mommy
"""
IMPORT_STATEMENT = """\
from clientsite.{app}.models import {models}
"""
TEST_BLOCK = """\
class {modelname}CreationTests(TestCase):
def setUp(self):
self.model = {modelname}
def test_create(self):
x = mommy.make(self.model)
x.save()
self.assertTrue(x.pk)
def test_factory_isinstance(self):
x = mommy.make(self.model)
self.assertTrue(isinstance(x, {modelname}))
"""
all_apps = apps.get_apps()
all_models = apps.get_models()
model_info = apps.all_models
I want to be able to use django.apps
within my script. The script is within an app like mysite/mommy_app/scripts/testtasm.py
I tried
cchilders:~/work_projects/mysite [ckc/fixture-replacements]$ ./manage.py mysite/mommy_models/scripts/testtasm.py
Unknown command: 'mysite/mommy_models/scripts/testtasm.py'
and failed.
django.setup()
also failed.
How can I use django features within a script without actually running runserver? Thank you.