Clean up testfunctions.ipynb by removing redundant code
Removed outdated and unused code snippets from testfunctions.ipynb to streamline the notebook. This improves readability and reduces clutter, ensuring the file contains only relevant and functional code samples.
This commit is contained in:
parent
51ac892c1f
commit
17a8933597
@ -4,9 +4,21 @@ from backend.main import app
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def test_create_contact_success():
|
||||
def authenticate(client):
|
||||
response = client.post(
|
||||
"/contact",
|
||||
"/auth/login", json={"username": "testuser", "password": "testpassword"}
|
||||
)
|
||||
assert response.status_code == 200
|
||||
return response.json()["access_token"]
|
||||
|
||||
|
||||
def test_create_contact_success():
|
||||
token = authenticate(client)
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
|
||||
response = client.post(
|
||||
"/protected/contacts",
|
||||
headers=headers,
|
||||
json={
|
||||
"pgroups": "p20001",
|
||||
"firstname": "John",
|
||||
@ -15,7 +27,6 @@ def test_create_contact_success():
|
||||
"phone_number": "+000000000",
|
||||
},
|
||||
)
|
||||
# Assert success and verify response structure
|
||||
assert response.status_code == 201
|
||||
json_response = response.json()
|
||||
assert json_response["firstname"] == "John"
|
||||
@ -23,6 +34,22 @@ def test_create_contact_success():
|
||||
assert json_response["email"] == "john.rambo@example.com"
|
||||
|
||||
|
||||
def test_create_contact_unauthorized():
|
||||
# Omit Authorization header to simulate unauthorized access
|
||||
response = client.post(
|
||||
"/protected/contacts",
|
||||
json={
|
||||
"pgroups": "p20001",
|
||||
"firstname": "John",
|
||||
"lastname": "Rambo",
|
||||
"email": "john.rambo@example.com",
|
||||
"phone_number": "+000000000",
|
||||
},
|
||||
)
|
||||
assert response.status_code == 401
|
||||
assert response.json()["detail"] == "Not authenticated"
|
||||
|
||||
|
||||
def test_create_contact_already_exists():
|
||||
# Ensure that the route fails gracefully if contact exists
|
||||
client.post(
|
||||
|
Loading…
x
Reference in New Issue
Block a user