More test
testing/og-dhcp-API/pipeline/head There was a failure building this commit Details

nginx_conf
Nicolas Arenas 2024-10-02 14:04:57 +02:00
parent aaa06152d1
commit 2a88fd7dc6
1 changed files with 76 additions and 29 deletions

View File

@ -2,20 +2,26 @@
Documentation This is a basic skeleton for a Robot Framework test suite. Documentation This is a basic skeleton for a Robot Framework test suite.
Library Collections Library Collections
Library RequestsLibrary Library RequestsLibrary
Library BuiltIn
*** Variables *** *** Variables ***
${BASE_URL} http://localhost:8005/ogdhcp/v1 ${BASE_URL} http://localhost:8005/ogdhcp/v1
${headers} Create Dictionary Content-Type application/json ${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 ${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 *** *** Test Cases ***
Get Status of the DHCP server Get Status of the DHCP server
[Documentation] Get status of the dhcp server and check services status [Documentation] Get status of the dhcp server and check services status
[Tags] status [Tags] status
${response}= GET ${BASE_URL}/status ${response}= GET ${BASE_URL}/status
Status Should Be 200 ${response} Status Should Be 200 ${response}
Log ${response.json()}
# Convertir la respuesta a JSON usando ${response.json()} # Convertir la respuesta a JSON usando ${response.json()}
${json}= Convert to Dictionary ${response.json()} ${json}= Convert to Dictionary ${response.json()}
Dictionary Should Contain Key ${json} success Dictionary Should Contain Key ${json} success
@ -25,20 +31,26 @@ Get Status of the DHCP server
Should Contain ${response.json()['message']['disk_usage']} total Should Contain ${response.json()['message']['disk_usage']} total
Get all subnets Get All Subnets
[Documentation] Get all subnets [Documentation] Obtener todas las subredes.
[Tags] subnets [Tags] subnets
${response}= GET ${BASE_URL}/subnets ${response}= GET ${BASE_URL}/subnets
Status Should Be 200 ${response}
# Convertir la respuesta a JSON usando ${response.json()} # Verificar código de estado HTTP
${json}= Convert to Dictionary ${response.json()} Should Be Equal As Numbers ${response.status_code} 200
Dictionary Should Contain Key ${json} success
Dictionary Should Contain Key ${json} message ${json}= ${response.json()}
${subnets}= Set Variable False
FOR ${subred} IN @{json_response['message']} # Verificar que la respuesta es una lista
Run Keyword If '${subred['id']}' == '1' Set Variable ${subred_encontrada} True Should Be True ${json} is list
END
Should Be True ${subred_encontrada} # 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 Post a new subnet
@ -51,7 +63,7 @@ Post a new subnet
Dictionary Should Contain Key ${json} success Dictionary Should Contain Key ${json} success
Dictionary Should Contain Key ${json} message Dictionary Should Contain Key ${json} message
Should Contain ${json["success"]} Subnet agregada correctamente 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"]["mask"]} ${new_subnet["mask"]}
Should Be Equal ${json["message"]["address"]} ${new_subnet["address"]} Should Be Equal ${json["message"]["address"]} ${new_subnet["address"]}
Should Be Equal ${json["message"]["nextServer"]} ${new_subnet["nextServer"]} 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 ${response}= PUT ${BASE_URL}/subnets/2 json=${modified_subnet} headers=${headers} expected_status=200
Status Should Be 200 Status Should Be 200
# Verificar la respuesta del PUT
${json}= Set Variable ${response.json()} # Verificar que la respuesta contiene clave 'success'
Should Be Equal ${json["status"]} success Dictionary Should Contain Key ${json} 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 # Validar el contenido del mensaje de éxito
${response_all}= GET ${BASE_URL}/subnets Should Be Equal ${json['success']} Subred modificada correctamente
Status Should Be 200 Should Be Equal ${json['message']['id']} 2
${json_all}= Set Variable ${response_all.json()}
# Iterar sobre todas las subredes para encontrar la subred con id=2 y verificar su máscara Modify a subnet with invalid id
FOR ${subnet} IN @{json_all} [Documentation] Este test verifica que la modificación de una subred falla cuando el ID no existe.
Run Keyword If '${subnet["id"]}' == '2' Should Be Equal ${subnet["mask"]} 255.255.192.0 ${headers}= Create Dictionary Content-Type=application/json
END ${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 Delete a new subnet by id
[Documentation] Delete a subnet by id [Documentation] Delete a subnet by id