blob: d256dd528c32f108bcb05415cd05ad01ac9f99fe [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
11Library HttpLibrary.HTTP
12Library ../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'] -%}
22{%- if m.name not in ['ServiceMonitoringAgentInfo', 'XOS'] -%}
23{% autoescape false %}
24{% endautoescape %}
25Create {{ m.name }} CREATE /xosapi/v1/${xos_service}/{{ m.name | lower}}s ${json_{{ m.name | lower}}_1}
26
27Update {{ m.name }} UPDATE /xosapi/v1/${xos_service}/{{ m.name | lower}}s ${json_{{ m.name | lower}}_updated_1} ${id}
28
29Get {{ m.name }} RETRIEVE /xosapi/v1/${xos_service}/{{ m.name | lower}}s ${json_{{ m.name | lower}}_updated_1} ${id} ${json_{{ m.name | lower}}_updated_key}
30
31Delete {{ m.name }} DELETE /xosapi/v1/${xos_service}/{{ m.name | lower}}s data_id=${id}
32{% else %}
33Create {{ m.name }} CREATE /xosapi/v1/${xos_service}/{{ m.name | lower}}es ${json_{{ m.name | lower}}_1}
34
35Update {{ m.name }} UPDATE /xosapi/v1/${xos_service}/{{ m.name | lower}}es ${json_{{ m.name | lower}}_updated_1} ${id}
36
37Get {{ m.name }} RETRIEVE /xosapi/v1/${xos_service}/{{ m.name | lower}}es ${json_{{ m.name | lower}}_updated_1} ${id} ${json_{{ m.name | lower}}_updated_key}
38
39Delete {{ m.name }} DELETE /xosapi/v1/${xos_service}/{{ m.name | lower}}es data_id=${id}
40{% endif %}
41{% endif %}
42{% endfor -%}
43
44*** Keywords ***
45Verify API Functionality
46 [Arguments] ${type} ${endpoint} ${data}=${EMPTY} ${data_id}=${EMPTY} ${key}=${EMPTY}
47 Run Keyword If "${type}" == "RETRIEVE" CORD Get ${endpoint} ${data_id} ${data} ${key}
48 Run Keyword If "${type}" == "CREATE" CORD Post ${endpoint} ${data}
49 Run Keyword If "${type}" == "UPDATE" CORD Put ${endpoint} ${data} ${data_id}
50 Run Keyword If "${type}" == "DELETE" CORD Delete ${endpoint} ${data_id}
51
52CORD Get
53 [Documentation] Make a GET call to the CORD controller
54 [Arguments] ${service} ${id} ${value} ${key}
55 ${resp}= Get Request ${SERVER_IP} ${service}/${id}
56 Log ${resp.content}
57 Should Be Equal As Strings ${resp.status_code} 200
58 ${updated_value}= Run Keyword If '${key}' != 'null' Get Json Value ${resp.content} /${key}
59 ${updated_value}= Run Keyword If '${key}' != 'null' Remove String ${updated_value} "
60 Run Keyword If '${key}' != 'null' Should Contain "${value}" ${updated_value}
61 [Return] ${resp}
62
63CORD Post
64 [Documentation] Make a POST call to the CORD controller
65 [Arguments] ${service} ${data}
66 ${data}= Evaluate json.dumps(${data}) json
67 ${resp}= Post Request ${SERVER_IP} uri=${service} data=${data}
68 Log ${resp.content}
69 Should Be Equal As Strings ${resp.status_code} 200
70 ${id}= Get Json Value ${resp.content} /id
71 Set Suite Variable ${id}
72 [Return] ${resp}
73
74CORD Put
75 [Documentation] Make a PUT call to the CORD controller
76 [Arguments] ${service} ${data} ${data_id}
77 ${data}= Evaluate json.dumps(${data}) json
78 ${resp}= Put Request ${SERVER_IP} uri=${service}/${data_id} data=${data}
79 Log ${resp.content}
80 Should Be Equal As Strings ${resp.status_code} 200
81 ${id}= Get Json Value ${resp.content} /id
82 Set Suite Variable ${id}
83 [Return] ${resp}
84
85CORD Delete
86 [Documentation] Make a DELETE call to the CORD controller
87 [Arguments] ${service} ${data_id}
88 ${resp}= Delete Request ${SERVER_IP} uri=${service}/${data_id}
89 Log ${resp.content}
90 Should Be Equal As Strings ${resp.status_code} 200
91 [Return] ${resp}
92
93Generate JSON Data
94 {%- for m in proto.messages -%}
95 {%- if m.name not in ['XOSBase'] -%}
96 {% autoescape false %}
97 {% endautoescape %}
98 ${json_{{ m.name | lower }}_1}= Set Variable { }
99 ${json_{{ m.name | lower }}_updated_1}= Set Variable { }
100 ${json_{{ m.name | lower}}_updated_key}= Set Variable null
101 Set Suite Variable ${json_{{ m.name | lower}}_updated_key}
102 # set required fields for {{ m.name | lower }} object
103 {% for f in m.fields -%}
104 {% if f.modifier == "required" -%}
105 {% if f.options.blank == "False" -%}
106 {% if not f.options.default -%}
107 {% if f.link -%}
108 ${tmp_{{ f.options.model | lower }}_id}= Create {{ f.options.model }}
109 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }}_id ${tmp_{{ f.options.model | lower }}_id}
110 {% else -%}
111 ${json_{{ m.name | lower}}_{{ f.name }}_1}= Generate Random Value {{ f.type }}
112 ${json_{{ m.name | lower }}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /{{ f.name }} "${json_{{ m.name | lower }}_{{ f.name }}_1}"
113 {% if loop.index0 == 0 -%}
114 ${json_{{ m.name | lower}}_updated_key}= Set Variable {{ f.name }}
115 ${json_{{ m.name | lower}}_{{ f.name }}_updated_1}= Generate Random Value {{ f.type }}
116 ${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}"
117 {% endif -%}
118 {% endif -%}
119 {% endif -%}
120 {% endif -%}
121 {% endif -%}
122 {% endfor -%}
123 {% 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
146 {% for f in m.fields -%}
147 {% 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 -%}
159 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value {{ f.type }}
160 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
161 {% endif -%}
162 {% endif -%}
163 {% endif -%}
164 {% endif -%}
165 {% endfor -%}
166 {% if m.name == "Site" -%}
167 ${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase
168 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /login_base "${json_{{ m.name | lower }}_login_base_tmp}"
169 {% endif %}
170 {% if m.name == "Slice" -%}
171 ${json_{{ m.name | lower}}_name}= Generate Random Slice Name
172 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /name "${json_{{ m.name | lower }}_name}"
173 {% endif %}
174 {% if m.name == "Network" -%}
175 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /permit_all_slices true
176 {% endif %}
177 ${json_{{ m.name | lower }}_tmp}= To JSON ${json_{{ m.name | lower }}_tmp}
178 ${resp}= CORD Post /xosapi/v1/${xos_service}/{{ m.name | lower}}s ${json_{{ m.name | lower }}_tmp}
179 ${id_{{ m.name | lower }}_tmp}= Get Json Value ${resp.content} /id
180 Append To List ${dependent_{{ m.name | lower }}_ids} ${id_{{ m.name | lower }}_tmp}
181 [Return] ${id_{{ m.name | lower }}_tmp}
182{% endif %}
183{% endfor -%}
184
185Setup
186 {% for m in proto.messages %}
187 {%- if m.name not in ['XOSBase'] -%}
188 ${model}= Set Variable {{ m.name | lower }}s
189 @{dependent_{{ m.name | lower }}_ids}= Create List ${model}
190 Set Suite Variable @{dependent_{{ m.name | lower }}_ids}
191 {% endif %}
192 {% endfor -%}
193 @{dependent_models}= Create List
194 Set Suite Variable ${dependent_models}
195 ${auth} = Create List ${USER} ${PASSWD}
196 ${HEADERS} Create Dictionary Content-Type=application/json
197 Create Session ${SERVER_IP} http://${SERVER_IP}:${SERVER_PORT} auth=${AUTH} headers=${HEADERS}
198 Generate JSON Data
199
200Teardown
201 {% for m in proto.messages %}
202 {%- if m.name not in ['XOSBase'] -%}
203 ${len}= Get Length ${dependent_{{ m.name | lower }}_ids}
204 : FOR ${INDEX} IN RANGE 1 ${len}
205 \ Run Keyword And Ignore Error CORD Delete /xosapi/v1/${xos_service}/${dependent_{{ m.name | lower }}_ids[0]} ${dependent_{{ m.name | lower }}_ids[${INDEX}]}
206 {% endif %}
207 {% endfor -%}
208 Delete All Sessions