Software Engineering Project
Milestone 5: API Tests Milestone 5: API Tests
Submitted by:
Jan ‘25 - Team 43
Name Roll Number
Prabhjeet Singh Maini 21f1006130
Ashok Killo 22f2000765
DHRUV PANDEY 21f1005911
N SENTHILKUMAR 21f1006434
SOUNATH MUKHERJEE 22f3001107
VIKAS JAISWAL 21f1006140
Away
VIVEK THOMAS 21f1005436
Submitted on:
19/03/2025
IITM BS Degree Program
Indian Institute of Technology, Madras, Chennai Tamil Nadu, India, 600036
1. Authentication API Tests
Description
These tests validate the endpoints related to user authentication, including registration and
login.
Endpoint: /auth/login
Method: POST
Test Cases
1. Test User Login (Valid Credentials)
● Inputs:
{
"email": "test@example.com",
"password": "password"
}
● Expected Output:
○ Status Code: 200
● JSON Response:
{
"access_token": "<generated_token>",
"user_info": {
"id": "<user_id>",
"name": "Test Student",
"email": "test@example.com",
"roles": ["Student"]
}
}
● Actual Output: Matches expected output
● Result: Passed
● Code:
def test_user_login_success(self, client, db, sample_student):
payload = {"email": "test@example.com", "password": "password"}
sample_student.user.save_password_hash(payload["password"])
response = client.post("/api/v1/auth/login", json=payload)
assert response.status_code == 200
assert "access_token" in response.get_json()
2. Test User Login (Invalid Email Format)
● Inputs:
{
"email": "invalid-email",
"password": "password123"
}
● Expected Output:
○ Status Code: 400
JSON Response:
{
"message": "Invalid email format"
}
● Actual Output: Matches expected output
● Result: Passed
2. Assignments API Tests
Description
These tests validate the endpoints related to assignments, including fetching and submitting
assignments.
Endpoint: /assignments/course/{course_id}
Method: GET
Test Cases
1. Test Fetch Assignments for a Course
● Inputs: { course_id: "CS101" }
● Expected Output:
○ Status Code: 200
○ JSON Response:
[
{ "id": "1", "title": "Assignment 1" },
{ "id": "2", "title": "Assignment 2" }
]
● Actual Output: Matches expected output
● Result: Passed
● Code:
def test_fetch_assignments_valid_course(self, client):
response = client.get("/assignments/course/CS101")
assert response.status_code == 200
assert "assignments" in response.get_json()
2. Test Fetch Assignments for an Invalid Course ID
● Inputs: { course_id: "INVALID" }
● Expected Output:
○ Status Code: 404
○ JSON Response:
{
"message": "Course not found"
}
● Actual Output: Matches expected output
● Result: Passed
3. Chat API Tests
Description
These tests validate the chat API endpoints.
Endpoint: /chat/start
Method: POST
Test Cases
1. Test Start a New Chat
● Inputs:
{
"message": "Hello!"
}
● Expected Output:
○ Status Code: 200
○ JSON Response:
{
"chat_id": "12345",
"message": "Hello!"
}
● Actual Output: Matches expected output
● Result: Passed
2. Test Start a Chat with Empty Message
● Inputs: {}
● Expected Output:
○ Status Code: 400
○ JSON Response:
{
"message": "Message content cannot be empty"
● Actual Output: Matches expected output
● Result: Passed
4. Courses API Tests
Description
These tests validate the endpoints related to courses, including fetching course details.
Endpoint: /courses/{id}
Method: GET
Test Cases
1. Test Fetch Course by ID
● Inputs: { id: "CS101" }
● Expected Output:
○ Status Code: 200
○ JSON Response:
{
"id": "CS101",
"name": "Introduction to Computer Science"
}
● Actual Output: Matches expected output
● Result: Passed
2. Test Fetch Course with Invalid ID
● Inputs: { id: "INVALID" }
● Expected Output:
○ Status Code: 404
○ JSON Response:
{
"message": "Course not found"
}
● Actual Output: Matches expected output
● Result: Passed