blob: 1e4121e76f18bf7f583789abfd8b2bc61a347bc9 [file] [log] [blame]
Kailash Khalasi8416bfe2017-12-20 13:06:37 -08001*** Settings ***
2Documentation Test Suite for XOS APIs
3Suite Setup Setup
4Suite Teardown Teardown
5Test Template Verify API Functionality
6Library Collections
7Library String
8Library OperatingSystem
9Library XML
10Library RequestsLibrary
Kailash Khalasi78735ea2018-05-01 13:48:26 -070011Library HttpLibrary.HTTP
Kailash Khalasi8416bfe2017-12-20 13:06:37 -080012Library ../Framework/utils/utils.py
13Library ../Framework/restApi.py
14Variables ../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 Khalasi8416bfe2017-12-20 13:06:37 -080022{% autoescape false %}
23{% endautoescape %}
Kailash Khalasi9302c182018-05-07 13:46:15 -060024Create {{ m.name }} CREATE /xosapi/v1/${xos_service}/{{ xproto_pluralize(m) | lower}} ${json_{{ m.name | lower}}_1}
Kailash Khalasi008d5642018-02-12 12:59:53 -080025 [Tags] {{ m.name }}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -080026
Kailash Khalasicceec832018-08-10 15:46:50 -070027Update {{ m.name }} UPDATE /xosapi/v1/${xos_service}/{{ xproto_pluralize(m) | lower}} ${json_{{ m.name | lower}}_amend_1} ${id}
Kailash Khalasi008d5642018-02-12 12:59:53 -080028 [Tags] {{ m.name }}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -080029
Kailash Khalasicceec832018-08-10 15:46:50 -070030Get {{ m.name }} RETRIEVE /xosapi/v1/${xos_service}/{{ xproto_pluralize(m) | lower}} ${json_{{ m.name | lower}}_amend_1} ${id} ${json_{{ m.name | lower}}_amend_key}
Kailash Khalasi008d5642018-02-12 12:59:53 -080031 [Tags] {{ m.name }}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -080032
Kailash Khalasi9302c182018-05-07 13:46:15 -060033Delete {{ m.name }} DELETE /xosapi/v1/${xos_service}/{{ xproto_pluralize(m) | lower}} data_id=${id}
Kailash Khalasi008d5642018-02-12 12:59:53 -080034 [Tags] {{ m.name }}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -080035{% endif %}
36{% endfor -%}
37
38*** Keywords ***
39Verify 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
46CORD 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
Kailash Khalasicceec832018-08-10 15:46:50 -070052 ${amend_value}= Run Keyword If '${key}' != 'null' Get Json Value ${resp.content} /${key}
53 ${amend_value}= Run Keyword If '${key}' != 'null' Remove String ${amend_value} "
54 Run Keyword If '${key}' != 'null' Should Contain "${value}" ${amend_value}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -080055 [Return] ${resp}
56
57CORD 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
68CORD 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
79CORD 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
87Generate 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 { }
Kailash Khalasicceec832018-08-10 15:46:50 -070093 ${json_{{ m.name | lower }}_amend_1}= Set Variable { }
94 ${json_{{ m.name | lower}}_amend_key}= Set Variable null
95 Set Suite Variable ${json_{{ m.name | lower}}_amend_key}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -080096 # set required fields for {{ m.name | lower }} object
Kailash Khalasi78735ea2018-05-01 13:48:26 -070097 {% for f in m.fields + xproto_base_fields(m, proto.message_table) -%}
Kailash Khalasicceec832018-08-10 15:46:50 -070098 {% if f.modifier == "required" and f.options.blank != "True" -%}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -080099 {% if not f.options.default -%}
100 {% if f.link -%}
101 ${tmp_{{ f.options.model | lower }}_id}= Create {{ f.options.model }}
102 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }}_id ${tmp_{{ f.options.model | lower }}_id}
Kailash Khalasi91d9dc02018-08-27 10:33:12 -0700103 {% elif f.name == "created" or f.name == "amend" or f.name =="expires" or f.name =='granted' -%}
104 ${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value float
105 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_1}"
106 {% elif f.name == "role" -%}
107 ${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value role
108 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_1}"
109 {% elif f.name == "direction" -%}
110 ${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value direction
111 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_1}"
112 {% elif f.name == "flavor" -%}
113 ${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value flavor
114 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_1}"
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800115 {% else -%}
116 ${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value {{ f.type }}
117 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_1}"
Kailash Khalasicceec832018-08-10 15:46:50 -0700118 {% if f.name == "created" or f.name == "amend" or f.name =="expires" or f.name =='granted' -%}
119 ${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value float
120 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_1}"
121 {% else -%}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800122 {% if loop.index0 == 0 -%}
Kailash Khalasicceec832018-08-10 15:46:50 -0700123 ${json_{{ m.name | lower}}_amend_key}= Set Variable {{ f.name }}
124 ${json_{{ m.name | lower}}_{{ f.name }}_amend_1}= Generate Random Value {{ f.type }}
125 ${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}"
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800126 {% endif -%}
127 {% endif -%}
128 {% endif -%}
129 {% endif -%}
130 {% endif -%}
131 {% endfor -%}
Kailash Khalasi0132fd52018-08-09 15:20:45 -0700132 {% if m.name == "User" -%}
Kailash Khalasi8c3546b2018-08-09 16:41:20 -0700133 ${json_{{ m.name | lower}}_email}= Set Variable testuser@opencord.org
134 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /email "${json_{{ m.name | lower }}_email}"
Kailash Khalasicceec832018-08-10 15:46:50 -0700135 ${json_{{ m.name | lower}}_email_amend_1}= Set Variable testuseramend@opencord.org
136 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /email "${json_{{ m.name | lower }}_email_amend_1}"
Kailash Khalasi0132fd52018-08-09 15:20:45 -0700137 {% endif %}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800138 {% if m.name == "Site" -%}
139 ${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase
140 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /login_base "${json_{{ m.name | lower }}_login_base_tmp}"
141 {% endif %}
Kailash Khalasi3566ed82018-08-27 13:16:49 -0700142 {% if m.name == "Flavor" -%}
143 ${json_{{ m.name | lower}}_flavor_tmp}= Set Variable m1.small
144 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /flavor "${json_{{ m.name | lower }}_flavor_tmp}"
145 {% endif %}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800146 {% if m.name == "Slice" -%}
147 ${json_{{ m.name | lower}}_name}= Generate Random Slice Name
148 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /name "${json_{{ m.name | lower }}_name}"
Kailash Khalasicceec832018-08-10 15:46:50 -0700149 ${json_{{ m.name | lower}}_name_amend_1}= Generate Random Slice Name
150 ${json_{{ m.name | lower}}_amend_1}= Set Json Value ${json_{{ m.name | lower }}_amend_1} /name "${json_{{ m.name | lower}}_name_amend_1}"
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800151 {% endif %}
152 ${json_{{ m.name | lower }}_1}= To JSON ${json_{{ m.name | lower }}_1}
Kailash Khalasicceec832018-08-10 15:46:50 -0700153 ${json_{{ m.name | lower }}_amend_1}= To JSON ${json_{{ m.name | lower }}_amend_1}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800154 Set Suite Variable ${json_{{ m.name | lower }}_1}
Kailash Khalasicceec832018-08-10 15:46:50 -0700155 Set Suite Variable ${json_{{ m.name | lower }}_amend_1}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800156 {% endif -%}
157 {% endfor %}
158
159{% for m in proto.messages %}
160{%- if m.name not in ['XOSBase'] -%}
161Create {{ m.name }}
162 ##Creating {{ m.name | lower }} object
163 ${json_{{ m.name | lower }}_tmp}= Set Variable { }
164 # set required fields for {{ m.name | lower }} object
Kailash Khalasi78735ea2018-05-01 13:48:26 -0700165 {% for f in m.fields + xproto_base_fields(m, proto.message_table) -%}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800166 {% if f.link -%}
Kailash Khalasicceec832018-08-10 15:46:50 -0700167 {% if f.modifier == "required" and f.options.blank != "True"-%}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800168 # create dependent {{ f.options.model }}
169 ${dependent_{{ f.options.model | lower }}_id}= Create {{ f.options.model }}
170 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }}_id ${dependent_{{ f.options.model | lower }}_id}
171 {% endif -%}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800172 {% else -%}
Kailash Khalasicceec832018-08-10 15:46:50 -0700173 {% if f.modifier == "required" and f.options.blank != "True"-%}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800174 {% if not f.options.default -%}
Kailash Khalasi1470fc32018-08-09 13:09:11 -0700175 {% if m.name == "User" and f.name == "email" -%}
176 ${json_user_email_tmp}= Generate Random Value {{ f.type }}
177 ${json_user_email_tmp}= Catenate SEPARATOR= ${json_user_email_tmp} @opencord.org
178 ${json_user_tmp}= Set Json Value ${json_user_tmp} /email "${json_user_email_tmp}"
179 {% else -%}
Kailash Khalasicceec832018-08-10 15:46:50 -0700180 {% if f.name == "created" or f.name == "amend" or f.name =="expires" or f.name =='granted' -%}
181 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value float
182 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
Kailash Khalasi91d9dc02018-08-27 10:33:12 -0700183 {% elif f.name == "role" -%}
184 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value role
185 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
186 {% elif f.name == "direction" -%}
187 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value direction
188 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
189 {% elif f.name == "flavor" -%}
190 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value flavor
191 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
Kailash Khalasicceec832018-08-10 15:46:50 -0700192 {% else -%}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800193 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value {{ f.type }}
194 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
195 {% endif -%}
196 {% endif -%}
197 {% endif -%}
198 {% endif -%}
Kailash Khalasi1470fc32018-08-09 13:09:11 -0700199 {% endif -%}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800200 {% endfor -%}
201 {% if m.name == "Site" -%}
202 ${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase
203 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /login_base "${json_{{ m.name | lower }}_login_base_tmp}"
204 {% endif %}
Kailash Khalasi3566ed82018-08-27 13:16:49 -0700205 {% if m.name == "Flavor" -%}
206 ${json_{{ m.name | lower}}_flavor_tmp}= Set Variable m1.small
207 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /flavor "${json_{{ m.name | lower }}_flavor_tmp}"
208 {% endif %}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800209 {% if m.name == "Slice" -%}
210 ${json_{{ m.name | lower}}_name}= Generate Random Slice Name
211 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /name "${json_{{ m.name | lower }}_name}"
Kailash Khalasi0e2bb702018-08-23 14:46:16 -0700212 {% endif -%}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800213 {% if m.name == "Network" -%}
214 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /permit_all_slices true
215 {% endif %}
216 ${json_{{ m.name | lower }}_tmp}= To JSON ${json_{{ m.name | lower }}_tmp}
217 ${resp}= CORD Post /xosapi/v1/${xos_service}/{{ m.name | lower}}s ${json_{{ m.name | lower }}_tmp}
218 ${id_{{ m.name | lower }}_tmp}= Get Json Value ${resp.content} /id
219 Append To List ${dependent_{{ m.name | lower }}_ids} ${id_{{ m.name | lower }}_tmp}
220 [Return] ${id_{{ m.name | lower }}_tmp}
221{% endif %}
222{% endfor -%}
223
224Setup
225 {% for m in proto.messages %}
226 {%- if m.name not in ['XOSBase'] -%}
227 ${model}= Set Variable {{ m.name | lower }}s
228 @{dependent_{{ m.name | lower }}_ids}= Create List ${model}
229 Set Suite Variable @{dependent_{{ m.name | lower }}_ids}
230 {% endif %}
231 {% endfor -%}
232 @{dependent_models}= Create List
233 Set Suite Variable ${dependent_models}
Kailash Khalasi68f9f632018-04-11 08:09:19 -0700234 ${auth} = Create List ${XOS_USER} ${XOS_PASSWD}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800235 ${HEADERS} Create Dictionary Content-Type=application/json
236 Create Session ${SERVER_IP} http://${SERVER_IP}:${SERVER_PORT} auth=${AUTH} headers=${HEADERS}
237 Generate JSON Data
238
239Teardown
240 {% for m in proto.messages %}
241 {%- if m.name not in ['XOSBase'] -%}
242 ${len}= Get Length ${dependent_{{ m.name | lower }}_ids}
243 : FOR ${INDEX} IN RANGE 1 ${len}
244 \ Run Keyword And Ignore Error CORD Delete /xosapi/v1/${xos_service}/${dependent_{{ m.name | lower }}_ids[0]} ${dependent_{{ m.name | lower }}_ids[${INDEX}]}
245 {% endif %}
246 {% endfor -%}
Kailash Khalasi9302c182018-05-07 13:46:15 -0600247 Delete All Sessions
Kailash Khalasi1470fc32018-08-09 13:09:11 -0700248