def test_item_attachment_properties(self):
     attached_item1 = self.get_test_item(folder=self.test_folder)
     att1 = ItemAttachment(name="attachment1", item=attached_item1)
     self.assertIn("name='attachment1'", str(att1))
     att1.item = attached_item1  # Test property setter
     with self.assertRaises(TypeError) as e:
         att1.item = "XXX"
     self.assertEqual(e.exception.args[0], "'value' 'XXX' must be of type <class 'exchangelib.items.item.Item'>")
     self.assertEqual(att1.item, attached_item1)  # Test property getter
     self.assertEqual(att1.item, attached_item1)  # Test property getter
     att1.attachment_id = "xxx"
     self.assertEqual(att1.item, attached_item1)  # Test property getter when attachment_id is set
     att1._item = None
     with self.assertRaises(ValueError):
         print(att1.item)  # Test property getter when we need to fetch the item
Ejemplo n.º 2
0
    def test_attachment_properties(self):
        binary_file_content = u'Hello from unicode æøå'.encode('utf-8')
        att1 = FileAttachment(name='my_file_1.txt',
                              content=binary_file_content)
        self.assertIn("name='my_file_1.txt'", str(att1))
        att1.content = binary_file_content  # Test property setter
        self.assertEqual(att1.content,
                         binary_file_content)  # Test property getter
        att1.attachment_id = 'xxx'
        self.assertEqual(att1.content, binary_file_content
                         )  # Test property getter when attachment_id is set
        att1._content = None
        with self.assertRaises(ValueError):
            print(att1.content
                  )  # Test property getter when we need to fetch the content

        attached_item1 = self.get_test_item(folder=self.test_folder)
        att2 = ItemAttachment(name='attachment1', item=attached_item1)
        self.assertIn("name='attachment1'", str(att2))
        att2.item = attached_item1  # Test property setter
        self.assertEqual(att2.item, attached_item1)  # Test property getter
        self.assertEqual(att2.item, attached_item1)  # Test property getter
        att2.attachment_id = 'xxx'
        self.assertEqual(
            att2.item,
            attached_item1)  # Test property getter when attachment_id is set
        att2._item = None
        with self.assertRaises(ValueError):
            print(att2.item
                  )  # Test property getter when we need to fetch the item
Ejemplo n.º 3
0
 def test_item_attachment_properties(self):
     attached_item1 = self.get_test_item(folder=self.test_folder)
     att1 = ItemAttachment(name='attachment1', item=attached_item1)
     self.assertIn("name='attachment1'", str(att1))
     att1.item = attached_item1  # Test property setter
     self.assertEqual(att1.item, attached_item1)  # Test property getter
     self.assertEqual(att1.item, attached_item1)  # Test property getter
     att1.attachment_id = 'xxx'
     self.assertEqual(
         att1.item,
         attached_item1)  # Test property getter when attachment_id is set
     att1._item = None
     with self.assertRaises(ValueError):
         print(att1.item
               )  # Test property getter when we need to fetch the item