def test_write(tmpenvdir): env = envdir.open(str(tmpenvdir)) env['WRITE'] = 'test' assert tmpenvdir.ensure('WRITE') assert tmpenvdir.join('WRITE').read() == 'test' envdir.read(str(tmpenvdir)) assert os.environ['WRITE'] == 'test'
def test_write_magic(tmpdir): tmp = tmpdir.mkdir('envdir') magic_scripts = tmpdir.join('test_magic_write.py') magic_scripts.write(""" import envdir, os, sys env = envdir.open() env['WRITE_MAGIC'] = 'test' """) subprocess.call(['python', str(magic_scripts)]) assert tmp.join('WRITE_MAGIC').read() == 'test' envdir.read(str(tmp)) assert os.environ['WRITE_MAGIC'] == 'test'
def test_read_magic_dir(capfd, tmpdir): "Python usage with magic envdir" tmp = tmpdir.mkdir('envdir') tmp.join('READ_MAGIC').write('test') magic_scripts = tmpdir.join('test_magic.py') magic_scripts.write(""" import envdir, os, sys envdir.read() if 'READ_MAGIC' in os.environ: sys.exit(42) """) status = subprocess.call(['python', str(magic_scripts)]) assert status == 42 # this should raise a Response with an error because envdir.run() # can't have all arguments with py.test.raises(SystemExit) as response: envdir.run('envdir', str(tmp)) out, err = capfd.readouterr() assert response.value.code == 2 assert "incorrect number of arguments" in err with py.test.raises(SystemExit) as response: envdir.run() out, err = capfd.readouterr() assert response.value.code == 2
#!/usr/bin/env python import os import sys try: import envdir except ImportError: envdir = None if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djangopeople.settings") if envdir is not None: if 'test' in sys.argv: env_dir = os.path.join('tests', 'env') else: env_dir = 'env' envdir.read(env_dir) from django.core.management import execute_from_command_line execute_from_command_line(sys.argv)
""" import os from pathlib import Path env = os.environ.get('ENVDIR', 'dev') parent_dir = Path(__file__).parent.parent # if env == 'prod': # import newrelic.agent # newrelic.agent.initialize(str(parent_dir / 'newrelic.ini')) import envdir envdir.read(str(parent_dir / 'envs' / env)) # We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks # if running multiple sites in the same mod_wsgi process. To fix this, use # mod_wsgi daemon mode with each site in its own daemon process, or use # os.environ["DJANGO_SETTINGS_MODULE"] = "ciupy3.settings" os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ciupy3.settings") os.environ.setdefault("DJANGO_CONFIGURATION", "Dev") # This application object is used by any WSGI server configured to use this # file. This includes Django's development server, if the WSGI_APPLICATION # setting points here. from configurations.wsgi import get_wsgi_application from whitenoise.django import DjangoWhiteNoise application = get_wsgi_application() application = DjangoWhiteNoise(application)
""" WSGI config for saja_expo project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ """ import sys import envdir from os.path import join, dirname, abspath # Root directory for this project PROJECT_DIR = dirname(dirname(dirname(abspath(__file__)))) # Add the apps folder to the path and read the env-vars. sys.path.append(join(PROJECT_DIR, 'apps')) envdir.read(join(PROJECT_DIR, 'envs')) # Load the wsgi application with django-configurations. from configurations.wsgi import get_wsgi_application application = get_wsgi_application()
def test_read_existing_var(tmpenvdir): tmpenvdir.join('READ_EXISTING').write('override') os.environ['READ_EXISTING'] = 'test' envdir.read(str(tmpenvdir)) assert os.environ['READ_EXISTING'] == 'override'
#!/usr/bin/env python import os import sys import envdir from pathlib import Path here = Path(__file__).parent path = here / 'envs' / os.environ.get('ENVDIR', 'dev') envdir.read(str(path)) if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ciupy3.settings") os.environ.setdefault("DJANGO_CONFIGURATION", "Dev") from configurations.management import execute_from_command_line execute_from_command_line(sys.argv)
def test_read(tmpenvdir): tmpenvdir.join('READ').write('test') applied = envdir.read(str(tmpenvdir)) assert 'READ' in os.environ assert 'READ' in applied
""" from os.path import join, dirname import envdir # We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks # if running multiple sites in the same mod_wsgi process. To fix this, use # mod_wsgi daemon mode with each site in its own daemon process, or use # os.environ["DJANGO_SETTINGS_MODULE"] = "hipikat.settings" # os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hipikat.settings.default") BASE_DIR = dirname(dirname(dirname(__file__))) # TODO: abstraction from where? uwsgi calls the virtualenv's local env # stuff but but... not postactivate... so project_settings not in path? envdir.read(join(BASE_DIR, "var", "env")) from werkzeug.contrib.profiler import ProfilerMiddleware # This application object is used by any WSGI server configured to use this # file. This includes Django's development server, if the WSGI_APPLICATION # setting points here. from django.core.wsgi import get_wsgi_application # application = get_wsgi_application() profile_dir = join(BASE_DIR, "var", "profiler") application = ProfilerMiddleware(get_wsgi_application(), profile_dir=profile_dir) # Apply WSGI middleware here.
""" WSGI config for qcat project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/ """ import sys import envdir from os.path import join, dirname, abspath # Root directory for this project QCAT_DIR = dirname(dirname(dirname(abspath(__file__)))) # Add the apps folder to the path and read the env-vars. sys.path.append(join(QCAT_DIR, 'apps')) envdir.read(join(QCAT_DIR, 'envs')) # Load the wsgi application with django-configurations. from configurations.wsgi import get_wsgi_application application = get_wsgi_application()
#!/usr/bin/env python import os import sys import envdir if __name__ == "__main__": if 'test' in sys.argv: env_dir = os.path.join('tests', 'envdir') else: env_dir = 'envdir' envdir.read(os.path.join(os.path.dirname(__file__), env_dir)) from django.core.management import execute_from_command_line execute_from_command_line(sys.argv)
#!/usr/bin/env python import sys from os.path import join, dirname import envdir if __name__ == "__main__": envdir.read(join(dirname(__file__), 'envs')) from configurations.management import execute_from_command_line execute_from_command_line(sys.argv)
""" Use this file to setup envdir and django-configurations, as this works nicely with PyCharms integrated (clickable) test feature. """ import os import envdir import configurations import pytest envdir.read(os.path.join(os.path.dirname(__file__), 'envs')) os.environ.__setitem__('DJANGO_CONFIGURATION', 'TestDefaultSite') configurations.setup() @pytest.fixture def es(request): """ In order to allow multiple Elasticsearch indices when running tests in parallel, overwrite ES_INDEX_PREFIX settings for each test function according to its slave id. Usage for tests that require Elasticsearch: @pytest.mark.usefixtures('es') """ from django.conf import settings from search.index import get_elasticsearch from search.search import get_indices_alias # Clear lru_cache of Elasticsearch indices. get_indices_alias.cache_clear()
#!/usr/bin/env python import envdir import os import sys if __name__ == "__main__": # Load the environment variables in the folder ``./envs/`` with *envdir*. envdir.read(os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir, 'envs')) # Please note that this is *django-configurations* and not *Django*. from configurations.management import execute_from_command_line execute_from_command_line(sys.argv)