*** Settings *** Documentation This is a basic skeleton for a Robot Framework test suite. Library Collections Library RequestsLibrary Library BuiltIn *** Variables *** ${BASE_URL} http://localhost:8005/ogdhcp/v1 ${headers} Create Dictionary Content-Type application/json ${new_subnet} Create Dictionary subnetId=2 mask=255.255.255.0 address=192.168.1.0 nextServer=192.168.1.1 bootFileName=pxelinux.0 ${modified_subnet} Create Dictionary mask=255.255.192.0 address=192.168.1.0 nextServer=192.168.1.1 bootFileName=pxelinux.0 *** Test Cases *** Get Status of the DHCP server [Documentation] Get status of the dhcp server and check services status [Tags] status ${response}= GET ${BASE_URL}/status Status Should Be 200 ${response} # Convertir la respuesta a JSON usando ${response.json()} ${json}= Convert to Dictionary ${response.json()} Dictionary Should Contain Key ${json} success Dictionary Should Contain Key ${json} message Should Contain ${response.json()['message']} disk_usage Should Contain ${response.json()['message']} subnets Should Contain ${response.json()['message']['disk_usage']} total Get all subnets [Documentation] Get all subnets [Tags] subnets ${response}= GET ${BASE_URL}/subnets Status Should Be 200 ${response} # Convertir la respuesta a JSON usando ${response.json()} ${json}= Convert to Dictionary ${response.json()} Dictionary Should Contain Key ${json} success Dictionary Should Contain Key ${json} message ${subnets}= Set Variable False FOR ${subred} IN @{json_response['message']} Run Keyword If '${subred['id']}' == '1' Set Variable ${subred_encontrada} True END Should Be True ${subred_encontrada} Post a new subnet [Documentation] Post a new subnet [Tags] subnets ${headers}= Create Dictionary Content-Type=application/json ${response}= POST ${BASE_URL}/subnets json=${new_subnet} headers=${headers} expected_status=200 Status Should Be 200 ${response} ${json}= Convert to Dictionary ${response.json()} Dictionary Should Contain Key ${json} success Dictionary Should Contain Key ${json} message Should Contain ${json["success"]} Subnet agregada correctamente Should Be Equal As Numbers ${json["message"]["id"]} 2 Should Be Equal ${json["message"]["mask"]} ${new_subnet["mask"]} Should Be Equal ${json["message"]["address"]} ${new_subnet["address"]} Should Be Equal ${json["message"]["nextServer"]} ${new_subnet["nextServer"]} Should Be Equal ${json["message"]["bootFileName"]} ${new_subnet["bootFileName"]} Post a new subnet with existing id [Documentation] Post a new subnet with invalid data [Tags] subnets ${headers}= Create Dictionary Content-Type=application/json ${response}= POST ${BASE_URL}/subnets json=${new_subnet} headers=${headers} expected_status=400 Status Should Be 400 ${response} ${json}= Convert to Dictionary ${response.json()} Dictionary Should Contain Key ${json} error Should Contain ${response.json()['error']} Subnet con id 2 ya existe Post a new subnet with existing address [Documentation] Post a new subnet with invalid data [Tags] subnets ${headers}= Create Dictionary Content-Type=application/json ${new_subnet_invalid}= Create Dictionary subnetId=3 mask=255.255.255.0 address=192.168.1.0 nextServer=192.168.1.1 bootFileName=pxelinux.0 ${response}= POST ${BASE_URL}/subnets json=${new_subnet_invalid} headers=${headers} expected_status=400 Status Should Be 400 ${response} ${json}= Convert to Dictionary ${response.json()} Dictionary Should Contain Key ${json} error Should Contain ${response.json()['error']} Error: La subred el subnet '192.168.1.0/24' ya existe en las subredes Modify an existing subnet by id [Documentation] Modify a subnet by id [Tags] subnets # Modificar la subred con id=2 ${response}= PUT ${BASE_URL}/subnets/2 json=${modified_subnet} headers=${headers} expected_status=200 Status Should Be 200 # Verificar la respuesta del PUT ${json}= Set Variable ${response.json()} Should Be Equal ${json["status"]} success Should Be Equal ${json["message"]} Subred modificada correctamente Should Be Equal ${json["subnetId"]} 2 # Obtener todas las subredes y verificar si la subred fue modificada ${response_all}= GET ${BASE_URL}/subnets Status Should Be 200 ${json_all}= Set Variable ${response_all.json()} # Iterar sobre todas las subredes para encontrar la subred con id=2 y verificar su máscara FOR ${subnet} IN @{json_all} Run Keyword If '${subnet["id"]}' == '2' Should Be Equal ${subnet["mask"]} 255.255.192.0 END Delete a new subnet by id [Documentation] Delete a subnet by id [Tags] subnets ${response}= DELETE ${BASE_URL}/subnets/2 headers=${headers} Status Should Be 200 ${json}= Set Variable ${response.json()} Should Be Equal ${json["status"]} success Should Be Equal ${json["message"]} Subred eliminada correctamente Should Be Equal ${json["subnetId"]} 2