For context, the app I built lets users paste in a GitHub URL and a job description. Then, it generates resume bullet points and interview practice questions.
I added automated unit tests for the backend to learn the basics of Pytest and so that I wouldn’t have to keep testing it manually.
View the full code here.
Test Cases
- All payload fields are valid
- Invalid URL
- Empty job description field
- Missing keywords
- Missing required fields (GitHub URL and job description)
Pytest
I defined a function for each test case. Here is the code I used for the first test case, which runs the app when all the payload fields are valid.
def test_valid_request():
payload = {
"repo_url": "https://github.com/erinjhu/project-summarizer",
"job_description": "software engineer",
"company_info": "waterloo",
"interviewer_info": "Erin Hu",
"ref_questions": "",
"keywords": ["automation", "testing"],
"complexity": 5,
"stats": 5,
"custom": "",
"create_proj_notes": True,
"create_role_notes": False,
"create_company_notes": False,
"create_interviewer_questions": False,
"create_interview_practice": True
}
response = client.post("/create-interview-prep", json=payload)
print(response.json())
assert response.status_code == 200
assert "practice_questions" in response.json()How the test case works
- Python dictionary for the payload
- Store key-value pairs for the fields that the user inputs
- These fields include the information about the job, along with what information the user wants the app to generate
- Store the response in a variable
- The payload is sent into the backend (built with FastAPI) as an HTTP POST request
- Use
json=payloadso that the payload is sent as a JSON, which is compatible with FastAPI - The backend passes the data through the Gemini API to generate the information the user wanted (e.g. project notes, interview practice questions)
- Check the response using assertions
- Assert that the HTTP status code is 200 to indicate that the request was successful
- Assert that the response contains interview practice questions because that was what the user asked for in the payload