def test_executefunction(self):
        """
        Test ExecuteFunction HelloWorld.

        This tests calls the ExecuteFunction function, with an
        id corresponding to the HelloWorld plugin function.
        """

        header = SSE.FunctionRequestHeader(functionId=HELLO_WORLD_ID,
                                           version="1")

        duals = strings_to_duals('Hello World!')
        rows = duals_to_rows(duals)

        # Trailing commas to make iterable sequences of tuples.
        bundled_rows = (SSE.BundledRows(rows=rows)),
        metadata = (('qlik-functionrequestheader-bin',
                     header.SerializeToString()), )

        result = self.stub.ExecuteFunction(request_iterator=iter(bundled_rows),
                                           metadata=metadata)

        for bundled_row in result:
            for row in bundled_row.rows:
                for dual in row.duals:
                    assert dual.strData == 'Hello World!'
예제 #2
0
 def _get_function_id(context):
     """
     Retrieve function id from header.
     :param context: context
     :return: function id
     """
     metadata = dict(context.invocation_metadata())
     header = SSE.FunctionRequestHeader()
     header.ParseFromString(metadata['qlik-functionrequestheader-bin'])
     return header.functionId
예제 #3
0
    def _get_call_info(self, context):
        """
        Retreive useful information for the function call.
        :param context: context
        :return: string containing header info
        """

        # Get metadata for the call from the context
        metadata = dict(context.invocation_metadata())

        # Get the function ID
        func_header = SSE.FunctionRequestHeader()
        func_header.ParseFromString(metadata['qlik-functionrequestheader-bin'])
        func_id = func_header.functionId

        # Get the common request header
        common_header = SSE.CommonRequestHeader()
        common_header.ParseFromString(metadata['qlik-commonrequestheader-bin'])

        # Get capabilities
        if not hasattr(self, 'capabilities'):
            self.capabilities = self.GetCapabilities(None, context)

        # Get the name of the capability called in the function
        capability = [
            function.name for function in self.capabilities.functions
            if function.functionId == func_id
        ][0]

        # Get the user ID using a regular expression
        match = re.match(
            r"UserDirectory=(?P<UserDirectory>\w*)\W+UserId=(?P<UserId>\w*)",
            common_header.userId, re.IGNORECASE)
        if match:
            userId = match.group('UserDirectory') + '/' + match.group('UserId')
        else:
            userId = common_header.userId

        # Get the app ID
        appId = common_header.appId
        # Get the call's origin
        peer = context.peer()

        return "{0} - Capability '{1}' called by user {2} from app {3}".format(
            peer, capability, userId, appId)
    def test_executefunction(self):
        """
        Test ExecuteFunction ColumnOperations.

        This tests calls the ExecuteFunction function, with an
        id corresponding to the ColumnOperations plugin function.
        """

        header = SSE.FunctionRequestHeader(functionId=SUM_OF_ROWS_ID, version="1")

        duals = numbers_to_duals(1, 2, 3, 4, 5)
        rows = duals_to_rows(duals)

        # Trailing commas to make iterable sequences of tuples.
        bundled_rows = (SSE.BundledRows(rows=rows)),
        metadata = (('qlik-functionrequestheader-bin', header.SerializeToString()),)

        result = self.stub.ExecuteFunction(request_iterator=iter(bundled_rows), metadata=metadata)

        for bundled_row in result:
            for row in bundled_row.rows:
                for dual in row.duals:
                    assert dual.numData == 15