Skip to content

Commit b8b5996

Browse files
test: add basic integration test for CRUD (#339)
**Issue number:** [ADDON-78485](https://splunk.atlassian.net/browse/ADDON-78485) ### PR Type **What kind of change does this PR introduce?** * [ ] Feature * [ ] Bug Fix * [ ] Refactoring (no functional or API changes) * [ ] Documentation Update * [x] Maintenance (dependency updates, CI, etc.) ## Summary ### Changes Add test for basic CRUD operation for RestHandler. ### User experience No impact. ## Checklist If an item doesn't apply to your changes, leave it unchecked. ### Review * [x] self-review - I have performed a self-review of this change according to the [development guidelines](https://splunk.github.io/addonfactory-ucc-generator/contributing/#development-guidelines) * [ ] Changes are documented. The documentation is understandable, examples work [(more info)](https://splunk.github.io/addonfactory-ucc-generator/contributing/#documentation-guidelines) * [x] PR title and description follows the [contributing principles](https://splunk.github.io/addonfactory-ucc-generator/contributing/#pull-requests) * [ ] meeting - I have scheduled a meeting or recorded a demo to explain these changes (if there is a video, put a link below and in the ticket) ### Tests See [the testing doc](https://splunk.github.io/addonfactory-ucc-generator/contributing/#build-and-test). * [ ] Unit - tests have been added/modified to cover the changes * [x] Integration - tests have been added/modified to cover the changes * [ ] Smoke - tests have been added/modified to cover the changes * [ ] UI - tests have been added/modified to cover the changes * [ ] coverage - I have checked the code coverage of my changes [(see more)](https://splunk.github.io/addonfactory-ucc-generator/contributing/#checking-the-code-coverage)
1 parent 3e7fccf commit b8b5996

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

tests/integration/test_rest_handler_handler.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16+
1617
from datetime import datetime
1718
from time import sleep
1819
from typing import List, Any
@@ -48,6 +49,95 @@ def _cookie_header():
4849
return f"splunkd_8000={session_key}"
4950

5051

52+
def test_basic_crud_operations():
53+
"""
54+
Test basic CRUD operations for splunktaucclib.rest_handler.handler.RestHandler
55+
"""
56+
input_name = "atest_in_ok"
57+
58+
# CREATE
59+
response = requests.post(
60+
f"https://{host}:{management_port}/servicesNS/-/demo/demo_demo?output_mode=json",
61+
data={"name": input_name, "interval": "123"},
62+
headers={
63+
"accept": "application/json",
64+
"Content-Type": "application/x-www-form-urlencoded",
65+
},
66+
auth=HTTPBasicAuth(admin, admin_password),
67+
verify=False,
68+
)
69+
assert response.status_code == 201
70+
71+
# GET
72+
response = requests.get(
73+
f"https://{host}:{management_port}/servicesNS/-/demo/demo_demo/{input_name}?output_mode=json",
74+
auth=HTTPBasicAuth(admin, admin_password),
75+
headers={
76+
"accept": "application/json",
77+
"Content-Type": "application/x-www-form-urlencoded",
78+
},
79+
verify=False,
80+
)
81+
entry = response.json().get("entry")
82+
assert len(entry) == 1
83+
assert entry[0].get("name") == input_name
84+
assert entry[0].get("content").get("interval") == "123"
85+
assert response.status_code == 200
86+
87+
# ALL
88+
response = requests.get(
89+
f"https://{host}:{management_port}/servicesNS/-/demo/demo_demo/?output_mode=json",
90+
auth=HTTPBasicAuth(admin, admin_password),
91+
verify=False,
92+
)
93+
entries = response.json().get("entry")
94+
names = [entry.get("name") for entry in entries]
95+
96+
assert len(entries) == 2
97+
assert set(names) == {"test_input", input_name}
98+
assert response.status_code == 200
99+
100+
# UPDATE
101+
new_interval = "111"
102+
response = requests.post(
103+
f"https://{host}:{management_port}/servicesNS/-/demo/demo_demo/{input_name}?output_mode=json",
104+
data={"interval": new_interval},
105+
auth=HTTPBasicAuth(admin, admin_password),
106+
verify=False,
107+
)
108+
109+
entry = response.json().get("entry")
110+
interval = entry[0].get("content").get("interval")
111+
assert response.status_code == 200
112+
assert interval == new_interval
113+
114+
# DELETE
115+
response = requests.delete(
116+
f"https://{host}:{management_port}/servicesNS/-/demo/demo_demo/{input_name}?output_mode=json",
117+
auth=HTTPBasicAuth(admin, admin_password),
118+
verify=False,
119+
)
120+
entry = response.json().get("entry")
121+
122+
assert response.status_code == 200
123+
assert len(entry) == 1
124+
125+
expected_msg = (
126+
f"REST Error [404]: Not Found -- Could not find object id={input_name}"
127+
)
128+
response = requests.get(
129+
f"https://{host}:{management_port}/servicesNS/-/demo/demo_demo/{input_name}?output_mode=json",
130+
auth=HTTPBasicAuth(admin, admin_password),
131+
headers={
132+
"accept": "application/json",
133+
"Content-Type": "application/x-www-form-urlencoded",
134+
},
135+
verify=False,
136+
)
137+
assert response.status_code == 500
138+
assert expected_msg in response.text
139+
140+
51141
def test_inputs_api_call():
52142
try:
53143
response = requests.get(

0 commit comments

Comments
 (0)