Пример #1
0
def test_prepare_list_of_templates_local_failure(mocker):
    get_repo_configuration_mock = mocker.patch(
        "commands.template.common.get_repository_configuration")
    get_repo_configuration_mock.return_value = "location", "access token"
    get_remote_templates_mock = mocker.patch(
        "commands.template.common.get_remote_templates")
    get_remote_templates_mock.return_value = {
        REMOTE_TEMPLATE_NAME: REMOTE_TEMPLATE
    }
    get_local_templates = mocker.patch(
        "commands.template.common.get_local_templates")
    get_local_templates.side_effect = ExceptionWithMessage(EXCEPTION_MESSAGE)

    list, error_messages = prepare_list_of_templates()

    assert len(list) == 1
    assert len(error_messages) == 1

    assert REMOTE_TEMPLATE.representation() in list
    assert LOCAL_TEMPLATE_2.representation() not in list
    assert Texts.ERROR_DURING_LOADING_LOCAL_TEMPLATES == error_messages[0]

    assert get_local_templates.call_count == 1
    assert get_remote_templates_mock.call_count == 1
    assert get_repo_configuration_mock.call_count == 1
Пример #2
0
def list_templates(state: State):
    """ List experiments. """
    with spinner(text=Texts.GETTING_LIST_OF_TEMPLATES_MSG):
        list_of_templates, error_messages = prepare_list_of_templates()

    for message in error_messages:
        click.echo(message)
    click.echo(
        tabulate.tabulate(list_of_templates,
                          headers=TEMPLATE_LIST_HEADERS,
                          tablefmt="orgtbl"))
Пример #3
0
def test_prepare_list_of_templates(mocker):
    get_repository_address_mock = mocker.patch("commands.template.common.get_repository_address")
    get_repository_address_mock.return_value = "location"
    get_remote_templates_mock = mocker.patch("commands.template.common.get_remote_templates")
    get_remote_templates_mock.return_value = {REMOTE_TEMPLATE_NAME: REMOTE_TEMPLATE}
    get_local_templates = mocker.patch("commands.template.common.get_local_templates")
    get_local_templates.return_value = {REMOTE_TEMPLATE_NAME: LOCAL_TEMPLATE_1, LOCAL_TEMPLATE_NAME: LOCAL_TEMPLATE_2}

    list, error_messages = prepare_list_of_templates()

    assert len(list) == 2

    assert REMOTE_TEMPLATE.representation() in list
    assert LOCAL_TEMPLATE_2.representation() in list

    assert get_repository_address_mock.call_count == 1
Пример #4
0
def test_prepare_list_of_templates_remote_failure(mocker):
    get_repository_address_mock = mocker.patch("commands.template.common.get_repository_address")
    get_repository_address_mock.return_value = "location"
    get_remote_templates_mock = mocker.patch("commands.template.common.get_remote_templates")
    get_remote_templates_mock.side_effect = ExceptionWithMessage(EXCEPTION_MESSAGE)
    get_local_templates = mocker.patch("commands.template.common.get_local_templates")
    get_local_templates.return_value = {LOCAL_TEMPLATE_NAME: LOCAL_TEMPLATE_1, REMOTE_TEMPLATE_NAME: LOCAL_TEMPLATE_2}

    list, error_messages = prepare_list_of_templates()

    assert len(list) == 2
    assert len(error_messages) == 1

    assert LOCAL_TEMPLATE_1.representation() in list
    assert LOCAL_TEMPLATE_2.representation() in list
    assert EXCEPTION_MESSAGE == error_messages[0]

    assert get_remote_templates_mock.call_count == 1
    assert get_local_templates.call_count == 1
    assert get_repository_address_mock.call_count == 1
Пример #5
0
def test_prepare_list_of_templates_only_remote(mocker):
    get_repo_configuration_mock = mocker.patch(
        "commands.template.common.get_repository_configuration")
    get_repo_configuration_mock.return_value = "location", "access token"
    get_remote_templates_mock = mocker.patch(
        "commands.template.common.get_remote_templates")
    get_remote_templates_mock.return_value = {
        REMOTE_TEMPLATE_NAME: REMOTE_TEMPLATE
    }
    get_local_templates = mocker.patch(
        "commands.template.common.get_local_templates")

    list, error_messages = prepare_list_of_templates()

    assert len(list) == 1

    assert REMOTE_TEMPLATE.representation() in list
    assert LOCAL_TEMPLATE_2.representation() not in list

    assert get_local_templates.call_count == 1
    assert get_remote_templates_mock.call_count == 1
    assert get_repo_configuration_mock.call_count == 1