def setUp(self):
        self.credentials = mock.Mock()
        self.credentials.search.return_value = [(None, None, False)]

        self.auth_func = mock.Mock()
        self.auth_func.return_value = download.addinfourl(StringIO.StringIO("SUCCESS"), {}, "", 200)

        self.func = download.inject_credentials(self.credentials)(self.auth_func)
def install(buildout):
    buildout._raw.setdefault("basicauth", {})
    basicauth = buildout["basicauth"]
    basicauth.setdefault("interactive", "yes")
    basicauth.setdefault("fetch-order", "\n".join(("lovely", "buildout", "pypi", "prompt")))

    credentials = Credentials(
        buildout, fetchers=basicauth.get_list("fetch-order"), interactive=basicauth.get_bool("interactive")
    )

    # Monkeypatch distribute
    logger.info("Monkeypatching distribute to add http auth support")
    package_index.open_with_auth = inject_credentials(credentials)(package_index.open_with_auth)

    logger.info("Monkeypatching urllib.urlretrieve to add http auth support")
    urllib.urlretrieve = inject_urlretrieve_credentials(credentials)(urllib.urlretrieve)

    # Load the buildout:protected-extensions now that we have basicauth
    load_protected_extensions(buildout)