Esempio n. 1
0
 def testShouldRetrieveCurrentSessionWhenGivenValidSessionId(self):
     # Given...
     class StubConnection (object):
         def request(self, url, method, data, headers):
             self.requestheaders = headers
             
             from StringIO import StringIO
             response = StringIO('<html><head><title>Reservation Manager</title></head><body><p>Jalani Bakari, you are signed in (Residential)!</body></html>')
             response.getheaders = lambda: {}
             return response
     StubConnection = Stub(PcsConnection)(StubConnection)
     conn = StubConnection()
     
     source = SessionScreenscrapeSource()
     @patch(source)
     def create_host_connection(self):
         return conn
     
     # When...
     session = source.fetch_session('valid_user', '12345abcde')
     
     # Then...
     self.assertEqual(session.user, 'valid_user')
     self.assertEqual(session.name, 'Jalani Bakari')
     self.assertEqual(session.id, '12345abcde')
Esempio n. 2
0
 def testShouldKnowAboutASimpleInvalidSessionDocumentBody(self):
     """Screenscrape source should have a simple document that triggers login failure"""
     source = SessionScreenscrapeSource()
     document = SessionScreenscrapeSource.SIMPLE_FAILURE_DOCUMENT
     
     is_valid = source.body_is_valid_session(document)
     
     self.assert_(not is_valid)
Esempio n. 3
0
 def testShouldThinkSessionDocumentIsInvalidIfTitleIsCorrect(self):
     """Login is failure if the response document has the correct title."""
     source = SessionScreenscrapeSource()
     document = "<html><head><title>Please Login</title></head><body></body></html>"
     
     is_valid = source.body_is_valid_session(document)
     
     self.assertEqual(is_valid, False)
Esempio n. 4
0
 def testShouldThinkSessionDocumentIsValidIfTitleIsCorrect(self):
     """Login is successful if the response document has the correct title."""
     source = SessionScreenscrapeSource()
     document = "<html><head><title>My Message Manager</title></head><body></body></html>"
     
     is_valid = source.body_is_valid_session(document)
     
     self.assertEqual(is_valid, True)
Esempio n. 5
0
 def testShouldCreateNoSessionIfLoginResultsInInvalidSessionDocument(self):
     """Expected session is returned from a failed login (expected session is None)."""
     source = SessionScreenscrapeSource()
     @patch(source)
     def login_to_pcs(self, conn, userid, password):
         return ("<html><head><title>Please Login</title></head><body></body></html>", {})
     
     try:
         session = source.create_session('uid', 'pass')
     
     except SessionLoginError:
         return
     
     self.fail('Should have raised SessionLoginError')
Esempio n. 6
0
 def testShouldNotGetStuckOnTheCallToConnectionDotRequest(self):
     """Resuming session will get expected response from connection"""
     source = SessionScreenscrapeSource()
     class StubConnection (object):
         def request(self, url, method, data, headers):
             self.requestheaders = headers
             
             from StringIO import StringIO
             response = StringIO('Body Text')
             response.getheaders = lambda: {'h1':1,'h2':2}
             return response
     StubConnection = Stub(PcsConnection)(StubConnection)
     conn = StubConnection()
     
     body, headers = source.reconnect_to_pcs(conn, '1234567')
Esempio n. 7
0
 def testShouldRaiseErrorWhenRetrievingExistingSessionFails(self):
     # Given...
     source = SessionScreenscrapeSource()
     @patch(source)
     def reconnect_to_pcs(self, conn, sessionid):
         return ("<html><head><title>Please Login</title></head><body></body></html>", {})
     
     # When...
     try:
         session = source.fetch_session('valid_user', 'expiredsession12345abcde')
     
     # Then...
     except SessionExpiredError:
         return
     
     self.fail('Should have raised SessionExpiredError')
Esempio n. 8
0
 def testShouldReturnExpectedBodyTextFromConnectionWhenLoggingIn(self):
     """Logging in will get the expected response from the connection"""
     source = SessionScreenscrapeSource()
     class StubConnection (object):
         def request(self, url, method, data, headers):
             from StringIO import StringIO
             response = StringIO('Body Text')
             response.getheaders = lambda: {'h1':1,'h2':2}
             return response
     StubConnection = Stub(PcsConnection)(StubConnection)
     conn = StubConnection()
     
     body, headers = source.login_to_pcs(conn, 'uid', 'pass')
     
     self.assertEqual(body, 'Body Text')
     self.assertEqual(headers, {'h1':1,'h2':2})
Esempio n. 9
0
 def testShouldSendCookiesToAndReturnExpectedBodyTextFromConnectionWhenReconnectingToSession(self):
     """Resuming session will get expected response from connection"""
     source = SessionScreenscrapeSource()
     class StubConnection (object):
         def request(self, url, method, data, headers):
             self.requestheaders = headers
             
             from StringIO import StringIO
             response = StringIO('Body Text')
             response.getheaders = lambda: {'h1':1,'h2':2}
             return response
     StubConnection = Stub(PcsConnection)(StubConnection)
     conn = StubConnection()
     
     body, headers = source.reconnect_to_pcs(conn, '1234567')
     
     self.assertEqual(conn.requestheaders, {'Cookie':'sid=1234567'})
     self.assertEqual(body, 'Body Text')
     self.assertEqual(headers, {'h1':1,'h2':2})
Esempio n. 10
0
 def testShouldCreateNewSessionAccordingToContentInValidSessionDocument(self):
     """Expected session is returned from a successful login."""
     source = SessionScreenscrapeSource()
     @patch(source)
     def login_to_pcs(self, conn, userid, password):
         return ("""<html>
               <head>
                 <title>My Message Manager</title>
               </head>
               <body>
                 <p>Mr. Bojangles, you are signed in. Yay!</p>
               </body>
             </html>
          """,
          {'set-cookie':'sid=abcde'})
          
     session = source.create_session('uid', 'pass')
     
     self.assertEqual(session.id, 'abcde')
     self.assertEqual(session.user, 'uid')
     self.assertEqual(session.name, 'Mr. Bojangles')