*** Settings *** Documentation API-specific keywords for Aniworld Robot Framework tests. ... Wraps common HTTP patterns and JSON assertions for REST API testing. Resource ${CURDIR}/common.resource *** Keywords *** # --------------------------------------------------------------------------- # Generic API Helpers # --------------------------------------------------------------------------- GET API [Arguments] ${endpoint} ${expected_status}=200 ${session}=auth [Documentation] Perform an authenticated GET request and return the response. ${resp}= GET On Session ${session} ${endpoint} expected_status=${expected_status} RETURN ${resp} POST API [Arguments] ${endpoint} ${payload}=${NONE} ${expected_status}=200 ${session}=auth [Documentation] Perform an authenticated POST request with optional JSON payload. IF $payload is ${NONE} ${resp}= POST On Session ${session} ${endpoint} expected_status=${expected_status} ELSE ${resp}= POST On Session ${session} ${endpoint} json=${payload} expected_status=${expected_status} END RETURN ${resp} PUT API [Arguments] ${endpoint} ${payload} ${expected_status}=200 ${session}=auth [Documentation] Perform an authenticated PUT request with JSON payload. ${resp}= PUT On Session ${session} ${endpoint} json=${payload} expected_status=${expected_status} RETURN ${resp} DELETE API [Arguments] ${endpoint} ${expected_status}=200 ${session}=auth [Documentation] Perform an authenticated DELETE request. ${resp}= DELETE On Session ${session} ${endpoint} expected_status=${expected_status} RETURN ${resp} # --------------------------------------------------------------------------- # JSON Response Helpers # --------------------------------------------------------------------------- Get JSON Value [Arguments] ${response} ${json_path} [Documentation] Extract a value from a JSON response using JSONPath. ${json}= Convert String To Json ${response.text} ${values}= Get Value From Json ${json} ${json_path} ${value}= Set Variable ${values}[0] RETURN ${value} Response Should Contain Keys [Arguments] ${response} @{keys} [Documentation] Assert that the JSON response contains all the specified top-level keys. ${json}= Convert String To Json ${response.text} FOR ${key} IN @{keys} Dictionary Should Contain Key ${json} ${key} END Response Should Be Valid JSON [Arguments] ${response} [Documentation] Assert that the response body is valid JSON. ${json}= Convert String To Json ${response.text} Should Not Be Empty ${json} # --------------------------------------------------------------------------- # Auth-Specific API Helpers # --------------------------------------------------------------------------- POST Auth Setup [Arguments] ${password} ${expected_status}=201 [Documentation] POST to /api/auth/setup with the given password. ${payload}= Create Dictionary master_password=${password} ${resp}= POST On Session anon /api/auth/setup json=${payload} expected_status=${expected_status} RETURN ${resp} POST Auth Login [Arguments] ${password} ${expected_status}=200 [Documentation] POST to /api/auth/login with the given password. ${payload}= Create Dictionary password=${password} ${resp}= POST On Session anon /api/auth/login json=${payload} expected_status=${expected_status} RETURN ${resp} GET Auth Status [Arguments] ${expected_status}=200 [Documentation] GET /api/auth/status. ${resp}= GET On Session anon /api/auth/status expected_status=${expected_status} RETURN ${resp} # --------------------------------------------------------------------------- # Config-Specific API Helpers # --------------------------------------------------------------------------- Get Current Config [Documentation] GET /api/config and return the parsed JSON. ${resp}= GET API /api/config ${json}= Convert String To Json ${resp.text} RETURN ${json} Update Config [Arguments] ${payload} [Documentation] PUT /api/config with the given payload. ${resp}= PUT API /api/config ${payload} RETURN ${resp} Validate Config [Arguments] ${payload} ${expected_status}=200 [Documentation] POST /api/config/validate with the given payload. ${resp}= POST API /api/config/validate ${payload} ${expected_status} RETURN ${resp} # --------------------------------------------------------------------------- # Queue-Specific API Helpers # --------------------------------------------------------------------------- Get Queue Status [Documentation] GET /api/queue/status and return the response. ${resp}= GET API /api/queue/status RETURN ${resp} Add To Queue [Arguments] ${payload} [Documentation] POST /api/queue/add with the given payload. ${resp}= POST API /api/queue/add ${payload} 201 RETURN ${resp} Start Queue [Documentation] POST /api/queue/start. ${resp}= POST API /api/queue/start RETURN ${resp} Stop Queue [Documentation] POST /api/queue/stop. ${resp}= POST API /api/queue/stop RETURN ${resp} Pause Queue [Documentation] POST /api/queue/pause. ${resp}= POST API /api/queue/pause RETURN ${resp} Resume Queue [Documentation] POST /api/queue/resume. ${resp}= POST API /api/queue/resume RETURN ${resp} Clear Completed [Documentation] DELETE /api/queue/completed. ${resp}= DELETE API /api/queue/completed RETURN ${resp} Clear Failed [Documentation] DELETE /api/queue/failed. ${resp}= DELETE API /api/queue/failed RETURN ${resp} Clear Pending [Documentation] DELETE /api/queue/pending. ${resp}= DELETE API /api/queue/pending RETURN ${resp} # --------------------------------------------------------------------------- # Anime-Specific API Helpers # --------------------------------------------------------------------------- Get Anime Status [Documentation] GET /api/anime/status. ${resp}= GET API /api/anime/status RETURN ${resp} Rescan Library [Documentation] POST /api/anime/rescan. ${resp}= POST API /api/anime/rescan RETURN ${resp} Get Scan Status [Documentation] GET /api/anime/scan/status. ${resp}= GET API /api/anime/scan/status RETURN ${resp} Search Anime [Arguments] ${query} [Documentation] GET /api/anime/search?query=${query}. ${resp}= GET API /api/anime/search?query=${query} RETURN ${resp} Add Series [Arguments] ${link} ${name} ${year}=${EMPTY} [Documentation] POST /api/anime/add with series details. ${payload}= Create Dictionary link=${link} name=${name} IF '${year}' != '${EMPTY}' Set To Dictionary ${payload} year=${year} END ${resp}= POST API /api/anime/add ${payload} 202 RETURN ${resp} Get Series Details [Arguments] ${key} [Documentation] GET /api/anime/{key}. ${resp}= GET API /api/anime/${key} RETURN ${resp} Delete Series [Arguments] ${key} [Documentation] DELETE /api/anime/{key}. ${resp}= DELETE API /api/anime/${key} RETURN ${resp} Get Series Episodes [Arguments] ${key} [Documentation] GET /api/anime/{key}/episodes. ${resp}= GET API /api/anime/${key}/episodes RETURN ${resp} # --------------------------------------------------------------------------- # Scheduler-Specific API Helpers # --------------------------------------------------------------------------- Get Scheduler Config [Documentation] GET /api/scheduler/config. ${resp}= GET API /api/scheduler/config RETURN ${resp} Update Scheduler Config [Arguments] ${payload} [Documentation] POST /api/scheduler/config. ${resp}= POST API /api/scheduler/config ${payload} RETURN ${resp} Trigger Rescan [Documentation] POST /api/scheduler/trigger-rescan. ${resp}= POST API /api/scheduler/trigger-rescan RETURN ${resp} # --------------------------------------------------------------------------- # NFO-Specific API Helpers # --------------------------------------------------------------------------- Get Nfo Diagnostics [Arguments] ${key} [Documentation] GET /api/nfo/{key}/diagnostics. ${resp}= GET API /api/nfo/${key}/diagnostics RETURN ${resp} Repair Nfo [Arguments] ${key} [Documentation] POST /api/nfo/{key}/repair. ${resp}= POST API /api/nfo/${key}/repair RETURN ${resp} Get Needs Repair [Documentation] GET /api/nfo/needs-repair. ${resp}= GET API /api/nfo/needs-repair RETURN ${resp} Scan Nfo [Documentation] POST /api/nfo/scan. ${resp}= POST API /api/nfo/scan RETURN ${resp} # --------------------------------------------------------------------------- # Logging-Specific API Helpers # --------------------------------------------------------------------------- Get Logging Config [Documentation] GET /api/logging/config. ${resp}= GET API /api/logging/config RETURN ${resp} List Log Files [Documentation] GET /api/logging/files. ${resp}= GET API /api/logging/files RETURN ${resp} Tail Log File [Arguments] ${filename} [Documentation] GET /api/logging/files/{filename}/tail. ${resp}= GET API /api/logging/files/${filename}/tail RETURN ${resp} Download Log File [Arguments] ${filename} [Documentation] GET /api/logging/files/{filename}/download. ${resp}= GET API /api/logging/files/${filename}/download RETURN ${resp} Write Test Logs [Documentation] POST /api/logging/test. ${resp}= POST API /api/logging/test RETURN ${resp} Cleanup Logs [Documentation] POST /api/logging/cleanup. ${resp}= POST API /api/logging/cleanup RETURN ${resp} # --------------------------------------------------------------------------- # Setup-Specific API Helpers # --------------------------------------------------------------------------- Get Unresolved Folders [Documentation] GET /api/setup/unresolved. ${resp}= GET API /api/setup/unresolved RETURN ${resp} Get Unresolved Folder Details [Arguments] ${folder_name} [Documentation] GET /api/setup/unresolved/{folder_name}. ${resp}= GET API /api/setup/unresolved/${folder_name} RETURN ${resp} Resolve Folder [Arguments] ${folder_name} ${provider_key} [Documentation] POST /api/setup/unresolved/{folder_name}/resolve. ${payload}= Create Dictionary provider_key=${provider_key} ${resp}= POST API /api/setup/unresolved/${folder_name}/resolve ${payload} RETURN ${resp}