Exemplo n.º 1
0
    def test_cai_grpc_converter(logger, log_store):
        condition_one: str = "'stop_phrases_config|stop_phrase_files': '<TRUNCATED!>'"
        condition_two: str = "'stop_phrases_config|stop_phrase_files|nested': 'test'"
        logger.addHandler(log_store)
        logger.grpc({"message": "Test log", "tags": ["test_tag"]})
        for log in log_store.messages["grpc"]:
            assert "{'message': 'Test log', 'tags': ['test_tag']}" in log
        log_store.reset()

        logger.grpc(_Resources.test_grpc_request, max_level=2)
        for log in log_store.messages["grpc"]:
            assert condition_one in log
            assert condition_two not in log
            assert "'tags': ['test', 'grpc']}" in log
        log_store.reset()

        logger.grpc(_Resources.test_grpc_request, max_level=3)
        for log in log_store.messages["grpc"]:
            assert condition_one not in log
            assert condition_two in log
            assert "'tags': ['test', 'grpc']}" in log
        log_store.reset()

        logger.grpc(_Resources.test_grpc_request)
        for log in log_store.messages["grpc"]:
            assert condition_one not in log
            assert condition_two in log
            assert "'tags': ['test', 'grpc']}" in log

        # not grpc logger
        logger.info(_Resources.test_grpc_request)
        for log in log_store.messages["info"]:
            assert "original" not in log
            assert "'tags': ['test']}" in log
            assert "'tags': ['test', 'grpc']}" not in log
Exemplo n.º 2
0
 def _setup_server(self) -> None:
     logger.info("attempting to setup server...")
     self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
     self._add_services()
     self._setup_reflection()
     self.server.add_insecure_port(f"[::]:{PORT}")  # type: ignore
     logger.info(f"SERVING SERVER AT SERVING PORT {PORT}")
     self.server.start()  # type: ignore
Exemplo n.º 3
0
 def CheckLogin(self, request: Empty, context: grpc.ServicerContext) -> Empty:
     """
     [AUTO-GENERATED FUNCTION]
     Missing associated documentation comment in .proto file.
     """
     logger.info("relaying CheckLogin() to nlu-client...")
     response = self.client.services.users.check_login()
     return response
Exemplo n.º 4
0
 def ListUsers(self, request: user_pb2.ListUsersRequest, context: grpc.ServicerContext) -> user_pb2.ListUsersResponse:
     """
     [AUTO-GENERATED FUNCTION]
     Missing associated documentation comment in .proto file.
     """
     logger.info("relaying ListUsers() to nlu-client...")
     response = self.client.services.users.list_users(request=request)
     return response
Exemplo n.º 5
0
 def DeleteUser(self, request: user_pb2.GetUserRequest, context: grpc.ServicerContext) -> Empty:
     """
     [AUTO-GENERATED FUNCTION]
     Missing associated documentation comment in .proto file.
     """
     logger.info("relaying DeleteUser() to nlu-client...")
     response = self.client.services.users.delete_user(request=request)
     return response
Exemplo n.º 6
0
 def UpdateServerRole(self, request: user_pb2.UpdateServerRoleRequest, context: grpc.ServicerContext) -> user_pb2.ServerRole:
     """
     [AUTO-GENERATED FUNCTION]
     Missing associated documentation comment in .proto file.
     """
     logger.info("relaying UpdateServerRole() to nlu-client...")
     response = self.client.services.users.update_server_role(request=request)
     return response
Exemplo n.º 7
0
    def CreateIntent(self, request: intent_pb2.CreateIntentRequest, context: grpc.ServicerContext) -> intent_pb2.Intent:
        """
        [AUTO-GENERATED FUNCTION]
        Creates an intent in the specified agent.

        """
        logger.info("relaying CreateIntent() to nlu-client...")
        response = self.client.services.intents.create_intent(request=request)
        return response
Exemplo n.º 8
0
    def ListIntents(self, request: intent_pb2.ListIntentsRequest, context: grpc.ServicerContext) -> intent_pb2.ListIntentsResponse:
        """
        [AUTO-GENERATED FUNCTION]
        Returns the list of all intents in the specified agent.

        """
        logger.info("relaying ListIntents() to nlu-client...")
        response = self.client.services.intents.list_intents(request=request)
        return response
Exemplo n.º 9
0
    def BatchDeleteIntents(self, request: intent_pb2.BatchDeleteIntentsRequest, context: grpc.ServicerContext) -> Operation:
        """
        [AUTO-GENERATED FUNCTION]
        Deletes intents in the specified agent.

        """
        logger.info("relaying BatchDeleteIntents() to nlu-client...")
        response = self.client.services.intents.batch_delete_intents(request=request)
        return response
Exemplo n.º 10
0
 def RunScraper(self, request: Empty,
                context: grpc.ServicerContext) -> qa_pb2.RunScraperResponse:
     """
     [AUTO-GENERATED FUNCTION]
     Missing associated documentation comment in .proto file.
     """
     logger.info("relaying RunScraper() to nlu-client...")
     response = self.qa_client.services.qa.run_scraper()
     return response
Exemplo n.º 11
0
 def GetAnswer(self, request: qa_pb2.GetAnswerRequest,
               context: grpc.ServicerContext) -> qa_pb2.GetAnswerResponse:
     """
     [AUTO-GENERATED FUNCTION]
     Missing associated documentation comment in .proto file.
     """
     logger.info("relaying GetAnswer() to nlu-client...")
     response = self.qa_client.services.qa.get_answer(request=request)
     return response
Exemplo n.º 12
0
    def DeleteIntent(self, request: intent_pb2.DeleteIntentRequest, context: grpc.ServicerContext) -> Empty:
        """
        [AUTO-GENERATED FUNCTION]
        Deletes the specified intent.

        """
        logger.info("relaying DeleteIntent() to nlu-client...")
        response = self.client.services.intents.delete_intent(request=request)
        return response
Exemplo n.º 13
0
    def GetIntent(self, request: intent_pb2.GetIntentRequest, context: grpc.ServicerContext) -> intent_pb2.Intent:
        """
        [AUTO-GENERATED FUNCTION]
        Retrieves the specified intent.

        """
        logger.info("relaying GetIntent() to nlu-client...")
        response = self.client.services.intents.get_intent(request=request)
        return response
Exemplo n.º 14
0
 def SetResources(self, request: agent_pb2.SetResourcesRequest,
                  context: grpc.ServicerContext) -> Empty:
     """
     [AUTO-GENERATED FUNCTION]
     Missing associated documentation comment in .proto file.
     """
     logger.info("relaying SetResources() to nlu-client...")
     response = self.client.services.agents.set_resources(request=request)
     return response
Exemplo n.º 15
0
    def test_log(log_store):
        CONSOLE_TEXT = "console log"
        logger_console.addHandler(log_store)
        logger_console.debug(CONSOLE_TEXT)
        assert CONSOLE_TEXT in log_store.messages["debug"]
        logger_console.info(CONSOLE_TEXT)
        assert CONSOLE_TEXT in log_store.messages["info"]
        logger_console.warning(CONSOLE_TEXT)
        assert CONSOLE_TEXT in log_store.messages["warning"]
        logger_console.error(CONSOLE_TEXT)
        assert CONSOLE_TEXT in log_store.messages["error"]
        logger_console.critical(CONSOLE_TEXT)
        assert CONSOLE_TEXT in log_store.messages["critical"]

        CONSOLE_TEXT = "debug log"
        logger_debug.addHandler(log_store)
        logger_debug.debug(CONSOLE_TEXT)
        assert CONSOLE_TEXT in log_store.messages["debug"]
        logger_debug.info(CONSOLE_TEXT)
        assert CONSOLE_TEXT in log_store.messages["info"]
        logger_debug.warning(CONSOLE_TEXT)
        assert CONSOLE_TEXT in log_store.messages["warning"]
        logger_debug.error(CONSOLE_TEXT)
        assert CONSOLE_TEXT in log_store.messages["error"]
        logger_debug.critical(CONSOLE_TEXT)
        assert CONSOLE_TEXT in log_store.messages["critical"]

        CONSOLE_TEXT = "root log"
        logger_root.addHandler(log_store)
        logger_root.debug(CONSOLE_TEXT)
        assert CONSOLE_TEXT in log_store.messages["debug"]
        logger_root.info(CONSOLE_TEXT)
        assert CONSOLE_TEXT in log_store.messages["info"]
        logger_root.warning(CONSOLE_TEXT)
        assert CONSOLE_TEXT in log_store.messages["warning"]
        logger_root.error(CONSOLE_TEXT)
        assert CONSOLE_TEXT in log_store.messages["error"]
        logger_root.critical(CONSOLE_TEXT)
        assert CONSOLE_TEXT in log_store.messages["critical"]

        assert len(log_store.messages["critical"]) == 3
        log_store.reset()
        assert len(log_store.messages["critical"]) == 0

        CONSOLE_TEXT = "root log 2"
        logger.addHandler(log_store)
        logger.debug(CONSOLE_TEXT)
        assert CONSOLE_TEXT in log_store.messages["debug"]
        logger.info(CONSOLE_TEXT)
        assert CONSOLE_TEXT in log_store.messages["info"]
        logger.warning(CONSOLE_TEXT)
        assert CONSOLE_TEXT in log_store.messages["warning"]
        logger.error(CONSOLE_TEXT)
        assert CONSOLE_TEXT in log_store.messages["error"]
        logger.critical(CONSOLE_TEXT)
        assert CONSOLE_TEXT in log_store.messages["critical"]
Exemplo n.º 16
0
    def UpdateAgent(self, request: agent_pb2.UpdateAgentRequest,
                    context: grpc.ServicerContext) -> agent_pb2.Agent:
        """
        [AUTO-GENERATED FUNCTION]
        Updates the specified agent.

        """
        logger.info("relaying UpdateAgent() to nlu-client...")
        response = self.client.services.agents.update_agent(request=request)
        return response
Exemplo n.º 17
0
    def RestoreAgent(self, request: agent_pb2.RestoreAgentRequest,
                     context: grpc.ServicerContext) -> Operation:
        """
        [AUTO-GENERATED FUNCTION]
        Restores the specified agent from a ZIP file.

        """
        logger.info("relaying RestoreAgent() to nlu-client...")
        response = self.client.services.agents.restore_agent(request=request)
        return response
Exemplo n.º 18
0
    def ExportAgent(self, request: agent_pb2.ExportAgentRequest,
                    context: grpc.ServicerContext) -> Operation:
        """
        [AUTO-GENERATED FUNCTION]
        Exports the specified agent to a ZIP file.

        """
        logger.info("relaying ExportAgent() to nlu-client...")
        response = self.client.services.agents.export_agent(request=request)
        return response
Exemplo n.º 19
0
    def BuildCache(self, request: agent_pb2.BuildCacheRequest,
                   context: grpc.ServicerContext) -> Operation:
        """
        [AUTO-GENERATED FUNCTION]
        Builds cache for the specified agent.

        """
        logger.info("relaying BuildCache() to nlu-client...")
        response = self.client.services.agents.build_cache(request=request)
        return response
Exemplo n.º 20
0
 def GetPlatformInfo(
         self, request: Empty, context: grpc.ServicerContext
 ) -> agent_pb2.GetPlatformInfoResponse:
     """
     [AUTO-GENERATED FUNCTION]
     Missing associated documentation comment in .proto file.
     """
     logger.info("relaying GetPlatformInfo() to nlu-client...")
     response = self.client.services.agents.get_platform_info()
     return response
Exemplo n.º 21
0
    def DeleteAllAgents(self, request: Empty,
                        context: grpc.ServicerContext) -> Empty:
        """
        [AUTO-GENERATED FUNCTION]
        Deletes all agents in the server (for development purposes only).

        """
        logger.info("relaying DeleteAllAgents() to nlu-client...")
        response = self.client.services.agents.delete_all_agents()
        return response
Exemplo n.º 22
0
    def GetSession(self, request: session_pb2.GetSessionRequest,
                   context: grpc.ServicerContext) -> session_pb2.Session:
        """
        [AUTO-GENERATED FUNCTION]
        GetSession: returns a session(=conversation) from ondewo-kb

        """
        logger.info("relaying GetSession() to nlu-client...")
        response = self.client.services.sessions.get_session(request=request)
        return response
Exemplo n.º 23
0
    def TrainAgent(self, request: agent_pb2.TrainAgentRequest,
                   context: grpc.ServicerContext) -> Operation:
        """
        [AUTO-GENERATED FUNCTION]
        Trains the specified agent.

        """
        logger.info("relaying TrainAgent() to nlu-client...")
        response = self.client.services.agents.train_agent(request=request)
        return response
Exemplo n.º 24
0
 def AddSessionLabels(self, request: session_pb2.AddSessionLabelsRequest,
                      context: grpc.ServicerContext) -> session_pb2.Session:
     """
     [AUTO-GENERATED FUNCTION]
     Missing associated documentation comment in .proto file.
     """
     logger.info("relaying AddSessionLabels() to nlu-client...")
     response = self.client.services.sessions.add_session_labels(
         request=request)
     return response
Exemplo n.º 25
0
    def ListSessions(
            self, request: session_pb2.ListSessionsRequest,
            context: grpc.ServicerContext) -> session_pb2.ListSessionsResponse:
        """
        [AUTO-GENERATED FUNCTION]
        *** SESSION RELATED ENDPOINTS *** //

        """
        logger.info("relaying ListSessions() to nlu-client...")
        response = self.client.services.sessions.list_sessions(request=request)
        return response
Exemplo n.º 26
0
    def DetectIntent(
            self, request: session_pb2.DetectIntentRequest,
            context: grpc.ServicerContext) -> session_pb2.DetectIntentResponse:
        """
        [AUTO-GENERATED FUNCTION]
        Processes a natural language query and returns structured, actionable data

        """
        logger.info("relaying DetectIntent() to nlu-client...")
        response = self.client.services.sessions.detect_intent(request=request)
        return response
Exemplo n.º 27
0
    def DeleteSession(self, request: session_pb2.DeleteSessionRequest,
                      context: grpc.ServicerContext) -> Empty:
        """
        [AUTO-GENERATED FUNCTION]
        DeleteSession: delete a session(=conversation) from ondewo-kb (for testing only)

        """
        logger.info("relaying DeleteSession() to nlu-client...")
        response = self.client.services.sessions.delete_session(
            request=request)
        return response
Exemplo n.º 28
0
    def TrackSessionStep(self, request: session_pb2.TrackSessionStepRequest,
                         context: grpc.ServicerContext) -> session_pb2.Session:
        """
        [AUTO-GENERATED FUNCTION]
        TrackSessionStep: append to an existing session; creates it if not existing

        """
        logger.info("relaying TrackSessionStep() to nlu-client...")
        response = self.client.services.sessions.track_session_step(
            request=request)
        return response
Exemplo n.º 29
0
    def CreateContext(self, request: context_pb2.CreateContextRequest,
                      context: grpc.ServicerContext) -> context_pb2.Context:
        """
        [AUTO-GENERATED FUNCTION]
        Creates a context.

        """
        logger.info("relaying CreateContext() to nlu-client...")
        response = self.client.services.contexts.create_context(
            request=request)
        return response
Exemplo n.º 30
0
    def DeleteAllContexts(self, request: context_pb2.DeleteAllContextsRequest,
                          context: grpc.ServicerContext) -> Empty:
        """
        [AUTO-GENERATED FUNCTION]
        Deletes all active contexts in the specified session.

        """
        logger.info("relaying DeleteAllContexts() to nlu-client...")
        response = self.client.services.contexts.delete_all_contexts(
            request=request)
        return response