def testIsValidToken(self): """ Test that the isValidToken method rejects invalid tokens and accepts valid ones. """ self.assertTrue(TokenResource.isValidToken('aValidToken'), msg='Expected isValidToken to accept a valid token.') self.assertTrue(TokenResource.isValidToken( TokenResource.VALID_TOKEN_CHARS), msg='Expected isValidToken to accept a valid token.') self.assertFalse( TokenResource.isValidToken('Token!'), msg='Expected isValidToken to accept an invalid token.') self.assertFalse( TokenResource.isValidToken('an invalid Token'), msg='Expected isValidToken to accept an invalid token.')
def testTokenGeneration(self): """ Verify that the token factory generates valid tokens. """ token = self._TOKEN_FACTORY.generateToken(None, self._DUMMY_CLIENT, self._VALID_SCOPE) self.assertIsInstance( token, str, message='Expected the token factory to return a string.') self.assertTrue( TokenResource.isValidToken(token), msg= 'The generated token is not valid according to the oauth2 specifications.' )