#!/usr/bin/python

def test_fost_authentication_works_on_drupal(
    base_url = "http://localhost:8888",
    key = 'Sn428Dzafk13UvHXhA+nKH91RvAIUi5gdtaU/txDHLvER',
    secret = '02606afd6ca2de9577c17a92046c721c',
    user = 'mike'
):
    try:
        from Fost.internet.useragent import agent as Agent

        agent = Agent(base = base_url)

        page = ''.join(agent.fetch('/drupal-6.2/').readlines())
        assert 'My account' not in page
        assert 'login' in page
        assert 'Log out' not in page

        agent.fost_authenticate(
            key = key,
            secret = secret,
            headers = {'HTTP-X_FOST_USER': user}
        )

        page = ''.join(agent.fetch('/drupal-6.2/').readlines())
        assert 'My account' in page
        assert 'Log out' in page
    except:
        print (
            "Note that the password should be changed in the php script and"
            " the md5 of the password be in the database for the test user"
            " account (users table), (password is the 'secret' argument)."
        )
        raise

if __name__ == '__main__':
    test_fost_authentication_works_on_drupal()
    