Ejemplo n.º 1
0
def test_repo_already_exists_org_account(caplog, plugin_dir):
    with mock.patch('datakit_github.commands.integrate.ask',
                    side_effect=['3', 'y', 'n']) as mocked:
        create_plugin_config(plugin_dir, {'github_api_key': TOKEN})
        cmd = Integrate(None, None, cmd_name='github integrate')
        parsed_args = mock.Mock()
        cmd.run(parsed_args)
        assert "ERROR: Failed to create fake-project for associatedpress: name already exists on this account" in caplog.text
Ejemplo n.º 2
0
def test_repo_already_initialized(caplog, plugin_dir):
    with mock.patch('datakit_github.commands.integrate.ask',
                    side_effect=['', 'y', 'y']) as mocked:
        create_plugin_config(plugin_dir, {'github_api_key': TOKEN})
        cmd = Integrate(None, None, cmd_name='github integrate')
        parsed_args = mock.Mock()
        cmd.run(parsed_args)
        assert "Repo has already been initialized locally!!" in caplog.text
Ejemplo n.º 3
0
def test_return_chosen_inputs(plugin_dir):
    with mock.patch('datakit_github.commands.integrate.ask', side_effect=['','y', 'y']) as mocked, \
        mock.patch('datakit_github.commands.integrate.Repository.push', return_value=None) as repo_push:
        create_plugin_config(plugin_dir, {'github_api_key': TOKEN})
        cmd = Integrate(None, None, cmd_name='github integrate')
        parsed_args = mock.Mock()
        choices = cmd.run(parsed_args)
        assert choices['repo_name'] == 'fake-project'
        assert choices['account'] == 'dkit-tester'
        assert choices['private_repo'] == True
Ejemplo n.º 4
0
def test_choose_org_account_private_error(caplog, plugin_dir):
    with mock.patch('datakit_github.commands.integrate.ask', side_effect=['3','y','y']) as mocked, \
        mock.patch('datakit_github.commands.integrate.Repository.push', return_value=None) as repo_push:
        create_plugin_config(plugin_dir, {'github_api_key': TOKEN})
        cmd = Integrate(None, None, cmd_name='github integrate')
        parsed_args = mock.Mock()
        cmd.run(parsed_args)
        assert "(1) zstumgoren" in caplog.text
        assert "(3) associatedpress" in caplog.text
        err_msg = "Visibility can't be private. Please upgrade your subscription to create a new private repository."
        assert err_msg in caplog.text
Ejemplo n.º 5
0
def test_choose_default_account_basic(caplog, plugin_dir):
    with mock.patch('datakit_github.commands.integrate.ask', side_effect=['','y', 'y']) as mocked, \
        mock.patch('datakit_github.commands.integrate.Repository.push', return_value=None) as repo_push:
        create_plugin_config(plugin_dir, {'github_api_key': TOKEN})
        cmd = Integrate(None, None, cmd_name='github integrate')
        parsed_args = mock.Mock()
        cmd.run(parsed_args)
        assert "Repo will be created on account: dkit-tester" in caplog.text
        assert "Repo created at https://github.com/dkit-tester/fake-project" in caplog.text
        assert "First commit made locally and pushed to remote" in caplog.text
        assert "View the project on Github at https://github.com/dkit-tester/fake-project" in caplog.text
        assert repo_push.call_count == 1
Ejemplo n.º 6
0
def test_choose_org_account_public_repo(caplog, plugin_dir):
    with mock.patch('datakit_github.commands.integrate.ask', side_effect=['3','y','n']) as mocked, \
        mock.patch('datakit_github.commands.integrate.Repository.push', return_value=None) as repo_push:
        create_plugin_config(plugin_dir, {'github_api_key': TOKEN})
        cmd = Integrate(None, None, cmd_name='github integrate')
        parsed_args = mock.Mock()
        cmd.run(parsed_args)
        assert "(1) zstumgoren" in caplog.text
        assert "(3) associatedpress" in caplog.text
        assert "Repo created at https://github.com/associatedpress/fake-project" in caplog.text
        assert "First commit made locally and pushed to remote" in caplog.text
        assert "View the project on Github at https://github.com/associatedpress/fake-project" in caplog.text
        assert repo_push.call_count == 1
Ejemplo n.º 7
0
# HACK: Need to direct logging calls to stdout
# to ensure user prompts display when hook is run
# by cookiecutter in a subprocess.
def get_logger():
    handler = logging.StreamHandler(sys.stdout)
    handler.setLevel(logging.INFO)
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    logger.addHandler(handler)
    return logger


create_github_repo = os.environ.get('PROGJ_GH_INTEGRATE', 'true')
if create_github_repo == 'true':
    sys.stdout.write("\n\n~~ Create a Github repo for this project ~~\n\n")
    cmd = Integrate(None, None, cmd_name='github integrate')
    cmd.log = get_logger()
    integrate_choices = cmd.run(argparse.ArgumentParser())

    # Add instructors as collaborators
    api_key = cmd.configs.get('github_api_key')
    g = github.Github(api_key)
    gh_user = integrate_choices['account']
    repo = g.get_repo("{}/{{ cookiecutter.repo_root }}".format(gh_user))
    add_collabs = os.environ.get('PROGJ_GH_ADD_COLLABS', 'true')
    if add_collabs == 'true':
        try:
            collaborators = os.environ['PROGJ_GH_COLLABORATORS'].split(':')
        except KeyError:
            collaborators = ['zstumgoren']
        for collaborator in collaborators:
Ejemplo n.º 8
0
def test_config_missing_error(caplog):
    cmd = Integrate(None, None, cmd_name='github integrate')
    parsed_args = mock.Mock()
    cmd.run(parsed_args)
    err_msg = "You must configure a Github API key to use this command!!"
    assert err_msg in caplog.text