Example #1
0
def setup_two_pages(tmp_path, record_pages):
    config_path, config = generate_local_config(tmp_path, pages=2)
    post_page_run_cmd = generate_run_cmd(
        runner=runner, app=app, default_args=["post-page"]
    )
    create_page = partial(run_with_config, default_run_cmd=post_page_run_cmd)
    result = create_page(
        config_file=config_path, record_pages=record_pages, input="Y\nN\nY\nY\nN\nY\n"
    )
    assert result.exit_code == 0
    page_ids = get_pages_ids_from_stdout(result.stdout)
    return config_path, config, page_ids
Example #2
0
def test_not_create_if_refused(make_one_page_config):
    config_file, config = make_one_page_config
    result = run_with_config(
        input=join_input("N"),
        config_file=config_file,
    )
    assert result.exit_code == 0
    assert ("Not creating page"
            in result.stdout), "Script did not report that page is not created"
    assert not page_created(page_title=config.pages[0].page_title
                            ), "Page was not supposed to be created"
    assert (len(get_pages_ids_from_stdout(
        result.stdout)) == 0), "Detected a page that was created!"
Example #3
0
def test_create_one_page_in_space_root(tmp_path, page_count):
    config_file, config = generate_local_config(tmp_path, pages=page_count)
    result: Result = run_with_config(config_file=config_file,
                                     input=join_input(user_input=("Y", ) *
                                                      page_count))
    created_pages = get_pages_ids_from_stdout(result.stdout)
    assert result.exit_code == 0
    assert (result.stderr is ""
            )  # if parent is not found - get_parent_content_id logs to stderr
    assert len(created_pages) == page_count
    for page_id in created_pages:
        parent = confluence_instance.get_parent_content_id(page_id)
        assert parent is None, "Page should had been created in space root"
Example #4
0
    def _create_pages(page_count: int = 1) -> Tuple[str, List[Tuple[int, str]]]:
        page_list = []
        config_file, config = generate_local_config(tmp_path, pages=page_count)
        runner = CliRunner()
        run_cmd = generate_run_cmd(runner=runner, app=app, default_args=["post-page"])
        result = run_with_config(
            input=join_input(user_input=("Y", "N", "Y") * page_count),
            config_file=config_file,
            record_pages=record_pages,
            default_run_cmd=run_cmd,
        )
        assert result.exit_code == 0
        created_page_ids = get_pages_ids_from_stdout(result.stdout)
        for number, page in enumerate(config.pages):
            page_list += (created_page_ids[number], page.page_title)

        return config_file, page_list
Example #5
0
def test_post_page_report(make_one_page_config):
    config_file, config = make_one_page_config
    result = run_with_config(input=join_input("N"), config_file=config_file)

    assert result.exit_code == 0
    assert ("Not creating page"
            in result.stdout), "Script did not report that page is not created"
    assert not page_created(page_title=config.pages[0].page_title
                            ), "Page was not supposed to be created"
    assert (len(get_pages_ids_from_stdout(
        result.stdout)) == 0), "Detected a page that was created!"
    page = config.pages[0]
    assert get_page_url(page.page_title, page.page_space,
                        confluence_instance) is None
    assert ("Created pages:\nNone\nUpdated pages:\nNone\nUnprocessed pages:"
            in result.stdout)
    assert (
        f"{page.page_space}::{page.page_title} Reason: User cancelled creation when prompted"
        in result.stdout)
Example #6
0
def test_skip_in_space_root():
    """Tests that page is properly skipped if the user aborted the creation on the space root prompt"""
    result, page_title = run_with_title(
        input="Y\n"  # do create page
        "N\n"  # do not look for parent
        "N\n",  # do not create in root
        config_file=real_confluence_config,
    )
    assert "Looking for page" in result.stdout
    assert "Should the page be created?" in result.stdout  # checking the prompt
    assert ("Should the script look for a parent in space"
            in result.stdout)  # checking the prompt
    assert "Create the page in the root" in result.stdout  # checking the prompt
    assert "will skip the page" in result.stdout  # checking the prompt
    assert result.exit_code == 0
    assert (confluence_instance.get_page_by_title(
        space=real_config.pages[0].page_space, title=page_title) is
            None), "Page should not had been created"
    assert (len(get_pages_ids_from_stdout(result.stdout)) == 0
            ), "Found a page number when it should not be found"