Exemple #1
0
    def test_login(self, mock_post):

        conn = microstrategy.Connection(base_url=BASE_URL, username=USERNAME,
                                        password=PASSWORD, project_name=PROJECT_NAME)

        mock_post.return_value.status_code = 200

        response = authentication.login(conn)

        self.assertEqual(response.status_code, 200)
Exemple #2
0
    def test_login_app_code_present(self, mock_post):
        """Checks that application code is present in request body."""
        conn = microstrategy.Connection(base_url=self.BASE_URL,
                                        username=self.USERNAME,
                                        password=self.PASSWORD,
                                        project_name=self.PROJECT_NAME)

        mock_post.return_value.status_code = 200
        response = authentication.login(conn)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(mock_post.call_args[1]['data']["applicationType"],
                         self.APPCODE)
Exemple #3
0
    def connect(self):
        """Authenticates the user and creates a new connection with the
        Intelligence Server.

        If an active connection is detected, the session is renewed.
        """
        response = authentication.session_renew(connection=self)
        if not response.ok:
            response = authentication.login(connection=self)
            self.session.headers['X-MSTR-AuthToken'] = response.headers['X-MSTR-AuthToken']
            if config.verbose:
                print("Connection to MicroStrategy Intelligence Server has been established.")
        else:
            if config.verbose:
                print("Connection to MicroStrategy Intelligence Server was renewed.")
Exemple #4
0
    def renew(self):
        """Checks if the session is still alive.

        If so, renews the session and extends session expiration.
        """
        status = authentication.session_renew(connection=self)

        if status.status_code == 204:
            if config.verbose:
                print("Your connection to MicroStrategy Intelligence Server was renewed.")
        else:
            response = authentication.login(connection=self)
            self.session.headers['X-MSTR-AuthToken'] = response.headers['X-MSTR-AuthToken']
            if config.verbose:
                print("""Connection with MicroStrategy Intelligence Server was not active.
                         \rNew connection has been established.""")
Exemple #5
0
    def test_login_app_code_dynamic(self, mock_post):
        """Tests that changing the app code works."""
        conn = microstrategy.Connection(base_url=self.BASE_URL,
                                        username=self.USERNAME,
                                        password=self.PASSWORD,
                                        project_name=self.PROJECT_NAME)

        app_code = 99
        conn.application_code = app_code

        mock_post.return_value.status_code = 200
        response = authentication.login(conn)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(conn.application_code, app_code)
        self.assertEqual(mock_post.call_args[1]['data']["applicationType"],
                         app_code)
Exemple #6
0
    def connect(self):
        """Creates a connection"""
        if self.__check_version():
            response = authentication.login(connection=self)

            if not response.ok:
                msg = 'Authentication error. Check user credentials or REST API URL and try again.'
                self.__response_handler(response=response, msg=msg)
            else:
                self.auth_token, self.cookies = response.headers[
                    'X-MSTR-AuthToken'], dict(response.cookies)

                # Fetch the list of projects the user has access to
                response = projects.projects(connection=self)

                if not response.ok:
                    msg = "Error connecting to project '{}'. Check project name and try again.".format(
                        self.project_name)
                    self.__response_handler(response=response, msg=msg)
                else:
                    # Find which project ID matches the project name provided
                    _projects = response.json()

                    if self.project_name is not None:
                        # Find which project ID matches the project name provided
                        for _project in _projects:
                            if _project[
                                    'name'] == self.project_name:  # Enter the desired project name here
                                self.project_id = _project['id']

                    else:
                        # Find which project name matches the project ID provided
                        for _project in _projects:
                            if _project[
                                    'id'] == self.project_id:  # Enter the desired project id here
                                self.project_name = _project['name']
        else:
            print("""
            This version of mstrio is only supported on MicroStrategy 11.1.0400 or higher.
            Current Intelligence Server version: {}
            Current MicroStrategy Web version: {}
            """.format(self.__iserver_version, self.__web_version))
            raise VersionException('MicroStrategy Version not supported.')
Exemple #7
0
 def _login(self):
     return authentication.login(connection=self)