Ejemplo n.º 1
0
    def _TestHttpClientRetryRequest(self, statuses):
        """Test retry logic in http_client request during ProgrammaticLogin.

    |statuses| is list of http codes to simulate, where 200 means success.
    """
        expect_success = statuses[-1] == 200

        self.mox.StubOutWithMock(atom.http.ProxiedHttpClient, 'request')
        rss = gdata_lib.RetrySpreadsheetsService()

        args = ('POST', 'https://www.google.com/accounts/ClientLogin')

        def _read():
            return 'Some response text'

        # This is the replay script for the test.
        # Simulate the return codes in statuses.
        for status in statuses:
            retstatus = cros_test_lib.EasyAttr(status=status, read=_read)
            atom.http.ProxiedHttpClient.request(
                *args, data=mox.IgnoreArg(),
                headers=mox.IgnoreArg()).AndReturn(retstatus)
        self.mox.ReplayAll()

        # This is the test verification.
        with self.OutputCapturer():
            if expect_success:
                rss.ProgrammaticLogin()
            else:
                self.assertRaises(gdata.service.Error, rss.ProgrammaticLogin)
            self.mox.VerifyAll()

        if not expect_success:
            # Retries did not help, request still failed.
            regexp = re.compile(r'^Giving up on HTTP request')
            self.AssertOutputContainsWarning(regexp=regexp)
        elif len(statuses) > 1:
            # Warning expected if retries were needed.
            self.AssertOutputContainsWarning()
        else:
            # First try worked, expect no warnings.
            self.AssertOutputContainsWarning(invert=True)
Ejemplo n.º 2
0
    def testLoginWithToken(self):
        mocked_scomm = self.MockScomm(connect=False)
        creds = self.GenerateCreds(skip_user=True)

        self.mox.StubOutClassWithMocks(gdata_lib, 'RetrySpreadsheetsService')

        source = 'SomeSource'

        # This is the replay script for the test.
        mocked_gdclient = gdata_lib.RetrySpreadsheetsService()
        mocked_gdclient.SetClientLoginToken(creds.docs_auth_token)
        self.mox.ReplayAll()

        # This is the test verification.
        with self.OutputCapturer():
            gdata_lib.SpreadsheetComm._Login(mocked_scomm, creds, source)
        self.mox.VerifyAll()
        self.assertFalse(hasattr(mocked_gdclient, 'email'))
        self.assertFalse(hasattr(mocked_gdclient, 'password'))
        self.assertEquals(source, mocked_gdclient.source)
        self.assertEquals(mocked_gdclient, mocked_scomm.gd_client)
Ejemplo n.º 3
0
    def testLoginWithUserPassword(self):
        mocked_scomm = self.MockScomm(connect=False)
        creds = self.GenerateCreds(skip_token=True)

        self.mox.StubOutClassWithMocks(gdata_lib, 'RetrySpreadsheetsService')

        source = 'SomeSource'

        # This is the replay script for the test.
        mocked_gdclient = gdata_lib.RetrySpreadsheetsService()
        mocked_gdclient.ProgrammaticLogin()
        mocked_gdclient.GetClientLoginToken().AndReturn(self.TOKEN)
        self.mox.ReplayAll()

        # This is the test verification.
        with self.OutputCapturer():
            gdata_lib.SpreadsheetComm._Login(mocked_scomm, creds, source)
        self.mox.VerifyAll()
        self.assertEquals(self.USER, mocked_gdclient.email)
        self.assertEquals(self.PASSWORD, mocked_gdclient.password)
        self.assertEquals(self.TOKEN, creds.docs_auth_token)
        self.assertEquals(source, mocked_gdclient.source)
        self.assertEquals(mocked_gdclient, mocked_scomm.gd_client)