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