ogdhcp/tests/API-dhcp/robot/API.robot

164 lines
8.0 KiB
Plaintext

*** Settings ***
Documentation This is a basic skeleton for a Robot Framework test suite.
Library Collections
Library RequestsLibrary
*** Variables ***
${BASE_URL} http://localhost:8005/ogdhcp/v1
${headers} Create Dictionary Content-Type application/json
${modified_subnet} Create Dictionary mask=255.255.192.0 address=192.168.1.0 nextServer=192.168.1.1 bootFileName=pxelinux.0
${wrong_subnet_data_netmask} Create Dictionary mask=333.333.333.333 address=192.168.1.0 nextServer=192.168.1.1 bootFileName=pxelinux.0
${wrong_subnet_data_address} Create Dictionary mask=255.255.255.0 address=444.168.1.0 nextServer=192.168.1.1 bootFileName=pxelinux.0
${wrong_subnet_data_server} Create Dictionary mask=255.255.255.0 address=192.168.1.0 nextServer=555.168.1.1 bootFileName=pxelinux.0
${invalid_net_id} 999
${valid_net_id} 2
${new_subnet} Create Dictionary subnetId=${valid_net_id} mask=255.255.255.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}
Log ${response.json()}
# 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] Obtener todas las subredes.
[Tags] subnets
${response}= GET ${BASE_URL}/subnets
# Verificar código de estado HTTP
Should Be Equal As Numbers ${response.status_code} 200
${json}= ${response.json()}
# Verificar que la respuesta es una lista
Should Be True ${json} is list
# Verificar que al menos una subred está presente
Should Not Be Empty ${json}
# Validar que la primera subred tiene ciertos campos
Dictionary Should Contain Key ${json[0]} id
Dictionary Should Contain Key ${json[0]} subnet
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"]} ${valid_net_id}
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 que la respuesta contiene clave 'success'
Dictionary Should Contain Key ${json} success
# Validar el contenido del mensaje de éxito
Should Be Equal ${json['success']} Subred modificada correctamente
Should Be Equal ${json['message']['id']} 2
Modify a subnet with invalid id
[Documentation] Este test verifica que la modificación de una subred falla cuando el ID no existe.
${headers}= Create Dictionary Content-Type=application/json
${modificar_subred}= Create Dictionary mask=255.255.192.0 address=192.168.1.0 nextServer=192.168.1.1 bootFileName=pxelinux.0
${response}= PUT ${BASE_URL}/ogdhcp/v1/subnets/${invalid_net_id} json=${modificar_subred} headers=${headers} expected_status=400
# Verificar código de estado HTTP
Should Be Equal As Numbers ${response.status_code} 400
${json}= Convert To Dictionary ${response.json()}
# Verificar que la respuesta contiene el error esperado
Should Be Equal ${json['error']} Error: La subred con el id '999' no existe
Modify subnet with error to save configuration
[Documentation] Este test verifica que la modificación falla cuando hay un error al guardar la configuración en Kea DHCP.
${headers}= Create Dictionary Content-Type=application/json
${modificar_subred}= Create Dictionary subnet="192.168.1.0/24" next-server="192.168.1.1" boot-file-name="pxelinux.0"
${response}= PUT ${BASE_URL}/ogdhcp/v1/subnets/2 json=${modificar_subred} headers=${headers} expected_status=400
# Verificar código de estado HTTP
Should Be Equal As Numbers ${response.status_code} 400
${json}= Convert To Dictionary ${response.json()}
# Verificar que la respuesta contiene el error esperado
Should Be Equal ${json['error']} Error al guardar la configuración en Kea DHCP: Unable to save configuration
Modify subnet with invalid configuration
[Documentation] Este test verifica que la modificación falla cuando hay un error en la configuración de Kea DHCP.
${headers}= Create Dictionary Content-Type=application/json
${modificar_subred}= Create Dictionary subnet="192.168.1.0" next-server="192.168.1.1" boot-file-name="pxelinux.0"
${response}= PUT ${BASE_URL}/ogdhcp/v1/subnets/2 json=${modificar_subred} headers=${headers}
# Verificar código de estado HTTP
Should Be Equal As Numbers ${response.status_code} 400
${json}= Convert To Dictionary ${response.json()}
# Verificar que la respuesta contiene el error esperado
Should Be Equal ${json['error']} Error kea configuration invalid: Invalid configuration syntax
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