def stub_config():
    """Builds a standardized Configuration object and returns it, but does
    not load it as the active configuration returned by
    dallinger.config.get_config()
    """
    defaults = {
        u'aws_region': u'us-east-1',
        u'base_port': 5000,
        u'clock_on': True,
        u'dallinger_email_address': u'*****@*****.**',
        u'database_url': u'postgresql://postgres@localhost/dallinger',
        u'dyno_type': u'standard-2x',
        u'heroku_team': u'dallinger',
        u'host': u'localhost',
        u'logfile': u'server.log',
        u'loglevel': 0,
        u'mode': u'debug',
        u'num_dynos_web': 2,
        u'num_dynos_worker': 2,
        u'threads': u'1',
        u'whimsical': True
    }
    from dallinger.config import default_keys
    from dallinger.config import Configuration
    config = Configuration()
    for key in default_keys:
        config.register(*key)
    config.extend(defaults.copy())
    config.ready = True

    return config
示例#2
0
 def test_setting_values_supports_synonyms(self):
     config = Configuration()
     config.register('num_participants', int, synonyms={
         'n',
     })
     config.ready = True
     config.extend({'n': 1})
     assert config.get('num_participants') == 1
示例#3
0
 def test_layering_of_configs(self):
     config = Configuration()
     config.register('num_participants', int)
     config.extend({'num_participants': 1})
     config.ready = True
     assert config.get('num_participants', 1) == 1
     config.extend({'num_participants': 2})
     assert config.get('num_participants', 1) == 2
示例#4
0
 def test_type_casts_follow_file_pointers(self):
     config = Configuration()
     config.register("data", six.text_type)
     config.ready = True
     with NamedTemporaryFile() as data_file:
         data_file.write("hello".encode("utf-8"))
         data_file.flush()
         config.extend({"data": "file:" + data_file.name}, cast_types=True)
     assert config.get("data") == "hello"
示例#5
0
def stub_config():
    """Builds a standardized Configuration object and returns it, but does
    not load it as the active configuration returned by
    dallinger.config.get_config()
    """
    defaults = {
        u'ad_group': u'Test ad group',
        u'approve_requirement': 95,
        u'auto_recruit': True,
        u'aws_access_key_id': u'fake aws key',
        u'aws_secret_access_key': u'fake aws secret',
        u'aws_region': u'us-east-1',
        u'base_payment': 0.01,
        u'base_port': 5000,
        u'browser_exclude_rule': u'MSIE, mobile, tablet',
        u'clock_on': True,
        u'contact_email_on_error': u'*****@*****.**',
        u'dallinger_email_address': u'*****@*****.**',
        u'dallinger_email_password': u'fake password',
        u'database_size': u'standard-0',
        u'database_url': u'postgresql://postgres@localhost/dallinger',
        u'description': u'fake HIT description',
        u'duration': 1.0,
        u'dyno_type': u'free',
        u'heroku_team': u'',
        u'host': u'0.0.0.0',
        u'id': u'some experiment uid',
        u'keywords': u'kw1, kw2, kw3',
        u'lifetime': 1,
        u'logfile': u'-',
        u'loglevel': 0,
        u'mode': u'debug',
        u'notification_url': u'https://url-of-notification-route',
        u'num_dynos_web': 1,
        u'num_dynos_worker': 1,
        u'organization_name': u'Monsters University',
        u'sentry': True,
        u'threads': u'1',
        u'title': u'fake experiment title',
        u'us_only': True,
        u'webdriver_type': u'phantomjs',
        u'whimsical': True
    }
    from dallinger.config import default_keys
    from dallinger.config import Configuration
    config = Configuration()
    for key in default_keys:
        config.register(*key)
    config.extend(defaults.copy())
    config.ready = True

    return config
示例#6
0
 def test_setting_unknown_key_is_ignored(self):
     config = Configuration()
     config.ready = True
     config.extend({'num_participants': 1})
     config.get('num_participants', None)
示例#7
0
 def test_get_before_ready_is_not_possible(self):
     config = Configuration()
     config.register('num_participants', int)
     config.extend({'num_participants': 1})
     with pytest.raises(RuntimeError):
         config.get('num_participants', 1)
示例#8
0
 def test_type_cast_types_failure_raises(self):
     config = Configuration()
     config.register('num_participants', int)
     config.ready = True
     with pytest.raises(TypeError):
         config.extend({'num_participants': 'A NUMBER'}, cast_types=True)
示例#9
0
 def test_type_mismatch_with_cast_types(self):
     config = Configuration()
     config.register('num_participants', int)
     config.ready = True
     config.extend({'num_participants': 1.0}, cast_types=True)
     assert config.get('num_participants', 1) == 1
示例#10
0
 def test_type_mismatch(self):
     config = Configuration()
     config.register('num_participants', int)
     with pytest.raises(TypeError):
         config.extend({'num_participants': 1.0})
示例#11
0
 def test_register_new_variable(self):
     config = Configuration()
     config.register('num_participants', int)
     config.extend({'num_participants': 1})
     config.ready = True
     assert config.get('num_participants', 1)
示例#12
0
 def test_get_strips_strings(self):
     config = Configuration()
     config.register("test_string", six.text_type)
     config.ready = True
     config.extend({"test_string": " something "})
     assert config.get("test_string") == "something"
示例#13
0
 def test_strict_extending_blocks_unknown_keys(self):
     config = Configuration()
     config.register('num_participants', int)
     config.ready = True
     with pytest.raises(KeyError):
         config.extend({'unknown_key': 1}, strict=True)
示例#14
0
 def test_attribute_access(self):
     config = Configuration()
     config.register('num_participants', int)
     config.ready = True
     config.extend({'num_participants': 1})
     assert config.num_participants == 1
示例#15
0
def stub_config():
    """Builds a standardized Configuration object and returns it, but does
    not load it as the active configuration returned by
    dallinger.config.get_config()
    """
    defaults = {
        u"ad_group": u"Test ad group",
        u"approve_requirement": 95,
        u"assign_qualifications": True,
        u"auto_recruit": True,
        u"aws_access_key_id": u"fake aws key",
        u"aws_secret_access_key": u"fake aws secret",
        u"aws_region": u"us-east-1",
        u"base_payment": 0.01,
        u"base_port": 5000,
        u"browser_exclude_rule": u"MSIE, mobile, tablet",
        u"clock_on": False,
        u"contact_email_on_error": u"*****@*****.**",
        u"dallinger_email_address": u"*****@*****.**",
        u"database_size": u"standard-0",
        u"disable_when_duration_exceeded": True,
        u"enable_global_experiment_registry": False,
        u"redis_size": u"premium-0",
        u"dashboard_user": u"admin",
        u"database_url": u"postgresql://postgres@localhost/dallinger",
        u"description": u"fake HIT description",
        u"duration": 1.0,
        u"dyno_type": u"free",
        u"heroku_app_id_root": u"fake-customid",
        u"heroku_auth_token": u"heroku secret",
        u"heroku_python_version": u"3.9.2",
        u"heroku_team": u"",
        u"host": u"0.0.0.0",
        u"id": u"TEST_EXPERIMENT_UID",  # This is a significant value; change with caution.
        u"keywords": u"kw1, kw2, kw3",
        u"lifetime": 1,
        u"logfile": u"-",
        u"loglevel": 0,
        u"mode": u"debug",
        u"num_dynos_web": 1,
        u"num_dynos_worker": 1,
        u"organization_name": u"Monsters University",
        u"sentry": True,
        u"smtp_host": u"smtp.fakehost.com:587",
        u"smtp_username": u"fake email username",
        u"smtp_password": u"fake email password",
        u"threads": u"1",
        u"title": u"fake experiment title",
        u"us_only": True,
        u"webdriver_type": u"chrome_headless",
        u"whimsical": True,
        u"replay": False,
        u"worker_multiplier": 1.5,
    }
    from dallinger.config import default_keys
    from dallinger.config import Configuration

    config = Configuration()
    for key in default_keys:
        config.register(*key)
    config.extend(defaults.copy())
    # Patch load() so we don't update any key/value pairs from actual files:
    config.load = mock.Mock(side_effect=lambda: setattr(config, "ready", True))
    config.ready = True

    return config
示例#16
0
 def test_type_mismatch_on_extend(self):
     config = Configuration()
     config.register("num_participants", int)
     with pytest.raises(TypeError):
         config.extend({"num_participants": 1.0})
示例#17
0
 def test_setting_values_supports_synonyms(self):
     config = Configuration()
     config.register("num_participants", int, synonyms={"n"})
     config.ready = True
     config.extend({"n": 1})
     assert config.get("num_participants") == 1
示例#18
0
 def test_dict_access(self):
     config = Configuration()
     config.register("num_participants", int)
     config.ready = True
     config.extend({"num_participants": 1})
     assert config["num_participants"] == 1