-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreset_test_data.py
More file actions
81 lines (70 loc) · 3.3 KB
/
reset_test_data.py
File metadata and controls
81 lines (70 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
Reset Test Data - Cleanup script for test endpoints
This will delete all test data created during endpoint testing
"""
from os import getenv
import requests
import json
# Configuration
BASE_URL = "http://ticketflow-2-n132.onrender.com/api" # change for local/global testing
AUTH_TOKEN = getenv("TEST_AUTH_TOKEN", "YOUR_TOKEN_HERE") # Use the same token from test_endpoints.py
headers = {
"Authorization": f"Bearer {AUTH_TOKEN}",
"Content-Type": "application/json"
}
def delete_test_data():
"""Delete test tickets, employees, categories, and comments"""
print("\n" + "="*60)
print("RESETTING TEST DATA")
print("="*60)
# Get all tickets
response = requests.get(f"{BASE_URL}/tickets/", headers=headers)
if response.status_code == 200:
tickets = response.json()["tickets"]
print(f"\nFound {len(tickets)} tickets to delete...")
for ticket in tickets:
if ticket["ticket_number"].startswith("TICK-"):
print(f"Deleting ticket {ticket['ticket_number']}...")
delete_resp = requests.delete(f"{BASE_URL}/tickets/{ticket['id']}", headers=headers)
if delete_resp.status_code == 200:
print(f" ✅ Deleted {ticket['ticket_number']}")
else:
print(f" ❌ Failed to delete {ticket['ticket_number']}: {delete_resp.status_code}")
# Get all employees
response = requests.get(f"{BASE_URL}/employees/", headers=headers)
if response.status_code == 200:
employees = response.json()["employees"]
print(f"\nFound {len(employees)} employees...")
# Delete test employee (Alice Johnson)
for emp in employees:
if emp["name"] == "Alice Johnson" and emp["email"] == "[email protected]":
print(f"Deleting test employee {emp['name']}...")
delete_resp = requests.delete(f"{BASE_URL}/employees/{emp['id']}", headers=headers)
if delete_resp.status_code == 200:
print(f" ✅ Deleted {emp['name']}")
else:
print(f" ❌ Failed to delete {emp['name']}: {delete_resp.status_code}")
# Get all categories
response = requests.get(f"{BASE_URL}/tickets/categories", headers=headers)
if response.status_code == 200:
categories = response.json()["categories"]
print(f"\nFound {len(categories)} categories...")
# Delete test category (Bug Fix)
for cat in categories:
if cat["name"] == "Bug Fix":
print(f"Deleting test category {cat['name']}...")
delete_resp = requests.delete(f"{BASE_URL}/tickets/categories/{cat['id']}", headers=headers)
if delete_resp.status_code == 200:
print(f" ✅ Deleted {cat['name']}")
else:
print(f" ❌ Failed to delete {cat['name']}: {delete_resp.status_code}")
print("\n" + "="*60)
print("RESET COMPLETE")
print("="*60)
print("\nYou can now re-run test_endpoints.py with a clean slate!")
if __name__ == "__main__":
if AUTH_TOKEN == "YOUR_TOKEN_HERE":
print("\n⚠️ WARNING: Please update AUTH_TOKEN in this script!")
print("Use the same token from test_endpoints.py")
else:
delete_test_data()