예제 #1
0
    def test_init_login_result_for_not_authorized_user(
            self,
            mock_request,
            mock_redirect_arg,
            mock_safe_url,
            mock_g,
            mock_make_response,
            mock_jsonify,
            mock_jwt
    ):
        """
        Test that checks if the correct response for a not authorized user is returned.
        """
        oauth_view = AuthOAuthView()
        oauth_view.appbuilder = MagicMock()

        provider = "OPENLMIS"
        redirect_url = "/superset/dashboard/3"
        state = '12345'

        with patch('superset_patchup.oauth.g.user.is_authenticated', False):
            with patch("superset_patchup.oauth.session", dict()) as session:
                mock_redirect_arg.return_value = redirect_url
                mock_jwt.encode.return_value = state

                oauth_view.login_init(provider=provider)

                mock_make_response.assert_called()
                assert call(isAuthorized=False, state=state) in mock_jsonify.call_args_list
                assert session.get('%s_oauthredir' % provider) == redirect_url
예제 #2
0
    def test_init_login_result_for_already_authorized_user(
            self, mock_g, mock_make_response, mock_jsonify):  # pylint: disable=R0201,W0613
        """
        Test that checks if the correct response for an already authorized
        user is returned.
        """
        oauth_view = AuthOAuthView()
        oauth_view.appbuilder = MagicMock()
        provider = "OPENLMIS"

        with patch("superset_patchup.oauth.g.user.is_authenticated", True):
            with patch("superset_patchup.oauth.session", dict()) as session:

                oauth_view.login_init(provider=provider)

                mock_make_response.assert_called()
                assert call(isAuthorized=True) in mock_jsonify.call_args_list
                assert (("%s_oauthredir" % provider) in session) is False