@@ -331,3 +331,27 @@ def test_from_authorized_user_file(self):
331331 assert creds .refresh_token == info ["refresh_token" ]
332332 assert creds .token_uri == credentials ._GOOGLE_OAUTH2_TOKEN_ENDPOINT
333333 assert creds .scopes == scopes
334+
335+ def test_to_json (self ):
336+ info = AUTH_USER_INFO .copy ()
337+ creds = credentials .Credentials .from_authorized_user_info (info )
338+
339+ # Test with no `strip` arg
340+ json_output = creds .to_json ()
341+ json_asdict = json .loads (json_output )
342+ assert json_asdict .get ("token" ) == creds .token
343+ assert json_asdict .get ("refresh_token" ) == creds .refresh_token
344+ assert json_asdict .get ("token_uri" ) == creds .token_uri
345+ assert json_asdict .get ("client_id" ) == creds .client_id
346+ assert json_asdict .get ("scopes" ) == creds .scopes
347+ assert json_asdict .get ("client_secret" ) == creds .client_secret
348+
349+ # Test with a `strip` arg
350+ json_output = creds .to_json (strip = ["client_secret" ])
351+ json_asdict = json .loads (json_output )
352+ assert json_asdict .get ("token" ) == creds .token
353+ assert json_asdict .get ("refresh_token" ) == creds .refresh_token
354+ assert json_asdict .get ("token_uri" ) == creds .token_uri
355+ assert json_asdict .get ("client_id" ) == creds .client_id
356+ assert json_asdict .get ("scopes" ) == creds .scopes
357+ assert json_asdict .get ("client_secret" ) is None
0 commit comments