class GoogleBaseAuthConnectionTest(GoogleTestCase): """ Tests for GoogleBaseAuthConnection """ def setUp(self): GoogleBaseAuthConnection.conn_class = GoogleAuthMockHttp self.mock_scopes = ['foo', 'bar'] kwargs = {'scopes': self.mock_scopes} self.conn = GoogleInstalledAppAuthConnection(*GCE_PARAMS, **kwargs) def test_scopes(self): self.assertEqual(self.conn.scopes, 'foo bar') def test_add_default_headers(self): old_headers = {} expected_headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Host': 'accounts.google.com'} new_headers = self.conn.add_default_headers(old_headers) self.assertEqual(new_headers, expected_headers) def test_token_request(self): request_body = {'code': 'asdf', 'client_id': self.conn.user_id, 'client_secret': self.conn.key, 'redirect_uri': self.conn.redirect_uri, 'grant_type': 'authorization_code'} new_token = self.conn._token_request(request_body) self.assertEqual(new_token['access_token'], STUB_IA_TOKEN['access_token']) exp = STUB_UTCNOW + datetime.timedelta( seconds=STUB_IA_TOKEN['expires_in']) self.assertEqual(new_token['expire_time'], _utc_timestamp(exp))
class GoogleBaseAuthConnectionTest(GoogleTestCase): """ Tests for GoogleBaseAuthConnection """ def setUp(self): GoogleBaseAuthConnection.conn_classes = (GoogleAuthMockHttp, GoogleAuthMockHttp) self.mock_scopes = ['foo', 'bar'] kwargs = {'scopes': self.mock_scopes} self.conn = GoogleInstalledAppAuthConnection(*GCE_PARAMS, **kwargs) def test_scopes(self): self.assertEqual(self.conn.scopes, 'foo bar') def test_add_default_headers(self): old_headers = {} expected_headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Host': 'accounts.google.com'} new_headers = self.conn.add_default_headers(old_headers) self.assertEqual(new_headers, expected_headers) def test_token_request(self): request_body = {'code': 'asdf', 'client_id': self.conn.user_id, 'client_secret': self.conn.key, 'redirect_uri': self.conn.redirect_uri, 'grant_type': 'authorization_code'} new_token = self.conn._token_request(request_body) self.assertEqual(new_token['access_token'], STUB_IA_TOKEN['access_token']) exp = STUB_UTCNOW + datetime.timedelta( seconds=STUB_IA_TOKEN['expires_in']) self.assertEqual(new_token['expire_time'], _utc_timestamp(exp))
class GoogleBaseAuthConnectionTest(LibcloudTestCase): """ Tests for GoogleBaseAuthConnection """ GoogleBaseAuthConnection._now = lambda x: datetime.datetime(2013, 6, 26, 19, 0, 0) def setUp(self): GoogleBaseAuthConnection.conn_classes = (GoogleAuthMockHttp, GoogleAuthMockHttp) self.mock_scopes = ['foo', 'bar'] kwargs = {'scopes': self.mock_scopes} self.conn = GoogleInstalledAppAuthConnection(*GCE_PARAMS, **kwargs) def test_scopes(self): self.assertEqual(self.conn.scopes, 'foo bar') def test_add_default_headers(self): old_headers = {} expected_headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Host': 'accounts.google.com'} new_headers = self.conn.add_default_headers(old_headers) self.assertEqual(new_headers, expected_headers) def test_token_request(self): request_body = {'code': 'asdf', 'client_id': self.conn.user_id, 'client_secret': self.conn.key, 'redirect_uri': self.conn.redirect_uri, 'grant_type': 'authorization_code'} new_token = self.conn._token_request(request_body) self.assertEqual(new_token['access_token'], 'installedapp') self.assertEqual(new_token['expire_time'], '2013-06-26T20:00:00Z')
class GoogleBaseAuthConnectionTest(LibcloudTestCase): """ Tests for GoogleBaseAuthConnection """ GoogleBaseAuthConnection._now = lambda x: datetime.datetime( 2013, 6, 26, 19, 0, 0) def setUp(self): GoogleBaseAuthConnection.conn_classes = (GoogleAuthMockHttp, GoogleAuthMockHttp) self.mock_scope = ['https://www.googleapis.com/auth/foo'] kwargs = {'scope': self.mock_scope} self.conn = GoogleInstalledAppAuthConnection(*GCE_PARAMS, **kwargs) def test_add_default_headers(self): old_headers = {} expected_headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Host': 'accounts.google.com' } new_headers = self.conn.add_default_headers(old_headers) self.assertEqual(new_headers, expected_headers) def test_token_request(self): request_body = { 'code': 'asdf', 'client_id': self.conn.user_id, 'client_secret': self.conn.key, 'redirect_uri': self.conn.redirect_uri, 'grant_type': 'authorization_code' } new_token = self.conn._token_request(request_body) self.assertEqual(new_token['access_token'], 'installedapp') self.assertEqual(new_token['expire_time'], '2013-06-26T20:00:00Z')
class GoogleBaseAuthConnectionTest(LibcloudTestCase): """ Tests for GoogleBaseAuthConnection """ GoogleBaseAuthConnection._now = lambda x: datetime.datetime(2013, 6, 26, 19, 0, 0) def setUp(self): GoogleBaseAuthConnection.conn_classes = (GoogleAuthMockHttp, GoogleAuthMockHttp) self.mock_scopes = ["foo", "bar"] kwargs = {"scopes": self.mock_scopes} self.conn = GoogleInstalledAppAuthConnection(*GCE_PARAMS, **kwargs) def test_scopes(self): self.assertEqual(self.conn.scopes, "foo bar") def test_add_default_headers(self): old_headers = {} expected_headers = {"Content-Type": "application/x-www-form-urlencoded", "Host": "accounts.google.com"} new_headers = self.conn.add_default_headers(old_headers) self.assertEqual(new_headers, expected_headers) def test_token_request(self): request_body = { "code": "asdf", "client_id": self.conn.user_id, "client_secret": self.conn.key, "redirect_uri": self.conn.redirect_uri, "grant_type": "authorization_code", } new_token = self.conn._token_request(request_body) self.assertEqual(new_token["access_token"], "installedapp") self.assertEqual(new_token["expire_time"], "2013-06-26T20:00:00Z")
class GoogleBaseAuthConnectionTest(GoogleTestCase): """ Tests for GoogleBaseAuthConnection """ def setUp(self): GoogleBaseAuthConnection.conn_class = GoogleAuthMockHttp self.mock_scopes = ["foo", "bar"] kwargs = {"scopes": self.mock_scopes} self.conn = GoogleInstalledAppAuthConnection(*GCE_PARAMS, **kwargs) def test_scopes(self): self.assertEqual(self.conn.scopes, "foo bar") def test_add_default_headers(self): old_headers = {} expected_headers = { "Content-Type": "application/x-www-form-urlencoded", "Host": "accounts.google.com", } new_headers = self.conn.add_default_headers(old_headers) self.assertEqual(new_headers, expected_headers) def test_token_request(self): request_body = { "code": "asdf", "client_id": self.conn.user_id, "client_secret": self.conn.key, "redirect_uri": self.conn.redirect_uri, "grant_type": "authorization_code", } new_token = self.conn._token_request(request_body) self.assertEqual(new_token["access_token"], STUB_IA_TOKEN["access_token"]) exp = STUB_UTCNOW + datetime.timedelta( seconds=STUB_IA_TOKEN["expires_in"]) self.assertEqual(new_token["expire_time"], _utc_timestamp(exp))