forked from keploy/samples-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_app.py
More file actions
32 lines (25 loc) · 870 Bytes
/
Copy pathtest_app.py
File metadata and controls
32 lines (25 loc) · 870 Bytes
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
import pytest
from flask import Flask, json
from pymongo import MongoClient
from app import app as flask_app # Assuming your Flask app is saved as app.py
@pytest.fixture
def client():
with flask_app.test_client() as client:
yield client
def test_get_nonexistent_student(client):
student_id = '999'
response = client.get(f'/students/{student_id}')
assert response.status_code == 200
data = json.loads(response.data)
assert data is None
def test_update_nonexistent_student(client):
student_id = '999'
updated_student = {
"name": "Nonexistent Student",
"age": 30,
"major": "Physics"
}
response = client.put(f'/students/{student_id}', json=updated_student)
assert response.status_code == 200
data = json.loads(response.data)
assert data["message"] == "Student updated successfully"