@@ -22,3 +22,94 @@ async def test_notify_allocation():
2222 await vm_client .notify_allocation (vm_id = vm_id )
2323 assert m .requests
2424 await vm_client .session .close ()
25+
26+ @pytest .mark .asyncio
27+ async def test_perform_operation ():
28+ account = ETHAccount (private_key = b"0x" + b"1" * 30 )
29+ vm_id = ItemHash ("cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe" )
30+ operation = "reboot"
31+
32+ with aioresponses () as m :
33+ vm_client = VmClient (
34+ account = account ,
35+ node_url = "http://localhost" ,
36+ session = aiohttp .ClientSession (),
37+ )
38+ m .post (f"http://localhost/control/machine/{ vm_id } /{ operation } " , status = 200 , payload = "mock_response_text" )
39+
40+ status , response_text = await vm_client .perform_operation (vm_id , operation )
41+ assert status == 200
42+ assert response_text == '"mock_response_text"' # ' ' cause by aioresponses
43+ await vm_client .session .close ()
44+
45+ @pytest .mark .asyncio
46+ async def test_stop_instance ():
47+ account = ETHAccount (private_key = b"0x" + b"1" * 30 )
48+ vm_id = ItemHash ("cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe" )
49+
50+ with aioresponses () as m :
51+ vm_client = VmClient (
52+ account = account ,
53+ node_url = "http://localhost" ,
54+ session = aiohttp .ClientSession (),
55+ )
56+ m .post (f"http://localhost/control/machine/{ vm_id } /stop" , status = 200 , payload = "mock_response_text" )
57+
58+ status , response_text = await vm_client .stop_instance (vm_id )
59+ assert status == 200
60+ assert response_text == '"mock_response_text"' # ' ' cause by aioresponses
61+ await vm_client .session .close ()
62+
63+ @pytest .mark .asyncio
64+ async def test_reboot_instance ():
65+ account = ETHAccount (private_key = b"0x" + b"1" * 30 )
66+ vm_id = ItemHash ("cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe" )
67+
68+ with aioresponses () as m :
69+ vm_client = VmClient (
70+ account = account ,
71+ node_url = "http://localhost" ,
72+ session = aiohttp .ClientSession (),
73+ )
74+ m .post (f"http://localhost/control/machine/{ vm_id } /reboot" , status = 200 , payload = "mock_response_text" )
75+
76+ status , response_text = await vm_client .reboot_instance (vm_id )
77+ assert status == 200
78+ assert response_text == '"mock_response_text"' # ' ' cause by aioresponses
79+ await vm_client .session .close ()
80+
81+ @pytest .mark .asyncio
82+ async def test_erase_instance ():
83+ account = ETHAccount (private_key = b"0x" + b"1" * 30 )
84+ vm_id = ItemHash ("cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe" )
85+
86+ with aioresponses () as m :
87+ vm_client = VmClient (
88+ account = account ,
89+ node_url = "http://localhost" ,
90+ session = aiohttp .ClientSession (),
91+ )
92+ m .post (f"http://localhost/control/machine/{ vm_id } /erase" , status = 200 , payload = "mock_response_text" )
93+
94+ status , response_text = await vm_client .erase_instance (vm_id )
95+ assert status == 200
96+ assert response_text == '"mock_response_text"' # ' ' cause by aioresponses
97+ await vm_client .session .close ()
98+
99+ @pytest .mark .asyncio
100+ async def test_expire_instance ():
101+ account = ETHAccount (private_key = b"0x" + b"1" * 30 )
102+ vm_id = ItemHash ("cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe" )
103+
104+ with aioresponses () as m :
105+ vm_client = VmClient (
106+ account = account ,
107+ node_url = "http://localhost" ,
108+ session = aiohttp .ClientSession (),
109+ )
110+ m .post (f"http://localhost/control/machine/{ vm_id } /expire" , status = 200 , payload = "mock_response_text" )
111+
112+ status , response_text = await vm_client .expire_instance (vm_id )
113+ assert status == 200
114+ assert response_text == '"mock_response_text"' # ' ' cause by aioresponses
115+ await vm_client .session .close ()
0 commit comments