Skip to content

Commit

Permalink
Added test for Validate Response edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
robinmackaij committed May 15, 2024
1 parent 063a0e4 commit 34f0dea
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
25 changes: 25 additions & 0 deletions tests/libcore/suites/test_validate_response.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
*** Settings ***
Library OpenApiLibCore
... source=${ORIGIN}/openapi.json
... origin=${ORIGIN}
... base_path=${EMPTY}
... mappings_path=${ROOT}/tests/user_implemented/custom_user_mappings.py
Variables ${ROOT}/tests/variables.py


*** Variables ***
${ORIGIN}= http://localhost:8000


*** Test Cases ***
Test Bool Response
${url}= Get Valid Url endpoint=/employees/{employee_id} method=patch
${request_data}= Get Request Data endpoint=/employees/{employee_id} method=patch
${response}= Authorized Request
... url=${url}
... method=patch
... params=${request_data.params}
... headers=${request_data.headers}
... json_data=${request_data.dto.as_dict()}

Validate Response path=/employees/{employee_id} response=${response}
19 changes: 15 additions & 4 deletions tests/server/testserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from uuid import uuid4

from fastapi import FastAPI, Header, HTTPException, Path, Query, Response
from fastapi.responses import JSONResponse
from pydantic import BaseModel, Field

API_KEY = "OpenApiLibCore"
Expand Down Expand Up @@ -310,10 +311,20 @@ def get_employee(employee_id: str) -> EmployeeDetails:
@app.patch(
"/employees/{employee_id}",
status_code=200,
response_model=EmployeeDetails,
responses={404: {"model": Detail}},
responses={
404: {"model": Detail},
200: {
"description": "A JSON boolean response",
"content": {
"application/json": {
"schema": {"type": "boolean"},
},
},
},
},
response_class=JSONResponse,
)
def patch_employee(employee_id: str, employee: EmployeeUpdate) -> EmployeeDetails:
def patch_employee(employee_id: str, employee: EmployeeUpdate) -> JSONResponse:
if employee_id not in EMPLOYEES.keys():
raise HTTPException(status_code=404, detail="Employee not found")
stored_employee_data = EMPLOYEES[employee_id]
Expand All @@ -337,7 +348,7 @@ def patch_employee(employee_id: str, employee: EmployeeUpdate) -> EmployeeDetail

updated_employee = stored_employee_data.model_copy(update=employee_update_data)
EMPLOYEES[employee_id] = updated_employee
return updated_employee
return JSONResponse(content=True)


@app.get("/available_employees", status_code=200, response_model=List[EmployeeDetails])
Expand Down

0 comments on commit 34f0dea

Please sign in to comment.