Kailash Khalasi | 8416bfe | 2017-12-20 13:06:37 -0800 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Documentation Test Suite for XOS APIs |
| 3 | Suite Setup Setup |
| 4 | Suite Teardown Teardown |
| 5 | Test Template Verify API Functionality |
| 6 | Library Collections |
| 7 | Library String |
| 8 | Library OperatingSystem |
| 9 | Library XML |
| 10 | Library RequestsLibrary |
Kailash Khalasi | 78735ea | 2018-05-01 13:48:26 -0700 | [diff] [blame] | 11 | Library HttpLibrary.HTTP |
Kailash Khalasi | 8416bfe | 2017-12-20 13:06:37 -0800 | [diff] [blame] | 12 | Library ../Framework/utils/utils.py |
| 13 | Library ../Framework/restApi.py |
| 14 | Variables ../Properties/RestApiProperties.py |
| 15 | |
| 16 | *** Variables *** |
| 17 | ${xos_service} core |
| 18 | |
| 19 | *** Test Cases *** TYPE API |
| 20 | {%- for m in proto.messages -%} |
| 21 | {%- if m.name not in ['XOSBase'] -%} |
| 22 | {%- if m.name not in ['ServiceMonitoringAgentInfo', 'XOS'] -%} |
| 23 | {% autoescape false %} |
| 24 | {% endautoescape %} |
| 25 | Create {{ m.name }} CREATE /xosapi/v1/${xos_service}/{{ m.name | lower}}s ${json_{{ m.name | lower}}_1} |
Kailash Khalasi | 008d564 | 2018-02-12 12:59:53 -0800 | [diff] [blame] | 26 | [Tags] {{ m.name }} |
Kailash Khalasi | 8416bfe | 2017-12-20 13:06:37 -0800 | [diff] [blame] | 27 | |
| 28 | Update {{ m.name }} UPDATE /xosapi/v1/${xos_service}/{{ m.name | lower}}s ${json_{{ m.name | lower}}_updated_1} ${id} |
Kailash Khalasi | 008d564 | 2018-02-12 12:59:53 -0800 | [diff] [blame] | 29 | [Tags] {{ m.name }} |
Kailash Khalasi | 8416bfe | 2017-12-20 13:06:37 -0800 | [diff] [blame] | 30 | |
| 31 | Get {{ m.name }} RETRIEVE /xosapi/v1/${xos_service}/{{ m.name | lower}}s ${json_{{ m.name | lower}}_updated_1} ${id} ${json_{{ m.name | lower}}_updated_key} |
Kailash Khalasi | 008d564 | 2018-02-12 12:59:53 -0800 | [diff] [blame] | 32 | [Tags] {{ m.name }} |
Kailash Khalasi | 8416bfe | 2017-12-20 13:06:37 -0800 | [diff] [blame] | 33 | |
| 34 | Delete {{ m.name }} DELETE /xosapi/v1/${xos_service}/{{ m.name | lower}}s data_id=${id} |
Kailash Khalasi | 008d564 | 2018-02-12 12:59:53 -0800 | [diff] [blame] | 35 | [Tags] {{ m.name }} |
Kailash Khalasi | 8416bfe | 2017-12-20 13:06:37 -0800 | [diff] [blame] | 36 | {% else %} |
| 37 | Create {{ m.name }} CREATE /xosapi/v1/${xos_service}/{{ m.name | lower}}es ${json_{{ m.name | lower}}_1} |
Kailash Khalasi | 008d564 | 2018-02-12 12:59:53 -0800 | [diff] [blame] | 38 | [Tags] {{ m.name }} |
Kailash Khalasi | 8416bfe | 2017-12-20 13:06:37 -0800 | [diff] [blame] | 39 | |
| 40 | Update {{ m.name }} UPDATE /xosapi/v1/${xos_service}/{{ m.name | lower}}es ${json_{{ m.name | lower}}_updated_1} ${id} |
Kailash Khalasi | 008d564 | 2018-02-12 12:59:53 -0800 | [diff] [blame] | 41 | [Tags] {{ m.name }} |
Kailash Khalasi | 8416bfe | 2017-12-20 13:06:37 -0800 | [diff] [blame] | 42 | |
| 43 | Get {{ m.name }} RETRIEVE /xosapi/v1/${xos_service}/{{ m.name | lower}}es ${json_{{ m.name | lower}}_updated_1} ${id} ${json_{{ m.name | lower}}_updated_key} |
Kailash Khalasi | 008d564 | 2018-02-12 12:59:53 -0800 | [diff] [blame] | 44 | [Tags] {{ m.name }} |
Kailash Khalasi | 8416bfe | 2017-12-20 13:06:37 -0800 | [diff] [blame] | 45 | |
| 46 | Delete {{ m.name }} DELETE /xosapi/v1/${xos_service}/{{ m.name | lower}}es data_id=${id} |
Kailash Khalasi | 008d564 | 2018-02-12 12:59:53 -0800 | [diff] [blame] | 47 | [Tags] {{ m.name }} |
Kailash Khalasi | 8416bfe | 2017-12-20 13:06:37 -0800 | [diff] [blame] | 48 | {% endif %} |
| 49 | {% endif %} |
| 50 | {% endfor -%} |
| 51 | |
| 52 | *** Keywords *** |
| 53 | Verify API Functionality |
| 54 | [Arguments] ${type} ${endpoint} ${data}=${EMPTY} ${data_id}=${EMPTY} ${key}=${EMPTY} |
| 55 | Run Keyword If "${type}" == "RETRIEVE" CORD Get ${endpoint} ${data_id} ${data} ${key} |
| 56 | Run Keyword If "${type}" == "CREATE" CORD Post ${endpoint} ${data} |
| 57 | Run Keyword If "${type}" == "UPDATE" CORD Put ${endpoint} ${data} ${data_id} |
| 58 | Run Keyword If "${type}" == "DELETE" CORD Delete ${endpoint} ${data_id} |
| 59 | |
| 60 | CORD Get |
| 61 | [Documentation] Make a GET call to the CORD controller |
| 62 | [Arguments] ${service} ${id} ${value} ${key} |
| 63 | ${resp}= Get Request ${SERVER_IP} ${service}/${id} |
| 64 | Log ${resp.content} |
| 65 | Should Be Equal As Strings ${resp.status_code} 200 |
| 66 | ${updated_value}= Run Keyword If '${key}' != 'null' Get Json Value ${resp.content} /${key} |
| 67 | ${updated_value}= Run Keyword If '${key}' != 'null' Remove String ${updated_value} " |
| 68 | Run Keyword If '${key}' != 'null' Should Contain "${value}" ${updated_value} |
| 69 | [Return] ${resp} |
| 70 | |
| 71 | CORD Post |
| 72 | [Documentation] Make a POST call to the CORD controller |
| 73 | [Arguments] ${service} ${data} |
| 74 | ${data}= Evaluate json.dumps(${data}) json |
| 75 | ${resp}= Post Request ${SERVER_IP} uri=${service} data=${data} |
| 76 | Log ${resp.content} |
| 77 | Should Be Equal As Strings ${resp.status_code} 200 |
| 78 | ${id}= Get Json Value ${resp.content} /id |
| 79 | Set Suite Variable ${id} |
| 80 | [Return] ${resp} |
| 81 | |
| 82 | CORD Put |
| 83 | [Documentation] Make a PUT call to the CORD controller |
| 84 | [Arguments] ${service} ${data} ${data_id} |
| 85 | ${data}= Evaluate json.dumps(${data}) json |
| 86 | ${resp}= Put Request ${SERVER_IP} uri=${service}/${data_id} data=${data} |
| 87 | Log ${resp.content} |
| 88 | Should Be Equal As Strings ${resp.status_code} 200 |
| 89 | ${id}= Get Json Value ${resp.content} /id |
| 90 | Set Suite Variable ${id} |
| 91 | [Return] ${resp} |
| 92 | |
| 93 | CORD Delete |
| 94 | [Documentation] Make a DELETE call to the CORD controller |
| 95 | [Arguments] ${service} ${data_id} |
| 96 | ${resp}= Delete Request ${SERVER_IP} uri=${service}/${data_id} |
| 97 | Log ${resp.content} |
| 98 | Should Be Equal As Strings ${resp.status_code} 200 |
| 99 | [Return] ${resp} |
| 100 | |
| 101 | Generate JSON Data |
| 102 | {%- for m in proto.messages -%} |
| 103 | {%- if m.name not in ['XOSBase'] -%} |
| 104 | {% autoescape false %} |
| 105 | {% endautoescape %} |
| 106 | ${json_{{ m.name | lower }}_1}= Set Variable { } |
| 107 | ${json_{{ m.name | lower }}_updated_1}= Set Variable { } |
| 108 | ${json_{{ m.name | lower}}_updated_key}= Set Variable null |
| 109 | Set Suite Variable ${json_{{ m.name | lower}}_updated_key} |
| 110 | # set required fields for {{ m.name | lower }} object |
Kailash Khalasi | 78735ea | 2018-05-01 13:48:26 -0700 | [diff] [blame] | 111 | {% for f in m.fields + xproto_base_fields(m, proto.message_table) -%} |
Kailash Khalasi | 8416bfe | 2017-12-20 13:06:37 -0800 | [diff] [blame] | 112 | {% if f.modifier == "required" -%} |
| 113 | {% if f.options.blank == "False" -%} |
| 114 | {% if not f.options.default -%} |
| 115 | {% if f.link -%} |
| 116 | ${tmp_{{ f.options.model | lower }}_id}= Create {{ f.options.model }} |
| 117 | ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }}_id ${tmp_{{ f.options.model | lower }}_id} |
| 118 | {% else -%} |
| 119 | ${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value {{ f.type }} |
| 120 | ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_1}" |
| 121 | {% if loop.index0 == 0 -%} |
| 122 | ${json_{{ m.name | lower}}_updated_key}= Set Variable {{ f.name }} |
| 123 | ${json_{{ m.name | lower}}_{{ f.name }}_updated_1}= Generate Random Value {{ f.type }} |
| 124 | ${json_{{ m.name | lower }}_updated_1}= Set Json Value ${json_{{ m.name | lower }}_updated__1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_updated_1}" |
| 125 | {% endif -%} |
| 126 | {% endif -%} |
| 127 | {% endif -%} |
| 128 | {% endif -%} |
| 129 | {% endif -%} |
| 130 | {% endfor -%} |
| 131 | {% if m.name == "Site" -%} |
| 132 | ${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase |
| 133 | ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /login_base "${json_{{ m.name | lower }}_login_base_tmp}" |
| 134 | {% endif %} |
| 135 | {% if m.name == "Slice" -%} |
| 136 | ${json_{{ m.name | lower}}_name}= Generate Random Slice Name |
| 137 | ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /name "${json_{{ m.name | lower }}_name}" |
| 138 | ${json_{{ m.name | lower}}_name_updated_1}= Generate Random Slice Name |
| 139 | ${json_{{ m.name | lower}}_updated_1}= Set Json Value ${json_{{ m.name | lower }}_updated_1} /name "${json_{{ m.name | lower}}_name_updated_1}" |
| 140 | {% endif %} |
| 141 | ${json_{{ m.name | lower }}_1}= To JSON ${json_{{ m.name | lower }}_1} |
| 142 | ${json_{{ m.name | lower }}_updated_1}= To JSON ${json_{{ m.name | lower }}_updated_1} |
| 143 | Set Suite Variable ${json_{{ m.name | lower }}_1} |
| 144 | Set Suite Variable ${json_{{ m.name | lower }}_updated_1} |
| 145 | {% endif -%} |
| 146 | {% endfor %} |
| 147 | |
| 148 | {% for m in proto.messages %} |
| 149 | {%- if m.name not in ['XOSBase'] -%} |
| 150 | Create {{ m.name }} |
| 151 | ##Creating {{ m.name | lower }} object |
| 152 | ${json_{{ m.name | lower }}_tmp}= Set Variable { } |
| 153 | # set required fields for {{ m.name | lower }} object |
Kailash Khalasi | 78735ea | 2018-05-01 13:48:26 -0700 | [diff] [blame] | 154 | {% for f in m.fields + xproto_base_fields(m, proto.message_table) -%} |
Kailash Khalasi | 8416bfe | 2017-12-20 13:06:37 -0800 | [diff] [blame] | 155 | {% if f.link -%} |
| 156 | {% if f.modifier == "required" -%} |
| 157 | {% if f.options.blank == "False" -%} |
| 158 | # create dependent {{ f.options.model }} |
| 159 | ${dependent_{{ f.options.model | lower }}_id}= Create {{ f.options.model }} |
| 160 | ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }}_id ${dependent_{{ f.options.model | lower }}_id} |
| 161 | {% endif -%} |
| 162 | {% endif -%} |
| 163 | {% else -%} |
| 164 | {% if f.modifier == "required" -%} |
| 165 | {% if f.options.blank == "False" -%} |
| 166 | {% if not f.options.default -%} |
| 167 | ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value {{ f.type }} |
| 168 | ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}" |
| 169 | {% endif -%} |
| 170 | {% endif -%} |
| 171 | {% endif -%} |
| 172 | {% endif -%} |
| 173 | {% endfor -%} |
| 174 | {% if m.name == "Site" -%} |
| 175 | ${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase |
| 176 | ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /login_base "${json_{{ m.name | lower }}_login_base_tmp}" |
| 177 | {% endif %} |
| 178 | {% if m.name == "Slice" -%} |
| 179 | ${json_{{ m.name | lower}}_name}= Generate Random Slice Name |
| 180 | ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /name "${json_{{ m.name | lower }}_name}" |
| 181 | {% endif %} |
| 182 | {% if m.name == "Network" -%} |
| 183 | ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /permit_all_slices true |
| 184 | {% endif %} |
| 185 | ${json_{{ m.name | lower }}_tmp}= To JSON ${json_{{ m.name | lower }}_tmp} |
| 186 | ${resp}= CORD Post /xosapi/v1/${xos_service}/{{ m.name | lower}}s ${json_{{ m.name | lower }}_tmp} |
| 187 | ${id_{{ m.name | lower }}_tmp}= Get Json Value ${resp.content} /id |
| 188 | Append To List ${dependent_{{ m.name | lower }}_ids} ${id_{{ m.name | lower }}_tmp} |
| 189 | [Return] ${id_{{ m.name | lower }}_tmp} |
| 190 | {% endif %} |
| 191 | {% endfor -%} |
| 192 | |
| 193 | Setup |
| 194 | {% for m in proto.messages %} |
| 195 | {%- if m.name not in ['XOSBase'] -%} |
| 196 | ${model}= Set Variable {{ m.name | lower }}s |
| 197 | @{dependent_{{ m.name | lower }}_ids}= Create List ${model} |
| 198 | Set Suite Variable @{dependent_{{ m.name | lower }}_ids} |
| 199 | {% endif %} |
| 200 | {% endfor -%} |
| 201 | @{dependent_models}= Create List |
| 202 | Set Suite Variable ${dependent_models} |
Kailash Khalasi | 68f9f63 | 2018-04-11 08:09:19 -0700 | [diff] [blame] | 203 | ${auth} = Create List ${XOS_USER} ${XOS_PASSWD} |
Kailash Khalasi | 8416bfe | 2017-12-20 13:06:37 -0800 | [diff] [blame] | 204 | ${HEADERS} Create Dictionary Content-Type=application/json |
| 205 | Create Session ${SERVER_IP} http://${SERVER_IP}:${SERVER_PORT} auth=${AUTH} headers=${HEADERS} |
| 206 | Generate JSON Data |
| 207 | |
| 208 | Teardown |
| 209 | {% for m in proto.messages %} |
| 210 | {%- if m.name not in ['XOSBase'] -%} |
| 211 | ${len}= Get Length ${dependent_{{ m.name | lower }}_ids} |
| 212 | : FOR ${INDEX} IN RANGE 1 ${len} |
| 213 | \ Run Keyword And Ignore Error CORD Delete /xosapi/v1/${xos_service}/${dependent_{{ m.name | lower }}_ids[0]} ${dependent_{{ m.name | lower }}_ids[${INDEX}]} |
| 214 | {% endif %} |
| 215 | {% endfor -%} |
Kailash Khalasi | 7261480 | 2018-05-02 09:21:23 -0700 | [diff] [blame] | 216 | Delete All Sessions |