import requests import time # Base URL for the server BASE_URL = 'http://localhost:5000/status' # Function to send a POST request with status data def send_status(source, status): response = requests.post(BASE_URL, json={"source": source, "status": status}) print(f"Sent {status} for {source}, Response: {response.json()}") # Function to test normal and force send modes for multiple sources def test_server(): sources = ['source1', 'source2', 'source3', 'source4', 'source5'] # Scenario 1: Normal behavior with source1 print("\nScenario 1: Normal behavior with source1") for _ in range(4): send_status('source1', 'OK') for _ in range(5): send_status('source1', 'FAIL') for _ in range(10): send_status('source1', 'OK') for _ in range(10): send_status('source1', 'OK') # Scenario 2: Force send and revert with source2 print("\nScenario 2: Force send and revert with source2") for _ in range(5): send_status('source2', 'FAIL') for _ in range(10): send_status('source2', 'OK') for _ in range(10): send_status('source2', 'OK') # Scenario 3: Random mix with source3 print("\nScenario 3: Random mix with source3") mix = ['OK', 'FAIL', 'OK', 'FAIL', 'OK', 'FAIL', 'OK', 'OK', 'OK', 'OK'] for status in mix: send_status('source3', status) for _ in range(5): send_status('source3', 'FAIL') for _ in range(10): send_status('source3', 'OK') # Scenario 4: Source4 fails and recovers print("\nScenario 4: Source4 fails and recovers") for _ in range(5): send_status('source4', 'FAIL') for _ in range(10): send_status('source4', 'OK') for _ in range(10): send_status('source4', 'OK') # Scenario 5: Source5 normal operation print("\nScenario 5: Source5 normal operation") for _ in range(10): send_status('source5', 'OK') for _ in range(10): send_status('source5', 'OK') if __name__ == '__main__': # Give some time for the server to start time.sleep(2) test_server()