
"""
Contributors can be viewed at:
http://svn.secondlife.com/svn/linden/projects/2008/pyogp/lib/base/trunk/CONTRIBUTORS.txt 

$LicenseInfo:firstyear=2008&license=apachev2$

Copyright 2009, Linden Research, Inc.

Licensed under the Apache License, Version 2.0.
You may obtain a copy of the License at:
    http://www.apache.org/licenses/LICENSE-2.0
or in 
    http://svn.secondlife.com/svn/linden/projects/2008/pyogp/lib/base/LICENSE.txt

$/LicenseInfo$
"""

Login
~~~~~

First the 'legacy' login case
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

First, initialize login and the loginuri

    >>> from pyogp.lib.client.login import Login
    >>> login = Login()
    >>> loginuri = 'http://localhost:12345/login.cgi'

Setup test: import of the mock network client handler

    >>> from pyogp.lib.base.tests.mock_xmlrpc import MockXMLRPC
    >>> from pyogp.lib.base.tests.base import MockXMLRPCLogin
    >>> loginhandler = MockXMLRPC(MockXMLRPCLogin(), loginuri)

Now, set up the login parameters:

    >>> from pyogp.lib.client.login import LegacyLoginParams
    >>> login_params = LegacyLoginParams('first', 'last', 'secret')

Now, login to the legacy login endpoint (using the mock test object as the endpoint).
The login function returns the response as a dict.

    >>> login.login(loginuri, login_params, 'start_location', handler = loginhandler)
    {'region_y': '256', 'region_x': '256', 'first_name': '"first"', 'secure_session_id': '00000000-0000-0000-0000-000000000000', 'sim_ip': '127.0.0.1', 'agent_access': 'M', 'circuit_code': '600000000', 'look_at': '[r0.9963859999999999939,r-0.084939700000000006863,r0]', 'session_id': '00000000-0000-0000-0000-000000000000', 'udp_blacklist': 'EnableSimulator,TeleportFinish,CrossedRegion', 'seed_capability': 'https://somesim:12043/cap/00000000-0000-0000-0000-000000000000', 'agent_id': '00000000-0000-0000-0000-000000000000', 'last_name': 'last', 'inventory_host': 'someinvhost', 'start_location': 'last', 'sim_port': '13001', 'message': 'message', 'login': 'true', 'seconds_since_epoch': '1234567890'}

Evaluate the login response stored in the login class

    >>> login.response['login']
    'true'

    >>> login.response['seed_capability']
    'https://somesim:12043/cap/00000000-0000-0000-0000-000000000000'

Next, LegacyLoginParams
~~~~~~~~~~~~~~~~~~~~~~~

This is easy, just test it

    >>> from pyogp.lib.client.login import LegacyLoginParams
    >>> login_params = LegacyLoginParams('first', 'last', 'pass')
    >>> login_params = login_params.serialize()

    >>> login_params
    {'passwd': 'pass', 'last': 'last', 'first': 'first'}

Now, how about testing the 'ogp' case
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

First, initialize login and the loginuri

    >>> from pyogp.lib.client.login import Login
    >>> login = Login()
    >>> loginuri = 'http://localhost:12345/auth.cgi'

Setup test: import of the mock network client handler

    >>> from pyogp.lib.base.network.tests.mockup_client import MockupClient
    >>> from pyogp.lib.base.tests.base import MockAgentDomainLogin
    >>> loginhandler = MockupClient(MockAgentDomainLogin())

Now, set up the login parameters:

    >>> from pyogp.lib.client.login import OGPLoginParams
    >>> login_params = OGPLoginParams('first', 'last', 'secret')

Now, login to the ogp login endpoint aka agent domain (using the mock test object as the endpoint).
The login function returns the response as a dict.

    >>> login.login(loginuri, login_params, 'start_location', handler = loginhandler)
    {'agent_seed_capability': 'http://127.0.0.1:12345/seed_cap', 'authenticated': True}

Evaluate the login response stored in the login class

    >>> login.response['authenticated']
    True

    >>> login.response['agent_seed_capability']
    'http://127.0.0.1:12345/seed_cap'

Next, OGPLoginParams
~~~~~~~~~~~~~~~~~~~~

This is easy, just test it

    >>> from pyogp.lib.client.login import OGPLoginParams
    >>> login_params = OGPLoginParams('first', 'last', 'pass')

    >>> login_params.content_type
    'application/llsd+xml'

    >>> login_params = login_params.serialize()
    >>> login_params
    '<?xml version="1.0" ?><llsd><map><key>lastname</key><string>last</string><key>password</key><string>pass</string><key>firstname</key><string>first</string></map></llsd>'
