def test_main_missing_args(monkeypatch, capsys): monkeypatch.setattr(sys, 'argv', ['ghcloneall']) with pytest.raises(SystemExit): ghcloneall.main() assert ( 'Please specify either --user or --organization' in capsys.readouterr().err )
def test_main_init_dry_run(monkeypatch, capsys, config_writes_allowed): monkeypatch.setattr(sys, 'argv', [ 'ghcloneall', '--init', '--user', 'mgedmin', '--pattern=*.vim', '--dry-run', ]) ghcloneall.main() assert capsys.readouterr().out == ( 'Did not write .ghcloneallrc because --dry-run was specified\n' )
def test_main_no_org_gists(monkeypatch, capsys): monkeypatch.setattr(sys, 'argv', [ 'ghcloneall', '--gists', '--org', 'bar', ]) with pytest.raises(SystemExit): ghcloneall.main() assert ( 'Please specify --user, not --organization, when using --gists' in capsys.readouterr().err )
def test_main_conflicting_args(monkeypatch, capsys): monkeypatch.setattr(sys, 'argv', [ 'ghcloneall', '--user', 'foo', '--org', 'bar', ]) with pytest.raises(SystemExit): ghcloneall.main() assert ( 'Please specify either --user or --organization, but not both' in capsys.readouterr().err )
def test_main_init_org_token(monkeypatch, capsys, config_writes_allowed): monkeypatch.setattr(sys, 'argv', [ 'ghcloneall', '--init', '--org', 'gtimelog', '--github-token', 'UNITTEST' ]) ghcloneall.main() assert capsys.readouterr().out == ('Wrote .ghcloneallrc\n') assert config_writes_allowed.read_text() == ('[ghcloneall]\n' 'github_org = gtimelog\n' 'github_token = UNITTEST\n' '\n')
def test_main_run_error_handling(monkeypatch, capsys): monkeypatch.setattr(sys, 'argv', [ 'ghcloneall', '--user', 'mgedmin', ]) with pytest.raises(SystemExit) as ctx: ghcloneall.main() assert str(ctx.value) == ( 'Failed to fetch https://api.github.com/users/mgedmin/repos' '?sort=full_name&per_page=100:\n' 'not found' )
def test_main_init_gists(monkeypatch, capsys, config_writes_allowed): monkeypatch.setattr(sys, 'argv', [ 'ghcloneall', '--init', '--user', 'mgedmin', '--gists', ]) ghcloneall.main() assert capsys.readouterr().out == ('Wrote .ghcloneallrc\n') assert config_writes_allowed.read_text() == ('[ghcloneall]\n' 'github_user = mgedmin\n' 'gists = True\n' '\n')
def test_main_run_gists(monkeypatch, mock_requests_get, capsys): monkeypatch.setattr(sys, 'argv', [ 'ghcloneall', '--user', 'mgedmin', '--gists', '--concurrency=1', ]) mock_requests_get.update(mock_multi_page_api_responses( url='https://api.github.com/users/mgedmin/gists', extra='', pages=[ [ gist('1234'), ], ], )) ghcloneall.main() assert show_ansi_result(capsys.readouterr().out) == ( '+ 1234 (new)\n' '1 repositories: 0 updated, 1 new, 0 dirty.' )
def test_main_run_start_from(monkeypatch, mock_requests_get, capsys): monkeypatch.setattr(sys, 'argv', [ 'ghcloneall', '--user', 'mgedmin', '--start-from', 'x', ]) mock_requests_get.update(mock_multi_page_api_responses( url='https://api.github.com/users/mgedmin/repos', pages=[ [ repo('ghcloneall'), repo('xyzzy'), ], ], )) ghcloneall.main() assert show_ansi_result(capsys.readouterr().out) == ( '+ xyzzy (new)\n' '1 repositories: 0 updated, 1 new, 0 dirty.' )
def test_main_reads_config_file(monkeypatch, capsys, config_writes_allowed): config_writes_allowed.write_text(u'[ghcloneall]\n' u'github_user = mgedmin\n' u'github_org = gtimelog\n' u'github_token = UNITTEST\n' u'gists = False\n' u'pattern = *.vim\n' u'include_forks = True\n' u'include_archived = False\n' u'include_private = False\n' u'include_disabled = False\n' u'\n') monkeypatch.setattr(sys, 'argv', [ 'ghcloneall', ]) with pytest.raises(SystemExit): ghcloneall.main() assert ('Please specify either --user or --organization, but not both' in capsys.readouterr().err)
def test_main_init_filter_flags(monkeypatch, capsys, config_writes_allowed): monkeypatch.setattr(sys, 'argv', [ 'ghcloneall', '--init', '--org', 'gtimelog', '--include-forks', '--exclude-private', '--exclude-disabled', '--exclude-archived', ]) ghcloneall.main() assert capsys.readouterr().out == ( 'Wrote .ghcloneallrc\n' ) assert config_writes_allowed.read_text() == ( '[ghcloneall]\n' 'github_org = gtimelog\n' 'include_forks = True\n' 'include_archived = False\n' 'include_private = False\n' 'include_disabled = False\n' '\n' )
def test_main_run(monkeypatch, mock_requests_get, capsys): monkeypatch.setattr(sys, 'argv', [ 'ghcloneall', '--user', 'mgedmin', '--concurrency=1', ]) mock_requests_get.update(mock_multi_page_api_responses( url='https://api.github.com/users/mgedmin/repos', pages=[ [ repo('ghcloneall'), repo('experiment', archived=True), repo('typo-fix', fork=True), repo('xyzzy', private=True, disabled=True), ], ], )) ghcloneall.main() assert show_ansi_result(capsys.readouterr().out) == ( '+ ghcloneall (new)\n' '+ xyzzy (new)\n' '2 repositories: 0 updated, 2 new, 0 dirty.' )
def test_main_keyboard_interrupt(monkeypatch, capsys): monkeypatch.setattr(ghcloneall, '_main', raise_keyboard_interrupt) ghcloneall.main()
def test_main_help(monkeypatch, capsys): monkeypatch.setattr(sys, 'argv', ['ghcloneall', '--help']) with pytest.raises(SystemExit): ghcloneall.main()