|
|
|
@ -19,27 +19,37 @@ def add_test_image(token):
|
|
|
|
|
)
|
|
|
|
|
return response.json()["id"]
|
|
|
|
|
|
|
|
|
|
def create_test_pin(token, user_id, image_id=None):
|
|
|
|
|
def create_test_pin(token, user_id, image_id=None, with_date=False):
|
|
|
|
|
if image_id is None:
|
|
|
|
|
image_id = add_test_image(token)
|
|
|
|
|
|
|
|
|
|
pin_data = {
|
|
|
|
|
"title": "Test Pin",
|
|
|
|
|
"description": "Test Description",
|
|
|
|
|
"location": [0,0],
|
|
|
|
|
"files": [image_id],
|
|
|
|
|
"user_id": user_id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if with_date:
|
|
|
|
|
pin_data["date"] = "2024-03-20T12:00:00"
|
|
|
|
|
|
|
|
|
|
response = client.post(
|
|
|
|
|
"/pin/add",
|
|
|
|
|
json={
|
|
|
|
|
"title": "Test Pin",
|
|
|
|
|
"description": "Test Description",
|
|
|
|
|
"location": [0,0],
|
|
|
|
|
"files": [image_id],
|
|
|
|
|
"user_id": user_id
|
|
|
|
|
},
|
|
|
|
|
json=pin_data,
|
|
|
|
|
headers={"Authorization": f"Bearer {token}"}
|
|
|
|
|
)
|
|
|
|
|
return response.json()["id"]
|
|
|
|
|
|
|
|
|
|
def test_add_pin(token, user_id):
|
|
|
|
|
# Test sans date
|
|
|
|
|
image_id = add_test_image(token)
|
|
|
|
|
pin_id = create_test_pin(token, user_id, image_id)
|
|
|
|
|
assert pin_id is not None
|
|
|
|
|
|
|
|
|
|
# Test avec date
|
|
|
|
|
pin_id_with_date = create_test_pin(token, user_id, image_id, with_date=True)
|
|
|
|
|
assert pin_id_with_date is not None
|
|
|
|
|
|
|
|
|
|
def test_add_pin_invalid_files_format(token, user_id):
|
|
|
|
|
response = client.post(
|
|
|
|
@ -63,6 +73,7 @@ def test_list_pins(token):
|
|
|
|
|
assert isinstance(data, list)
|
|
|
|
|
|
|
|
|
|
def test_get_pin(token, user_id):
|
|
|
|
|
# Test sans date
|
|
|
|
|
image_id = add_test_image(token)
|
|
|
|
|
pin_id = create_test_pin(token, user_id, image_id)
|
|
|
|
|
|
|
|
|
@ -76,6 +87,17 @@ def test_get_pin(token, user_id):
|
|
|
|
|
assert data["description"] == "Test Description"
|
|
|
|
|
assert data["location"] == [0,0]
|
|
|
|
|
assert image_id in data["files"]
|
|
|
|
|
assert "date" not in data
|
|
|
|
|
|
|
|
|
|
# Test avec date
|
|
|
|
|
pin_id_with_date = create_test_pin(token, user_id, image_id, with_date=True)
|
|
|
|
|
response = client.get(
|
|
|
|
|
f"/pin/{pin_id_with_date}",
|
|
|
|
|
headers={"Authorization": f"Bearer {token}"}
|
|
|
|
|
)
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
data = response.json()
|
|
|
|
|
assert data["date"] == "2024-03-20T12:00:00"
|
|
|
|
|
|
|
|
|
|
def test_get_pin_wrong_format(token):
|
|
|
|
|
response = client.get(f"/pin/randomIdThatDoesntExists", headers={"Authorization": f"Bearer {token}"})
|
|
|
|
@ -89,6 +111,7 @@ def test_update_pin(token, user_id):
|
|
|
|
|
image_id = add_test_image(token)
|
|
|
|
|
pin_id = create_test_pin(token, user_id, image_id)
|
|
|
|
|
|
|
|
|
|
# Test mise à jour sans date
|
|
|
|
|
response = client.patch(
|
|
|
|
|
f"/pin/{pin_id}",
|
|
|
|
|
json={
|
|
|
|
@ -111,6 +134,30 @@ def test_update_pin(token, user_id):
|
|
|
|
|
assert data["description"] == "Updated Description"
|
|
|
|
|
assert data["location"] == [1,1]
|
|
|
|
|
assert image_id in data["files"]
|
|
|
|
|
assert "date" not in data
|
|
|
|
|
|
|
|
|
|
# Test mise à jour avec date
|
|
|
|
|
response = client.patch(
|
|
|
|
|
f"/pin/{pin_id}",
|
|
|
|
|
json={
|
|
|
|
|
"title": "Updated Pin With Date",
|
|
|
|
|
"description": "Updated Description",
|
|
|
|
|
"location": [1,1],
|
|
|
|
|
"files": [image_id],
|
|
|
|
|
"user_id": user_id,
|
|
|
|
|
"date": "2024-03-21T12:00:00"
|
|
|
|
|
},
|
|
|
|
|
headers={"Authorization": f"Bearer {token}"}
|
|
|
|
|
)
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
|
|
|
|
|
get_response = client.get(
|
|
|
|
|
f"/pin/{pin_id}",
|
|
|
|
|
headers={"Authorization": f"Bearer {token}"}
|
|
|
|
|
)
|
|
|
|
|
data = get_response.json()
|
|
|
|
|
assert data["title"] == "Updated Pin With Date"
|
|
|
|
|
assert data["date"] == "2024-03-21T12:00:00"
|
|
|
|
|
|
|
|
|
|
def test_update_wrong_format(token):
|
|
|
|
|
response = client.get(f"/pin/randomIdThatDoesntExists", headers={"Authorization": f"Bearer {token}"})
|
|
|
|
|