def test_variable_env_secrets_backend(self):
     env_secrets_backend = EnvironmentVariablesBackend()
     variable_value = env_secrets_backend.get_variable(key="hello")
     self.assertEqual('World', variable_value)
     self.assertIsNone(
         env_secrets_backend.get_variable(key="non_existent_key"))
     self.assertEqual('', env_secrets_backend.get_variable(key="empty_str"))
    def test_connection_env_secrets_backend(self):
        sample_conn_1 = SampleConn("sample_1", "A")
        env_secrets_backend = EnvironmentVariablesBackend()
        os.environ[sample_conn_1.var_name] = sample_conn_1.conn_uri
        conn_list = env_secrets_backend.get_connections(sample_conn_1.conn_id)
        self.assertEqual(1, len(conn_list))
        conn = conn_list[0]

        # we could make this more precise by defining __eq__ method for Connection
        self.assertEqual(sample_conn_1.host.lower(), conn.host)
Ejemplo n.º 3
0
def update_dag_registry(**kwargs):
    with create_session() as session:

        model_dags = [
            dag for dag in session.query(DagModel) for tag in dag.tags
            if tag.name == "model"
        ]
        print(f"MODEL DAGS: {model_dags}")
        cf_client = connect_to_cornflow(EnvironmentVariablesBackend())
        deployed_dags = [
            dag["id"] for dag in cf_client.get_deployed_dags(encoding="br")
        ]
        print(f"DEPLOYED DAGS: {deployed_dags}")
        for model in model_dags:
            if model.dag_id not in deployed_dags:
                response = cf_client.create_deployed_dag(
                    name=model.dag_id,
                    description=model.description,
                    encoding="br")
                print(f"DAG: {response['id']} registered")
Ejemplo n.º 4
0
 def test_variable_env_secrets_backend(self):
     env_secrets_backend = EnvironmentVariablesBackend()
     variable_value = env_secrets_backend.get_variable(key="hello")
     assert 'World' == variable_value
     assert env_secrets_backend.get_variable(key="non_existent_key") is None
     assert '' == env_secrets_backend.get_variable(key="empty_str")
Ejemplo n.º 5
0
 def solve(**kwargs):
     return utils.cf_solve_app(app, EnvironmentVariablesBackend(), **kwargs)