|
6 | 6 | from flask import Flask
|
7 | 7 | from flask_jwt_extended.exceptions import JWTEncodeError, JWTDecodeError
|
8 | 8 | from flask_jwt_extended.utils import _encode_access_token, _encode_refresh_token, \
|
9 |
| - _decode_jwt, create_access_token |
| 9 | + _decode_jwt, create_access_token, create_refresh_token |
10 | 10 | from flask_jwt_extended.jwt_manager import JWTManager
|
11 | 11 |
|
12 | 12 |
|
@@ -302,7 +302,7 @@ def test_decode_invalid_jwt(self):
|
302 | 302 | encoded_token = jwt.encode(token_data, 'secret', 'HS256').decode('utf-8')
|
303 | 303 | _decode_jwt(encoded_token, 'secret', 'HS256')
|
304 | 304 |
|
305 |
| - def test_create_access_token_with_object(self): |
| 305 | + def test_create_jwt_with_object(self): |
306 | 306 | # Complex object to test building a JWT from. Normally if you are using
|
307 | 307 | # this functionality, this is something that would be retrieved from
|
308 | 308 | # disk somewhere (think sqlalchemy)
|
@@ -330,9 +330,14 @@ def user_identity_lookup(user):
|
330 | 330 | # Create the token using the complex object
|
331 | 331 | with app.test_request_context():
|
332 | 332 | user = TestUser(username='foo', roles=['bar', 'baz'])
|
333 |
| - token = create_access_token(identity=user) |
334 |
| - |
335 |
| - # Decode the token and make sure the values are set properly |
336 |
| - token_data = _decode_jwt(token, app.secret_key, app.config['JWT_ALGORITHM']) |
337 |
| - self.assertEqual(token_data['identity'], 'foo') |
338 |
| - self.assertEqual(token_data['user_claims']['roles'], ['bar', 'baz']) |
| 333 | + access_token = create_access_token(identity=user) |
| 334 | + refresh_token = create_refresh_token(identity=user) |
| 335 | + |
| 336 | + # Decode the tokens and make sure the values are set properly |
| 337 | + access_token_data = _decode_jwt(access_token, app.secret_key, |
| 338 | + app.config['JWT_ALGORITHM']) |
| 339 | + refresh_token_data = _decode_jwt(refresh_token, app.secret_key, |
| 340 | + app.config['JWT_ALGORITHM']) |
| 341 | + self.assertEqual(access_token_data['identity'], 'foo') |
| 342 | + self.assertEqual(access_token_data['user_claims']['roles'], ['bar', 'baz']) |
| 343 | + self.assertEqual(refresh_token_data['identity'], 'foo') |
0 commit comments