#!/usr/bin/python
# Copyright 2010 Felspar Company Limited. All rights reserved. 
# See the file 'LICENSE' for licensing information

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

    agent = Agent(base = base_url)
    response = agent.fetch('/drupal-6.2/')
    assert 'X-Username' not in response.headers, (
        response.headers
    )

    agent.fost_authenticate(
        key = key,
        secret = secret,
        headers = {'HTTP-X_FOST_USER': user}
    )
    response = agent.fetch('/drupal-6.2/')
    
    page = ''.join(response.readlines())
    assert 'X-Username' in response.headers \
        and response.headers['X-Username'] == user, (
        response.headers
    )

if __name__ == '__main__':
    test_username_header_is_set_during_authentication()
    