import uuid def login_as_new_end_user(test_client): """Register and log in a fresh end user for testing.""" email = f"ticket_{uuid.uuid4().hex[:8]}@example.com" password = "TicketTest123!" # 1) Register resp = test_client.post( "/register", data={ "email": email, "password": password, "confirm_password": password, }, follow_redirects=False, ) assert resp.status_code in (200, 302, 303, 307) # 2) Login resp = test_client.post( "/login", data={"email": email, "password": password}, follow_redirects=False, ) assert resp.status_code in (200, 302, 303, 307) return email def test_end_user_can_create_ticket_and_see_it(test_client): """Smoke test: end user can create a ticket and access ticket history.""" # Log in as a fresh end user (cookies are kept in the same client) login_as_new_end_user(test_client) # 1) Create ticket via the real submission route title = "Printer not working" description = "The printer on floor 2 is offline." resp = test_client.post( "/tickets/new", # NOTE: plural 'tickets' – matches the actual app route data={ "title": title, "description": description, # If your form has extra optional fields like priority/category, # you can include them here, but they are not required for this smoke test. # "priority": "Medium", # "category": "Hardware", }, follow_redirects=False, ) # We just care that the app accepts the request (OK or redirect). assert resp.status_code in (200, 302, 303, 307) # 2) Hit the ticket history route history = test_client.get("/ticket/history") # NOTE: singular 'ticket' – this is the working route # History page should at least load successfully. assert history.status_code == 200 # Soft sanity check: page looks like some sort of ticket list/history, # but we don't rely on the exact ticket description text. assert ("Ticket" in history.text) or ("History" in history.text)