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')
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')