blob: 79cc0e4139a92957cc149a1767cbdc21d6665cf6 [file] [log] [blame]
*** Settings ***
Documentation Test Suite for XOS APIs
Suite Setup Setup
Suite Teardown Teardown
Test Template Verify API Functionality
Library Collections
Library String
Library OperatingSystem
Library XML
Library RequestsLibrary
Library CORDRobot
Library ImportResource resources=CORDRobot
Variables ../Properties/RestApiProperties.py
*** Variables ***
${xos_service} core
*** Test Cases *** TYPE API
{%- for m in proto.messages -%}
{%- if m.name not in ['XOSBase'] -%}
{% autoescape false %}
{% endautoescape %}
Create {{ m.name }} CREATE /xosapi/v1/${xos_service}/{{ xproto_pluralize(m) | lower}} ${json_{{ m.name | lower}}_1}
[Tags] {{ m.name }}
Update {{ m.name }} UPDATE /xosapi/v1/${xos_service}/{{ xproto_pluralize(m) | lower}} ${json_{{ m.name | lower}}_amend_1} ${id}
[Tags] {{ m.name }}
Get {{ m.name }} RETRIEVE /xosapi/v1/${xos_service}/{{ xproto_pluralize(m) | lower}} ${json_{{ m.name | lower}}_amend_1} ${id} ${json_{{ m.name | lower}}_amend_key}
[Tags] {{ m.name }}
Delete {{ m.name }} DELETE /xosapi/v1/${xos_service}/{{ xproto_pluralize(m) | lower}} data_id=${id}
[Tags] {{ m.name }}
{% endif %}
{% endfor -%}
*** Keywords ***
Verify API Functionality
[Arguments] ${type} ${endpoint} ${data}=${EMPTY} ${data_id}=${EMPTY} ${key}=${EMPTY}
Run Keyword If "${type}" == "RETRIEVE" CORD Get ${endpoint} ${data_id} ${data} ${key}
Run Keyword If "${type}" == "CREATE" CORD Post ${endpoint} ${data}
Run Keyword If "${type}" == "UPDATE" CORD Put ${endpoint} ${data} ${data_id}
Run Keyword If "${type}" == "DELETE" CORD Delete ${endpoint} ${data_id}
CORD Get
[Documentation] Make a GET call to the CORD controller
[Arguments] ${service} ${id} ${value} ${key}
${resp}= Get Request ${SERVER_IP} ${service}/${id}
Log ${resp.content}
Should Be Equal As Strings ${resp.status_code} 200
${amend_value}= Run Keyword If '${key}' != 'null' Get From Dictionary ${resp.json()} ${key}
${amend_value}= Run Keyword If '${key}' != 'null' Remove String ${amend_value} "
Run Keyword If '${key}' != 'null' Should Contain "${value}" ${amend_value}
[Return] ${resp}
CORD Post
[Documentation] Make a POST call to the CORD controller
[Arguments] ${service} ${data}
${data}= Evaluate json.dumps(${data}) json
${resp}= Post Request ${SERVER_IP} uri=${service} data=${data}
Log ${resp.content}
Should Be Equal As Strings ${resp.status_code} 200
${id}= Get From Dictionary ${resp.json()} id
Set Suite Variable ${id}
[Return] ${resp}
CORD Put
[Documentation] Make a PUT call to the CORD controller
[Arguments] ${service} ${data} ${data_id}
${data}= Evaluate json.dumps(${data}) json
${resp}= Put Request ${SERVER_IP} uri=${service}/${data_id} data=${data}
Log ${resp.content}
Should Be Equal As Strings ${resp.status_code} 200
${id}= Get From Dictionary ${resp.json()} id
Set Suite Variable ${id}
[Return] ${resp}
CORD Delete
[Documentation] Make a DELETE call to the CORD controller
[Arguments] ${service} ${data_id}
${resp}= Delete Request ${SERVER_IP} uri=${service}/${data_id}
Log ${resp.content}
Should Be Equal As Strings ${resp.status_code} 200
[Return] ${resp}
Generate JSON Data
{%- for m in proto.messages -%}
{%- if m.name not in ['XOSBase'] -%}
{% autoescape false %}
{% endautoescape %}
${json_{{ m.name | lower }}_1}= Set Variable { }
${json_{{ m.name | lower }}_amend_1}= Set Variable { }
${json_{{ m.name | lower}}_amend_key}= Set Variable null
Set Suite Variable ${json_{{ m.name | lower}}_amend_key}
# set required fields for {{ m.name | lower }} object
{% for f in m.fields + xproto_base_fields(m, proto.message_table) -%}
{% if f.modifier == "required" and f.options.blank != "True" -%}
{% if not f.options.default -%}
{% if f.link -%}
${tmp_{{ f.options.model | lower }}_id}= Create {{ f.options.model }}
${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }}_id ${tmp_{{ f.options.model | lower }}_id}
{% elif f.name == "created" or f.name == "amend" or f.name =="expires" or f.name =='granted' -%}
${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value float
${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_1}"
{% elif f.name == "role" -%}
${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value role
${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_1}"
{% elif f.name == "direction" -%}
${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value direction
${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_1}"
{% elif f.name == "flavor" -%}
${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value flavor
${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_1}"
{% else -%}
${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value {{ f.type }}
${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_1}"
{% if f.name == "created" or f.name == "amend" or f.name =="expires" or f.name =='granted' -%}
${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value float
${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_1}"
{% else -%}
{% if loop.index0 == 0 -%}
${json_{{ m.name | lower}}_amend_key}= Set Variable {{ f.name }}
${json_{{ m.name | lower}}_{{ f.name }}_amend_1}= Generate Random Value {{ f.type }}
${json_{{ m.name | lower }}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_amend_1}"
{% endif -%}
{% endif -%}
{% endif -%}
{% endif -%}
{% endif -%}
{% endfor -%}
{% if m.name == "User" -%}
${json_{{ m.name | lower}}_email}= Set Variable testuser@opencord.org
${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /email "${json_{{ m.name | lower }}_email}"
${json_{{ m.name | lower}}_email_amend_1}= Set Variable testuseramend@opencord.org
${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /email "${json_{{ m.name | lower }}_email_amend_1}"
{% endif %}
{% if m.name == "Site" -%}
${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase
${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /login_base "${json_{{ m.name | lower }}_login_base_tmp}"
{% endif %}
{% if m.name == "Flavor" -%}
${json_{{ m.name | lower}}_flavor_tmp}= Set Variable m1.small
${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /flavor "${json_{{ m.name | lower }}_flavor_tmp}"
{% endif %}
{% if m.name == "ServiceGraphConstraint" -%}
${json_{{ m.name | lower}}_constraints_tmp}= Generate Random Value string
${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /constraints "${json_{{ m.name | lower }}_constraints_tmp}"
{% endif %}
{% if m.name == "Slice" -%}
${json_{{ m.name | lower}}_name}= Generate Random Slice Name
${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /name "${json_{{ m.name | lower }}_name}"
${json_{{ m.name | lower}}_name_amend_1}= Generate Random Slice Name
${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /name "${json_{{ m.name | lower}}_name_amend_1}"
{% endif %}
${json_{{ m.name | lower }}_1}= To JSON ${json_{{ m.name | lower }}_1}
${json_{{ m.name | lower }}_amend_1}= To JSON ${json_{{ m.name | lower }}_amend_1}
Set Suite Variable ${json_{{ m.name | lower }}_1}
Set Suite Variable ${json_{{ m.name | lower }}_amend_1}
{% endif -%}
{% endfor %}
{% for m in proto.messages %}
{%- if m.name not in ['XOSBase'] -%}
Create {{ m.name }}
##Creating {{ m.name | lower }} object
${json_{{ m.name | lower }}_tmp}= Set Variable { }
# set required fields for {{ m.name | lower }} object
{% for f in m.fields + xproto_base_fields(m, proto.message_table) -%}
{% if f.link -%}
{% if f.modifier == "required" and f.options.blank != "True"-%}
# create dependent {{ f.options.model }}
${dependent_{{ f.options.model | lower }}_id}= Create {{ f.options.model }}
${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }}_id ${dependent_{{ f.options.model | lower }}_id}
{% endif -%}
{% else -%}
{% if f.modifier == "required" and f.options.blank != "True"-%}
{% if not f.options.default -%}
{% if m.name == "User" and f.name == "email" -%}
${json_user_email_tmp}= Generate Random Value {{ f.type }}
${json_user_email_tmp}= Catenate SEPARATOR= ${json_user_email_tmp} @opencord.org
${json_user_tmp}= Set Json Value ${json_user_tmp} /email "${json_user_email_tmp}"
{% else -%}
{% if f.name == "created" or f.name == "amend" or f.name =="expires" or f.name =='granted' -%}
${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value float
${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
{% elif f.name == "role" -%}
${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value role
${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
{% elif f.name == "direction" -%}
${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value direction
${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
{% elif f.name == "flavor" -%}
${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value flavor
${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
{% else -%}
${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value {{ f.type }}
${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
{% endif -%}
{% endif -%}
{% endif -%}
{% endif -%}
{% endif -%}
{% endfor -%}
{% if m.name == "Site" -%}
${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase
${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /login_base "${json_{{ m.name | lower }}_login_base_tmp}"
{% endif %}
{% if m.name == "Flavor" -%}
${json_{{ m.name | lower}}_flavor_tmp}= Set Variable m1.small
${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /flavor "${json_{{ m.name | lower }}_flavor_tmp}"
{% endif %}
{% if m.name == "ServiceGraphConstraint" -%}
${json_{{ m.name | lower}}_contraints_tmp}= Generate Random Value string
${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /contraints "${json_{{ m.name | lower }}_contraints_tmp}"
{% endif %}
{% if m.name == "Slice" -%}
${json_{{ m.name | lower}}_name}= Generate Random Slice Name
${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /name "${json_{{ m.name | lower }}_name}"
{% endif -%}
{% if m.name == "Network" -%}
${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /permit_all_slices true
{% endif %}
${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /no_policy true
${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /no_sync true
${json_{{ m.name | lower }}_tmp}= To JSON ${json_{{ m.name | lower }}_tmp}
${resp}= CORD Post /xosapi/v1/${xos_service}/{{ m.name | lower}}s ${json_{{ m.name | lower }}_tmp}
${id_{{ m.name | lower }}_tmp}= Get From Dictionary ${resp.json()} id
Append To List ${dependent_{{ m.name | lower }}_ids} ${id_{{ m.name | lower }}_tmp}
[Return] ${id_{{ m.name | lower }}_tmp}
{% endif %}
{% endfor -%}
Setup
{% for m in proto.messages %}
{%- if m.name not in ['XOSBase'] -%}
${model}= Set Variable {{ m.name | lower }}s
@{dependent_{{ m.name | lower }}_ids}= Create List ${model}
Set Suite Variable @{dependent_{{ m.name | lower }}_ids}
{% endif %}
{% endfor -%}
@{dependent_models}= Create List
Set Suite Variable ${dependent_models}
${auth} = Create List ${XOS_USER} ${XOS_PASSWD}
${HEADERS} Create Dictionary Content-Type=application/json
Create Session ${SERVER_IP} http://${SERVER_IP}:${SERVER_PORT} auth=${AUTH} headers=${HEADERS}
Generate JSON Data
Teardown
{% for m in proto.messages %}
{%- if m.name not in ['XOSBase'] -%}
${len}= Get Length ${dependent_{{ m.name | lower }}_ids}
: FOR ${INDEX} IN RANGE 1 ${len}
\ Run Keyword And Ignore Error CORD Delete /xosapi/v1/${xos_service}/${dependent_{{ m.name | lower }}_ids[0]} ${dependent_{{ m.name | lower }}_ids[${INDEX}]}
{% endif %}
{% endfor -%}
Delete All Sessions