def test_fail_refresh(self): m = mox.Mox() httplib2_response = m.CreateMock(object) httplib2_response.status = 400 httplib2_request = m.CreateMock(object) httplib2_request.__call__(( 'http://metadata.google.internal/0.1/meta-data/service-accounts/' 'default/acquire' '?scope=http%3A%2F%2Fexample.com%2Fa%20http%3A%2F%2Fexample.com%2Fb' )).AndReturn((httplib2_response, '{"accessToken": "this-is-a-token"}')) m.ReplayAll() c = AppAssertionCredentials( scope=['http://example.com/a', 'http://example.com/b']) try: c._refresh(httplib2_request) self.fail('Should have raised exception on 400') except AccessTokenRefreshError: pass m.UnsetStubs() m.VerifyAll()
def test_fail_refresh(self): m = mox.Mox() httplib2_response = m.CreateMock(object) httplib2_response.status = 400 httplib2_request = m.CreateMock(object) httplib2_request.__call__( ('http://metadata.google.internal/0.1/meta-data/service-accounts/' 'default/acquire' '?scope=http%3A%2F%2Fexample.com%2Fa%20http%3A%2F%2Fexample.com%2Fb' )).AndReturn((httplib2_response, '{"accessToken": "this-is-a-token"}')) m.ReplayAll() c = AppAssertionCredentials(scope=['http://example.com/a', 'http://example.com/b']) try: c._refresh(httplib2_request) self.fail('Should have raised exception on 400') except AccessTokenRefreshError: pass m.UnsetStubs() m.VerifyAll()
def test_good_refresh(self): m = mox.Mox() httplib2_response = m.CreateMock(object) httplib2_response.status = 200 httplib2_request = m.CreateMock(object) httplib2_request.__call__(( 'http://metadata.google.internal/0.1/meta-data/service-accounts/' 'default/acquire' '?scope=http%3A%2F%2Fexample.com%2Fa%20http%3A%2F%2Fexample.com%2Fb' )).AndReturn((httplib2_response, '{"accessToken": "this-is-a-token"}')) m.ReplayAll() c = AppAssertionCredentials( scope=['http://example.com/a', 'http://example.com/b']) c._refresh(httplib2_request) self.assertEquals('this-is-a-token', c.access_token) m.UnsetStubs() m.VerifyAll()
def test_good_refresh(self): m = mox.Mox() httplib2_response = m.CreateMock(object) httplib2_response.status = 200 httplib2_request = m.CreateMock(object) httplib2_request.__call__( ('http://metadata.google.internal/0.1/meta-data/service-accounts/' 'default/acquire' '?scope=http%3A%2F%2Fexample.com%2Fa%20http%3A%2F%2Fexample.com%2Fb' )).AndReturn((httplib2_response, '{"accessToken": "this-is-a-token"}')) m.ReplayAll() c = AppAssertionCredentials(scope=['http://example.com/a', 'http://example.com/b']) c._refresh(httplib2_request) self.assertEquals('this-is-a-token', c.access_token) m.UnsetStubs() m.VerifyAll()