def test_the_is_token_revoked_method_of_user_repository(app, mocker):
    """
  GIVEN the TokenRepository instance
  WHEN the is_token_revoked() method is call
  THEN check session method calls
  """

    from app.model import TokenRepository, Token
    token_repository = TokenRepository()
    token_repository.session = UnifiedAlchemyMagicMock()

    token = Token()
    token.id = 1
    token.jti = "27d1b1a3-45b4-4a5f-83ed-b823f5ea1dbe"
    token.token_type = "access"
    token.user_identity = "test"
    token.revoked = True
    token.expires = datetime.now()

    token_repository.session.add(token)
    token_repository.session.commit()

    decoded_token = mocker.MagicMock()
    decoded_token['jti'] = token.jti

    result = token_repository.is_token_revoked(decoded_token)
    assert result
    (token_repository.session.query.return_value.filter_by.
     assert_called_once_with(jti=decoded_token['jti']))
def test_the_is_token_revoked_method_of_user_repository_with_inexistent_token(
        app, mocker):
    """
  GIVEN the TokenRepository instance
  WHEN the is_token_revoked() method is call with inexistent token
  THEN check session method calls
  """

    from app.model import TokenRepository, Token
    token_repository = TokenRepository()
    token_repository.session = UnifiedAlchemyMagicMock()

    decoded_token = mocker.MagicMock()
    decoded_token['jti'] = "xxxxxxxxxxxxxx"

    result = token_repository.is_token_revoked(decoded_token)
    assert result
    (token_repository.session.query.return_value.filter_by.
     assert_called_once_with(jti=decoded_token['jti']))