blob: fc84f11bfa7727ed45fdfc461a5556b7dba42b92 [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 Khalasi9302c182018-05-07 13:46:15 -060027Update {{ m.name }} UPDATE /xosapi/v1/${xos_service}/{{ xproto_pluralize(m) | lower}} ${json_{{ m.name | lower}}_updated_1} ${id}
Kailash Khalasi008d5642018-02-12 12:59:53 -080028 [Tags] {{ m.name }}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -080029
Kailash Khalasi9302c182018-05-07 13:46:15 -060030Get {{ 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 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
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
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 { }
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 Khalasi78735ea2018-05-01 13:48:26 -070097 {% for f in m.fields + xproto_base_fields(m, proto.message_table) -%}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -080098 {% 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 -%}
Kailash Khalasi0132fd52018-08-09 15:20:45 -0700117 {% if m.name == "User" -%}
Kailash Khalasi8c3546b2018-08-09 16:41:20 -0700118 ${json_{{ m.name | lower}}_email}= Set Variable testuser@opencord.org
119 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /email "${json_{{ m.name | lower }}_email}"
120 ${json_{{ m.name | lower}}_email_updated_1}= Set Variable testuserupdated@opencord.org
121 ${json_{{ m.name | lower}}_updated_1}= Set Json Value ${json_{{ m.name | lower }}_updated_1} /email "${json_{{ m.name | lower }}_email_updated_1}"
Kailash Khalasi0132fd52018-08-09 15:20:45 -0700122 {% endif %}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800123 {% if m.name == "Site" -%}
124 ${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase
125 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /login_base "${json_{{ m.name | lower }}_login_base_tmp}"
126 {% endif %}
127 {% if m.name == "Slice" -%}
128 ${json_{{ m.name | lower}}_name}= Generate Random Slice Name
129 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /name "${json_{{ m.name | lower }}_name}"
130 ${json_{{ m.name | lower}}_name_updated_1}= Generate Random Slice Name
131 ${json_{{ m.name | lower}}_updated_1}= Set Json Value ${json_{{ m.name | lower }}_updated_1} /name "${json_{{ m.name | lower}}_name_updated_1}"
132 {% endif %}
133 ${json_{{ m.name | lower }}_1}= To JSON ${json_{{ m.name | lower }}_1}
134 ${json_{{ m.name | lower }}_updated_1}= To JSON ${json_{{ m.name | lower }}_updated_1}
135 Set Suite Variable ${json_{{ m.name | lower }}_1}
136 Set Suite Variable ${json_{{ m.name | lower }}_updated_1}
137 {% endif -%}
138 {% endfor %}
139
140{% for m in proto.messages %}
141{%- if m.name not in ['XOSBase'] -%}
142Create {{ m.name }}
143 ##Creating {{ m.name | lower }} object
144 ${json_{{ m.name | lower }}_tmp}= Set Variable { }
145 # set required fields for {{ m.name | lower }} object
Kailash Khalasi78735ea2018-05-01 13:48:26 -0700146 {% for f in m.fields + xproto_base_fields(m, proto.message_table) -%}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800147 {% if f.link -%}
148 {% if f.modifier == "required" -%}
149 {% if f.options.blank == "False" -%}
150 # create dependent {{ f.options.model }}
151 ${dependent_{{ f.options.model | lower }}_id}= Create {{ f.options.model }}
152 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }}_id ${dependent_{{ f.options.model | lower }}_id}
153 {% endif -%}
154 {% endif -%}
155 {% else -%}
156 {% if f.modifier == "required" -%}
157 {% if f.options.blank == "False" -%}
158 {% if not f.options.default -%}
Kailash Khalasi1470fc32018-08-09 13:09:11 -0700159 {% if m.name == "User" and f.name == "email" -%}
160 ${json_user_email_tmp}= Generate Random Value {{ f.type }}
161 ${json_user_email_tmp}= Catenate SEPARATOR= ${json_user_email_tmp} @opencord.org
162 ${json_user_tmp}= Set Json Value ${json_user_tmp} /email "${json_user_email_tmp}"
163 {% else -%}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800164 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value {{ f.type }}
165 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
166 {% endif -%}
167 {% endif -%}
168 {% endif -%}
169 {% endif -%}
Kailash Khalasi1470fc32018-08-09 13:09:11 -0700170 {% endif -%}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800171 {% endfor -%}
172 {% if m.name == "Site" -%}
173 ${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase
174 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /login_base "${json_{{ m.name | lower }}_login_base_tmp}"
175 {% endif %}
176 {% if m.name == "Slice" -%}
177 ${json_{{ m.name | lower}}_name}= Generate Random Slice Name
178 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /name "${json_{{ m.name | lower }}_name}"
179 {% endif %}
180 {% if m.name == "Network" -%}
181 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /permit_all_slices true
182 {% endif %}
183 ${json_{{ m.name | lower }}_tmp}= To JSON ${json_{{ m.name | lower }}_tmp}
184 ${resp}= CORD Post /xosapi/v1/${xos_service}/{{ m.name | lower}}s ${json_{{ m.name | lower }}_tmp}
185 ${id_{{ m.name | lower }}_tmp}= Get Json Value ${resp.content} /id
186 Append To List ${dependent_{{ m.name | lower }}_ids} ${id_{{ m.name | lower }}_tmp}
187 [Return] ${id_{{ m.name | lower }}_tmp}
188{% endif %}
189{% endfor -%}
190
191Setup
192 {% for m in proto.messages %}
193 {%- if m.name not in ['XOSBase'] -%}
194 ${model}= Set Variable {{ m.name | lower }}s
195 @{dependent_{{ m.name | lower }}_ids}= Create List ${model}
196 Set Suite Variable @{dependent_{{ m.name | lower }}_ids}
197 {% endif %}
198 {% endfor -%}
199 @{dependent_models}= Create List
200 Set Suite Variable ${dependent_models}
Kailash Khalasi68f9f632018-04-11 08:09:19 -0700201 ${auth} = Create List ${XOS_USER} ${XOS_PASSWD}
Kailash Khalasi8416bfe2017-12-20 13:06:37 -0800202 ${HEADERS} Create Dictionary Content-Type=application/json
203 Create Session ${SERVER_IP} http://${SERVER_IP}:${SERVER_PORT} auth=${AUTH} headers=${HEADERS}
204 Generate JSON Data
205
206Teardown
207 {% for m in proto.messages %}
208 {%- if m.name not in ['XOSBase'] -%}
209 ${len}= Get Length ${dependent_{{ m.name | lower }}_ids}
210 : FOR ${INDEX} IN RANGE 1 ${len}
211 \ Run Keyword And Ignore Error CORD Delete /xosapi/v1/${xos_service}/${dependent_{{ m.name | lower }}_ids[0]} ${dependent_{{ m.name | lower }}_ids[${INDEX}]}
212 {% endif %}
213 {% endfor -%}
Kailash Khalasi9302c182018-05-07 13:46:15 -0600214 Delete All Sessions
Kailash Khalasi1470fc32018-08-09 13:09:11 -0700215