Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setup(self):
"""Set up the environment by moving to the demos directory."""
os.chdir("tests/experiment")
config = get_config()
config.ready = False
from dallinger.heroku import clock
self.clock = clock
def test_remote_base_url(self):
from dallinger.utils import get_base_url
config = get_config()
config.ready = True
config.set("host", "https://dlgr-bogus.herokuapp.com")
config.set("num_dynos_web", 1)
assert get_base_url() == "https://dlgr-bogus.herokuapp.com"
def _s3_resource(dallinger_region=False):
"""A boto3 S3 resource using the AWS keys in the config."""
config = get_config()
if not config.ready:
config.load()
region = "us-east-1" if dallinger_region else config.get("aws_region")
return boto3.resource(
"s3",
region_name=region,
aws_access_key_id=config.get("aws_access_key_id"),
aws_secret_access_key=config.get("aws_secret_access_key"),
)
def launch():
config = dallinger.config.get_config()
if not config.ready:
config.load()
scheduler.start()
def awaken(app, databaseurl):
"""Restore the database from a given url."""
id = app
config = get_config()
config.load()
subprocess.check_call([
"heroku",
"addons:create",
"heroku-postgresql:{}".format(config.get('database_size')),
"--app", app_name(id),
])
subprocess.check_call(["heroku", "pg:wait", "--app", app_name(id)])
bucket = data.user_s3_bucket()
key = bucket.lookup('{}.dump'.format(id))
url = key.generate_url(expires_in=300)
subprocess.check_call([
def launch():
config = get_config()
config.load()
LOG_LEVELS = [
logging.DEBUG,
logging.INFO,
logging.WARNING,
logging.ERROR,
logging.CRITICAL,
]
LOG_LEVEL = LOG_LEVELS[config.get("loglevel")]
logging.basicConfig(format="%(asctime)s %(message)s", level=LOG_LEVEL)
# Avoid duplicate logging to stderr
error_logger = logging.getLogger("gunicorn.error")
error_logger.propagate = False
access_logger = logging.getLogger("gunicorn.access")
access_logger.propagate = False
def extra_parameters():
config = get_config()
config.register("num_participants", int)
def deploy(verbose, app):
"""Deploy app using Heroku to MTurk."""
if app:
verify_id(None, None, app)
# Load configuration.
config = get_config()
config.load()
# Set the mode.
config.extend({
"mode": u"live",
"logfile": u"-",
})
# Do shared setup.
deploy_sandbox_shared_setup(verbose=verbose, app=app)
def setup_experiment(debug=True, verbose=False, app=None, exp_config=None):
"""Check the app and, if compatible with Dallinger, freeze its state."""
log(header, chevrons=False)
# Verify that the Postgres server is running.
try:
psycopg2.connect(database="x", user="postgres", password="nada")
except psycopg2.OperationalError as e:
if "could not connect to server" in str(e):
raise RuntimeError("The Postgres server isn't running.")
# Load configuration.
config = get_config()
if not config.ready:
config.load()
# Check that the demo-specific requirements are satisfied.
try:
with open("requirements.txt", "r") as f:
dependencies = [r for r in f.readlines() if r[:3] != "-e "]
except:
dependencies = []
pkg_resources.require(dependencies)
# Generate a unique id for this experiment.
from dallinger.experiment import Experiment
generated_uid = public_id = Experiment.make_uuid()
def _config():
config = get_config()
if not config.ready:
config.load()
return config