def test_init_finds_auth_token_in_environment( capsys, git_repo, with_auth_token_envvar, changes_config_in_tmpdir, with_releases_directory_and_bumpversion_file_prompt, ): responses.add( responses.GET, LABEL_URL, json=BUG_LABEL_JSON, status=200, content_type='application/json', ) changes.initialise() # envvar setting is not written to the config file assert not changes_config_in_tmpdir.exists() expected_output = textwrap.dedent( """\ Found Github Auth Token in the environment... Releases directory {} not found, creating it.... """.format( Path('docs').joinpath('releases') ) ) out, _ = capsys.readouterr() assert expected_output == out
def test_status(capsys, configured): responses.add( responses.GET, LABEL_URL, json=BUG_LABEL_JSON, status=200, content_type='application/json', ) changes.initialise() status.status() expected_output = textwrap.dedent( """\ Status [michaeljoseph/test_app]... Repository: michaeljoseph/test_app... Latest Version... 0.0.1 Changes... 0 changes found since 0.0.1 """ ) out, _ = capsys.readouterr() assert expected_output == out
def test_init_prompts_for_auth_token_and_writes_tool_config( capsys, git_repo, changes_config_in_tmpdir, answer_prompts ): responses.add( responses.GET, LABEL_URL, json=BUG_LABEL_JSON, status=200, content_type='application/json', ) changes.initialise() assert changes_config_in_tmpdir.exists() expected_config = textwrap.dedent( """\ [changes] auth_token = "foo" """ ) assert expected_config == changes_config_in_tmpdir.read_text() expected_output = textwrap.dedent( """\ No auth token found, asking for it... You need a Github Auth Token for changes to create a release. Releases directory {} not found, creating it.... """.format( Path('docs').joinpath('releases') ) ) out, _ = capsys.readouterr() assert expected_output == out
def test_publish_no_staged_release(capsys, configured): changes.initialise() publish.publish() expected_output = textwrap.dedent( """\ No staged release to publish... """ ) out, _ = capsys.readouterr() assert expected_output == out
def test_stage_draft(capsys, configured): github_merge_commit(111) responses.add( responses.GET, ISSUE_URL, json=PULL_REQUEST_JSON, status=200, content_type='application/json', ) responses.add( responses.GET, LABEL_URL, json=BUG_LABEL_JSON, status=200, content_type='application/json', ) changes.initialise() stage.stage(draft=True) release_notes_path = Path( 'docs/releases/0.0.2-{}.md'.format(date.today().isoformat()) ) expected_output = textwrap.dedent( """\ Staging [fix] release for version 0.0.2... Running: bumpversion --dry-run --verbose --no-commit --no-tag --allow-dirty patch... Generating Release... Would have created {}:... """.format( release_notes_path ) ) expected_release_notes_content = [ '# 0.0.2 ({})'.format(date.today().isoformat()), '', '## Bug', ' ', '* #111 The title of the pull request', ' ', '...', ] out, _ = capsys.readouterr() assert ( expected_output.splitlines() + expected_release_notes_content == out.splitlines() ) assert not release_notes_path.exists()
def test_stage_draft(capsys, configured): github_merge_commit(111) responses.add( responses.GET, ISSUE_URL, json=PULL_REQUEST_JSON, status=200, content_type='application/json', ) responses.add( responses.GET, LABEL_URL, json=BUG_LABEL_JSON, status=200, content_type='application/json', ) changes.initialise() stage.stage(draft=True) release_notes_path = Path( 'docs/releases/0.0.2-{}.md'.format(date.today().isoformat()) ) expected_output = textwrap.dedent( """\ Staging [fix] release for version 0.0.2... Running: bumpversion --dry-run --verbose --no-commit --no-tag --allow-dirty patch... Generating Release... Would have created {}:... """.format( release_notes_path ) ) expected_release_notes_content = [ '# 0.0.2 ({})'.format(date.today().isoformat()), '', '## Bug', '* #111 The title of the pull request', '...', ] out, _ = capsys.readouterr() assert ( expected_output.splitlines() + expected_release_notes_content == out.splitlines() ) assert not release_notes_path.exists()
def test_stage_discard_nothing_staged(capsys, configured): changes.initialise() stage.discard(release_name='Icarus', release_description='The first flight') expected_output = textwrap.dedent( """\ No staged release to discard... """ ) out, _ = capsys.readouterr() assert expected_output == out
def test_stage(capsys, configured): responses.add( responses.GET, LABEL_URL, json=BUG_LABEL_JSON, status=200, content_type='application/json', ) github_merge_commit(111) responses.add( responses.GET, ISSUE_URL, json=PULL_REQUEST_JSON, status=200, content_type='application/json', ) changes.initialise() stage.stage( draft=False, release_name='Icarus', release_description='The first flight' ) release_notes_path = Path( 'docs/releases/0.0.2-{}-Icarus.md'.format(date.today().isoformat()) ) expected_output = textwrap.dedent( """\ Staging [fix] release for version 0.0.2... Running: bumpversion --verbose --allow-dirty --no-commit --no-tag patch... Generating Release... Writing release notes to {}... """.format( release_notes_path ) ) out, _ = capsys.readouterr() assert expected_output == out assert release_notes_path.exists() expected_release_notes = [ '# 0.0.2 ({}) Icarus'.format(date.today().isoformat()), 'The first flight', '## Bug', ' ', '* #111 The title of the pull request', ' ', ] assert expected_release_notes == release_notes_path.read_text().splitlines()
def test_stage(capsys, configured): responses.add( responses.GET, LABEL_URL, json=BUG_LABEL_JSON, status=200, content_type='application/json', ) github_merge_commit(111) responses.add( responses.GET, ISSUE_URL, json=PULL_REQUEST_JSON, status=200, content_type='application/json', ) changes.initialise() stage.stage( draft=False, release_name='Icarus', release_description='The first flight' ) release_notes_path = Path( 'docs/releases/0.0.2-{}-Icarus.md'.format(date.today().isoformat()) ) expected_output = textwrap.dedent( """\ Staging [fix] release for version 0.0.2... Running: bumpversion --verbose --allow-dirty --no-commit --no-tag patch... Generating Release... Writing release notes to {}... """.format( release_notes_path ) ) out, _ = capsys.readouterr() assert expected_output == out assert release_notes_path.exists() expected_release_notes = [ '# 0.0.2 ({}) Icarus'.format(date.today().isoformat()), 'The first flight', '## Bug', '* #111 The title of the pull request', ] assert expected_release_notes == release_notes_path.read_text().splitlines()
def work_in(dirname=None): """ Context manager version of os.chdir. When exited, returns to the working directory prior to entering. """ curdir = os.getcwd() try: if dirname is not None: os.chdir(dirname) requests_cache.configure(expire_after=60 * 10 * 10) changes.initialise() yield finally: os.chdir(curdir)
def test_status_with_changes(capsys, configured): responses.add( responses.GET, LABEL_URL, json=BUG_LABEL_JSON, status=200, content_type='application/json', ) github_merge_commit(111) responses.add( responses.GET, ISSUE_URL, json=PULL_REQUEST_JSON, status=200, content_type='application/json', ) changes.initialise() status.status() expected_output = textwrap.dedent( """\ Status [michaeljoseph/test_app]... Repository: michaeljoseph/test_app... Latest Version... 0.0.1 Changes... 1 changes found since 0.0.1 #111 The title of the pull request by @michaeljoseph [bug] Computed release type fix from changes issue tags... Proposed version bump 0.0.1 => 0.0.2... """ ) out, _ = capsys.readouterr() assert expected_output == out
def test_stage_discard(capsys, configured): responses.add( responses.GET, LABEL_URL, json=BUG_LABEL_JSON, status=200, content_type='application/json', ) github_merge_commit(111) responses.add( responses.GET, ISSUE_URL, json=PULL_REQUEST_JSON, status=200, content_type='application/json', ) changes.initialise() stage.stage( draft=False, release_name='Icarus', release_description='The first flight' ) release_notes_path = Path( 'docs/releases/0.0.2-{}-Icarus.md'.format(date.today().isoformat()) ) assert release_notes_path.exists() result = git(shlex.split('-c color.status=false status --short --branch')) modified_files = [ '## master', ' M .bumpversion.cfg', # ' M CHANGELOG.md', ' M version.txt', '?? docs/', '', ] assert '\n'.join(modified_files) == result stage.discard(release_name='Icarus', release_description='The first flight') expected_output = textwrap.dedent( """\ Staging [fix] release for version 0.0.2... Running: bumpversion --verbose --allow-dirty --no-commit --no-tag patch... Generating Release... Writing release notes to {release_notes_path}... Discarding currently staged release 0.0.2... Running: git checkout -- version.txt .bumpversion.cfg... Running: rm {release_notes_path}... """.format( release_notes_path=release_notes_path ) ) out, _ = capsys.readouterr() assert expected_output == out result = git(shlex.split('-c color.status=false status --short --branch')) modified_files = ['## master', ''] assert '\n'.join(modified_files) == result
def test_publish(capsys, configured, answer_prompts): github_merge_commit(111) responses.add( responses.GET, ISSUE_URL, json=PULL_REQUEST_JSON, status=200, content_type='application/json', ) responses.add( responses.GET, LABEL_URL, json=BUG_LABEL_JSON, status=200, content_type='application/json', ) responses.add( responses.POST, RELEASES_URL, json={'upload_url': 'foo'}, status=200, content_type='application/json', ) changes.initialise() stage.stage( draft=False, release_name='Icarus', release_description='The first flight' ) release_notes_path = Path( 'docs/releases/0.0.2-{}-Icarus.md'.format(date.today().isoformat()) ) assert release_notes_path.exists() publish.publish() pre = textwrap.dedent( """\ Staging [fix] release for version 0.0.2... Running: bumpversion --verbose --allow-dirty --no-commit --no-tag patch... Generating Release... Writing release notes to {release_notes_path}... Publishing release 0.0.2... Running: git add version.txt .bumpversion.cfg {release_notes_path}... Running: git commit --message="# 0.0.2 ({release_date}) Icarus """.format( release_notes_path=release_notes_path, release_date=date.today().isoformat() ) ).splitlines() expected_release_notes_content = [ 'The first flight', '## Bug', '* #111 The title of the pull request', ] post = textwrap.dedent( """\ "... Running: git tag 0.0.2... Running: git push --tags... Creating GitHub Release... Published release 0.0.2... """ ).splitlines() out, _ = capsys.readouterr() assert pre + expected_release_notes_content + post == out.splitlines() last_commit = git(shlex.split('show --name-only')) expected_files = ['version.txt', '.bumpversion.cfg', release_notes_path] assert [ expected_file for expected_file in expected_files if str(expected_file) in last_commit ] assert '0.0.2' in git(shlex.split('tag --list')) assert release_notes_path.exists() expected_release_notes = [ '# 0.0.2 ({}) Icarus'.format(date.today().isoformat()), 'The first flight', '## Bug', '* #111 The title of the pull request', ] assert expected_release_notes == release_notes_path.read_text().splitlines()
def test_publish(capsys, configured, answer_prompts): github_merge_commit(111) responses.add( responses.GET, ISSUE_URL, json=PULL_REQUEST_JSON, status=200, content_type='application/json', ) responses.add( responses.GET, LABEL_URL, json=BUG_LABEL_JSON, status=200, content_type='application/json', ) responses.add( responses.POST, RELEASES_URL, json={'upload_url': 'foo'}, status=200, content_type='application/json', ) changes.initialise() stage.stage( draft=False, release_name='Icarus', release_description='The first flight' ) release_notes_path = Path( 'docs/releases/0.0.2-{}-Icarus.md'.format(date.today().isoformat()) ) assert release_notes_path.exists() publish.publish() pre = textwrap.dedent( """\ Staging [fix] release for version 0.0.2... Running: bumpversion --verbose --allow-dirty --no-commit --no-tag patch... Generating Release... Writing release notes to {release_notes_path}... Publishing release 0.0.2... Running: git add version.txt .bumpversion.cfg {release_notes_path}... Running: git commit --message="# 0.0.2 ({release_date}) Icarus """.format( release_notes_path=release_notes_path, release_date=date.today().isoformat() ) ).splitlines() expected_release_notes_content = [ 'The first flight', '## Bug', ' ', '* #111 The title of the pull request', ' ', ] post = textwrap.dedent( """\ "... Running: git tag 0.0.2... Running: git push --tags... Creating GitHub Release... Published release 0.0.2... """ ).splitlines() out, _ = capsys.readouterr() assert pre + expected_release_notes_content + post == out.splitlines() last_commit = git(shlex.split('show --name-only')) expected_files = ['version.txt', '.bumpversion.cfg', release_notes_path] assert [ expected_file for expected_file in expected_files if str(expected_file) in last_commit ] assert '0.0.2' in git(shlex.split('tag --list')) assert release_notes_path.exists() expected_release_notes = [ '# 0.0.2 ({}) Icarus'.format(date.today().isoformat()), 'The first flight', '## Bug', ' ', '* #111 The title of the pull request', ' ', ] assert expected_release_notes == release_notes_path.read_text().splitlines()