From 4e4ba47f9e770121d929e3f7462dca44a8742426 Mon Sep 17 00:00:00 2001 From: GianlucaBresolin <117901582+GianlucaBresolin@users.noreply.github.com> Date: Tue, 12 Mar 2024 12:17:29 +0100 Subject: [PATCH] Aggiunta test NewDocument. --- .../adapter/_in/web/ask_chatbot_controller.py | 13 +++ .../web/change_configuration_controller.py | 18 +++- .../_in/web/conceal_documents_controller.py | 16 +++- .../_in/web/delete_chats_controller.py | 14 ++- .../_in/web/delete_documents_controller.py | 17 +++- .../_in/web/embed_documents_controller.py | 12 +++ .../_in/web/enable_documents_controller.py | 16 +++- .../_in/web/get_chat_messages_controller.py | 19 +++- .../adapter/_in/web/get_chats_controller.py | 18 +++- .../_in/web/get_configuration_controller.py | 12 ++- .../get_configuration_options_controller.py | 12 ++- .../web/get_document_content_controller.py | 13 ++- .../_in/web/get_documents_controller.py | 21 +++- .../web/presentation_domain/new_document.py | 10 ++ .../adapter/_in/web/rename_chat_controller.py | 13 +++ .../_in/web/upload_documents_controller.py | 13 ++- .../service/get_documents_facade_service.py | 3 +- .../src/backend/domain/exception/exception.py | 3 + .../_in/web/ask_chatbot_controller_test.py | 8 ++ .../presentation_domain/new_document_test.py | 96 +++++++++++++++++++ .../document_operation_response_test.py | 17 ++++ .../test_document_operation_response.py | 16 ---- 22 files changed, 332 insertions(+), 48 deletions(-) create mode 100644 3 - PB/MVP/src/backend/domain/exception/exception.py create mode 100644 3 - PB/MVP/tests/backend/domain/adapter/_in/web/ask_chatbot_controller_test.py create mode 100644 3 - PB/MVP/tests/backend/domain/adapter/_in/web/presentation_domain/new_document_test.py create mode 100644 3 - PB/MVP/tests/backend/domain/document/document_operation_response_test.py delete mode 100644 3 - PB/MVP/tests/backend/domain/test_document_operation_response.py diff --git a/3 - PB/MVP/src/backend/adapter/_in/web/ask_chatbot_controller.py b/3 - PB/MVP/src/backend/adapter/_in/web/ask_chatbot_controller.py index 782eb0c8..9ea1f8c9 100644 --- a/3 - PB/MVP/src/backend/adapter/_in/web/ask_chatbot_controller.py +++ b/3 - PB/MVP/src/backend/adapter/_in/web/ask_chatbot_controller.py @@ -5,11 +5,24 @@ from domain.chat.chat_id import ChatId from datetime import datetime, timezone +""" +This class is the controller for the use case AskChatbotUseCase. It receives the user's message and the chatId and returns a MessageResponse. +Attributes: + useCase (AskChatbotUseCase): The use case for asking the chatbot. +""" class AskChatbotController: def __init__(self, askChatbotUseCase: AskChatbotUseCase): self.askChatbotUseCase = askChatbotUseCase def askChatbot(self, message: str, chatId: int = None) -> MessageResponse: + """ + Receives the user's message and the chatId and returns a MessageResponse. + Args: + message (str): The user's message. + chatId (int): The chat's id. + Returns: + MessageResponse: the response of the operation. + """ userMessage = Message( message, datetime.now(timezone.utc), diff --git a/3 - PB/MVP/src/backend/adapter/_in/web/change_configuration_controller.py b/3 - PB/MVP/src/backend/adapter/_in/web/change_configuration_controller.py index 1838e252..ab4b145c 100644 --- a/3 - PB/MVP/src/backend/adapter/_in/web/change_configuration_controller.py +++ b/3 - PB/MVP/src/backend/adapter/_in/web/change_configuration_controller.py @@ -1,14 +1,26 @@ from typing import List from application.port._in.change_configuration_use_case import ChangeConfigurationUseCase -#from .configuration_service import ConfigurationService from domain.configuration.configuration_operation_response import ConfigurationOperationResponse from domain.configuration.llm_model_configuration import LLMModelType +""" +This class is the controller for the use case ChangeConfigurationUseCase. It receives the new LLM model and returns a ConfigurationOperationResponse. +Attributes: + useCase (ChangeConfigurationUseCase): The use case for changing the configuration. +""" + class ChangeConfigurationController: - def __init__(self, changeConfigurationUseCase: ChangeConfigurationUseCase): #configurationService: ConfigurationService + def __init__(self, changeConfigurationUseCase: ChangeConfigurationUseCase): self.useCase = changeConfigurationUseCase - + def changeLLMModel(self, LLModel: str) -> ConfigurationOperationResponse: + """ + Receives the new LLM model and returns a ConfigurationOperationResponse. + Args: + LLModel (str): The new LLM model. + Returns: + ConfigurationOperationResponse: the response of the operation. + """ try: LLMModelChoice = LLMModelType[LLModel.upper()] return self.useCase.changeLLMModel(LLMModelChoice) diff --git a/3 - PB/MVP/src/backend/adapter/_in/web/conceal_documents_controller.py b/3 - PB/MVP/src/backend/adapter/_in/web/conceal_documents_controller.py index 185c650f..307d6c7a 100644 --- a/3 - PB/MVP/src/backend/adapter/_in/web/conceal_documents_controller.py +++ b/3 - PB/MVP/src/backend/adapter/_in/web/conceal_documents_controller.py @@ -3,9 +3,21 @@ from domain.document.document_operation_response import DocumentOperationResponse from domain.document.document_id import DocumentId +""" +This class is the controller for the use case ConcealDocumentsUseCase. It receives the documents' ids and returns a list of DocumentOperationResponse. +Attributes: + useCase (ConcealDocumentsUseCase): The use case for concealing documents. +""" class ConcealDocumentsController: def __init__(self, concealDocumentsUseCase: ConcealDocumentsUseCase): self.useCase = concealDocumentsUseCase - - def concealDocuments(self, documentsIds: List[str]) -> List[DocumentOperationResponse]: + + def concealDocuments(self, documentsIds: List[str]) -> List[DocumentOperationResponse]: + """ + Receives the documents' ids and returns a list of DocumentOperationResponse. + Args: + documentsIds (List[str]): The documents' ids. + Returns: + List[DocumentOperationResponse]: the response of the operation. + """ return self.useCase.concealDocuments([DocumentId(documentId) for documentId in documentsIds]) \ No newline at end of file diff --git a/3 - PB/MVP/src/backend/adapter/_in/web/delete_chats_controller.py b/3 - PB/MVP/src/backend/adapter/_in/web/delete_chats_controller.py index 1186e9a3..d73cb755 100644 --- a/3 - PB/MVP/src/backend/adapter/_in/web/delete_chats_controller.py +++ b/3 - PB/MVP/src/backend/adapter/_in/web/delete_chats_controller.py @@ -3,9 +3,21 @@ from typing import List from domain.chat.chat_id import ChatId +""" +This class is the controller for the use case DeleteChatsUseCase. It receives the chats' ids and returns a list of ChatOperationResponse. +Attributes: + useCase (DeleteChatsUseCase): The use case for deleting chats. +""" class DeleteChatsController: def __init__(self, deleteChatUseCase: DeleteChatsUseCase): self.useCase = deleteChatUseCase - + def deleteChats(self, chatsIdsList: List[int]) -> List[ChatOperationResponse]: + """ + Receives the chats' ids and returns a list of ChatOperationResponse. + Args: + chatsIdsList (List[int]): The chats' ids. + Returns: + List[ChatOperationResponse]: the response of the operation. + """ return self.useCase.deleteChats([ChatId(chatId) for chatId in chatsIdsList]) \ No newline at end of file diff --git a/3 - PB/MVP/src/backend/adapter/_in/web/delete_documents_controller.py b/3 - PB/MVP/src/backend/adapter/_in/web/delete_documents_controller.py index fb500a57..6edd2544 100644 --- a/3 - PB/MVP/src/backend/adapter/_in/web/delete_documents_controller.py +++ b/3 - PB/MVP/src/backend/adapter/_in/web/delete_documents_controller.py @@ -3,9 +3,22 @@ from domain.document.document_operation_response import DocumentOperationResponse from domain.document.document_id import DocumentId +""" +This class is the controller for the use case DeleteDocumentsUseCase. It receives the documents' ids and returns a list of DocumentOperationResponse. +Attributes: + useCase (DeleteDocumentsUseCase): The use case for deleting documents. +""" class DeleteDocumentsController: def __init__(self, deleteDocumentsUseCase: DeleteDocumentsUseCase): self.useCase = deleteDocumentsUseCase - - def deleteDocuments(self, documentsIds: List[str]) -> List[DocumentOperationResponse]: + + + def deleteDocuments(self, documentsIds: List[str]) -> List[DocumentOperationResponse]: + """ + Receives the documents' ids and returns a list of DocumentOperationResponse. + Args: + documentsIds (List[str]): The documents' ids. + Returns: + List[DocumentOperationResponse]: the response of the operation. + """ return self.useCase.deleteDocuments([DocumentId(documentId) for documentId in documentsIds]) \ No newline at end of file diff --git a/3 - PB/MVP/src/backend/adapter/_in/web/embed_documents_controller.py b/3 - PB/MVP/src/backend/adapter/_in/web/embed_documents_controller.py index 306f8625..54a417b3 100644 --- a/3 - PB/MVP/src/backend/adapter/_in/web/embed_documents_controller.py +++ b/3 - PB/MVP/src/backend/adapter/_in/web/embed_documents_controller.py @@ -4,9 +4,21 @@ from domain.document.document_operation_response import DocumentOperationResponse from domain.document.document_id import DocumentId +""" +This class is the controller for the use case EmbedDocumentsUseCase. It receives the documents' ids and returns a list of DocumentOperationResponse. +Attributes: + useCase (EmbedDocumentsUseCase): The use case for embedding documents. +""" class EmbedDocumentsController: def __init__(self, embedDocumentsUseCase: EmbedDocumentsUseCase): self.useCase = embedDocumentsUseCase def embedDocuments(self, documentsIds: List[str]) -> List[DocumentOperationResponse]: + """ + Receives the documents' ids and returns a list of DocumentOperationResponse. + Args: + documentsIds (List[str]): The documents' ids. + Returns: + List[DocumentOperationResponse]: the response of the operation. + """ return self.useCase.embedDocuemnts([DocumentId(documentId) for documentId in documentsIds]) \ No newline at end of file diff --git a/3 - PB/MVP/src/backend/adapter/_in/web/enable_documents_controller.py b/3 - PB/MVP/src/backend/adapter/_in/web/enable_documents_controller.py index 5ac0e5dd..bda9b0cd 100644 --- a/3 - PB/MVP/src/backend/adapter/_in/web/enable_documents_controller.py +++ b/3 - PB/MVP/src/backend/adapter/_in/web/enable_documents_controller.py @@ -3,9 +3,21 @@ from domain.document.document_operation_response import DocumentOperationResponse from domain.document.document_id import DocumentId +""" +This class is the controller for the use case EnableDocumentsUseCase. It receives the documents' ids and returns a list of DocumentOperationResponse. +Attributes: + useCase (EnableDocumentsUseCase): The use case for enabling documents. +""" class EnableDocumentsController: def __init__(self, enableDocumentsUseCase: EnableDocumentsUseCase): self.useCase = enableDocumentsUseCase - - def enableDocuments(self, documentsIds: List[str]) -> List[DocumentOperationResponse]: + + def enableDocuments(self, documentsIds: List[str]) -> List[DocumentOperationResponse]: + """ + Receives the documents' ids and returns a list of DocumentOperationResponse. + Args: + documentsIds (List[str]): The documents' ids. + Returns: + List[DocumentOperationResponse]: the response of the operation. + """ return self.useCase.enableDocuments([DocumentId(documentId) for documentId in documentsIds]) \ No newline at end of file diff --git a/3 - PB/MVP/src/backend/adapter/_in/web/get_chat_messages_controller.py b/3 - PB/MVP/src/backend/adapter/_in/web/get_chat_messages_controller.py index e29da985..5bce950f 100644 --- a/3 - PB/MVP/src/backend/adapter/_in/web/get_chat_messages_controller.py +++ b/3 - PB/MVP/src/backend/adapter/_in/web/get_chat_messages_controller.py @@ -2,10 +2,21 @@ from domain.chat.chat import Chat from domain.chat.chat_id import ChatId - +""" +This class is the controller for the use case GetChatMessagesUseCase. It receives the chat's id and returns the chat's messages. +Attributes: + useCase (GetChatMessagesUseCase): The use case for getting the chat's messages. +""" class GetChatMessagesController: - def __init__(self, useCase: GetChatMessagesUseCase): - self.useCase = useCase + def __init__(self, getChatMessagesUseCase: GetChatMessagesUseCase): + self.useCase = getChatMessagesUseCase - def getChatMessages(self, chatId: int)->Chat: + def getChatMessages(self, chatId: int) -> Chat: + """ + Receives the chat's id and returns the chat's messages. + Args: + chatId (int): The chat's id. + Returns: + Chat: the chat containing the messages required. + """ return self.useCase.getChatMessages(ChatId(chatId)) \ No newline at end of file diff --git a/3 - PB/MVP/src/backend/adapter/_in/web/get_chats_controller.py b/3 - PB/MVP/src/backend/adapter/_in/web/get_chats_controller.py index 39d5645c..1f39da6a 100644 --- a/3 - PB/MVP/src/backend/adapter/_in/web/get_chats_controller.py +++ b/3 - PB/MVP/src/backend/adapter/_in/web/get_chats_controller.py @@ -4,12 +4,22 @@ from domain.chat.chat_filter import ChatFilter from domain.chat.chat_preview import ChatPreview - - +""" +This class is the controller for the use case GetChatsUseCase. It receives the search filter and returns a list of ChatPreview. +Attributes: + useCase (GetChatsUseCase): The use case for getting chats. +""" class GetChatsController: - def __init__(self, getChatsUseCase:GetChatsUseCase): + def __init__(self, getChatsUseCase: GetChatsUseCase): self.useCase = getChatsUseCase - + def getChats(self, searchFilter:str)-> List[ChatPreview]: + """ + Receives the search filter and returns a list of ChatPreview. + Args: + searchFilter (str): The search filter. + Returns: + List[ChatPreview]: the list of ChatPreview that match the search filter. + """ filter = ChatFilter(searchFilter) return self.useCase.getChats(filter) \ No newline at end of file diff --git a/3 - PB/MVP/src/backend/adapter/_in/web/get_configuration_controller.py b/3 - PB/MVP/src/backend/adapter/_in/web/get_configuration_controller.py index 84abbd57..5db1394c 100644 --- a/3 - PB/MVP/src/backend/adapter/_in/web/get_configuration_controller.py +++ b/3 - PB/MVP/src/backend/adapter/_in/web/get_configuration_controller.py @@ -2,9 +2,19 @@ from application.port._in.get_configuration_use_case import GetConfigurationUseCase from domain.configuration.configuration import Configuration +""" +This class is the controller for the use case GetConfigurationUseCase. It returns the current configuration. +Attributes: + useCase (GetConfigurationUseCase): The use case for getting the configuration. +""" class GetConfigurationController: def __init__(self, getConfigurationUseCase: GetConfigurationUseCase): self.useCase = getConfigurationUseCase - + def getConfiguration(self) -> Configuration: + """ + Returns the current configuration. + Returns: + Configuration: the current configuration. + """ return self.useCase.getConfiguration() \ No newline at end of file diff --git a/3 - PB/MVP/src/backend/adapter/_in/web/get_configuration_options_controller.py b/3 - PB/MVP/src/backend/adapter/_in/web/get_configuration_options_controller.py index 6b910e41..2548047f 100644 --- a/3 - PB/MVP/src/backend/adapter/_in/web/get_configuration_options_controller.py +++ b/3 - PB/MVP/src/backend/adapter/_in/web/get_configuration_options_controller.py @@ -2,9 +2,19 @@ from application.port._in.get_configuration_options_use_case import GetConfigurationOptionsUseCase from domain.configuration.configuration_options import ConfigurationOptions +""" +This class is the controller for the use case GetConfigurationOptionsUseCase. It returns the current configuration options. +Attributes: + useCase (GetConfigurationOptionsUseCase): The use case for getting the configuration options. +""" class GetConfigurationOptionsController: def __init__(self, getConfigurationOptionsUseCase: GetConfigurationOptionsUseCase): self.useCase = getConfigurationOptionsUseCase - + def getConfigurationOptions(self) -> ConfigurationOptions: + """ + Returns the current configuration options. + Returns: + ConfigurationOptions: the current configuration options. + """ return self.useCase.getConfigurationOptions() \ No newline at end of file diff --git a/3 - PB/MVP/src/backend/adapter/_in/web/get_document_content_controller.py b/3 - PB/MVP/src/backend/adapter/_in/web/get_document_content_controller.py index 45744098..c5b42440 100644 --- a/3 - PB/MVP/src/backend/adapter/_in/web/get_document_content_controller.py +++ b/3 - PB/MVP/src/backend/adapter/_in/web/get_document_content_controller.py @@ -2,11 +2,22 @@ from domain.document.document import Document from domain.document.document_id import DocumentId - +""" +This class is the controller for the use case GetDocumentsContentUseCase. It receives the document's id and returns the document's content. +Attributes: + useCase (GetDocumentsContentUseCase): The use case for getting the document's content. +""" class GetDocumentContentController: def __init__(self, getDocumentContentUseCase: GetDocumentsContentUseCase): self.useCase = getDocumentContentUseCase def getDocumentContent(self, documentId: str) -> Document: + """ + Receives the document's id and returns the document's content. + Args: + documentId (str): The document's id. + Returns: + Document: the Document containg the relative content. + """ document = self.useCase.getDocumentsContent([DocumentId(documentId)]) return document[0] diff --git a/3 - PB/MVP/src/backend/adapter/_in/web/get_documents_controller.py b/3 - PB/MVP/src/backend/adapter/_in/web/get_documents_controller.py index 20090e55..f9b7a075 100644 --- a/3 - PB/MVP/src/backend/adapter/_in/web/get_documents_controller.py +++ b/3 - PB/MVP/src/backend/adapter/_in/web/get_documents_controller.py @@ -2,17 +2,28 @@ from application.port._in.get_documents_use_case import GetDocumentsUseCase from domain.document.document_filter import DocumentFilter -from domain.document.document_id import DocumentId from domain.document.light_document import LightDocument +from domain.exception.exception import ElaborationException +from api_exceptions import APIElaborationException - +""" +This class is the controller for the use case GetDocumentsUseCase. It receives the search filter and returns a list of LightDocument. +Attributes: + useCase (GetDocumentsUseCase): The use case for getting documents. +""" class GetDocumentsController: def __init__(self, getDocumentsUseCase: GetDocumentsUseCase): self.useCase = getDocumentsUseCase def getDocuments(self, searchFilter: str) -> List[LightDocument]: + """ + Receives the search filter and returns a list of LightDocument. + Args: + searchFilter (str): The search filter. + Returns: + List[LightDocument]: the list of LightDocument that match the search filter. + """ try: return self.useCase.getDocuments(DocumentFilter(searchFilter)) - # TODO: Catch specific exceptions (custom exception per Exception("Il numero di documenti e di status non corrisponde.") in GetDocumentsFacadeService) - except Exception as e: - return [] \ No newline at end of file + except ElaborationException as e: + raise APIElaborationException(e.message) \ No newline at end of file diff --git a/3 - PB/MVP/src/backend/adapter/_in/web/presentation_domain/new_document.py b/3 - PB/MVP/src/backend/adapter/_in/web/presentation_domain/new_document.py index 43b916d2..5098d92e 100644 --- a/3 - PB/MVP/src/backend/adapter/_in/web/presentation_domain/new_document.py +++ b/3 - PB/MVP/src/backend/adapter/_in/web/presentation_domain/new_document.py @@ -13,6 +13,11 @@ """ This module contains the NewDocument dataclass, which represents a new document to be uploaded to the system. +Attributes: + documentId (str): The document's id. + type (str): The document's type. + size (float): The document's size. + content (bytes): The document's content. """ @dataclass class NewDocument: @@ -22,6 +27,11 @@ class NewDocument: content: bytes def toDocument(self) -> Document: + """ + Converts the NewDocument to a Document. + Returns: + Document: The Document object. + """ documentType = DocumentType.PDF if self.type.upper() == "PDF" else DocumentType.DOCX return Document( DocumentStatus(Status.ENABLED), diff --git a/3 - PB/MVP/src/backend/adapter/_in/web/rename_chat_controller.py b/3 - PB/MVP/src/backend/adapter/_in/web/rename_chat_controller.py index c525f022..d807ec65 100644 --- a/3 - PB/MVP/src/backend/adapter/_in/web/rename_chat_controller.py +++ b/3 - PB/MVP/src/backend/adapter/_in/web/rename_chat_controller.py @@ -2,9 +2,22 @@ from domain.chat.chat_operation_response import ChatOperationResponse from application.port._in.rename_chat_use_case import RenameChatUseCase +""" +This class is the controller for the use case RenameChatUseCase. It receives the chat's id and the new title and returns a ChatOperationResponse. +Attributes: + useCase (RenameChatUseCase): The use case for renaming a chat. +""" class RenameChatController: def __init__(self, renameChatUseCase: RenameChatUseCase): self.useCase = renameChatUseCase def renameChat(self, chatId: int, title: str) -> ChatOperationResponse: + """ + Receives the chat's id and the new title and returns a ChatOperationResponse. + Args: + chatId (int): The chat's id. + title (str): The new title. + Returns: + ChatOperationResponse: the response of the operation. + """ self.useCase.renameChat(ChatId(chatId), title) \ No newline at end of file diff --git a/3 - PB/MVP/src/backend/adapter/_in/web/upload_documents_controller.py b/3 - PB/MVP/src/backend/adapter/_in/web/upload_documents_controller.py index 005f8a92..b989b93b 100644 --- a/3 - PB/MVP/src/backend/adapter/_in/web/upload_documents_controller.py +++ b/3 - PB/MVP/src/backend/adapter/_in/web/upload_documents_controller.py @@ -9,17 +9,20 @@ It also receives the force upload parameter and sends the documents to the use case. Attributes: useCase (UploadDocumentsUseCase): The use case for uploading documents. - Methods: - toDocument(self, newDocument: NewDocument) -> Document: - Converts a new document to a document domain model. - uploadDocuments(self, newDocuments: List[NewDocument], forceUpload: bool = False) -> List[DocumentOperationResponse]: - Receives the new documents and force upload parameter and sends them to the use case. """ class UploadDocumentsController: def __init__(self, uploadDocumentsUseCase: UploadDocumentsUseCase): self.useCase = uploadDocumentsUseCase def uploadDocuments(self, newDocuments: List[NewDocument], forceUpload: bool = False) -> List[DocumentOperationResponse]: + """ + Receives the new documents and the force upload parameter and sends them to the use case. + Args: + newDocuments (List[NewDocument]): The new documents. + forceUpload (bool): The force upload parameter. + Returns: + List[DocumentOperationResponse]: the response of the operation. + """ documents = [newDocument.toDocument() for newDocument in newDocuments] return self.useCase.uploadDocuments(documents, forceUpload) diff --git a/3 - PB/MVP/src/backend/application/service/get_documents_facade_service.py b/3 - PB/MVP/src/backend/application/service/get_documents_facade_service.py index ed928eb8..156eebee 100644 --- a/3 - PB/MVP/src/backend/application/service/get_documents_facade_service.py +++ b/3 - PB/MVP/src/backend/application/service/get_documents_facade_service.py @@ -5,6 +5,7 @@ from domain.document.light_document import LightDocument from application.service.get_documents_status import GetDocumentsStatus from application.service.get_documents_metadata import GetDocumentsMetadata +from domain.exception.exception import ElaborationException class GetDocumentsFacadeService(GetDocumentsUseCase): @@ -18,7 +19,7 @@ def getDocuments(self, documentFilter: DocumentFilter) -> List[LightDocument]: documentsId = [document.id for document in documentsMetadataList] documentsStatusList = self.getDocumentsStatus.getDocumentsStatus(documentsId) if len(documentsMetadataList) != len(documentsStatusList): - raise Exception("Il numero di documenti e di status non corrisponde.") + raise ElaborationException("Il numero di documenti e di status non corrisponde.") listOfLightDocument = [] for documentMetadata, documentStatus in zip(documentsMetadataList, documentsStatusList): lightdocs = LightDocument(metadata=documentMetadata, status=documentStatus) diff --git a/3 - PB/MVP/src/backend/domain/exception/exception.py b/3 - PB/MVP/src/backend/domain/exception/exception.py new file mode 100644 index 00000000..bb7e9d5d --- /dev/null +++ b/3 - PB/MVP/src/backend/domain/exception/exception.py @@ -0,0 +1,3 @@ +class ElaborationException(Exception): + def __init__(self, message): + self.message = message \ No newline at end of file diff --git a/3 - PB/MVP/tests/backend/domain/adapter/_in/web/ask_chatbot_controller_test.py b/3 - PB/MVP/tests/backend/domain/adapter/_in/web/ask_chatbot_controller_test.py new file mode 100644 index 00000000..fac3ae12 --- /dev/null +++ b/3 - PB/MVP/tests/backend/domain/adapter/_in/web/ask_chatbot_controller_test.py @@ -0,0 +1,8 @@ +from adapter._in.web.ask_chatbot_controller import AskChatbotController +from domain.chat.message import MessageSender + +def test_askChatbot_with_existent_chat(mocker): + pass + +def test_askChatbot_without_chat(mocker): + pass \ No newline at end of file diff --git a/3 - PB/MVP/tests/backend/domain/adapter/_in/web/presentation_domain/new_document_test.py b/3 - PB/MVP/tests/backend/domain/adapter/_in/web/presentation_domain/new_document_test.py new file mode 100644 index 00000000..b17b2bd9 --- /dev/null +++ b/3 - PB/MVP/tests/backend/domain/adapter/_in/web/presentation_domain/new_document_test.py @@ -0,0 +1,96 @@ +import unittest + +from adapter._in.web.presentation_domain.new_document import NewDocument +from domain.document.document_status import Status +from domain.document.document_metadata import DocumentType + +from domain.document.document_status import DocumentStatus +from domain.document.document_metadata import DocumentMetadata +from domain.document.document_id import DocumentId +from domain.document.plain_document import PlainDocument +from domain.document.document_content import DocumentContent +from domain.document.document import Document + +def test_toDocument_pdf_type(): + newDocument = NewDocument('123', 'pdf', 1.0, b'content') + + with unittest.mock.patch('adapter._in.web.presentation_domain.new_document.Document') as MockDocument, \ + unittest.mock.patch('adapter._in.web.presentation_domain.new_document.DocumentMetadata') as MockDocumentMetadata, \ + unittest.mock.patch('adapter._in.web.presentation_domain.new_document.DocumentStatus') as MockDocumentStatus, \ + unittest.mock.patch('adapter._in.web.presentation_domain.new_document.PlainDocument') as MockPlainDocument, \ + unittest.mock.patch('adapter._in.web.presentation_domain.new_document.DocumentContent') as MockDocumentContent, \ + unittest.mock.patch('adapter._in.web.presentation_domain.new_document.DocumentId') as MockDocumentId: + + MockDocumentContent.return_value = DocumentContent(b'content') + MockDocumentId.return_value = DocumentId('123') + MockDocumentMetadata.return_value = DocumentMetadata(DocumentId('123'), DocumentType.PDF, 1.0, unittest.mock.ANY) + MockPlainDocument.return_value = PlainDocument(DocumentMetadata(DocumentId('123'), DocumentType.PDF, 1.0, unittest.mock.ANY), DocumentContent(b'content')) + MockDocumentStatus.return_value = DocumentStatus(Status.ENABLED) + MockDocument.return_value = Document(DocumentStatus(Status.ENABLED), PlainDocument(DocumentMetadata(DocumentId('123'), DocumentType.PDF, 1.0, unittest.mock.ANY), DocumentContent(b'content'))) + + document = newDocument.toDocument() + + MockDocument.assert_called_once_with( + DocumentStatus(Status.ENABLED), + PlainDocument( + MockDocumentMetadata.return_value, + DocumentContent(b'content') + ) + ) + MockDocumentMetadata.assert_called_once_with( + DocumentId('123'), + DocumentType.PDF, + 1.0, + unittest.mock.ANY + ) + MockDocumentStatus.assert_called_once_with(Status.ENABLED) + MockPlainDocument.assert_called_once_with( + MockDocumentMetadata.return_value, + DocumentContent(b'content') + ) + MockDocumentContent.assert_called_once_with(b'content') + MockDocumentId.assert_called_once_with('123') + + assert isinstance(document, Document) + +def test_toDocument_docx_type(): + newDocument = NewDocument('123', 'docx', 1.0, b'content') + + with unittest.mock.patch('adapter._in.web.presentation_domain.new_document.Document') as MockDocument, \ + unittest.mock.patch('adapter._in.web.presentation_domain.new_document.DocumentMetadata') as MockDocumentMetadata, \ + unittest.mock.patch('adapter._in.web.presentation_domain.new_document.DocumentStatus') as MockDocumentStatus, \ + unittest.mock.patch('adapter._in.web.presentation_domain.new_document.PlainDocument') as MockPlainDocument, \ + unittest.mock.patch('adapter._in.web.presentation_domain.new_document.DocumentContent') as MockDocumentContent, \ + unittest.mock.patch('adapter._in.web.presentation_domain.new_document.DocumentId') as MockDocumentId: + + MockDocumentContent.return_value = DocumentContent(b'content') + MockDocumentId.return_value = DocumentId('123') + MockDocumentMetadata.return_value = DocumentMetadata(DocumentId('123'), DocumentType.DOCX, 1.0, unittest.mock.ANY) + MockPlainDocument.return_value = PlainDocument(DocumentMetadata(DocumentId('123'), DocumentType.DOCX, 1.0, unittest.mock.ANY), DocumentContent(b'content')) + MockDocumentStatus.return_value = DocumentStatus(Status.ENABLED) + MockDocument.return_value = Document(DocumentStatus(Status.ENABLED), PlainDocument(DocumentMetadata(DocumentId('123'), DocumentType.DOCX, 1.0, unittest.mock.ANY), DocumentContent(b'content'))) + + document = newDocument.toDocument() + + MockDocument.assert_called_once_with( + DocumentStatus(Status.ENABLED), + PlainDocument( + MockDocumentMetadata.return_value, + DocumentContent(b'content') + ) + ) + MockDocumentMetadata.assert_called_once_with( + DocumentId('123'), + DocumentType.DOCX, + 1.0, + unittest.mock.ANY + ) + MockDocumentStatus.assert_called_once_with(Status.ENABLED) + MockPlainDocument.assert_called_once_with( + MockDocumentMetadata.return_value, + DocumentContent(b'content') + ) + MockDocumentContent.assert_called_once_with(b'content') + MockDocumentId.assert_called_once_with('123') + + assert isinstance(document, Document) \ No newline at end of file diff --git a/3 - PB/MVP/tests/backend/domain/document/document_operation_response_test.py b/3 - PB/MVP/tests/backend/domain/document/document_operation_response_test.py new file mode 100644 index 00000000..f159a612 --- /dev/null +++ b/3 - PB/MVP/tests/backend/domain/document/document_operation_response_test.py @@ -0,0 +1,17 @@ +from domain.document.document_operation_response import DocumentOperationResponse + +def test_ok_method_true(mocker): + documentIdMock = mocker.Mock() + documentIdMock.value = "example_id" + + response = DocumentOperationResponse(documentId=documentIdMock, status=True, message="Success") + + assert response.ok() == True + +def test_ok_method_false(mocker): + documentIdMock = mocker.Mock() + documentIdMock.value = "example_id" + + response = DocumentOperationResponse(documentId=documentIdMock, status=False, message="Failure") + + assert response.ok() == False \ No newline at end of file diff --git a/3 - PB/MVP/tests/backend/domain/test_document_operation_response.py b/3 - PB/MVP/tests/backend/domain/test_document_operation_response.py deleted file mode 100644 index e0b12778..00000000 --- a/3 - PB/MVP/tests/backend/domain/test_document_operation_response.py +++ /dev/null @@ -1,16 +0,0 @@ -from domain.document.document_operation_response import DocumentOperationResponse -from domain.document.document_id import DocumentId - -def test_ok_method_true(): - document_id = DocumentId("example_id") - - response = DocumentOperationResponse(documentId=document_id, status=True, message="Success") - - assert response.ok() == True - -def test_ok_method_false(): - document_id = DocumentId("example_id") - - response = DocumentOperationResponse(documentId=document_id, status=False, message="Failure") - - assert response.ok() == False