forked from kruize/autotune
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kruize#1372 from msvinaykumar/bulkTestCases
bulk test cases
- Loading branch information
Showing
4 changed files
with
143 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
tests/scripts/local_monitoring_tests/rest_apis/test_bulkAPI.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
""" | ||
Copyright (c) 2024 Red Hat, IBM Corporation and others. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
import logging | ||
import pytest | ||
import requests | ||
import sys | ||
|
||
sys.path.append("../../") | ||
from helpers.fixtures import * | ||
from helpers.kruize import * | ||
from helpers.utils import * | ||
|
||
# Set up logging | ||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@pytest.mark.sanity | ||
@pytest.mark.parametrize("bulk_request_payload, expected_job_id_present", [ | ||
({}, True), # Test with an empty payload to check if a job_id is created. | ||
({ | ||
"filter": { | ||
"exclude": { | ||
"namespace": [], | ||
"workload": [], | ||
"containers": [], | ||
"labels": {} | ||
}, | ||
"include": { | ||
"namespace": [], | ||
"workload": [], | ||
"containers": [], | ||
"labels": {} | ||
} | ||
}, | ||
"time_range": {} | ||
}, True) # Test with a sample payload with some JSON content | ||
]) | ||
def test_bulk_post_request(cluster_type, bulk_request_payload, expected_job_id_present, caplog): | ||
form_kruize_url(cluster_type) | ||
URL = get_kruize_url() | ||
|
||
with caplog.at_level(logging.INFO): | ||
# Log request payload and curl command for POST request | ||
response = post_bulk_api(bulk_request_payload) | ||
|
||
# Check if job_id is present in the response | ||
job_id_present = "job_id" in response.json() and isinstance(response.json()["job_id"], str) | ||
assert job_id_present == expected_job_id_present, f"Expected job_id presence to be {expected_job_id_present} but was {job_id_present}" | ||
|
||
# If a job_id is generated, run the GET request test | ||
if job_id_present: | ||
validate_job_status(response.json()["job_id"], URL, caplog) | ||
|