def test_get_conn_uri(self): param = { 'SecretId': 'airflow/connections/test_postgres', 'SecretString': 'postgresql://*****:*****@host:5432/airflow', } secrets_manager_backend = SecretsManagerBackend() secrets_manager_backend.client.put_secret_value(**param) returned_uri = secrets_manager_backend.get_conn_uri(conn_id="test_postgres") assert 'postgresql://*****:*****@host:5432/airflow' == returned_uri
def test_connection_prefix_none_value(self, mock_get_secret): """ Test that if Variable key is not present in AWS Secrets Manager, SecretsManagerBackend.get_conn_uri should return None, SecretsManagerBackend._get_secret should not be called """ kwargs = {'connections_prefix': None} secrets_manager_backend = SecretsManagerBackend(**kwargs) self.assertIsNone(secrets_manager_backend.get_conn_uri("test_mysql")) mock_get_secret.assert_not_called()
def test_get_conn_uri_non_existent_key(self): """ Test that if the key with connection ID is not present, SecretsManagerBackend.get_connections should return None """ conn_id = "test_mysql" param = { 'SecretId': 'airflow/connections/test_postgres', 'SecretString': 'postgresql://*****:*****@host:5432/airflow', } secrets_manager_backend = SecretsManagerBackend() secrets_manager_backend.client.put_secret_value(**param) assert secrets_manager_backend.get_conn_uri(conn_id=conn_id) is None assert [] == secrets_manager_backend.get_connections(conn_id=conn_id)