Пример #1
0
 def test_bot_factory(self):
     from dallinger.command_line import bot_factory
     from dallinger.command_line import setup_experiment
     from dallinger.bots import BotBase
     setup_experiment()
     bot = bot_factory('some url')
     assert isinstance(bot, BotBase)
Пример #2
0
    def test_setup_excludes_sensitive_config(self):
        from dallinger.command_line import setup_experiment
        config = get_config()
        # Auto detected as sensitive
        config.register('a_password', unicode)
        # Manually registered as sensitive
        config.register('something_sensitive', unicode, sensitive=True)
        # Not sensitive at all
        config.register('something_normal', unicode)

        config.extend({
            'a_password': u'secret thing',
            'something_sensitive': u'hide this',
            'something_normal': u'show this'
        })

        exp_id, dst = setup_experiment()

        # The temp dir should have a config with the sensitive variables missing
        deploy_config = SafeConfigParser()
        deploy_config.read(os.path.join(dst, 'config.txt'))
        assert (deploy_config.get('Parameters',
                                  'something_normal') == u'show this')
        with raises(NoOptionError):
            deploy_config.get('Parameters', 'a_password')
        with raises(NoOptionError):
            deploy_config.get('Parameters', 'something_sensitive')
Пример #3
0
    def config(self):
        from dallinger.command_line import setup_experiment
        cwd = os.getcwd()
        config = get_config()
        if not config.ready:
            config.load()

        (id, tmp) = setup_experiment(verbose=True, exp_config={})

        os.chdir(tmp)
        yield config
        os.chdir(cwd)
Пример #4
0
    def test_setup_with_custom_dict_config(self):
        from dallinger.command_line import setup_experiment
        config = get_config()
        assert config.get('num_dynos_web') == 1

        exp_id, dst = setup_experiment(exp_config={'num_dynos_web': 2})
        # Config is updated
        assert config.get('num_dynos_web') == 2

        # Code snapshot is saved
        os.path.exists(os.path.join('snapshots', exp_id + '-code.zip'))

        # There should be a modified configuration in the temp dir
        deploy_config = SafeConfigParser()
        deploy_config.read(os.path.join(dst, 'config.txt'))
        assert int(deploy_config.get('Parameters', 'num_dynos_web')) == 2
Пример #5
0
    def test_setup_creates_new_experiment(self):
        from dallinger.command_line import setup_experiment
        # Baseline
        exp_dir = os.getcwd()
        assert found_in('experiment.py', exp_dir)
        assert not found_in('dallinger_experiment.py', exp_dir)
        assert not found_in('experiment_id.txt', exp_dir)
        assert not found_in('Procfile', exp_dir)
        assert not found_in('launch.py', exp_dir)
        assert not found_in('worker.py', exp_dir)
        assert not found_in('clock.py', exp_dir)

        exp_id, dst = setup_experiment()

        # dst should be a temp dir with a cloned experiment for deployment
        assert (exp_dir != dst)
        assert ('/tmp' in dst)

        assert found_in('experiment_id.txt', dst)
        assert not found_in('experiment.py', dst)
        assert found_in('dallinger_experiment.py', dst)
        assert found_in('models.py', dst)
        assert found_in('Procfile', dst)
        assert found_in('launch.py', dst)
        assert found_in('worker.py', dst)
        assert found_in('clock.py', dst)

        assert filecmp.cmp(os.path.join(dst, 'dallinger_experiment.py'),
                           os.path.join(exp_dir, 'experiment.py'))

        assert found_in(os.path.join("static", "css", "dallinger.css"), dst)
        assert found_in(os.path.join("static", "scripts", "dallinger2.js"),
                        dst)
        assert found_in(
            os.path.join("static", "scripts", "reconnecting-websocket.js"),
            dst)
        assert found_in(os.path.join("static", "scripts", "reqwest.min.js"),
                        dst)
        assert found_in(os.path.join("static", "scripts", "spin.min.js"), dst)
        assert found_in(os.path.join("static", "robots.txt"), dst)
        assert found_in(os.path.join("templates", "error.html"), dst)
        assert found_in(os.path.join("templates", "launch.html"), dst)
        assert found_in(os.path.join("templates", "complete.html"), dst)
Пример #6
0
    def test_setup_creates_new_experiment(self):
        from dallinger.command_line import setup_experiment
        # Baseline
        exp_dir = os.getcwd()
        assert (os.path.exists('experiment.py') is True)
        assert (os.path.exists('dallinger_experiment.py') is False)
        assert (os.path.exists('experiment_id.txt') is False)
        assert (os.path.exists('Procfile') is False)
        assert (os.path.exists('launch.py') is False)
        assert (os.path.exists('worker.py') is False)
        assert (os.path.exists('clock.py') is False)

        exp_id, dst = setup_experiment()

        # dst should be a temp dir with a cloned experiment for deployment
        assert (exp_dir != dst)
        assert ('/tmp' in dst)
        os.chdir(dst)
        assert (os.path.exists('experiment_id.txt') is True)
        assert (os.path.exists('experiment.py') is False)
        assert (os.path.exists('dallinger_experiment.py') is True)
        assert (os.path.exists('models.py') is True)
        assert (filecmp.cmp('dallinger_experiment.py',
                            os.path.join(exp_dir, 'experiment.py')) is True)

        assert (os.path.exists('Procfile') is True)
        assert (os.path.exists('launch.py') is True)
        assert (os.path.exists('worker.py') is True)
        assert (os.path.exists('clock.py') is True)
        assert (os.path.exists(os.path.join("static", "css", "dallinger.css"))
                is True)
        assert (os.path.exists(
            os.path.join("static", "scripts", "dallinger.js")) is True)
        assert (os.path.exists(
            os.path.join("static", "scripts", "reqwest.min.js")) is True)
        assert (os.path.exists(os.path.join("static", "robots.txt")) is True)
        assert (os.path.exists(os.path.join("templates", "error.html")) is
                True)
        assert (os.path.exists(os.path.join("templates", "launch.html")) is
                True)
        assert (os.path.exists(os.path.join("templates", "complete.html")) is
                True)