Ejemplo n.º 1
0
async def test_create_release_notes(test_repo_directory, with_checkboxes):
    """create_release_notes should create release notes for a particular release, possibly with checkboxes"""
    make_empty_commit("initial", "initial commit", cwd=test_repo_directory)
    check_call(["git", "tag", "v0.0.1"], cwd=test_repo_directory)
    make_empty_commit("User 1", "Commit #1", cwd=test_repo_directory)
    make_empty_commit("User 2", "Commit #2", cwd=test_repo_directory)
    make_empty_commit("User 2", "Commit #3", cwd=test_repo_directory)

    notes = await create_release_notes("0.0.1",
                                       with_checkboxes=with_checkboxes,
                                       base_branch="master",
                                       root=test_repo_directory)
    lines = notes.split("\n")
    if with_checkboxes:
        assert_starts_with(lines, [
            "## User 2",
            "  - [ ] Commit #3",
            "  - [ ] Commit #2",
            "",
            "## User 1",
            "  - [ ] Commit #1",
            "",
        ])
    else:
        assert_starts_with(lines, [
            '- Commit #3',
            '- Commit #2',
            '- Commit #1',
            "",
        ])
Ejemplo n.º 2
0
async def test_any_new_commits(test_repo_directory, has_commits):
    """any_new_commits should return a bool value saying whether there are new commits or not"""
    make_empty_commit("initial", "initial commit", cwd=test_repo_directory)
    check_call(["git", "tag", "v0.0.1"], cwd=test_repo_directory)

    if has_commits:
        make_empty_commit("User 1", "After 1", cwd=test_repo_directory)
    check_call(["git", "tag", "v0.0.2"], cwd=test_repo_directory)

    assert await any_new_commits(
        "0.0.1", base_branch="master", root=test_repo_directory) is has_commits
Ejemplo n.º 3
0
async def test_create_release_notes_amp(test_repo_directory, with_checkboxes):
    """create_release_notes should not escape html entities"""
    make_empty_commit("initial", "initial commit", cwd=test_repo_directory)
    check_call(["git", "tag", "v0.0.1"], cwd=test_repo_directory)
    make_empty_commit("User 1", "Commit & ' \"", cwd=test_repo_directory)

    notes = await create_release_notes("0.0.1",
                                       with_checkboxes=with_checkboxes,
                                       base_branch="master",
                                       root=test_repo_directory)
    assert "Commit & \' \"" in notes
Ejemplo n.º 4
0
async def test_create_release_notes_empty(test_repo_directory,
                                          with_checkboxes):
    """create_release_notes should return a string saying there are no new commits"""
    make_empty_commit("initial", "initial commit", cwd=test_repo_directory)
    check_call(["git", "tag", "v0.0.1"], cwd=test_repo_directory)

    notes = await create_release_notes("0.0.1",
                                       with_checkboxes=with_checkboxes,
                                       base_branch="master",
                                       root=test_repo_directory)
    assert notes == "No new commits"
Ejemplo n.º 5
0
async def test_init_working_dir_real():
    """make sure init_working_dir can pull and checkout a real repo"""
    # the fake access token won't matter here since this operation is read-only
    repo_url = "https://github.com/mitodl/release-script.git"
    access_token = ""
    async with init_working_dir(
            access_token,
            repo_url,
    ) as other_directory:
        assert os.path.exists(other_directory)
        check_call(["git", "status"], cwd=other_directory)
    assert not os.path.exists(other_directory)
Ejemplo n.º 6
0
async def test_verify_new_commits(test_repo_directory):
    """verify_new_commits should error if there is no commit to put in the release"""
    check_call(["git", "tag", "v0.0.1"], cwd=test_repo_directory)
    check_call(["git", "checkout", "master"], cwd=test_repo_directory)

    with pytest.raises(Exception) as ex:
        await verify_new_commits("0.0.1",
                                 base_branch="master",
                                 root=test_repo_directory)
    assert ex.value.args[0] == "No new commits to put in release"
    make_empty_commit("User 1", "  Release 0.0.1  ", cwd=test_repo_directory)
    # No exception
    await verify_new_commits("0.0.1",
                             base_branch="master",
                             root=test_repo_directory)
Ejemplo n.º 7
0
async def test_update_release_notes_initial(test_repo_directory):
    """If RELEASE.rst doesn't exist update_release_notes should create it"""
    check_call(["git", "checkout", "master"], cwd=test_repo_directory)
    check_call(["git", "tag", "v0.2.0"], cwd=test_repo_directory)

    make_empty_commit("User 1",
                      "A commit between 2 and 3",
                      cwd=test_repo_directory)
    check_call(["git", "tag", "v0.3.0"], cwd=test_repo_directory)
    os.unlink(os.path.join(test_repo_directory, "RELEASE.rst"))
    await update_release_notes("0.2.0",
                               "0.3.0",
                               base_branch="master",
                               root=test_repo_directory)

    with open(os.path.join(test_repo_directory, "RELEASE.rst"),
              "r",
              encoding="utf-8") as f:
        assert (f.read() == """Release Notes
=============

Version 0.3.0
-------------

- A commit between 2 and 3

""")
Ejemplo n.º 8
0
async def test_update_release_notes(test_repo_directory):
    """update_release_notes should update the existing release notes and add new notes for the new commits"""
    check_call(["git", "checkout", "master"], cwd=test_repo_directory)
    check_call(["git", "tag", "v0.2.0"], cwd=test_repo_directory)

    make_empty_commit("User 1", "Before", cwd=test_repo_directory)
    check_call(["git", "tag", "v0.3.0"], cwd=test_repo_directory)
    await update_release_notes("0.2.0",
                               "0.3.0",
                               base_branch="master",
                               root=test_repo_directory)

    make_empty_commit("User 2", "After 1", cwd=test_repo_directory)
    make_empty_commit("User 2", "After 2", cwd=test_repo_directory)
    make_empty_commit("User 3", "After 3", cwd=test_repo_directory)
    await update_release_notes("0.3.0",
                               "0.4.0",
                               base_branch="master",
                               root=test_repo_directory)

    assert open(os.path.join(test_repo_directory,
                             "RELEASE.rst")).read() == """Release Notes
Ejemplo n.º 9
0
async def test_update_release_notes(test_repo_directory):
    """update_release_notes should update the existing release notes and add new notes for the new commits"""
    check_call(["git", "checkout", "master"], cwd=test_repo_directory)
    check_call(["git", "tag", "v0.2.0"], cwd=test_repo_directory)

    make_empty_commit("User 1", "Before", cwd=test_repo_directory)
    check_call(["git", "tag", "v0.3.0"], cwd=test_repo_directory)
    await update_release_notes("0.2.0",
                               "0.3.0",
                               base_branch="master",
                               root=test_repo_directory)

    make_empty_commit("User 2", "After 1", cwd=test_repo_directory)
    make_empty_commit("User 2", "After 2", cwd=test_repo_directory)
    make_empty_commit("User 3", "After 3", cwd=test_repo_directory)
    await update_release_notes("0.3.0",
                               "0.4.0",
                               base_branch="master",
                               root=test_repo_directory)

    with open(os.path.join(test_repo_directory, "RELEASE.rst"),
              "r",
              encoding="utf-8") as f:
        assert (f.read() == """Release Notes
=============

Version 0.4.0
-------------

- After 3
- After 2
- After 1
- Release 0.3.0

Version 0.3.0
-------------

- Before

Version 0.2.0
-------------

- Added missing release_notes template files.
- Changed to ``django-server-status``.
- Added logging message for webhooks with non-200 responses.
- Removed ``dredd``, removed unused HTTP methods from API, added unit tests.
- Added generator script for life-like data.
- Implemented receiving JSON on ``create-ccx`` endpoint.
- Added support for course modules.
- Fixed ``requests`` installation.
- Added additional logging.
- Incoming requests send uuids, not course ids.
- Included the course/module's instance in webhook.
- disabled SSL being necessary for celery.
- Added status.
- Enabled ``redis`` in the web container.
- Made webhook fixes.
- Added API endpoint to create ccxs on edX.
- Now fetching module listing through course structure api.

Version 0.1.0
-------------

- Initial release
""")
Ejemplo n.º 10
0
def make_empty_commit(user, message, *, cwd):
    """Helper function to create an empty commit as a particular user"""
    check_call(["git", "config", "user.email", f"{user}@example.com"], cwd=cwd)
    check_call(["git", "config", "user.name", user], cwd=cwd)
    check_call(["git", "commit", "--allow-empty", "-m", message], cwd=cwd)