|
|
|
@ -1,27 +1,18 @@
|
|
|
|
|
from test_main import *
|
|
|
|
|
|
|
|
|
|
def test_add_pin():
|
|
|
|
|
login_response = client.post("/login", data={"username": "testuser", "password": "testpassword"})
|
|
|
|
|
token = login_response.json()["access_token"]
|
|
|
|
|
|
|
|
|
|
def test_add_pin(token):
|
|
|
|
|
response = client.post("/pin/add", json={"title": "Test Pin", "description": "Test Description", "location": "Test location", "files": ["Test file 1"]}, headers={"Authorization": f"Bearer {token}"})
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
data = response.json()
|
|
|
|
|
assert "id" in data
|
|
|
|
|
|
|
|
|
|
def test_list_pins():
|
|
|
|
|
login_response = client.post("/login", data={"username": "testuser", "password": "testpassword"})
|
|
|
|
|
token = login_response.json()["access_token"]
|
|
|
|
|
|
|
|
|
|
def test_list_pins(token):
|
|
|
|
|
response = client.get("/pins", headers={"Authorization": f"Bearer {token}"})
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
data = response.json()
|
|
|
|
|
assert isinstance(data, list)
|
|
|
|
|
|
|
|
|
|
def test_get_pin():
|
|
|
|
|
login_response = client.post("/login", data={"username": "testuser", "password": "testpassword"})
|
|
|
|
|
token = login_response.json()["access_token"]
|
|
|
|
|
|
|
|
|
|
def test_get_pin(token):
|
|
|
|
|
add_pin_response = client.post("/pin/add", json={"title": "Test Pin", "description": "Test Description", "location": "Test location", "files": ["Test file 1"]}, headers={"Authorization": f"Bearer {token}"})
|
|
|
|
|
pin_id = add_pin_response.json()["id"]
|
|
|
|
|
|
|
|
|
@ -33,18 +24,17 @@ def test_get_pin():
|
|
|
|
|
assert data["location"] == "Test location"
|
|
|
|
|
assert data["files"] == ["Test file 1"]
|
|
|
|
|
|
|
|
|
|
# Test wrong format
|
|
|
|
|
|
|
|
|
|
def test_get_pin_wrong_format(token):
|
|
|
|
|
response = client.get(f"/pin/randomIdThatDoesntExists", headers={"Authorization": f"Bearer {token}"})
|
|
|
|
|
assert response.status_code == 422
|
|
|
|
|
|
|
|
|
|
# Test inexistant id
|
|
|
|
|
def test_get_pin_unknown_id(token):
|
|
|
|
|
response = client.get(f"/pin/123456789987654321abcdef", headers={"Authorization": f"Bearer {token}"})
|
|
|
|
|
assert response.status_code == 404
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_update_pin():
|
|
|
|
|
login_response = client.post("/login", data={"username": "testuser", "password": "testpassword"})
|
|
|
|
|
token = login_response.json()["access_token"]
|
|
|
|
|
|
|
|
|
|
def test_update_pin(token):
|
|
|
|
|
|
|
|
|
|
add_pin_response = client.post("/pin/add", json={"title": "Test Pin", "description": "Test Description", "location": "Test location", "files": ["Test file 1"]}, headers={"Authorization": f"Bearer {token}"})
|
|
|
|
|
pin_id = add_pin_response.json()["id"]
|
|
|
|
@ -59,10 +49,11 @@ def test_update_pin():
|
|
|
|
|
assert data["location"] == "Updated location"
|
|
|
|
|
assert data["files"] == ["Updated file 1"]
|
|
|
|
|
|
|
|
|
|
# Test wrong format
|
|
|
|
|
|
|
|
|
|
def test_update_wrong_format(token):
|
|
|
|
|
response = client.get(f"/pin/randomIdThatDoesntExists", headers={"Authorization": f"Bearer {token}"})
|
|
|
|
|
assert response.status_code == 422
|
|
|
|
|
|
|
|
|
|
# Test inexistant id
|
|
|
|
|
def test_update_wrong_unknown_id(token):
|
|
|
|
|
response = client.get(f"/pin/123456789987654321abcdef", headers={"Authorization": f"Bearer {token}"})
|
|
|
|
|
assert response.status_code == 404
|