Esempio n. 1
0
def test_submit_update_no_change(in_process, git_repo_path, init_sha, git_sha):
    testfile = git_repo_path / "X"
    testfile.write_text("a")
    git_out("add", ".")
    msgfile = git_repo_path / "msg"
    msgfile.write_text("""\
Bug 1 - A

Differential Revision: http://example.test/D123
""")
    git_out("commit", "--file", "msg")
    sha = git_sha()
    call_conduit.reset_mock()
    call_conduit.side_effect = (
        # ping
        dict(),
        # diffusion.repository.search
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="git"))]),
        # diffusion.revision.search
        dict(data=[search_rev(rev=123)]),
        # diffusion.diff.search
        dict(data=[search_diff(node=sha)]),
        # whoami
        dict(phid="PHID-USER-1"),
    )

    mozphab.main(
        ["submit", "--yes"] + [init_sha],
        is_development=True,
    )
    assert call_conduit.call_count == 5
Esempio n. 2
0
def test_submit_update_reviewers_not_updated(in_process, hg_repo_path):
    call_conduit.reset_mock()
    call_conduit.side_effect = (
        {},
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="hg"))]),
        dict(data=[search_rev(rev=123, reviewers=["PHID-USER-1"])]),
        dict(data=[search_diff()]),
        dict(phid="PHID-USER-1"),
        [{"userName": "******", "phid": "PHID-USER-1"}],
    )
    arc_call_conduit.reset_mock()
    check_call_by_line.reset_mock()
    testfile = hg_repo_path / "X"
    testfile.write_text("a")
    hg_out("add")

    # Write out our commit message as if the program had already run and appended
    # a Differential Revision keyword to the commit body for tracking.
    hg_out(
        "commit",
        "--message",
        """\
Bug 1 - A

Differential Revision: http://example.test/D123
""",
    )

    mozphab.main(
        ["submit", "--arc", "--yes", "--bug", "1", "-r", "alice", "."],
        is_development=True,
    )

    arc_call_conduit.assert_called_once_with("conduit.ping", {}, mock.ANY)
    check_call_by_line.assert_called_once()
Esempio n. 3
0
def test_submit_create_with_user_bookmark(in_process, hg_repo_path):
    call_conduit.reset_mock()
    call_conduit.side_effect = (
        dict(),
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="hg"))]),
        [{"userName": "******", "phid": "PHID-USER-1"}],
    )

    testfile = hg_repo_path / "X"
    testfile.write_text("a")
    hg_out("add")
    hg_out("commit", "--message", "A r?alice")

    user_bookmark_name = "user bookmark"
    hg_out("bookmark", user_bookmark_name)

    mozphab.main(["submit", "--arc", "--yes", "--bug", "1", "."], is_development=True)

    log = hg_out("log", "--template", r"{desc}\n", "--rev", ".")
    expected = """
Bug 1 - A r?alice

Differential Revision: http://example.test/D123
"""
    assert log.strip() == expected.strip()

    assert hg_out("bookmark").startswith(" * " + user_bookmark_name)
Esempio n. 4
0
def test_submit_create_no_bug(in_process, hg_repo_path):
    call_conduit.reset_mock()
    call_conduit.side_effect = (
        # ping
        dict(),
        # diffusion.repository.search
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="hg"))]),
        [dict(userName="******", phid="PHID-USER-1")],
        # differential.creatediff
        dict(dict(phid="PHID-DIFF-1", diffid="1")),
        # differential.revision.edit
        dict(object=dict(id="123")),
        # differential.setdiffproperty
        dict(),
    )
    write_text(hg_repo_path / "x", "a")
    hg_out("add")
    hg_out("commit", "--message", "A r?alice")
    mozphab.main(["submit", "--yes", "--no-bug", "."], is_development=True)

    log = hg_out("log", "--template", r"{desc}\n", "--rev", ".")
    expected = """
A r?alice

Differential Revision: http://example.test/D123
"""
    assert log.strip() == expected.strip()
Esempio n. 5
0
def test_submit_single_last(in_process, hg_repo_path):
    call_conduit.side_effect = (
        # ping
        dict(),
        # diffusion.repository.search
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="hg"))]),
        # differential.creatediff
        dict(dict(phid="PHID-DIFF-1", diffid="1")),
        # differential.revision.edit
        dict(object=dict(id="123")),
        # differential.setdiffproperty
        dict(),
    )
    write_text(hg_repo_path / "X", "a\n")
    hg_out("add", "X")
    hg_out("commit", "-m", "A")
    write_text(hg_repo_path / "X", "b\n")
    hg_out("commit", "-m", "B")

    mozphab.main(["submit", "--yes", "--bug", "1", "--single"], is_development=True)

    log = hg_out("log", "--template", r"{desc}\n---\n", "--limit", "2")
    expected = """\
Bug 1 - B

Differential Revision: http://example.test/D123
---
A
---
"""
    assert log == expected
Esempio n. 6
0
def test_submit_create_no_bug(in_process, git_repo_path, init_sha):
    call_conduit.reset_mock()
    call_conduit.side_effect = (
        # ping
        dict(),
        # diffusion.repository.search
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="git"))]),
        # user search
        [dict(userName="******", phid="PHID-USER-1")],
        # differential.creatediff
        dict(dict(phid="PHID-DIFF-1", diffid="1")),
        # differential.setdiffproperty
        dict(),
        # differential.revision.edit
        dict(object=dict(id="123")),
        # differential.setdiffproperty
        dict(),
    )
    testfile = git_repo_path / "X"
    testfile.write_text("a\n")
    git_out("add", ".")
    msgfile = git_repo_path / "msg"
    msgfile.write_text("A r?alice")
    git_out("commit", "--file", "msg")

    mozphab.main(["submit", "--yes", "--no-bug", init_sha], is_development=True)

    log = git_out("log", "--format=%s%n%n%b", "-1")
    expected = """
A r?alice

Differential Revision: http://example.test/D123
"""
    assert log.strip() == expected.strip()
Esempio n. 7
0
def test_submit_create_added_not_commited(in_process, git_repo_path, init_sha):
    call_conduit.side_effect = (
        # ping
        dict(),
        # diffusion.repository.search
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="git"))]),
        # user search
        [dict(userName="******", phid="PHID-USER-1")],
        # differential.creatediff
        dict(dict(phid="PHID-DIFF-1", diffid="1")),
        # differential.setdiffproperty
        dict(),
        # differential.revision.edit
        dict(object=dict(id="123")),
        # differential.setdiffproperty
        dict(),
    )
    (git_repo_path / "X").write_text("ą\r\nb\nc\n", encoding="utf-8")
    (git_repo_path / "Y").write_text("no line ending")
    git_out("add", ".")
    (git_repo_path / "msg").write_text("Ą r?alice", encoding="utf-8")
    git_out("commit", "--file", "msg")
    (git_repo_path / "untracked").write_text("a\n")
    git_out("add", "untracked")

    with pytest.raises(exceptions.Error) as excinfo:
        mozphab.main(["submit", "--yes", "--bug", "1", init_sha], is_development=True)

    assert "Uncommitted changes present." in str(excinfo.value)
Esempio n. 8
0
def test_submit_single_last(in_process, git_repo_path, init_sha):
    call_conduit.side_effect = (
        # ping
        dict(),
        # diffusion.repository.search
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="git"))]),
        # differential.creatediff
        dict(dict(phid="PHID-DIFF-1", diffid="1")),
        # differential.setdiffproperty
        dict(),
        # differential.revision.edit
        dict(object=dict(id="123")),
        # differential.setdiffproperty
        dict(),
    )
    (git_repo_path / "X").write_text("a\n")
    git_out("add", "X")
    git_out("commit", "-am", "A")
    (git_repo_path / "X").write_text("b\n")
    git_out("commit", "-am", "B")

    mozphab.main(["submit", "--yes", "--bug", "1", "--single"], is_development=True)

    log = git_out("log", "--format=%s%n%n%b", "-2")
    expected = """\
Bug 1 - B

Differential Revision: http://example.test/D123
A


"""
    assert log == expected
Esempio n. 9
0
def test_submit_create_binary(in_process, hg_repo_path, data_file):
    call_conduit.side_effect = (
        # ping
        dict(),
        # diffusion.repository.search
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="hg"))]),
        # file upload
        dict(),
        # differential.creatediff
        dict(dict(phid="PHID-DIFF-1", diffid="1")),
        # differential.setdiffproperty
        dict(),
        # differential.revision.edit
        dict(object=dict(id="123")),
    )
    shutil.copyfile(str(data_file), str(hg_repo_path / "img.png"))
    hg_out("add")
    hg_out("commit", "-m", "IMG")

    mozphab.main(["submit", "--yes", "--bug", "1", "."], is_development=True)

    log = hg_out("log", "--template", r"{desc}\n", "--rev", ".")
    expected = """
Bug 1 - IMG

Differential Revision: http://example.test/D123
"""
    assert log.strip() == expected.strip()
Esempio n. 10
0
def test_submit_update(in_process, git_repo_path, init_sha):
    call_conduit.reset_mock()
    call_conduit.side_effect = (
        # ping
        dict(),
        # diffusion.repository.search
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="git"))]),
        dict(
            data=[
                {
                    "fields": {
                        "bugzilla.bug-id": "1",
                        "status": {"value": "needs-review", "closed": False},
                        "authorPHID": "PHID-USER-1",
                    },
                    "phid": "PHID-DREV-y7x5hvdpe2gyerctdqqz",
                    "id": 123,
                    "attachments": {"reviewers": {"reviewers": []}},
                }
            ]
        ),
        # whoami
        dict(phid="PHID-USER-1"),
        # differential.creatediff
        dict(dict(phid="PHID-DIFF-1", diffid="1")),
        # differential.setdiffproperty
        dict(),
        # differential.revision.edit
        dict(object=dict(id="123")),
    )
    testfile = git_repo_path / "X"
    testfile.write_text("ą", encoding="utf-8")
    git_out("add", ".")
    msgfile = git_repo_path / "msg"
    msgfile.write_text(
        """\
Bug 1 - Ą

Differential Revision: http://example.test/D123
""",
        encoding="utf-8",
    )
    git_out("commit", "--file", "msg")

    mozphab.main(
        ["submit", "--yes"]
        + ["--bug", "1"]
        + ["--message", "update message ćwikła"]
        + [init_sha],
        is_development=True,
    )

    log = git_out("log", "--format=%s%n%n%b", "-1")
    expected = """\
Bug 1 - Ą

Differential Revision: http://example.test/D123

"""
    assert log == expected
Esempio n. 11
0
def test_submit_utf8_author_arc(in_process, git_repo_path, init_sha):
    call_conduit.reset_mock()
    call_conduit.side_effect = (
        dict(),
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="git"))]),
        [{"userName": "******", "phid": "PHID-USER-1"}],
    )
    testfile = git_repo_path / "X"
    testfile.write_text("a")
    git_out("add", ".")
    git_out(
        "commit",
        "--date",
        "Tue, 22 Jan 2019 13:42:48 +0000",
        "--author",
        "ćwikła <ćwikł[email protected]>",
        "--message",
        "A r?alice",
    )

    mozphab.main(
        ["submit", "--arc", "--yes", "--bug", "1", init_sha], is_development=True
    )

    log = git_out("log", "--format=%aD+++%an+++%ae", "-1")
    expected = "Tue, 22 Jan 2019 13:42:48 +0000+++ćwikła+++ćwikł[email protected]\n"
    assert log == expected
Esempio n. 12
0
def test_submit_create_arc(in_process, git_repo_path, init_sha):
    call_conduit.side_effect = (
        dict(),
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="git"))]),
        [{
            "userName": "******",
            "phid": "PHID-USER-1"
        }],
    )
    testfile = git_repo_path / "X"
    testfile.write_text("a")
    git_out("add", ".")
    git_out("commit", "--message", "A r?alice")
    testfile = git_repo_path / "untracked"
    testfile.write_text("a")

    mozphab.main(["submit", "--arc", "--yes", "--bug", "1", init_sha],
                 is_development=True)

    log = git_out("log", "--format=%s%n%n%b", "-1")
    expected = """
Bug 1 - A r?alice

Differential Revision: http://example.test/D123
"""
    assert log.strip() == expected.strip()
Esempio n. 13
0
def test_submit_update_revision_not_found(in_process, git_repo_path, init_sha):
    call_conduit.reset_mock()
    call_conduit.side_effect = (
        # ping
        dict(),
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="git"))]),
        # response for searching D123 and D124
        dict(
            data=[
                {
                    "fields": {
                        "bugzilla.bug-id": "1",
                        "status": {"value": "needs-review", "closed": False},
                    },
                    "phid": "PHID-DREV-y7x5hvdpe2gyerctdqqz",
                    "id": 123,
                    "attachments": {"reviewers": {"reviewers": []}},
                }
            ]
        ),
        # moz-phab asks again for D124
        dict(data=[]),
        # moz-phab asks again for D124
        dict(data=[]),
        # moz-phab asks again for D124
        dict(data=[]),
    )
    testfile = git_repo_path / "X"
    testfile.write_text(u"ą", encoding="utf-8")
    git_out("add", ".")
    msgfile = git_repo_path / "msg"
    msgfile.write_text(
        u"""\
Bug 1 - Ą

Differential Revision: http://example.test/D123
""",
        encoding="utf-8",
    )
    git_out("commit", "--file", "msg")
    testfile.write_text(u"missing repo")
    msgfile.write_text(
        u"""\
Bug 1 - missing revision

Differential Revision: http://example.test/D124
"""
    )
    git_out("commit", "--all", "--file", "./msg")

    with pytest.raises(exceptions.Error) as excinfo:
        mozphab.main(
            ["submit", "--yes"]
            + ["--bug", "1"]
            + ["--message", "update message ćwikła"]
            + [init_sha],
            is_development=True,
        )
    assert "query result for revision D124" in str(excinfo.value)
Esempio n. 14
0
def test_submit_update_no_new_reviewers(in_process, hg_repo_path):
    call_conduit.reset_mock()
    call_conduit.side_effect = (
        {},
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="hg"))]),
        dict(data=[search_rev(rev=123, status="changes-planned")]),
        dict(data=[search_diff()]),
        dict(phid="PHID-USER-1"),
        [{
            "userName": "******",
            "phid": "PHID-USER-1"
        }],
    )
    arc_call_conduit.reset_mock()
    arc_call_conduit.side_effect = (
        {},
        {
            "data": {}
        },
    )  # set reviewers response
    check_call_by_line.reset_mock()
    testfile = hg_repo_path / "X"
    testfile.write_text("a")
    hg_out("add")

    # Write out our commit message as if the program had already run and appended
    # a Differential Revision keyword to the commit body for tracking.
    hg_out(
        "commit",
        "--message",
        """\
Bug 1 - A

Differential Revision: http://example.test/D123
""",
    )

    mozphab.main(
        ["submit", "--arc", "--yes", "--bug", "1", "-r", "alice", "."],
        is_development=True,
    )
    arc_call_conduit.assert_called_with(
        "differential.revision.edit",
        {
            "objectIdentifier":
            "D123",
            "transactions": [
                {
                    "type": "reviewers.set",
                    "value": ["PHID-USER-1"]
                },
                {
                    "type": "request-review"
                },
            ],
        },
        mock.ANY,
    )
    check_call_by_line.assert_called_once()
Esempio n. 15
0
def test_sentry_enabled(_telemetry, _check, mock_init_sentry, mock_parse_args):
    config.report_to_sentry = True
    args = MagicMock()
    args.needs_repo = False  # skip FS operations
    mock_parse_args.return_value = args

    mozphab.main([], is_development=False)

    mock_init_sentry.assert_called_once()
Esempio n. 16
0
def test_sentry_not_enabled_if_config_disabled(_, mock_init_sentry,
                                               mock_parse_args):
    config.report_to_sentry = False
    args = MagicMock()
    args.needs_repo = False  # skip FS operations
    mock_parse_args.return_value = args

    mozphab.main([], is_development=True)

    mock_init_sentry.assert_not_called()
Esempio n. 17
0
def test_empty_file(in_process, git_repo_path, init_sha):
    # Add an empty file
    call_conduit.side_effect = (
        # ping
        dict(),
        # diffusion.repository.search
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="git"))]),
        # differential.creatediff
        dict(dict(phid="PHID-DIFF-1", diffid="1")),
        # differential.setdiffproperty
        dict(),
        # differential.revision.edit
        dict(object=dict(id="123")),
        # differential.setdiffproperty
        dict(),
    )
    testfile = git_repo_path / "X"
    testfile.touch()
    git_out("add", ".")
    git_out("commit", "--message", "A")

    mozphab.main(["submit", "--yes", "--bug", "1", init_sha],
                 is_development=True)

    log = git_out("log", "--format=%s%n%n%b", "-1")
    expected = """
Bug 1 - A

Differential Revision: http://example.test/D123
"""
    assert log.strip() == expected.strip()

    # Rempve an empty file
    call_conduit.reset_mock()
    call_conduit.side_effect = (
        # differential.creatediff
        dict(dict(phid="PHID-DIFF-2", diffid="2")),
        # differential.setdiffproperty
        dict(),
        # differential.revision.edit
        dict(object=dict(id="124")),
        # differential.setdiffproperty
        dict(),
    )
    testfile.unlink()
    git_out("commit", "-a", "--message", "B")
    mozphab.main(["submit", "--yes", "--bug", "1", "HEAD~"],
                 is_development=True)
    log = git_out("log", "--format=%s%n%n%b", "-1")
    expected = """
Bug 1 - B

Differential Revision: http://example.test/D124
"""
    assert log.strip() == expected.strip()
Esempio n. 18
0
def test_submit_update_bug_id_arc(in_process, git_repo_path, init_sha):
    call_conduit.reset_mock()
    call_conduit.side_effect = (
        dict(),
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="git"))]),
        {
            "data": [
                {
                    "id": 123,
                    "phid": "PHID-REV-1",
                    "fields": {
                        "bugzilla.bug-id": "1",
                        "status": {"value": "needs-review", "closed": False},
                        "authorPHID": "PHID-USER-1",
                    },
                    "attachments": {"reviewers": {"reviewers": []}},
                }
            ]
        },  # get reviewers for updated revision
        dict(phid="PHID-USER-1"),
    )
    arc_call_conduit.reset_mock()
    arc_call_conduit.side_effect = (
        {},
        {"data": {}},
    )
    testfile = git_repo_path / "X"
    testfile.write_text("a")
    git_out("add", ".")

    # Write out our commit message as if the program had already run and appended
    # a Differential Revision keyword to the commit body for tracking.
    git_out(
        "commit",
        "--message",
        """\
Bug 1 - A

Differential Revision: http://example.test/D123
""",
    )

    mozphab.main(
        ["submit", "--arc", "--yes", "--bug", "2", init_sha], is_development=True
    )

    arc_call_conduit.assert_called_with(
        "differential.revision.edit",
        {
            "objectIdentifier": "D123",
            "transactions": [{"type": "bugzilla.bug-id", "value": "2"}],
        },
        mock.ANY,
    )
Esempio n. 19
0
def test_submit_update_arc(in_process, git_repo_path, init_sha):
    call_conduit.reset_mock()
    call_conduit.side_effect = (
        {},  # ping
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="git"))]),
        {  # differential.revision.search
            "data": [
                {
                    "fields": {
                        "bugzilla.bug-id": "1",
                        "status": {"value": "needs-review", "closed": False},
                        "authorPHID": "PHID-USER-1",
                    },
                    "phid": "PHID-DREV-y7x5hvdpe2gyerctdqqz",
                    "id": 123,
                    "attachments": {"reviewers": {"reviewers": []}},
                }
            ]
        },
        dict(phid="PHID-USER-1"),
    )
    testfile = git_repo_path / "X"
    testfile.write_text("a")
    git_out("add", ".")

    # Write out our commit message as if the program had already run and appended
    # a Differential Revision keyword to the commit body for tracking.
    git_out(
        "commit",
        "--message",
        """\
Bug 1 - A

Differential Revision: http://example.test/D123
""",
    )

    mozphab.main(
        ["submit", "--arc", "--yes"]
        + ["--bug", "1"]
        + ["--message", "update message ćwikła"]
        + [init_sha],
        is_development=True,
    )

    log = git_out("log", "--format=%s%n%n%b", "-1")
    expected = """\
Bug 1 - A

Differential Revision: http://example.test/D123

"""
    assert log == expected
Esempio n. 20
0
def test_submit_update(in_process, git_repo_path, init_sha):
    call_conduit.reset_mock()
    call_conduit.side_effect = (
        # ping
        dict(),
        # diffusion.repository.search
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="git"))]),
        # diffusion.revision.search
        dict(data=[search_rev(rev=123)]),
        # diffusion.diff.search
        dict(data=[search_diff()]),
        # whoami
        dict(phid="PHID-USER-1"),
        # differential.creatediff
        dict(dict(phid="PHID-DIFF-1", diffid="1")),
        # differential.setdiffproperty
        dict(),
        # differential.revision.edit
        dict(object=dict(id="123")),
        # differential.setdiffproperty
        dict(),
    )
    testfile = git_repo_path / "X"
    testfile.write_text("ą", encoding="utf-8")
    git_out("add", ".")
    msgfile = git_repo_path / "msg"
    msgfile.write_text(
        """\
Bug 1 - Ą

Differential Revision: http://example.test/D123
""",
        encoding="utf-8",
    )
    git_out("commit", "--file", "msg")

    mozphab.main(
        ["submit", "--yes"]
        + ["--bug", "1"]
        + ["--message", "update message ćwikła"]
        + [init_sha],
        is_development=True,
    )

    assert call_conduit.call_count == 9
    log = git_out("log", "--format=%s%n%n%b", "-1")
    expected = """\
Bug 1 - Ą

Differential Revision: http://example.test/D123

"""
    assert log == expected
Esempio n. 21
0
def test_new_separate_revisions_to_stack(in_process, git_repo_path, init_sha):
    call_conduit.side_effect = (
        # ping
        dict(),
        # search revisions
        dict(data=[
            dict(
                phid="PHID-1",
                id=1,
                fields=dict(status=dict(value="needs-review")),
            ),
            dict(
                phid="PHID-2",
                id=2,
                fields=dict(status=dict(value="needs-review")),
            ),
        ]),
        # edge search
        dict(data=[]),
        # differential.edit_revision
        dict(data=[dict(phid="PHID-1", id=1)]),
    )

    f = git_repo_path / "X"
    f.write_text("A")
    git_out("add", ".")
    msgfile = git_repo_path / "msg"
    msgfile.write_text("""\
Bug 1: A r?alice

Differential Revision: http://example.test/D1
""")
    git_out("commit", "--file", "msg")
    f.write_text("B")
    msgfile = git_repo_path / "msg"
    msgfile.write_text("""\
Bug 1: B r?alice

Differential Revision: http://example.test/D2
""")
    git_out("commit", "-a", "--file", "msg")
    mozphab.main(["reorg", "--yes", init_sha], is_development=True)
    assert (mock.call(
        "differential.revision.edit",
        {
            "objectIdentifier": "PHID-1",
            "transactions": [{
                "type": "children.set",
                "value": ["PHID-2"]
            }],
        },
    ) in call_conduit.call_args_list)
Esempio n. 22
0
def test_submit_update_bug_id(in_process, hg_repo_path):
    call_conduit.reset_mock()
    call_conduit.side_effect = (
        {},
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="hg"))]),
        dict(data=[search_rev(rev=123, reviewers=["PHID-USER-1"])]),
        dict(data=[search_diff()]),
        dict(phid="PHID-USER-1"),
        [{
            "userName": "******",
            "phid": "PHID-USER-1"
        }],
    )
    arc_call_conduit.reset_mock()
    # response from setting the bug id
    arc_call_conduit.side_effect = (
        {},
        {
            "data": {}
        },
    )
    testfile = hg_repo_path / "X"
    testfile.write_text("a")
    hg_out("add")

    # Write out our commit message as if the program had already run and appended
    # a Differential Revision keyword to the commit body for tracking.
    hg_out(
        "commit",
        "--message",
        """\
Bug 1 - A

Differential Revision: http://example.test/D123
""",
    )

    mozphab.main(["submit", "--arc", "--yes", "--bug", "2", "-r", "alice"],
                 is_development=True)

    arc_call_conduit.assert_called_with(
        "differential.revision.edit",
        {
            "objectIdentifier": "D123",
            "transactions": [{
                "type": "bugzilla.bug-id",
                "value": "2"
            }],
        },
        mock.ANY,
    )
    assert call_conduit.call_count == 6
Esempio n. 23
0
def test_no_need_to_reorganise(in_process, git_repo_path, init_sha):
    # One commit
    call_conduit.side_effect = (
        dict(),  # ping
        dict(data=[dict(phid="PHID-1", id=1)]),  # differential.get_revision
        # Revision is not related to any other revision. There is no stack.
        dict(data=[]),  # edge.search
    )

    f = git_repo_path / "X"
    f.write_text("A")
    git_out("add", ".")
    msgfile = git_repo_path / "msg"
    msgfile.write_text("""\
Bug 1: A r?alice

Differential Revision: http://example.test/D1
""")
    git_out("commit", "--file", "msg")
    with pytest.raises(exceptions.Error) as e:
        mozphab.main(["reorg", "--yes", init_sha], is_development=True)

    assert (str(e.value)) == "Reorganisation is not needed."

    # Stack of commits
    call_conduit.side_effect = (
        dict(data=[dict(phid="PHID-1", id=1),
                   dict(phid="PHID-2", id=2)]),
        # PHID-2 is the only child of PHID-1.
        dict(data=[
            dict(
                sourcePHID="PHID-1",
                destinationPHID="PHID-2",
                edgeType="revision.child",
            )
        ]),
    )

    f.write_text("B")
    msgfile = git_repo_path / "msg"
    msgfile.write_text("""\
Bug 1: B r?alice

Differential Revision: http://example.test/D2
""")
    git_out("commit", "-a", "--file", "msg")

    with pytest.raises(exceptions.Error) as e:
        mozphab.main(["reorg", "--yes", init_sha], is_development=True)

    assert (str(e.value)) == "Reorganisation is not needed."
Esempio n. 24
0
def test_submit_update_revision_not_found(in_process, git_repo_path, init_sha):
    call_conduit.reset_mock()
    call_conduit.side_effect = (
        # ping
        dict(),
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="git"))]),
        # response for searching D123 and D124
        dict(data=[search_rev(rev=123)]),
        dict(data=[search_diff()]),
        # moz-phab asks again for D124
        dict(data=[]),
        # whoami
        dict(phid="PHID-USER-1"),
        # moz-phab asks again for D124
        dict(data=[]),
        # moz-phab asks again for D124
        dict(data=[]),
    )
    testfile = git_repo_path / "X"
    testfile.write_text(u"ą", encoding="utf-8")
    git_out("add", ".")
    msgfile = git_repo_path / "msg"
    msgfile.write_text(
        u"""\
Bug 1 - Ą

Differential Revision: http://example.test/D123
""",
        encoding="utf-8",
    )
    git_out("commit", "--file", "msg")
    testfile.write_text(u"missing repo")
    msgfile.write_text(
        u"""\
Bug 1 - missing revision

Differential Revision: http://example.test/D124
"""
    )
    git_out("commit", "--all", "--file", "./msg")

    with pytest.raises(exceptions.Error) as excinfo:
        mozphab.main(
            ["submit", "--yes"]
            + ["--bug", "1"]
            + ["--message", "update message ćwikła"]
            + [init_sha],
            is_development=True,
        )
    assert "query result for revision D124" in str(excinfo.value)
Esempio n. 25
0
def _submit(repo, start, end, expected, wip=False):
    mozphab.main(
        [
            "submit",
            "--yes",
            *(["--wip"] if wip else []),
            "--bug",
            "1",
            repo["rev_map"][start],
            repo["rev_map"][end],
        ],
        is_development=True,
    )
    log = hg_out("log", "--graph", "--template", r"{desc|firstline}\n")
    assert log.strip() == expected.strip()
Esempio n. 26
0
def test_submit_create_binary(in_process, git_repo_path, init_sha, data_file):
    call_conduit.reset_mock()
    call_conduit.side_effect = (
        # ping
        dict(),
        # diffusion.repository.search
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="git"))]),
        # file.allocate
        dict(dict(filePHID=None, upload=True)),
        # file.upload
        dict(),
        # differential.creatediff
        dict(dict(phid="PHID-DIFF-1", diffid="1")),
        # differential.setdiffproperty
        dict(),
        # differential.revision.edit
        dict(object=dict(id="123")),
        # differential.setdiffproperty
        dict(),
    )
    shutil.copyfile(str(data_file), str(git_repo_path / "img.png"))
    git_out("add", ".")
    git_out("commit", "-m", "IMG")

    mozphab.main(["submit", "--yes", "--bug", "1", init_sha],
                 is_development=True)

    log = git_out("log", "--format=%s%n%n%b", "-1")
    expected = """
Bug 1 - IMG

Differential Revision: http://example.test/D123
"""
    assert log.strip() == expected.strip()
    assert (mock.call(
        "file.allocate",
        {
            "name": "img.png",
            "contentHash": mock.ANY,
            "contentLength": 182
        },
    ) in call_conduit.call_args_list)
    assert (mock.call("file.upload", {
        "data_base64": mock.ANY,
        "name": "img.png"
    }) in call_conduit.call_args_list)
Esempio n. 27
0
def test_submit_update(in_process, hg_repo_path):
    call_conduit.reset_mock()
    arc_call_conduit.reset_mock()
    call_conduit.side_effect = (
        {},
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="hg"))]),
        dict(data=[search_rev(rev=123)]),
        dict(data=[search_diff()]),
        # get reviewers for updated revision
        dict(phid="PHID-USER-1"),
        dict(data=[search_rev(rev=123, reviewers=["PHID-USER-1"])]),
    )
    check_call_by_line.reset_mock()
    testfile = hg_repo_path / "X"
    testfile.write_text("a")
    hg_out("add")

    # Write out our commit message as if the program had already run and appended
    # a Differential Revision keyword to the commit body for tracking.
    hg_out(
        "commit",
        "--message",
        """\
Bug 1 - A

Differential Revision: http://example.test/D123
""",
    )

    mozphab.main(["submit", "--arc", "--yes", "--bug", "1", "."],
                 is_development=True)

    log = hg_out("log", "--template", r"{desc}\n", "--rev", ".")
    expected = """\
Bug 1 - A

Differential Revision: http://example.test/D123
"""
    assert log == expected
    assert call_conduit.call_count == 5
    arc_call_conduit.assert_called_once_with("conduit.ping", {}, mock.ANY)
    check_call_by_line.assert_called_once()  # update
Esempio n. 28
0
def test_submit_create_binary_existing(in_process, hg_repo_path, data_file):
    call_conduit.reset_mock()
    call_conduit.side_effect = (
        # ping
        dict(),
        # diffusion.repository.search
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="hg"))]),
        # file.allocate
        dict(dict(filePHID="PHID-FILE-1", upload=False)),
        # no file.upload call
        # differential.creatediff
        dict(dict(phid="PHID-DIFF-1", diffid="1")),
        # differential.setdiffproperty
        dict(),
        # differential.revision.edit
        dict(object=dict(id="123")),
        # differential.setdiffproperty
        dict(),
    )
    shutil.copyfile(str(data_file), str(hg_repo_path / "img.png"))
    hg_out("add")
    hg_out("commit", "-m", "IMG")

    mozphab.main(["submit", "--yes", "--bug", "1", "."], is_development=True)

    log = hg_out("log", "--template", r"{desc}\n", "--rev", ".")
    expected = """
Bug 1 - IMG

Differential Revision: http://example.test/D123
"""
    assert log.strip() == expected.strip()
    assert (mock.call(
        "file.allocate",
        {
            "name": "img.png",
            "contentHash": mock.ANY,
            "contentLength": 182
        },
    ) in call_conduit.call_args_list)
    assert mock.call("file.upload",
                     mock.ANY) not in call_conduit.call_args_list
Esempio n. 29
0
def test_submit_create_binary_arc(in_process, git_repo_path, init_sha, data_file):
    call_conduit.side_effect = (
        dict(),
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="git"))]),
        [{"userName": "******", "phid": "PHID-USER-1"}],
    )
    shutil.copyfile(str(data_file), str(git_repo_path / "img.png"))
    git_out("add", ".")
    git_out("commit", "--message", "IMG")

    mozphab.main(
        ["submit", "--arc", "--yes", "--bug", "1", init_sha], is_development=True
    )
    expected = """
Bug 1 - IMG

Differential Revision: http://example.test/D123
"""
    log = git_out("log", "--format=%s%n%n%b", "-1")
    assert log.strip() == expected.strip()
Esempio n. 30
0
def test_submit_update_arc(in_process, git_repo_path, init_sha):
    call_conduit.reset_mock()
    call_conduit.side_effect = (
        {},  # ping
        dict(data=[dict(phid="PHID-REPO-1", fields=dict(vcs="git"))]),
        dict(data=[search_rev(rev=123)]),
        dict(data=[search_diff()]),
        dict(phid="PHID-USER-1"),
    )
    testfile = git_repo_path / "X"
    testfile.write_text("a")
    git_out("add", ".")

    # Write out our commit message as if the program had already run and appended
    # a Differential Revision keyword to the commit body for tracking.
    git_out(
        "commit",
        "--message",
        """\
Bug 1 - A

Differential Revision: http://example.test/D123
""",
    )

    mozphab.main(
        ["submit", "--arc", "--yes"]
        + ["--bug", "1"]
        + ["--message", "update message ćwikła"]
        + [init_sha],
        is_development=True,
    )

    log = git_out("log", "--format=%s%n%n%b", "-1")
    expected = """\
Bug 1 - A

Differential Revision: http://example.test/D123

"""
    assert log == expected