forked from linode/linode_api4-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_test.py
More file actions
100 lines (80 loc) · 3.24 KB
/
Copy pathimage_test.py
File metadata and controls
100 lines (80 loc) · 3.24 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from datetime import datetime
from io import BytesIO
from typing import Any, BinaryIO
from unittest.mock import patch
from test.base import ClientBaseCase
from linode_api4.objects import Image
# A minimal gzipped image that will be accepted by the API
TEST_IMAGE_CONTENT = (
b"\x1F\x8B\x08\x08\xBD\x5C\x91\x60\x00\x03\x74\x65\x73\x74\x2E\x69"
b"\x6D\x67\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00"
)
class ImageTest(ClientBaseCase):
"""
Tests methods of the Image class
"""
def test_get_image(self):
"""
Tests that an image is loaded correctly by ID
"""
image = Image(self.client, 'linode/debian9')
self.assertEqual(image._populated, False)
self.assertEqual(image.label, 'Debian 9')
self.assertEqual(image._populated, True)
self.assertEqual(image.vendor, 'Debian')
self.assertEqual(image.description, None)
self.assertEqual(image.deprecated, False)
self.assertEqual(image.status, "available")
self.assertEqual(image.type, "manual")
self.assertEqual(image.created_by, "linode")
self.assertEqual(image.size, 1100)
self.assertEqual(image.eol, datetime(
year=2026, month=7, day=1, hour=4, minute=0, second=0
))
self.assertEqual(image.expiry, datetime(
year=2026, month=8, day=1, hour=4, minute=0, second=0
))
self.assertEqual(image.updated, datetime(
year=2020, month=7, day=1, hour=4, minute=0, second=0
))
def test_image_create_upload(self):
"""
Test that an image upload URL can be created successfully.
"""
with self.mock_post("/images/upload") as m:
image, url = self.client.image_create_upload(
"Realest Image Upload",
"us-southeast",
description="very real image upload.",
)
self.assertEqual(m.call_url, "/images/upload")
self.assertEqual(m.method, "post")
self.assertEqual(
m.call_data,
{
"label": "Realest Image Upload",
"region": "us-southeast",
"description": "very real image upload."
}
)
self.assertEqual(image.id, "private/1337")
self.assertEqual(image.label, "Realest Image Upload")
self.assertEqual(image.description, "very real image upload.")
self.assertEqual(url, "https://linode.com/")
def test_image_upload(self):
"""
Test that an image can be uploaded.
"""
def put_mock(url: str, data: BinaryIO = None, **kwargs):
self.assertEqual(url, "https://linode.com/")
self.assertEqual(data.read(), TEST_IMAGE_CONTENT)
with patch("requests.put", put_mock), self.mock_post("/images/upload"):
image = self.client.image_upload(
"Realest Image Upload",
"us-southeast",
BytesIO(TEST_IMAGE_CONTENT),
description="very real image upload.",
)
self.assertEqual(image.id, "private/1337")
self.assertEqual(image.label, "Realest Image Upload")
self.assertEqual(image.description, "very real image upload.")