Code indexing in gitaly is broken and leads to code not being visible to the user. We work on the issue with highest priority.

Skip to content
Snippets Groups Projects
Commit 546c5702 authored by GotthardG's avatar GotthardG
Browse files

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.
parent b63f6965
No related branches found
No related tags found
No related merge requests found
Pipeline #48338 passed
from fastapi.testclient import TestClient
from backend.main import app
client = TestClient(app)
def test_create_contact_success():
response = client.post(
"/contact",
json={
"pgroups": "p20001",
"firstname": "John",
"lastname": "Rambo",
"email": "john.rambo@example.com",
"phone_number": "+000000000",
},
)
# Assert success and verify response structure
assert response.status_code == 201
json_response = response.json()
assert json_response["firstname"] == "John"
assert json_response["lastname"] == "Rambo"
assert json_response["email"] == "john.rambo@example.com"
def test_create_contact_already_exists():
# Ensure that the route fails gracefully if contact exists
client.post(
"/contact",
json={
"pgroups": "p20001",
"firstname": "John",
"lastname": "Rambo",
"email": "john.rambo@example.com",
"phone_number": "+000000000",
},
)
response = client.post(
"/contact",
json={
"pgroups": "p20001",
"firstname": "John",
"lastname": "Rambo",
"email": "john.rambo@example.com",
"phone_number": "+000000000",
},
)
assert response.status_code == 400
assert (
response.json()["detail"]
== "This contact already exists in the provided pgroup."
)
def test_get_active_contacts():
# Seed with some test data
client.post(
"/contact",
json={
"pgroups": "p20001",
"firstname": "John",
"lastname": "Rambo",
"email": "john.rambo@example.com",
"phone_number": "+000000000",
},
)
response = client.get("/contacts", params={"active_pgroup": "p20001"})
assert response.status_code == 200
json_response = response.json()
assert isinstance(json_response, list)
assert json_response[0]["firstname"] == "John"
assert json_response[0]["lastname"] == "Rambo"
def test_get_contacts_invalid_pgroup():
response = client.get("/contacts", params={"active_pgroup": "invalid_pgroup"})
assert response.status_code == 400
assert response.json()["detail"] == "Invalid pgroup provided."
def test_update_contact_success():
# Create a contact first
contact = client.post(
"/contact",
json={
"pgroups": "p20001",
"firstname": "John",
"lastname": "Rambo",
"email": "john.rambo@example.com",
"phone_number": "+000000000",
},
).json()
response = client.put(
f"/contacts/{contact['id']}",
json={
"firstname": "Johnny",
"lastname": "Ramboski",
"pgroups": "p20001",
},
)
assert response.status_code == 200
json_response = response.json()
assert json_response["firstname"] == "Johnny"
assert json_response["lastname"] == "Ramboski"
def test_delete_contact():
# Create a contact first
contact = client.post(
"/contact",
json={
"pgroups": "p20001",
"firstname": "John",
"lastname": "Rambo",
"email": "john.rambo@example.com",
"phone_number": "+000000000",
},
).json()
response = client.delete(f"/contacts/{contact['id']}")
assert response.status_code == 204
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment