Exemplo n.º 1
0
 def test1_upload_attachment(self):
     with open(self.attachment_path, 'rb') as content_file:
         file_content = content_file.read()
     attachment_file_information = AttachmentfileCreationInformation(
         self.attachment_file_name, file_content)
     created_file = self.__class__.target_item.attachment_files.add(
         attachment_file_information).execute_query()
     self.assertIsNotNone(created_file.properties["FileName"])
    def add(self, attachment_file_information):
        """
        Creates an attachment
        :type attachment_file_information: AttachmentfileCreationInformation
        """
        if isinstance(attachment_file_information, dict):
            attachment_file_information = AttachmentfileCreationInformation(
                attachment_file_information.get('filename'),
                attachment_file_information.get('content'))

        target_file = File(self.context)
        self.add_child(target_file)
        qry = ServiceOperationQuery(
            self, "add", {
                "filename": attachment_file_information.filename,
            }, attachment_file_information.content, None, target_file)
        self.context.add_query(qry)
        return target_file