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