def main(package="mezzanine", args=()): """ This is the main test function called via ``python setup.py test``. It's responsible for hacking the ``project_template`` dir into an actual project to test against. """ from mezzanine.utils.importing import path_for_import package_path = path_for_import(package) project_path = os.path.join(package_path, "project_template") os.environ["DJANGO_SETTINGS_MODULE"] = "project_name.test_settings" project_app_path = os.path.join(project_path, "project_name") local_settings_path = os.path.join(project_app_path, "local_settings.py") test_settings_path = os.path.join(project_app_path, "test_settings.py") sys.path.insert(0, package_path) sys.path.insert(0, project_path) if not os.path.exists(test_settings_path): shutil.copy(local_settings_path + ".template", test_settings_path) with open(test_settings_path, "r") as f: local_settings = f.read() with open(test_settings_path, "w") as f: test_settings = """ from . import settings globals().update(i for i in settings.__dict__.items() if i[0].isupper()) # Require the mezzanine.accounts app. We use settings.INSTALLED_APPS here so # the syntax test doesn't complain about an undefined name. if "mezzanine.accounts" not in settings.INSTALLED_APPS: INSTALLED_APPS = list(settings.INSTALLED_APPS) + ["mezzanine.accounts", "django.contrib.messages"] # Use the MD5 password hasher by default for quicker test runs. PASSWORD_HASHERS = ('django.contrib.auth.hashers.MD5PasswordHasher',) """ f.write(test_settings + local_settings) def cleanup_test_settings(): import os # Outer scope sometimes unavailable in atexit functions. for fn in [test_settings_path, test_settings_path + 'c']: try: os.remove(fn) except OSError: pass atexit.register(cleanup_test_settings) django.setup() from django.core.management.commands import test if django.VERSION < (1, 10): sys.exit(test.Command().execute(*args, verbosity=1)) sys.exit(call_command(test.Command(), *args, verbosity=1))
def main(package="mezzanine"): """ This is the main test function called via ``python setup.py test``. It's responsible for hacking the ``project_template`` dir into an actual project to test against. """ from mezzanine.utils.importing import path_for_import os.environ["DJANGO_SETTINGS_MODULE"] = "project_template.test_settings" package_path = path_for_import(package) project_path = os.path.join(package_path, "project_template") local_settings_path = os.path.join(project_path, "local_settings.py") test_settings_path = os.path.join(project_path, "test_settings.py") sys.path.insert(0, package_path) sys.path.insert(0, project_path) if not os.path.exists(test_settings_path): shutil.copy(local_settings_path + ".template", test_settings_path) with open(test_settings_path, "r") as f: local_settings = f.read() with open(test_settings_path, "w") as f: test_reqs_str = """ from project_template import settings globals().update(settings.__dict__) INSTALLED_APPS = list(settings.INSTALLED_APPS) + ["mezzanine.accounts"] """ if django.VERSION >= (1, 7): test_reqs_str += "import django\ndjango.setup()" f.write(test_reqs_str + local_settings) atexit.register(lambda: os.remove(test_settings_path)) from django.core.management.commands import test sys.exit(test.Command().execute(verbosity=1))
def main(): """ This is the main test function called via ``python setup.py test``. """ os.environ["DJANGO_SETTINGS_MODULE"] = "project.settings" django.setup() from django.core.management.commands import test sys.exit(test.Command().execute(verbosity=1))
def runtests(): import os, sys, shutil, atexit from mezzanine.utils.importing import path_for_import os.environ["DJANGO_SETTINGS_MODULE"] = "project_template.settings" mezz_path = path_for_import("mezzanine") sys.path.insert(0, mezz_path) project_path = os.path.join(mezz_path, "project_template") local_settings_path = os.path.join(project_path, "local_settings.py") if not os.path.exists(local_settings_path): shutil.copy(local_settings_path + ".template", local_settings_path) atexit.register(lambda: os.remove(local_settings_path)) from django.core.management.commands import test sys.exit(test.Command().execute(verbosity=1))
def runtests(): import os, sys, shutil, atexit from mezzanine.utils.importing import path_for_import os.environ["DJANGO_SETTINGS_MODULE"] = "project_template.settings" mezz_path = path_for_import("mezzanine") project_path = os.path.join(mezz_path, "project_template") local_settings_path = os.path.join(project_path, "local_settings.py") sys.path.insert(0, mezz_path) sys.path.insert(0, project_path) if not os.path.exists(local_settings_path): shutil.copy(local_settings_path + ".template", local_settings_path) with open(local_settings_path, "a") as f: f.write(""" INSTALLED_APPS = ( "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.redirects", "django.contrib.sessions", "django.contrib.sites", "django.contrib.sitemaps", "django.contrib.staticfiles", "mezzanine.boot", "mezzanine.conf", "mezzanine.core", "mezzanine.generic", "mezzanine.blog", "mezzanine.forms", "mezzanine.pages", "mezzanine.galleries", "mezzanine.twitter", "mezzanine.accounts", "mezzanine.mobile", ) """) atexit.register(lambda: os.remove(local_settings_path)) from django.core.management.commands import test sys.exit(test.Command().execute(verbosity=1))
def runtests(): test_runner_path = os.path.dirname(__file__) project_template_path = os.path.join( test_runner_path, 'misago/project_template/project_name') avatars_store_path = os.path.join( test_runner_path, 'misago/project_template/avatar_store') media_path = os.path.join( test_runner_path, 'misago/project_template/media') test_project_path = os.path.join(test_runner_path, "testproject") test_project_avatars_path = os.path.join(test_runner_path, "avatar_store") test_project_media_path = os.path.join(test_runner_path, "media") if not os.path.exists(test_project_path): shutil.copytree(project_template_path, test_project_path) shutil.copytree(avatars_store_path, test_project_avatars_path) shutil.copytree(media_path, test_project_media_path) settings_path = os.path.join(test_project_path, "settings.py") with open(settings_path, "r") as py_file: settings_file = py_file.read() # Do some configuration magic settings_file = settings_file.replace("{{ project_name }}", "testproject") settings_file = settings_file.replace("{{ secret_key }}", "t3stpr0j3ct") settings_file += """ EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend' CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', 'LOCATION': 'uniqu3-sn0wf14k3' } } """ if os.environ.get('TRAVIS'): settings_file += """ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'travis_ci_test', 'USER': '******', 'PASSWORD': '', 'HOST': '127.0.0.1', 'PORT': '', } } TEST_NAME = 'travis_ci_test' """ else: settings_file += """ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'misago_postgres', 'USER': '******', 'PASSWORD': '', 'HOST': '', 'PORT': '', } } """ % pwd.getpwuid(os.getuid())[0] with open(settings_path, "w") as py_file: py_file.write(settings_file) os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings") setup() setup_test_environment() if __name__ == '__main__': args = sys.argv[1:] else: args = [] from django.core.management.commands import test sys.exit(test.Command().execute(*args, verbosity=1))
def run_django(*args, **kwargs): setup() setup_test_environment() from django.core.management.commands import test sys.exit(test.Command().execute(*args, **kwargs))
def runtests(): test_runner_path = os.path.dirname(__file__) project_template_path = os.path.join(test_runner_path, 'misago/project_template') project_package_path = os.path.join( test_runner_path, 'misago/project_template/project_name') test_project_path = os.path.join(test_runner_path, "testproject") if not os.path.exists(test_project_path): shutil.copytree(project_template_path, test_project_path) for filename in os.listdir(project_package_path): src_path = os.path.join(project_package_path, filename) dst_path = os.path.join(test_project_path, filename) shutil.copy2(src_path, dst_path) settings_path = os.path.join(test_project_path, "settings.py") with open(settings_path, "r") as py_file: settings_file = py_file.read() # Do some configuration magic settings_file = settings_file.replace( "os.path.dirname(os.path.dirname(__file__))", "os.path.dirname(__file__)") settings_file = settings_file.replace("{{ project_name }}", "testproject") settings_file = settings_file.replace("{{ secret_key }}", "t3stpr0j3ct") settings_file += """ # disable account validation via API's MISAGO_NEW_REGISTRATIONS_VALIDATORS = () # store mails in memory EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend' # use in-memory cache CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', 'LOCATION': 'uniqu3-sn0wf14k3' } } # Use MD5 password hashing to speed up test suite PASSWORD_HASHERS = ( 'django.contrib.auth.hashers.MD5PasswordHasher', ) """ if os.environ.get('TRAVIS'): settings_file += """ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'travis_ci_test', 'USER': '******', 'PASSWORD': '', 'HOST': '127.0.0.1', 'PORT': '', } } TEST_NAME = 'travis_ci_test' """ else: settings_file += """ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'misago_postgres', 'USER': '******', 'PASSWORD': '', 'HOST': '', 'PORT': '', } } """ % pwd.getpwuid(os.getuid())[0] with open(settings_path, "w") as py_file: py_file.write(settings_file) os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings") setup() setup_test_environment() if __name__ == '__main__': args = sys.argv[1:] else: args = [] from django.core.management.commands import test sys.exit(test.Command().execute(*args, verbosity=1, noinput=True))