Skip to content

Commit

Permalink
Create test_api.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bufanoc authored Dec 23, 2024
1 parent 064bf40 commit 611771b
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions backend/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import requests
import json

BASE_URL = 'http://localhost:5000/api'

def test_health():
response = requests.get(f'{BASE_URL}/health')
print('Health Check:', response.json())

def test_logical_switches():
# List switches
print('\n=== Testing Logical Switches ===')
response = requests.get(f'{BASE_URL}/logical-switches')
print('List Switches:', response.json())

# Create switch
switch_data = {
'name': 'test-switch',
'external_ids': {'description': 'Test switch'}
}
response = requests.post(f'{BASE_URL}/logical-switches', json=switch_data)
print('Create Switch:', response.json())

if response.status_code == 201:
switch_id = response.json().get('name')

# Get switch details
response = requests.get(f'{BASE_URL}/logical-switches/{switch_id}')
print('Get Switch:', response.json())

# Delete switch
response = requests.delete(f'{BASE_URL}/logical-switches/{switch_id}')
print('Delete Switch Status:', response.status_code)

def main():
try:
test_health()
test_logical_switches()
except requests.exceptions.ConnectionError:
print("Error: Could not connect to the backend server. Make sure it's running on port 5000")
except Exception as e:
print(f"Error occurred: {str(e)}")

if __name__ == '__main__':
main()

0 comments on commit 611771b

Please sign in to comment.