99from save_and_restore_api import SaveRestoreAPI as SaveRestoreAPI_Threads
1010from save_and_restore_api .aio import SaveRestoreAPI as SaveRestoreAPI_Async
1111
12- from .common import _is_async
13-
14- admin_username , admin_password = "admin" , "adminPass"
15- user_username , user_password = "user" , "userPass"
16- read_username , read_password = "johndoe" , "1234"
17-
18- base_url = "http://localhost:8080/save-restore"
12+ from .common import (
13+ _is_async ,
14+ admin_password ,
15+ admin_username ,
16+ base_url ,
17+ clear_sar , # noqa: F401
18+ read_password ,
19+ read_username ,
20+ user_password ,
21+ user_username ,
22+ )
1923
2024
2125def test_version_01 ():
@@ -77,7 +81,6 @@ def test_login_01(username, password, roles, library, code):
7781 """
7882 if not _is_async (library ):
7983 with SaveRestoreAPI_Threads (base_url = base_url , timeout = 2 ) as SR :
80- SR .open ()
8184 if code == 200 :
8285 response = SR .login (username = username , password = password )
8386 assert response ["userName" ] == username
@@ -88,7 +91,6 @@ def test_login_01(username, password, roles, library, code):
8891 else :
8992 async def testing ():
9093 async with SaveRestoreAPI_Async (base_url = base_url , timeout = 2 ) as SR :
91- SR .open ()
9294 if code == 200 :
9395 response = await SR .login (username = username , password = password )
9496 assert response ["userName" ] == username
@@ -107,13 +109,12 @@ async def testing():
107109 ("abc" , 404 ),
108110])
109111# fmt: on
110- def test_get_node_01 (node_uid , library , code ):
112+ def test_get_node_01 (clear_sar , node_uid , library , code ): # noqa: F811
111113 """
112114 Tests for the 'login' API.
113115 """
114116 if not _is_async (library ):
115117 with SaveRestoreAPI_Threads (base_url = base_url , timeout = 2 ) as SR :
116- SR .open ()
117118 if code == 200 :
118119 response = SR .get_node (node_uid )
119120 assert response ["uniqueId" ] == node_uid
@@ -123,7 +124,6 @@ def test_get_node_01(node_uid, library, code):
123124 else :
124125 async def testing ():
125126 async with SaveRestoreAPI_Async (base_url = base_url , timeout = 2 ) as SR :
126- SR .open ()
127127 if code == 200 :
128128 response = await SR .get_node (node_uid )
129129 assert response ["uniqueId" ] == node_uid
@@ -134,8 +134,62 @@ async def testing():
134134 asyncio .run (testing ())
135135
136136
137+ # fmt: off
138+ @pytest .mark .parametrize ("library" , ["THREADS" , "ASYNC" ])
139+ # fmt: on
140+ def test_add_node_01 (clear_sar , library ): # noqa: F811
141+ """
142+ Tests for the 'add_node' API.
143+ """
144+ if not _is_async (library ):
145+ with SaveRestoreAPI_Threads (base_url = base_url , timeout = 2 ) as SR :
146+ SR .set_auth (username = user_username , password = user_password )
147+
148+ response = SR .add_node (SR .ROOT_NODE_UID , name = "Test Folder" , nodeType = "FOLDER" )
149+ assert response ["name" ] == "Test Folder"
150+ assert response ["nodeType" ] == "FOLDER"
151+ folder_uid = response ["uniqueId" ]
152+
153+ response = SR .add_node (folder_uid , name = "Test Config 1" , nodeType = "CONFIGURATION" )
154+ assert response ["name" ] == "Test Config 1"
155+ assert response ["nodeType" ] == "CONFIGURATION"
156+ node_uid_1 = response ["uniqueId" ]
157+
158+ response = SR .add_node (folder_uid , name = "Test Config 2" , nodeType = "CONFIGURATION" )
159+ assert response ["name" ] == "Test Config 2"
160+ assert response ["nodeType" ] == "CONFIGURATION"
161+ node_uid_2 = response ["uniqueId" ]
162+
163+ SR .delete_nodes ([node_uid_1 , node_uid_2 ])
164+ SR .delete_nodes ([folder_uid ])
165+
166+ else :
167+ async def testing ():
168+ async with SaveRestoreAPI_Async (base_url = base_url , timeout = 2 ) as SR :
169+ SR .set_auth (username = user_username , password = user_password )
170+
171+ response = await SR .add_node (SR .ROOT_NODE_UID , name = "Test Folder" , nodeType = "FOLDER" )
172+ assert response ["name" ] == "Test Folder"
173+ assert response ["nodeType" ] == "FOLDER"
174+ folder_uid = response ["uniqueId" ]
175+
176+ response = await SR .add_node (folder_uid , name = "Test Config 1" , nodeType = "CONFIGURATION" )
177+ assert response ["name" ] == "Test Config 1"
178+ assert response ["nodeType" ] == "CONFIGURATION"
179+ node_uid_1 = response ["uniqueId" ]
180+
181+ response = await SR .add_node (folder_uid , name = "Test Config 2" , nodeType = "CONFIGURATION" )
182+ assert response ["name" ] == "Test Config 2"
183+ assert response ["nodeType" ] == "CONFIGURATION"
184+ node_uid_2 = response ["uniqueId" ]
185+
186+ await SR .delete_nodes ([node_uid_1 , node_uid_2 ])
187+ await SR .delete_nodes ([folder_uid ])
188+
189+ asyncio .run (testing ())
190+
137191
138- def test_comm ():
192+ def test_comm (clear_sar ): # noqa: F811
139193 SR = SaveRestoreAPI_Threads (base_url = base_url , timeout = 2 )
140194 SR .set_auth (username = user_username , password = user_password )
141195 SR .open ()
0 commit comments