def setUp(self):
        self._host = os.environ.get("MONGODB_TESTHOST")
        self._port = int(os.environ.get("MONGODB_TESTPORT"))
        self._user = os.environ.get("MONGODB_TESTUSER2")
        self._pw = os.environ.get("MONGODB_TESTPW2")
        self._db = os.environ.get("MONGODB_TESTDB")
        self._col = os.environ.get("MONGODB_TESTCOL")
        self._auth_source = os.environ.get("MONGODB_TEST2AUTH")

        config = alfred3.config.ExperimentConfig(expdir=None)
        config.read_dict({"metadata": {"session_id": "123"}})
        secrets = alfred3.config.ExperimentSecrets(expdir=None)

        self.config = {"exp_config": config, "exp_secrets": secrets}

        self.exp = alfred3.Experiment(config=self.config)

        self.agent = alfred3.saving_agent.MongoSavingAgent(
            host=self._host,
            port=self._port,
            database=self._db,
            collection=self._col,
            user=self._user,
            password=self._pw,
            experiment=self.exp,
            auth_source=self._auth_source,
            use_ssl=False,
            ca_file_path=None,
            activation_level=10,
        )

        self.exp.saving_agent_controller.add_saving_agent(self.agent)
        self.connector = mongotools.ExpMongoDBConnector(self.exp)
示例#2
0
    def test_admin_without_password(self, tmp_path):
        exp = al.Experiment()
        exp.admin += al.Page(name="admin_test")

        config = ExperimentConfig(tmp_path)
        secrets = ExperimentSecrets(tmp_path)
        urlargs = {"admin": "true"}

        with pytest.raises(AlfredError):
            exp.create_session("sid1", config, secrets, **urlargs)
示例#3
0
    def test_admin_missing_password(self, tmp_path):
        exp = al.Experiment()
        exp.admin += al.Page(name="admin_test")

        config = ExperimentConfig(tmp_path)
        secrets = ExperimentSecrets(tmp_path)
        urlargs = {"admin": "true"}

        secrets.read_dict({"general": {"adminpass_lvl2": "test"}})

        with pytest.raises(AlfredError) as excinfo:
            exp.create_session("sid1", config, secrets, **urlargs)

        msg = str(excinfo.value)
        assert "lvl1" in msg and "lvl3" in msg and not "lvl2" in msg
示例#4
0
    def test_admin(self, tmp_path):
        exp = al.Experiment()
        exp.admin += al.Page(name="admin_test")

        config = ExperimentConfig(tmp_path)
        secrets = ExperimentSecrets(tmp_path)
        secrets.read_dict({
            "general": {
                "adminpass_lvl1": "test1",
                "adminpass_lvl2": "test2",
                "adminpass_lvl3": "test3"
            }
        })
        urlargs = {"admin": "true"}

        session = exp.create_session("sid1", config, secrets, **urlargs)
        assert session.admin_mode
示例#5
0
    def test_admin_equal_passwords(self, tmp_path):
        exp = al.Experiment()
        exp.admin += al.Page(name="admin_test")

        config = ExperimentConfig(tmp_path)
        secrets = ExperimentSecrets(tmp_path)
        urlargs = {"admin": "true"}

        secrets.read_dict({
            "general": {
                "adminpass_lvl1": "test",
                "adminpass_lvl2": "test",
                "adminpass_lvl3": "test1"
            }
        })

        with pytest.raises(AlfredError) as excinfo:
            exp.create_session("sid1", config, secrets, **urlargs)

        msg = str(excinfo.value)
        assert "Passwords must be unique to a level" in msg
示例#6
0
import alfred3 as al

exp = al.Experiment()

class Section(al.Section):

    def on_leave(self):
        self.log.info(f"{self.name}: on_leve executed")
    
    def on_enter(self):
        self.log.info(f"{self.name}: on_enter executed")
    
    def on_resume(self):
        self.log.info(f"{self.name}: on_resume executed")
    
    def on_hand_over(self):
        self.log.info(f"{self.name}: on_hand_over executed")
    
    def validate_on_forward(self):
        self.log.info(f"{self.name}: validate_on_forward executed")
        return super().validate_on_forward()
    
    def validate_on_backward(self):
        self.log.info(f"{self.name}: validate_on_backward executed")
        return super().validate_on_backward()
    
    def validate_on_jumpfrom(self):
        self.log.info(f"{self.name}: validate_on_jumpfrom executed")
        return super().validate_on_jumpfrom()
    
    def validate_on_jumpto(self):
 def test_no_mongo_agent(self):
     exp = alfred3.Experiment(config=self.config)
     with self.assertRaises(ValueError):
         connector = mongotools.ExpMongoDBConnector(exp)
         connector.connect()