Skip to content
Snippets Groups Projects
Commit 28f2e91c authored by Neda Moeini's avatar Neda Moeini
Browse files

Added some unit tests for callback result endpoint.

parent 892c32ea
No related branches found
No related tags found
1 merge request!142Added middleware to modify porecess details response and replace the callback...
......@@ -3,7 +3,7 @@
from typing import Any
from uuid import UUID
from fastapi import APIRouter, HTTPException, status, Depends
from fastapi import APIRouter, Depends, HTTPException, status
from orchestrator.db import ProcessStepTable
from orchestrator.schemas.base import OrchestratorBaseModel
......
......@@ -61,6 +61,7 @@ class ModifyProcessEndpointResponse(BaseHTTPMiddleware):
Args:
----
request (Request): The incoming HTTP request.
Returns:
-------
str: The token from the request headers in specific format.
......@@ -71,8 +72,7 @@ class ModifyProcessEndpointResponse(BaseHTTPMiddleware):
# Remove the "Bearer " prefix from the token
token = authorization_header.replace(bearer_prefix, "")
return f"?token={token}"
else:
return ""
return ""
async def modify_response_body(self, response_body: dict[str, Any], request: Request) -> None:
"""Modify the response body as needed.
......
from test.fixtures import nokia_router_subscription_factory, site_subscription_factory # noqa: F401
from uuid import uuid4
import pytest
from orchestrator.db import (
ProcessStepTable,
ProcessSubscriptionTable,
ProcessTable,
db,
)
from orchestrator.workflow import ProcessStatus
@pytest.fixture()
def create_process(faker, nokia_router_subscription_factory):
process_id = uuid4()
process = ProcessTable(process_id=process_id, workflow_name=faker.sentence(), last_status=ProcessStatus.SUSPENDED)
subscription = nokia_router_subscription_factory()
process_subscription = ProcessSubscriptionTable(process_id=process_id, subscription_id=subscription)
db.session.add(process)
db.session.add(process_subscription)
db.session.commit()
return process_id
def test_callback_results_endpoint(test_client, create_process, faker):
expected_result = {"id": 1, "output": faker.sentence()}
step = ProcessStepTable(
process_id=create_process,
name="Modify",
status="suspend",
state={"subscription_id": uuid4(), "callback_result": expected_result},
)
db.session.add(step)
db.session.commit()
response = test_client.get(f"/api/v1/processes/steps/{step.step_id}/callback-results")
assert response.status_code == 200
assert response.json() == {"callback_results": expected_result}
def test_callback_results_endpoint_with_wrong_step_id(test_client):
response = test_client.get(f"/api/v1/processes/steps/{uuid4()}/callback-results")
assert response.status_code == 404
assert response.json() == {"detail": "Callback result not found."}
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