added another example of OGP Login so that it could be tested added a test class for the OGP Login added some dependencies to the test runner that is produced by buildout
This commit is contained in:
committed by
Salad Dais
parent
5726a40b3c
commit
f608ca3921
70
pyogp/lib/base/OGPLogin.py
Normal file
70
pyogp/lib/base/OGPLogin.py
Normal file
@@ -0,0 +1,70 @@
|
||||
from pyogp.lib.base.credentials import PlainPasswordCredential
|
||||
from pyogp.lib.base.agentdomain import AgentDomain
|
||||
from pyogp.lib.base.regiondomain import Region
|
||||
|
||||
from pyogp.lib.base.interfaces import IPlaceAvatarAdapter
|
||||
|
||||
import getpass, sys
|
||||
from optparse import OptionParser
|
||||
|
||||
import pprint
|
||||
|
||||
class OGPLogin(object):
|
||||
""" This class can be used to log in to an agent domain and start communicating with a region domain """
|
||||
|
||||
def __init__(self, credents, loginuri, regionuri):
|
||||
self.credentials = credents #PlainPasswordCredential(credents.firstname, credents.lastname, credents.password)
|
||||
self.loginuri = loginuri
|
||||
self.regionuri = regionuri
|
||||
|
||||
def login(self):
|
||||
|
||||
print "login to the agent domain: " + self.loginuri
|
||||
agentd, agent = self.loginToAgentD()
|
||||
print "logged in, we now have an agent: ", agent
|
||||
print "and a domain: ", agentd
|
||||
|
||||
print "now we try to place the avatar on a region"
|
||||
avatar = self.placeAvatarCap()
|
||||
print "placed avatar cap, got back: ", avatar
|
||||
|
||||
#avatar.establish_presence()
|
||||
|
||||
def loginToAgentD(self):
|
||||
""" Logs into the agent domain, getting the agentd seed cap """
|
||||
self.agentdomain = AgentDomain(self.loginuri)
|
||||
self.agent = self.agentdomain.login(self.credentials)
|
||||
return self.agentdomain, self.agent
|
||||
|
||||
def getCapabilities(self, seed_cap, caps):
|
||||
""" This is the method that SHOULD be used (but isn't) to get capabilities from the seedcap """
|
||||
pass
|
||||
|
||||
def placeAvatarCap(self):
|
||||
""" actually gets the place_avatar cap and posts to it """
|
||||
region = Region(self.regionuri)
|
||||
place = IPlaceAvatarAdapter(self.agent)
|
||||
self.avatar = place(region)
|
||||
return self.avatar
|
||||
|
||||
def main():
|
||||
parser = OptionParser()
|
||||
|
||||
parser.add_option("-a", "--agentdomain", dest="loginuri", default="https://login1.aditi.lindenlab.com/cgi-bin/auth.cgi",
|
||||
help="URI of Agent Domain")
|
||||
parser.add_option("-r", "--region", dest="regionuri", default="http://sim1.vaak.lindenlab.com:13000",
|
||||
help="URI of Region to connect to")
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
options.firstname = args[0]
|
||||
options.lastname = args[1]
|
||||
options.password = getpass.getpass()
|
||||
|
||||
pprint.pprint(options)
|
||||
credents = PlainPasswordCredential(options.firstname, options.lastname, options.password)
|
||||
|
||||
return OGPLogin(credents, options.loginuri, options.regionuri).login()
|
||||
|
||||
if __name__=="__main__":
|
||||
main()
|
||||
0
pyogp/lib/base/tests/__init__.py
Normal file
0
pyogp/lib/base/tests/__init__.py
Normal file
28
pyogp/lib/base/tests/test_ogplogin.py
Normal file
28
pyogp/lib/base/tests/test_ogplogin.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import unittest, doctest
|
||||
from pyogp.lib.base.credentials import PlainPasswordCredential
|
||||
from pyogp.lib.base.agentdomain import AgentDomain
|
||||
from pyogp.lib.base.regiondomain import Region
|
||||
|
||||
from pyogp.lib.base.interfaces import IPlaceAvatarAdapter
|
||||
|
||||
from pyogp.lib.base.OGPLogin import OGPLogin
|
||||
|
||||
class TestOGPLogin(unittest.TestCase):
|
||||
def test_login(self):
|
||||
credentials = PlainPasswordCredential('firstname', 'lastname', 'password')
|
||||
#create a login, giving it the credentials, the loginuri, and the regionuri
|
||||
ogpLogin = OGPLogin(credentials, 'https://login1.aditi.lindenlab.com/cgi-bin/auth.cgi', 'http://sim1.vaak.lindenlab.com:13000')
|
||||
|
||||
#gets seedcap, and an agent that can be placed in a region
|
||||
agentdomain, agent = ogpLogin.loginToAgentD()
|
||||
assert agentdomain.seed_cap != None or agentdomain.seed_cap != {}, "Login to agent domain failed"
|
||||
|
||||
#attempts to place the agent in a region
|
||||
avatar = ogpLogin.placeAvatarCap()
|
||||
assert avatar['connect'] == True, "Place avatar failed"
|
||||
|
||||
def test_suite():
|
||||
from unittest import TestSuite, makeSuite
|
||||
suite = TestSuite()
|
||||
suite.addTest(makeSuite(TestOGPLogin))
|
||||
return suite
|
||||
Reference in New Issue
Block a user