====================
Handler Installation
====================

By default the install function looks for the password file at
~/.buildout/.httpauth and installs a basic auth opener.

It does not fail if the file cannot be found.

    >>> import os
    >>> from lovely.buildouthttp.buildouthttp import install
    >>> install()

We can supply the path to the file for testing.

    >>> install(pwd_path='a')

If the file cannot be parsed an exception is raised.

    >>> fp = os.path.join(tmp,'pwd.txt')
    >>> import os
    >>> f = open(fp, 'w')
    >>> _ = f.write('The realm,https://example.com/ something')
    >>> f.close()
    >>> install(pwd_path=fp)
    Traceback (most recent call last):
    ...
    RuntimeError: Authentication file cannot be parsed ...pwd.txt:1

Some working examples.

    >>> f = open(fp, 'w')
    >>> _ = f.write('The realm,https://example.com/,username,password')
    >>> f.close()
    >>> install(pwd_path=fp)
    >>> f = open(fp, 'w')
    >>> _ = f.write('The realm,https://example.com/,username,password\n\n\n')
    >>> f.close()
    >>> install(pwd_path=fp)
    >>> f = open(fp, 'w')
    >>> _ = f.write('')
    >>> f.close()
    >>> install(pwd_path=fp)

Now let's try with the ``.httpauth`` file in the buildout directory.

    >>> buildout_dir = os.path.join(tmp, 'test-buildout')
    >>> os.mkdir(buildout_dir)
    >>> buildout = {'buildout': {'directory': buildout_dir}}
    >>> install(buildout=buildout)
    >>> buildout_fp = os.path.join(buildout_dir, '.httpauth')
    >>> f = open(buildout_fp, 'w')
    >>> _ = f.write('The realm,https://example.com/ not valid')
    >>> f.close()
    >>> install(buildout=buildout)
    Traceback (most recent call last):
    ...
    RuntimeError: Authentication file cannot be parsed ...None:1
    >>> f = open(buildout_fp, 'w')
    >>> _ = f.write('The realm,https://example.com/,username,password')
    >>> f.close()
    >>> install(buildout=buildout)

Then with the file passed in and the file from the buildout directory.

    >>> f = open(fp, 'w')
    >>> _ = f.write('The realm,https://example.com/,username,password')
    >>> f.close()
    >>> install(buildout=buildout, pwd_path=fp)
