-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathattachment_service_test.py
More file actions
47 lines (40 loc) · 2.17 KB
/
attachment_service_test.py
File metadata and controls
47 lines (40 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import json
import os
from pathlib import Path
from pyopenproject.business.exception.business_error import BusinessError
from pyopenproject.model.attachment import Attachment
from tests.test_cases.openproject_test_case import OpenProjectTestCase
class AttachmentServiceTestCase(OpenProjectTestCase):
def setUp(self):
super().setUp()
ATTACHMENT = os.path.join(self.TEST_CASES, '../data/attachment.json')
ATTACHMENT_TO_CREATE = os.path.join(self.TEST_CASES, '../data/attachment-created.json')
self.IMAGE = os.path.join(self.TEST_CASES, '../img/cute-cat.png')
self.attSer = self.op.get_attachment_service()
with open(ATTACHMENT) as f:
self.attachment = Attachment(json.load(f))
with open(ATTACHMENT_TO_CREATE) as f:
self.created_attachment = Attachment(json.load(f))
def test_create_and_delete(self):
created_attachment = self.attSer.create(filename="cute-cat.png",
description="A cute kitty, cuddling with its friends!",
file_path=self.IMAGE)
self.assertIsNotNone(created_attachment)
self.assertEqual(created_attachment.id, self.attSer.find(created_attachment).id)
self.attSer.delete(created_attachment)
# Can't find a deleted attached: 404 Client Error: Not Found for url
with self.assertRaises(BusinessError):
self.attSer.find(created_attachment)
def test_find(self):
a = Attachment({'id': 1})
attachment = self.attSer.find(a)
self.assertIsNotNone(attachment)
self.assertEqual(self.attachment.fileName, attachment.fileName)
def test_download_by_context(self):
file_content = self.attSer.download_by_context(
attachment=self.attachment,
folder=f'{str(Path.home())}/Downloads')
self.assertIsNotNone(file_content)
self.assertTrue(Path(f'{str(Path.home())}/Downloads/{self.attachment.fileName}').is_file())
os.remove(f'{str(Path.home())}/Downloads/{self.attachment.fileName}')
self.assertFalse(Path(f'{str(Path.home())}/Downloads/{self.attachment.fileName}').is_file())