forked from proxmoxer/proxmoxer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_local.py
56 lines (38 loc) · 1.42 KB
/
test_local.py
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
import tempfile
from proxmoxer.backends import local
# pylint: disable=no-self-use
class TestLocalBackend:
def test_init(self):
back = local.Backend()
assert isinstance(back.session, local.LocalSession)
class TestLocalSession:
_session = local.LocalSession()
def test_upload_file_obj(self):
size = 100
with tempfile.NamedTemporaryFile("w+b") as f_obj, tempfile.NamedTemporaryFile(
"rb"
) as dest_obj:
f_obj.write(b"a" * size)
f_obj.seek(0)
self._session.upload_file_obj(f_obj, dest_obj.name)
# reset file cursor to start of file after copy
f_obj.seek(0)
assert f_obj.read() == dest_obj.read()
def test_upload_file_obj_end(self):
size = 100
with tempfile.NamedTemporaryFile("w+b") as f_obj, tempfile.NamedTemporaryFile(
"rb"
) as dest_obj:
f_obj.write(b"a" * size)
# do not seek to start of file before copy
self._session.upload_file_obj(f_obj, dest_obj.name)
assert b"" == dest_obj.read()
def test_exec(self):
cmd = [
"python3",
"-c",
'import sys; sys.stdout.write("stdout content"); sys.stderr.write("stderr content")',
]
stdout, stderr = self._session._exec(cmd)
assert stdout == "stdout content"
assert stderr == "stderr content"