示例#1
0
def test_minor_edit(action, make_one_page_config, tmp_path, setup_page):
    """Tests that minor edit action is recorded on the page. API does not allow creation of the
    page to be a minor edit, only an update"""
    if action == "create":
        config_file, config = make_one_page_config
        result = run_with_config(config_file=config_file,
                                 pre_args=["--minor-edit"],
                                 input="Y\nN\nY\n")
        page_id = get_page_id_from_stdout(result.stdout)
    else:
        overwrite_file, new_text, overwrite_config = mk_fake_file(
            tmp_path, filename="overwrite")
        config_file, (page_id, page_title) = setup_page(1)

        result = run_with_config(
            config_file=overwrite_config,
            pre_args=["--page-title", page_title, "--minor-edit"],
        )

    assert result.exit_code == 0
    last_update = confluence_instance.get_content_history(page_id).get(
        "lastUpdated")

    if action == "create":
        assert not last_update.get(
            "minorEdit"), "Creation was marked as minor edit"
    else:
        # Looks like Atlassian stopped exposing this in the API :( no notifications are sent out though
        with pytest.raises(AssertionError):
            assert last_update.get(
                "minorEdit"), "Page update was not marked as minor edit"
示例#2
0
def test_post_page_with_real_file(make_one_page_config, tmp_path):
    config_file, config = make_one_page_config
    _, content, page_file = generate_fake_page(tmp_path)

    result: Result = run_with_config(
        config_file=config_file,
        other_args=[page_file, "post-page"],
        input=create_single_page_input,
    )
    assert result.exit_code == 0
    assert get_page_body(get_page_id_from_stdout(
        result.stdout)) == f"<p>{content}</p>"
示例#3
0
def setup_page(tmp_path, record_pages):
    """Prepares a page to upload files to"""
    config_path, config = generate_local_config(tmp_path, pages=1)
    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\n"
    )
    assert result.exit_code == 0
    return get_page_id_from_stdout(result.stdout), config_path
示例#4
0
def test_post_single_page_with_parent(setup_page, parent_page_title_source,
                                      tmp_path):
    """Tests that the parent_page_title is applied to create the page in the proper place.
    Tests scenarios of providing the parent title in dialog (through user input), as --parent-page-title argument,
    or in config"""

    # Create the first page, it will be the parent
    config, (parent_id, parent_page_title) = setup_page(1)
    page_title = next(fake_title_generator)

    if parent_page_title_source == "dialog":
        result, _ = run_with_title(
            input=join_input("Y", "Y", parent_page_title, "Y"),
            config_file=real_confluence_config,
        )
        assert "Which page should the script look for?" in result.stdout
        assert "URL is:" in result.stdout
        assert "Proceed to create the page" in result.stdout
    else:

        if parent_page_title_source == "cmdline":
            result = run_with_config(
                input=f"Y\n",  # create page
                pre_args=[
                    "--parent-page-title",
                    parent_page_title,
                    "--page-title",
                    page_title,
                ],
                config_file=real_confluence_config,
            )
        else:
            config_file = mk_tmp_file(
                tmp_path=tmp_path,
                key_to_update="pages.page1.page_parent_title",
                value_to_update=parent_page_title,
            )
            result, _ = run_with_title(
                input=f"Y\n",
                config_file=config_file  # create page
            )
        assert (
            "Which page should the script look for?" not in result.stdout
        ), "If the parent page title is explicitly supplied, script should not look for parent"

    assert "Found page #" in result.stdout
    assert result.exit_code == 0
    assert get_page_id_from_stdout(
        result.stdout) in confluence_instance.get_child_id_list(parent_id)
示例#5
0
def test_page_overridden_title(make_one_page_config):
    """Tests that the title supplied through command line is applied"""
    config_file, config = make_one_page_config
    result, page_title = run_with_title(
        input=
        create_single_page_input,  # create page, do not look for parent, create in root
        config_file=config_file,
    )
    assert result.exit_code == 0
    created_page_title = get_page_title(get_page_id_from_stdout(result.stdout))
    assert (created_page_title == page_title
            ), "Page title was not applied from command line"
    assert created_page_title != config.pages[0].page_title, (
        "Page title is the same as in config,"
        " should have been overwritten")
示例#6
0
def test_upload_files_single_page_title_supplied(setup_page, gen_attachments):
    """Runs
    confluence_poster --config <config> --page-title <some page name> post-page --upload-files file1 file2...
    And makes sure the files were attached to the proper page
    """
    page_id, config_file = setup_page
    file_to_upload, filename = gen_attachments[0]

    new_title = next(fake_title_generator)
    # Create the page first
    create_page = run_with_config(
        config_file=config_file,
        pre_args=["--page-title", new_title],
        default_run_cmd=generate_run_cmd(runner, app, default_args=["post-page"]),
        input="Y\nN\nY\n",
    )
    created_page_id = get_page_id_from_stdout(create_page.stdout)
    result: Result = upload_files(
        config_file=config_file,
        other_args=[file_to_upload],
        pre_args=["--page-title", new_title],
    )

    assert result.exit_code == 0
    assert (
        len(
            confluence_instance.get_attachments_from_content(created_page_id)["results"]
        )
        == 1
    )
    assert (
        confluence_instance.get_attachments_from_content(created_page_id)["results"][0][
            "title"
        ]
        == filename
    )
    assert (
        len(confluence_instance.get_attachments_from_content(page_id)["results"]) == 0
    ), "The original page should not have any attachments"
示例#7
0
def test_post_new_page_stdin(make_one_page_config, tmp_path, file_format):
    """Tests posting three sources with the effectively same text"""
    config_file, config = make_one_page_config

    content = {
        "html": """<h1>Title</h1>
<ul>
<li>one</li>
<li>two</li>
</ul>""",
        "confluencewiki": """h1. Title
* one
* two""",
        "markdown": """# Title
* one
* two""",
    }

    result: Result = run_with_config(
        config_file=config_file,
        other_args=[
            "-",
            "--force-create",
            "post-page",
            "--create-in-space-root",
            "--file-format",
            file_format,
        ],
        input=content[file_format],
    )
    assert result.exit_code == 0
    assert BeautifulSoup(
        get_page_body(get_page_id_from_stdout(result.stdout)),
        features="lxml",
    ) == BeautifulSoup(
        content["html"],
        features="lxml",
    )