Skip to content

Commit 43851b9

Browse files
committed
add tests
1 parent 7ad8012 commit 43851b9

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import sys
2+
import unittest
3+
import logging
4+
from typing import Dict
5+
6+
from scaleway_core.client import Client
7+
from .custom_api import InstanceUtilsV1API
8+
9+
logger = logging.getLogger()
10+
logger.level = logging.DEBUG
11+
stream_handler = logging.StreamHandler(sys.stdout)
12+
logger.addHandler(stream_handler)
13+
14+
15+
class TestServerUserData(unittest.TestCase):
16+
def setUp(self) -> None:
17+
self.client = Client()
18+
self.instance_api = InstanceUtilsV1API(self.client, bypass_validation=True)
19+
self.server = self.instance_api._create_server(
20+
commercial_type="DEV1-S",
21+
zone="fr-par-1",
22+
image="ubuntu_jammy",
23+
name="my-server-web",
24+
volumes={},
25+
)
26+
27+
def test_set_and_get_server_user_data(self) -> None:
28+
key = "hello"
29+
content = b"\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10"
30+
self.instance_api.set_server_user_data(
31+
server_id=self.server.server.id, key=key, content=content
32+
)
33+
user_data = self.instance_api.get_server_user_data(server_id=self.server.server.id, key=key)
34+
self.assertIsNotNone(user_data)
35+
36+
def test_set_and_get_all_user_data(self):
37+
key = "hello"
38+
key_bis = "second key"
39+
content_bis = b"test content"
40+
another_key = "third key"
41+
another_content = b"another content to test"
42+
content = b"you should"
43+
44+
user_data: Dict[str, bytes] = {key_bis:content_bis, another_key:another_content, key:content}
45+
self.instance_api.set_all_server_user_data(server_id=self.server.server.id, user_data=user_data)
46+
response = self.instance_api.get_all_server_user_data(server_id=self.server.server.id)
47+
self.assertIsNotNone(response)

scaleway/scaleway/instance/v1/tests.py

Whitespace-only changes.

0 commit comments

Comments
 (0)