def test_load_from_symphony_directory(simple_config_path): tmp_config_filename = str(uuid.uuid4()) + "-config.yaml" tmp_config_path = Path.home() / ".symphony" / tmp_config_filename tmp_config_path.touch(exist_ok=True) resource_config_content = Path(simple_config_path).read_text() tmp_config_path.write_text(resource_config_content) config = BdkConfigLoader.load_from_symphony_dir(tmp_config_filename) assert config.bot.username == "youbot"
def test_retry_configuration(): config_path = get_config_resource_filepath("retry_config.yaml") config = BdkConfigLoader.load_from_file(config_path) assert config.retry.max_attempts == 2 assert config.retry.initial_interval.total_seconds() == 1.0 assert config.retry.multiplier == 3 assert config.retry.max_interval.total_seconds() == 2.0
async def run(): config = BdkConfigLoader.load_from_symphony_dir("config.yaml") async with SymphonyBdk(config) as bdk: connection_service = bdk.connections() user_connection = await connection_service.list_connections( status=ConnectionStatus.ALL) logging.info(user_connection)
def test_load_default_headers_defined_at_child_level_only(): config = BdkConfigLoader.load_from_file(get_config_resource_filepath("config_headers_child_only.yaml")) assert config.default_headers is None assert config.pod.default_headers is None assert config.key_manager.default_headers is None assert config.session_auth.default_headers is None assert config.agent.default_headers == {"user-agent": "custom-user-agent", "header-key": "header-value"}
async def run(): config = BdkConfigLoader.load_from_symphony_dir("config.yaml") async with SymphonyBdk(config) as bdk: auth_session = bdk.bot_session() logging.info(await auth_session.key_manager_token) logging.info(await auth_session.session_token) logging.info("Obo example:") obo_auth_session = bdk.obo(username="******") logging.info(await obo_auth_session.session_token)
async def run(): config = BdkConfigLoader.load_from_symphony_dir("config_injector.yaml") async with SymphonyBdk(config) as bdk: stream_id = await create_test_room(bdk.streams()) await send_messages(bdk.messages(), stream_id) await check_all_messages_have_been_replied_to(bdk.messages(), config.bot.username, stream_id)
def test_load_default_headers_defined_at_global_and_child_level(): global_headers = {"user-agent": "global-user-agent", "header-key": "global-header-value"} config = BdkConfigLoader.load_from_file(get_config_resource_filepath("config_headers_global_child.yaml")) assert config.default_headers == global_headers assert config.pod.default_headers == global_headers assert config.key_manager.default_headers == global_headers assert config.session_auth.default_headers == global_headers assert config.agent.default_headers == {"user-agent": "agent-user-agent", "header-key": "agent-header-value"}
def test_load_proxy_defined_at_child_level_only(): config = BdkConfigLoader.load_from_file(get_config_resource_filepath("config_proxy_child_only.yaml")) assert config.proxy is None assert config.pod.proxy is None assert config.key_manager.proxy is None assert config.session_auth.proxy is None assert config.agent.proxy.host == "agent-proxy.symphony.com" assert config.agent.proxy.port == 5678 assert config.agent.proxy.username is None assert config.agent.proxy.password is None
def test_load_proxy_defined_at_global_level(): config = BdkConfigLoader.load_from_file(get_config_resource_filepath("config_global_proxy.yaml")) assert config.proxy.host == "proxy.symphony.com" assert config.proxy.port == 1234 assert config.proxy.username == "proxyuser" assert config.proxy.password == "proxypass" assert config.agent.proxy == config.proxy assert config.pod.proxy == config.proxy assert config.key_manager.proxy == config.proxy assert config.session_auth.proxy == config.proxy
async def run(): async with SymphonyBdk( BdkConfigLoader.load_from_symphony_dir("config.yaml")) as bdk: activities = bdk.activities() messages = bdk.messages() @activities.slash("/hello") async def on_hello(context: CommandContext): await messages.send_message( context.stream_id, "<messageML>Hello, World!</messageML>") await bdk.datafeed().start()
async def run(): config = BdkConfigLoader.load_from_symphony_dir("config.yaml") async with SymphonyBdk(config) as bdk: ext_app_authenticator = bdk.app_authenticator() app_auth = await ext_app_authenticator.authenticate_extension_app( "appToken") ta = app_auth.app_token ts = app_auth.symphony_token logging.debug("App token: %s, Symphony token: %s", ta, ts) logging.debug("Is token pair valid: %s", await ext_app_authenticator.is_token_pair_valid(ta, ts))
async def run(): config = BdkConfigLoader.load_from_symphony_dir("config.yaml") async with SymphonyBdk(config) as bdk: datafeed_loop = bdk.datafeed() datafeed_loop.subscribe(RealTimeEventListenerImpl()) t = asyncio.create_task(datafeed_loop.start()) # start DF loop await asyncio.sleep(10) await datafeed_loop.stop() # stop after 10s await t # wait for DF loop to finish
async def run(): config = BdkConfigLoader.load_from_symphony_dir("config.yaml") async with SymphonyBdk(config) as bdk: user_service = bdk.users() logging.info(await user_service.list_users_by_ids([12987981103610])) query = UserSearchQuery(query='bot', filters=UserSearchFilter(company='Symphony')) async for uid in await user_service.search_all_users(query, local=False): logging.debug(uid) async for i in await user_service.list_all_user_details_by_filter(user_filter=UserFilter(status="ENABLED", role="INDIVIDUAL"), max_number=100): logging.debug(i.user_attributes.display_name)
async def run(): async with SymphonyBdk(BdkConfigLoader.load_from_symphony_dir("config.yaml")) as bdk: activities = bdk.activities() messages = bdk.messages() @activities.slash("/go") async def on_hello(context: CommandContext): pick_emoji = ["cat", "dromedary_camel", "dolphin", "dog", "hamster", "goat", "panda_face", "koala", "frog", "penguin"] previous_message: V4Message = await messages.send_message(context.stream_id, "Let the show begin!") for i in range(0, len(pick_emoji)): time.sleep(1) mml = "<emoji shortcode=\"{}\" /><br/><br/>Update <b>#{}</b>".format(pick_emoji[i], (i + 1)) previous_message = await messages.update_message(previous_message.stream.stream_id, previous_message.message_id, mml) await bdk.datafeed().start()
def test_default_retry_configuration(): config_path = get_config_resource_filepath("config.yaml") config = BdkConfigLoader.load_from_file(config_path) assert config.retry.max_attempts == BdkRetryConfig.DEFAULT_MAX_ATTEMPTS assert config.retry.initial_interval == timedelta( milliseconds=BdkRetryConfig.DEFAULT_INITIAL_INTERVAL) assert config.retry.multiplier == BdkRetryConfig.DEFAULT_MULTIPLIER assert config.retry.max_interval == timedelta( milliseconds=BdkRetryConfig.DEFAULT_MAX_INTERVAL) # Datafeed default retry assert config.datafeed.retry.max_attempts == sys.maxsize assert config.datafeed.retry.initial_interval == timedelta( milliseconds=BdkRetryConfig.DEFAULT_INITIAL_INTERVAL) assert config.datafeed.retry.multiplier == BdkRetryConfig.DEFAULT_MULTIPLIER assert config.datafeed.retry.max_interval == timedelta( milliseconds=BdkRetryConfig.DEFAULT_MAX_INTERVAL)
def test_load_client_global_config(global_config_path): expected_scheme = "https" expected_host = "devx1.symphony.com" expected_default_headers = {"user-agent": "custom-user-agent", "header-key": "header-value"} config = BdkConfigLoader.load_from_file(global_config_path) assert config.scheme == expected_scheme assert config.host == expected_host assert config.port == 8443 assert config.default_headers == expected_default_headers assert config.pod.scheme == expected_scheme assert config.pod.host == "diff-pod.symphony.com" assert config.pod.port == 8443 assert config.pod.context == "context" assert config.pod.default_headers == expected_default_headers assert config.scheme == expected_scheme assert config.agent.scheme == expected_scheme assert config.agent.host == expected_host assert config.agent.port == 443 assert config.agent.get_formatted_context() == "/context" assert config.agent.default_headers == expected_default_headers assert config.key_manager.scheme == expected_scheme assert config.key_manager.host == expected_host assert config.key_manager.port == 8443 assert config.key_manager.get_formatted_context() == "/diff-context" assert config.key_manager.default_headers == expected_default_headers assert config.session_auth.scheme == "http" assert config.session_auth.host == expected_host assert config.session_auth.port == 8443 assert config.session_auth.context == "context" assert config.session_auth.default_headers == expected_default_headers
def test_load_from_file(simple_config_path): config = BdkConfigLoader.load_from_file(simple_config_path) assert config.bot.username == "youbot"
def fixture_app_cert_config(): return BdkConfigLoader.load_from_file(get_config_resource_filepath("config_obo_cert.yaml"))
async def run(): async with SymphonyBdk( BdkConfigLoader.load_from_symphony_dir("config.yaml")) as bdk: bdk.activities().register(SlashGifCommandActivity(bdk.messages())) bdk.activities().register(ReplyFormReplyActivity(bdk.messages())) await bdk.datafeed().start()
def test_load_from_content(simple_config_path): config_path = Path(simple_config_path) content = config_path.read_text() config = BdkConfigLoader.load_from_content(content) assert config.bot.username == "youbot"
def test_update_certificate(simple_config_path): config = BdkConfigLoader.load_from_file(simple_config_path) certificate_path = get_resource_filepath("cert/certificate.cert", as_text=True) config.bot.certificate.path = certificate_path assert config.bot.certificate._path == certificate_path
def fixture_config(): config = BdkConfigLoader.load_from_file(get_config_resource_filepath("config.yaml")) return config
async def run(): async with SymphonyBdk( BdkConfigLoader.load_from_symphony_dir("config.yaml")) as bdk: bdk.activities().register(JoinRoomActivity(bdk.messages())) await bdk.datafeed().start()
def fixture_config(): config = BdkConfigLoader.load_from_file(get_config_resource_filepath("config.yaml")) config.datafeed.retry = minimal_retry_config() config.datafeed.version = "v2" return config
def test_load_from_file_not_found(wrong_path): fail_error_message = f"Config file has not been found at: {Path(wrong_path).absolute()}" with pytest.raises(BdkConfigError, match=re.escape(fail_error_message)): BdkConfigLoader.load_from_file(wrong_path)
from symphony.bdk.core.config.loader import BdkConfigLoader config_1 = BdkConfigLoader.load_from_file("/absolute/path/to/config.yaml") with open("/absolute/path/to/config.yaml") as config_file: config_2 = BdkConfigLoader.load_from_content(config_file.read()) config_3 = BdkConfigLoader.load_from_symphony_dir("config.yaml")
def test_update_private_key(simple_config_path): config = BdkConfigLoader.load_from_file(simple_config_path) private_key = "private_key_path/private_key.pem" config.bot.private_key.content = private_key assert config.bot.private_key._content == private_key assert config.bot.private_key._path is None
def test_update_certificate(simple_config_path): config = BdkConfigLoader.load_from_file(simple_config_path) certificate_path = "certificate_path/certificate.cert" config.bot.certificate.path = certificate_path assert config.bot.certificate._path == certificate_path