Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions tests/integration/test_rest_handler_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

from datetime import datetime
from time import sleep
from typing import List, Any
Expand Down Expand Up @@ -48,6 +49,95 @@ def _cookie_header():
return f"splunkd_8000={session_key}"


def test_basic_crud_operations():
"""
Test basic CRUD operations for splunktaucclib.rest_handler.handler.RestHandler
"""
input_name = "atest_in_ok"

# CREATE
response = requests.post(
f"https://{host}:{management_port}/servicesNS/-/demo/demo_demo?output_mode=json",
data={"name": input_name, "interval": "123"},
headers={
"accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
},
auth=HTTPBasicAuth(admin, admin_password),
verify=False,
)
assert response.status_code == 201

# GET
response = requests.get(
f"https://{host}:{management_port}/servicesNS/-/demo/demo_demo/{input_name}?output_mode=json",
auth=HTTPBasicAuth(admin, admin_password),
headers={
"accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
},
verify=False,
)
entry = response.json().get("entry")
assert len(entry) == 1
assert entry[0].get("name") == input_name
assert entry[0].get("content").get("interval") == "123"
assert response.status_code == 200

# ALL
response = requests.get(
f"https://{host}:{management_port}/servicesNS/-/demo/demo_demo/?output_mode=json",
auth=HTTPBasicAuth(admin, admin_password),
verify=False,
)
entries = response.json().get("entry")
names = [entry.get("name") for entry in entries]

assert len(entries) == 2
assert set(names) == {"test_input", input_name}
assert response.status_code == 200

# UPDATE
new_interval = "111"
response = requests.post(
f"https://{host}:{management_port}/servicesNS/-/demo/demo_demo/{input_name}?output_mode=json",
data={"interval": new_interval},
auth=HTTPBasicAuth(admin, admin_password),
verify=False,
)

entry = response.json().get("entry")
interval = entry[0].get("content").get("interval")
assert response.status_code == 200
assert interval == new_interval

# DELETE
response = requests.delete(
f"https://{host}:{management_port}/servicesNS/-/demo/demo_demo/{input_name}?output_mode=json",
auth=HTTPBasicAuth(admin, admin_password),
verify=False,
)
entry = response.json().get("entry")

assert response.status_code == 200
assert len(entry) == 1

expected_msg = (
f"REST Error [404]: Not Found -- Could not find object id={input_name}"
)
response = requests.get(
f"https://{host}:{management_port}/servicesNS/-/demo/demo_demo/{input_name}?output_mode=json",
auth=HTTPBasicAuth(admin, admin_password),
headers={
"accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
},
verify=False,
)
assert response.status_code == 500
assert expected_msg in response.text


def test_inputs_api_call():
try:
response = requests.get(
Expand Down
Loading