def test_rebuild_gpg_homedirs_lockfile(context, mocker):
    def fake_context(*args):
        return (context, None)

    mocker.patch.object(sgpg, "get_context_from_cmdln", new=fake_context)
    mocker.patch.object(sgpg, "update_logging_config", new=noop_sync)

    touch(context.config['gpg_lockfile'])
    sgpg.rebuild_gpg_homedirs(event_loop=context.event_loop)
def test_rebuild_gpg_homedirs_exception(context, mocker, nuke_dir):
    def fake_context(*args):
        return (context, None)

    if nuke_dir:
        rm(context.config['git_key_repo_dir'])

    mocker.patch.object(sgpg, "get_context_from_cmdln", new=fake_context)
    mocker.patch.object(sgpg, "update_logging_config", new=noop_sync)
    mocker.patch.object(sgpg, "rebuild_gpg_home_signed", new=die_sync)
    mocker.patch.object(sgpg, "retry_async", new=noop_async)
    mocker.patch.object(sgpg, "update_ownertrust", new=noop_sync)
    mocker.patch.object(sgpg, "verify_signed_tag", new=noop_async)
    mocker.patch.object(sgpg, "overwrite_gpg_home", new=noop_sync)
    mocker.patch.object(sgpg, "update_signed_git_repo", new=noop_async)
    mocker.patch.object(sgpg, "build_gpg_homedirs_from_repo", new=noop_sync)

    with pytest.raises(SystemExit):
        sgpg.rebuild_gpg_homedirs(event_loop=context.event_loop)
def test_rebuild_gpg_homedirs(context, mocker, new_rev_found):
    def fake_context(*args):
        return (context, None)

    async def new_revision(*args, **kwargs):
        if new_rev_found:
            return ("NEW REVISION!!!", "tag")
        else:
            return (None, "tag")

    mocker.patch.object(sgpg, "get_context_from_cmdln", new=fake_context)
    mocker.patch.object(sgpg, "update_logging_config", new=noop_sync)
    mocker.patch.object(sgpg, "rebuild_gpg_home_signed", new=noop_sync)
    mocker.patch.object(sgpg, "retry_async", new=new_revision)
    mocker.patch.object(sgpg, "update_ownertrust", new=noop_sync)
    mocker.patch.object(sgpg, "check_ownertrust", new=noop_sync)
    mocker.patch.object(sgpg, "verify_signed_tag", new=noop_async)
    mocker.patch.object(sgpg, "overwrite_gpg_home", new=noop_sync)
    mocker.patch.object(sgpg, "get_last_good_git_revision", new=noop_sync)
    mocker.patch.object(sgpg, "build_gpg_homedirs_from_repo", new=noop_sync)
    mocker.patch.object(sgpg, "write_last_good_git_revision", new=noop_sync)

    sgpg.rebuild_gpg_homedirs(event_loop=context.event_loop)