def test_get_item_target_path_positive(self, exists_mock, join_mock): """Test for get_item_source_path positive result.""" result = try_get_item_target_path("packages", AUTHOR, "skills", "skill-name") expected_result = "some-path" self.assertEqual(result, expected_result) join_mock.assert_called_once_with("packages", AUTHOR, "skills", "skill-name") exists_mock.assert_called_once_with("some-path")
def _save_item_locally(ctx: Context, item_type: str, item_id: PublicId) -> None: """ Save item to local packages. :param item_type: str type of item (connection/protocol/skill). :param item_id: the public id of the item. :return: None """ item_type_plural = item_type + "s" source_path = try_get_item_source_path( ctx.cwd, None, item_type_plural, item_id.name ) target_path = try_get_item_target_path( ctx.agent_config.registry_path, ctx.agent_config.author, item_type_plural, item_id.name, ) _check_package_public_id(source_path, item_type, item_id) copytree(source_path, target_path) click.echo( '{} "{}" successfully saved in packages folder.'.format( item_type.title(), item_id ) )
def _save_agent_locally(ctx: Context, is_mixed: bool = False) -> None: """ Save agent to local packages. :param ctx: the context :return: None """ for item_type_plural in ("connections", "contracts", "protocols", "skills"): dependencies = getattr(ctx.agent_config, item_type_plural) for public_id in dependencies: if is_mixed: _check_is_item_in_registry_mixed( PublicId.from_str(str(public_id)), item_type_plural, ctx.agent_config.registry_path, ) else: _check_is_item_in_local_registry( PublicId.from_str(str(public_id)), item_type_plural, ctx.agent_config.registry_path, ) item_type_plural = "agents" target_dir = try_get_item_target_path( ctx.agent_config.registry_path, ctx.agent_config.author, item_type_plural, ctx.agent_config.name, ) if not os.path.exists(target_dir): os.makedirs(target_dir, exist_ok=True) source_path = os.path.join(ctx.cwd, DEFAULT_AEA_CONFIG_FILE) target_path = os.path.join(target_dir, DEFAULT_AEA_CONFIG_FILE) copyfile(source_path, target_path) click.echo( f'Agent "{ctx.agent_config.name}" successfully saved in packages folder.' )
def _save_item_locally(ctx: Context, item_type: str, item_id: PublicId) -> None: """ Save item to local packages. :param item_type: str type of item (connection/protocol/skill). :param item_id: the public id of the item. :return: None """ item_type_plural = item_type + "s" try: # try non vendor first source_path = try_get_item_source_path(ctx.cwd, None, item_type_plural, item_id.name) except ClickException: # failed on user's packages # try vendors source_path = try_get_item_source_path( os.path.join(ctx.cwd, "vendor"), item_id.author, item_type_plural, item_id.name, ) check_package_public_id(source_path, item_type, item_id) target_path = try_get_item_target_path( ctx.agent_config.registry_path, ctx.agent_config.author, item_type_plural, item_id.name, ) copytree(source_path, target_path) click.echo( f'{item_type.title()} "{item_id}" successfully saved in packages folder.' )
def test_get_item_target_path_already_exists(self, exists_mock, join_mock): """Test for get_item_target_path item already exists.""" with self.assertRaises(ClickException): try_get_item_target_path("skills", AUTHOR, "skill-name", "packages_path")