|
11 | 11 |
|
12 | 12 | from .common import ( |
13 | 13 | _is_async, |
| 14 | + _select_auth, |
14 | 15 | admin_password, |
15 | 16 | admin_username, |
16 | 17 | base_url, |
17 | 18 | clear_sar, # noqa: F401 |
| 19 | + create_root_folder, |
18 | 20 | read_password, |
19 | 21 | read_username, |
20 | 22 | user_password, |
@@ -119,6 +121,77 @@ async def testing(): |
119 | 121 | asyncio.run(testing()) |
120 | 122 |
|
121 | 123 |
|
| 124 | +# ============================================================================================= |
| 125 | +# TESTS FOR SEARCH-CONTROLLER API METHODS |
| 126 | +# ============================================================================================= |
| 127 | + |
| 128 | +# fmt: off |
| 129 | +@pytest.mark.parametrize("library", ["THREADS", "ASYNC"]) |
| 130 | +# fmt: on |
| 131 | +def test_search_01(clear_sar, library): # noqa: F811 |
| 132 | + """ |
| 133 | + Tests for the 'search' API. |
| 134 | + """ |
| 135 | + root_folder_uid = create_root_folder() |
| 136 | + |
| 137 | + if not _is_async(library): |
| 138 | + with SaveRestoreAPI_Threads(base_url=base_url, timeout=2) as SR: |
| 139 | + _select_auth(SR=SR, usesetauth=True) |
| 140 | + |
| 141 | + configurationNode = {"name": "Test Config", "description": "Created for testing"} |
| 142 | + configurationData = {"pvList": []} |
| 143 | + |
| 144 | + response = SR.config_create( |
| 145 | + root_folder_uid, |
| 146 | + configurationNode=configurationNode, |
| 147 | + configurationData=configurationData, |
| 148 | + ) |
| 149 | + config_uid = response["configurationNode"]["uniqueId"] |
| 150 | + |
| 151 | + response = SR.search({"name": "Test Config"}) |
| 152 | + assert response["hitCount"] == 1 |
| 153 | + assert response["nodes"][0]["name"] == "Test Config" |
| 154 | + assert response["nodes"][0]["uniqueId"] == config_uid |
| 155 | + |
| 156 | + response = SR.search({"description": "for testing"}) |
| 157 | + assert response["hitCount"] == 1 |
| 158 | + assert response["nodes"][0]["name"] == "Test Config" |
| 159 | + assert response["nodes"][0]["uniqueId"] == config_uid |
| 160 | + |
| 161 | + response = SR.search({"name": "No such config"}) |
| 162 | + assert response["hitCount"] == 0 |
| 163 | + |
| 164 | + else: |
| 165 | + async def testing(): |
| 166 | + async with SaveRestoreAPI_Async(base_url=base_url, timeout=2) as SR: |
| 167 | + _select_auth(SR=SR, usesetauth=True) |
| 168 | + |
| 169 | + configurationNode = {"name": "Test Config", "description": "Created for testing"} |
| 170 | + configurationData = {"pvList": []} |
| 171 | + |
| 172 | + response = await SR.config_create( |
| 173 | + root_folder_uid, |
| 174 | + configurationNode=configurationNode, |
| 175 | + configurationData=configurationData, |
| 176 | + ) |
| 177 | + config_uid = response["configurationNode"]["uniqueId"] |
| 178 | + |
| 179 | + response = await SR.search({"name": "Test Config"}) |
| 180 | + assert response["hitCount"] == 1 |
| 181 | + assert response["nodes"][0]["name"] == "Test Config" |
| 182 | + assert response["nodes"][0]["uniqueId"] == config_uid |
| 183 | + |
| 184 | + response = await SR.search({"description": "for testing"}) |
| 185 | + assert response["hitCount"] == 1 |
| 186 | + assert response["nodes"][0]["name"] == "Test Config" |
| 187 | + assert response["nodes"][0]["uniqueId"] == config_uid |
| 188 | + |
| 189 | + response = await SR.search({"name": "No such config"}) |
| 190 | + assert response["hitCount"] == 0 |
| 191 | + |
| 192 | + asyncio.run(testing()) |
| 193 | + |
| 194 | + |
122 | 195 | # ============================================================================================= |
123 | 196 | # TESTS FOR AUTHENTICATION-CONTROLLER API METHODS |
124 | 197 | # ============================================================================================= |
|
0 commit comments