|
11 | 11 | base_url, |
12 | 12 | clear_sar, # noqa: F401 |
13 | 13 | create_root_folder, |
14 | | - user_password, # noqa: F401 |
15 | | - user_username, |
16 | 14 | ) |
17 | 15 |
|
18 | 16 | # ============================================================================================= |
|
24 | 22 | @pytest.mark.parametrize("usesetauth", [True, False]) |
25 | 23 | @pytest.mark.parametrize("library", ["THREADS", "ASYNC"]) |
26 | 24 | # fmt: on |
27 | | -def test_config_create_01(clear_sar, library, usesetauth): # noqa: F811 |
| 25 | +def test_tags_01(clear_sar, library, usesetauth): # noqa: F811 |
28 | 26 | """ |
29 | | - Tests for the 'config_create' and 'config_get' API. |
| 27 | + Tests for the 'tags_get', 'tags_add' and 'tags_delete' API. |
30 | 28 | """ |
31 | 29 |
|
32 | 30 | root_folder_uid = create_root_folder() |
33 | 31 |
|
34 | | - pv_list = [ |
35 | | - { |
36 | | - "pvName": "13SIM1:{SimDetector-Cam:1}cam1:BinX" |
37 | | - }, |
38 | | - { |
39 | | - "pvName": "13SIM1:{SimDetector-Cam:1}cam1:BinY", |
40 | | - "comparison": { |
41 | | - "comparisonMode": "ABSOLUTE", |
42 | | - "tolerance": 2.7 |
43 | | - } |
44 | | - }, |
45 | | - { |
46 | | - "pvName": "13SIM1:{SimDetector-Cam:2}cam2:BinX", |
47 | | - "readbackPvName": None, |
48 | | - "readOnly": False, |
49 | | - }, |
50 | | - { |
51 | | - "pvName": "13SIM1:{SimDetector-Cam:2}cam2:BinY", |
52 | | - "readbackPvName": None, |
53 | | - "readOnly": False, |
54 | | - } |
55 | | - ] |
56 | | - |
57 | | - configurationNode = { |
58 | | - "name": "Config", |
59 | | - } |
60 | | - configurationData = { |
61 | | - "pvList": pv_list, |
62 | | - } |
63 | | - |
64 | 32 | if not _is_async(library): |
65 | 33 | with SaveRestoreAPI_Threads(base_url=base_url, timeout=2) as SR: |
66 | 34 | auth = _select_auth(SR=SR, usesetauth=usesetauth) |
67 | 35 |
|
68 | | - response = SR.node_add(root_folder_uid, name="Child Folder", nodeType="FOLDER", **auth) |
| 36 | + response = SR.node_add(root_folder_uid, name="folder", nodeType="FOLDER", **auth) |
69 | 37 | folder_uid = response["uniqueId"] |
70 | 38 |
|
| 39 | + response = SR.config_create( |
| 40 | + folder_uid, configurationNode={"name": "config_1"}, configurationData={"pvList": []}, **auth |
| 41 | + ) |
| 42 | + config_1_uid = response["configurationNode"]["uniqueId"] |
71 | 43 |
|
72 | 44 | response = SR.config_create( |
73 | | - folder_uid, configurationNode=configurationNode, configurationData=configurationData, **auth |
| 45 | + folder_uid, configurationNode={"name": "config_2"}, configurationData={"pvList": []}, **auth |
74 | 46 | ) |
75 | | - assert response["configurationNode"]["name"] == "Config" |
76 | | - assert response["configurationNode"]["nodeType"] == "CONFIGURATION" |
77 | | - assert response["configurationNode"]["userName"] == user_username |
78 | | - assert len(response["configurationData"]["pvList"]) == len(pv_list) |
| 47 | + config_2_uid = response["configurationNode"]["uniqueId"] |
| 48 | + |
| 49 | + tag_1 = {"name": "tag_1"} |
| 50 | + tag_2 = {"name": "tag_2", "comment": "This is tag 2"} |
| 51 | + |
| 52 | + response = SR.tags_get() |
| 53 | + assert len(response) == 0 |
79 | 54 |
|
80 | | - config_uid = response["configurationNode"]["uniqueId"] |
| 55 | + response = SR.tags_add(uniqueNodeIds=[config_1_uid], tag=tag_1, **auth) |
| 56 | + assert len(response) == 1 |
| 57 | + assert response[0]["uniqueId"] == config_1_uid |
| 58 | + assert [_["name"] for _ in response[0]["tags"]] == ["tag_1"] |
81 | 59 |
|
82 | | - response = SR.config_get(config_uid) |
83 | | - assert response["uniqueId"] == config_uid |
84 | | - assert len(response["pvList"]) == len(pv_list) |
| 60 | + response = SR.tags_add(uniqueNodeIds=[config_1_uid, config_2_uid, folder_uid], tag=tag_2, **auth) |
| 61 | + assert len(response) == 3 |
| 62 | + assert response[0]["uniqueId"] == config_1_uid |
| 63 | + assert [_["name"] for _ in response[0]["tags"]] == ["tag_1", "tag_2"] |
| 64 | + assert response[1]["uniqueId"] == config_2_uid |
| 65 | + assert [_["name"] for _ in response[1]["tags"]] == ["tag_2"] |
| 66 | + assert response[2]["uniqueId"] == folder_uid |
| 67 | + assert [_["name"] for _ in response[2]["tags"]] == ["tag_2"] |
85 | 68 |
|
86 | | - response = SR.node_get(config_uid) |
87 | | - assert response["uniqueId"] == config_uid |
88 | | - assert response["name"] == "Config" |
89 | | - assert response["nodeType"] == "CONFIGURATION" |
90 | | - assert response["userName"] == user_username |
| 69 | + response = SR.tags_get() # Returns the list of ALL tags |
| 70 | + assert len(response) == 4 |
| 71 | + |
| 72 | + response = SR.tags_delete(uniqueNodeIds=[config_1_uid, folder_uid], tag={"name": "tag_2"}, **auth) |
| 73 | + assert len(response) == 2 |
| 74 | + assert response[0]["uniqueId"] == config_1_uid |
| 75 | + assert [_["name"] for _ in response[0]["tags"]] == ["tag_1"] |
| 76 | + assert response[1]["uniqueId"] == folder_uid |
| 77 | + assert [_["name"] for _ in response[1]["tags"]] == [] |
| 78 | + |
| 79 | + response = SR.tags_get() |
| 80 | + assert len(response) == 2 |
91 | 81 |
|
92 | 82 | else: |
93 | 83 | async def testing(): |
94 | 84 | async with SaveRestoreAPI_Async(base_url=base_url, timeout=2) as SR: |
95 | 85 | auth = _select_auth(SR=SR, usesetauth=usesetauth) |
96 | 86 |
|
97 | | - response = await SR.node_add(root_folder_uid, name="Child Folder", nodeType="FOLDER", **auth) |
| 87 | + response = await SR.node_add(root_folder_uid, name="folder", nodeType="FOLDER", **auth) |
98 | 88 | folder_uid = response["uniqueId"] |
99 | 89 |
|
100 | 90 | response = await SR.config_create( |
101 | | - folder_uid, configurationNode=configurationNode, configurationData=configurationData, **auth |
| 91 | + folder_uid, configurationNode={"name": "config_1"}, configurationData={"pvList": []}, **auth |
| 92 | + ) |
| 93 | + config_1_uid = response["configurationNode"]["uniqueId"] |
| 94 | + |
| 95 | + response = await SR.config_create( |
| 96 | + folder_uid, configurationNode={"name": "config_2"}, configurationData={"pvList": []}, **auth |
102 | 97 | ) |
103 | | - assert response["configurationNode"]["name"] == "Config" |
104 | | - assert response["configurationNode"]["nodeType"] == "CONFIGURATION" |
105 | | - assert response["configurationNode"]["userName"] == user_username |
106 | | - assert len(response["configurationData"]["pvList"]) == len(pv_list) |
107 | | - |
108 | | - config_uid = response["configurationNode"]["uniqueId"] |
109 | | - |
110 | | - response = await SR.config_get(config_uid) |
111 | | - assert response["uniqueId"] == config_uid |
112 | | - assert len(response["pvList"]) == len(pv_list) |
113 | | - |
114 | | - response = await SR.node_get(config_uid) |
115 | | - assert response["uniqueId"] == config_uid |
116 | | - assert response["name"] == "Config" |
117 | | - assert response["nodeType"] == "CONFIGURATION" |
118 | | - assert response["userName"] == user_username |
| 98 | + config_2_uid = response["configurationNode"]["uniqueId"] |
| 99 | + |
| 100 | + tag_1 = {"name": "tag_1"} |
| 101 | + tag_2 = {"name": "tag_2", "comment": "This is tag 2"} |
| 102 | + |
| 103 | + response = await SR.tags_get() |
| 104 | + assert len(response) == 0 |
| 105 | + |
| 106 | + response = await SR.tags_add(uniqueNodeIds=[config_1_uid], tag=tag_1, **auth) |
| 107 | + assert len(response) == 1 |
| 108 | + assert response[0]["uniqueId"] == config_1_uid |
| 109 | + assert [_["name"] for _ in response[0]["tags"]] == ["tag_1"] |
| 110 | + |
| 111 | + response = await SR.tags_add( |
| 112 | + uniqueNodeIds=[config_1_uid, config_2_uid, folder_uid], tag=tag_2, **auth |
| 113 | + ) |
| 114 | + assert len(response) == 3 |
| 115 | + assert response[0]["uniqueId"] == config_1_uid |
| 116 | + assert [_["name"] for _ in response[0]["tags"]] == ["tag_1", "tag_2"] |
| 117 | + assert response[1]["uniqueId"] == config_2_uid |
| 118 | + assert [_["name"] for _ in response[1]["tags"]] == ["tag_2"] |
| 119 | + assert response[2]["uniqueId"] == folder_uid |
| 120 | + assert [_["name"] for _ in response[2]["tags"]] == ["tag_2"] |
| 121 | + |
| 122 | + response = await SR.tags_get() # Returns the list of ALL tags |
| 123 | + assert len(response) == 4 |
| 124 | + |
| 125 | + response = await SR.tags_delete( |
| 126 | + uniqueNodeIds=[config_1_uid, folder_uid], tag={"name": "tag_2"}, **auth |
| 127 | + ) |
| 128 | + assert len(response) == 2 |
| 129 | + assert response[0]["uniqueId"] == config_1_uid |
| 130 | + assert [_["name"] for _ in response[0]["tags"]] == ["tag_1"] |
| 131 | + assert response[1]["uniqueId"] == folder_uid |
| 132 | + assert [_["name"] for _ in response[1]["tags"]] == [] |
| 133 | + |
| 134 | + response = await SR.tags_get() |
| 135 | + assert len(response) == 2 |
| 136 | + |
119 | 137 |
|
120 | 138 | asyncio.run(testing()) |
0 commit comments