Tests fix

This commit is contained in:
gustavoschaedler 2023-06-16 23:07:23 +01:00
commit 96b3331573

View file

@ -57,7 +57,8 @@ def test_read_flows(client: TestClient, json_flow: str):
assert response.json()["name"] == flow.name assert response.json()["name"] == flow.name
assert response.json()["data"] == flow.data assert response.json()["data"] == flow.data
flow_style = FlowStyleCreate(color="red", emoji="👍", flow_id=response.json()["id"]) flow_style = FlowStyleCreate(
color="red", emoji="👍", flow_id=response.json()["id"])
response = client.post( response = client.post(
"api/v1/flow_styles/", json=jsonable_encoder(flow_style.dict()) "api/v1/flow_styles/", json=jsonable_encoder(flow_style.dict())
) )
@ -128,7 +129,8 @@ def test_update_flow(client: TestClient, json_flow: str):
description="updated description", description="updated description",
data=data, data=data,
) )
response = client.patch(f"api/v1/flows/{flow_id}", json=updated_flow.dict()) response = client.patch(
f"api/v1/flows/{flow_id}", json=updated_flow.dict())
assert response.status_code == 200 assert response.status_code == 200
assert response.json()["name"] == updated_flow.name assert response.json()["name"] == updated_flow.name
@ -237,18 +239,19 @@ def test_create_flow_with_invalid_data(client: TestClient):
def test_get_nonexistent_flow(client: TestClient): def test_get_nonexistent_flow(client: TestClient):
uuid = uuid4() uuid = uuid4()
with pytest.raises(RuntimeError) as excinfo: response = client.get(f"api/v1/flows/{uuid}")
client.get(f"api/v1/flows/{uuid}") assert response.status_code == 404
assert str(excinfo.value) == "File at path static/index.html does not exist."
def test_update_flow_idempotency(client: TestClient, json_flow: str): def test_update_flow_idempotency(client: TestClient, json_flow: str):
flow_data = json.loads(json_flow) flow_data = json.loads(json_flow)
data = flow_data["data"] data = flow_data["data"]
flow_data = FlowCreate(name="Test Flow", description="description", data=data) flow_data = FlowCreate(
name="Test Flow", description="description", data=data)
response = client.post("api/v1/flows/", json=flow_data.dict()) response = client.post("api/v1/flows/", json=flow_data.dict())
flow_id = response.json()["id"] flow_id = response.json()["id"]
updated_flow = FlowCreate(name="Updated Flow", description="description", data=data) updated_flow = FlowCreate(
name="Updated Flow", description="description", data=data)
response1 = client.put(f"api/v1/flows/{flow_id}", json=updated_flow.dict()) response1 = client.put(f"api/v1/flows/{flow_id}", json=updated_flow.dict())
response2 = client.put(f"api/v1/flows/{flow_id}", json=updated_flow.dict()) response2 = client.put(f"api/v1/flows/{flow_id}", json=updated_flow.dict())
assert response1.json() == response2.json() assert response1.json() == response2.json()
@ -263,16 +266,14 @@ def test_update_nonexistent_flow(client: TestClient, json_flow: str):
description="description", description="description",
data=data, data=data,
) )
with pytest.raises(RuntimeError) as excinfo: response = client.patch(f"api/v1/flows/{uuid}", json=updated_flow.dict())
client.patch(f"api/v1/flows/{uuid}", json=updated_flow.dict()) assert response.status_code == 404
assert str(excinfo.value) == "File at path static/index.html does not exist."
def test_delete_nonexistent_flow(client: TestClient): def test_delete_nonexistent_flow(client: TestClient):
uuid = uuid4() uuid = uuid4()
with pytest.raises(RuntimeError) as excinfo: response = client.delete(f"api/v1/flows/{uuid}")
client.delete(f"api/v1/flows/{uuid}") assert response.status_code == 404
assert str(excinfo.value) == "File at path static/index.html does not exist."
def test_read_empty_flows(client: TestClient): def test_read_empty_flows(client: TestClient):
@ -312,7 +313,8 @@ def test_create_flow_style(client: TestClient):
def test_read_flow_styles(client: TestClient): def test_read_flow_styles(client: TestClient):
response = client.get("api/v1/flow_styles/") response = client.get("api/v1/flow_styles/")
assert response.status_code == 200 assert response.status_code == 200
flow_styles = [FlowStyleRead(**flow_style) for flow_style in response.json()] flow_styles = [FlowStyleRead(**flow_style)
for flow_style in response.json()]
assert not flow_styles assert not flow_styles
# Create test data # Create test data
flow_style = FlowStyleCreate(color="red", emoji="🔴") flow_style = FlowStyleCreate(color="red", emoji="🔴")
@ -321,7 +323,8 @@ def test_read_flow_styles(client: TestClient):
# Check response data # Check response data
response = client.get("api/v1/flow_styles/") response = client.get("api/v1/flow_styles/")
assert response.status_code == 200 assert response.status_code == 200
flow_styles = [FlowStyleRead(**flow_style) for flow_style in response.json()] flow_styles = [FlowStyleRead(**flow_style)
for flow_style in response.json()]
assert len(flow_styles) == 1 assert len(flow_styles) == 1
assert flow_styles[0].color == flow_style.color assert flow_styles[0].color == flow_style.color
assert flow_styles[0].emoji == flow_style.emoji assert flow_styles[0].emoji == flow_style.emoji
@ -359,6 +362,5 @@ def test_delete_flow_style(client: TestClient):
assert response.status_code == 200 assert response.status_code == 200
assert response.json() == {"message": "FlowStyle deleted successfully"} assert response.json() == {"message": "FlowStyle deleted successfully"}
with pytest.raises(RuntimeError) as excinfo:
response = client.get(f"api/v1/flow_styles/{created_flow_style.id}") response = client.get(f"api/v1/flow_styles/{created_flow_style.id}")
assert str(excinfo.value) == "File at path static/index.html does not exist." assert response.status_code == 404