From 2a88fd7dc6cd2eb3e173804c7aeb6ef863e4c202 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Wed, 2 Oct 2024 14:04:57 +0200 Subject: [PATCH] More test --- tests/API-dhcp/robot/API.robot | 105 ++++++++++++++++++++++++--------- 1 file changed, 76 insertions(+), 29 deletions(-) diff --git a/tests/API-dhcp/robot/API.robot b/tests/API-dhcp/robot/API.robot index 0255bdf..eacb82e 100644 --- a/tests/API-dhcp/robot/API.robot +++ b/tests/API-dhcp/robot/API.robot @@ -2,20 +2,26 @@ 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 +${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 @@ -25,20 +31,26 @@ Get Status of the DHCP server Should Contain ${response.json()['message']['disk_usage']} total -Get all subnets - [Documentation] Get all subnets +Get All Subnets + [Documentation] Obtener todas las subredes. [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} + ${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 @@ -51,7 +63,7 @@ Post a new subnet 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 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"]} @@ -88,21 +100,56 @@ Modify an existing subnet by id ${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 + + # Verificar que la respuesta contiene clave 'success' + Dictionary Should Contain Key ${json} success - # 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()} + # Validar el contenido del mensaje de éxito + Should Be Equal ${json['success']} Subred modificada correctamente + Should Be Equal ${json['message']['id']} 2 - # 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 +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