blob: ab5a15f91fee7a7b4a981da42e43754a3f7dd156 [file] [log] [blame]
Kailash Khalasi72614802018-05-02 09:21:23 -07001*** Settings ***
2Documentation Setup and Teardown Functionality for XOS API Tests
3Library Collections
4Library String
5Library OperatingSystem
6Library XML
7Library RequestsLibrary
8Library HttpLibrary.HTTP
9Library ../Framework/utils/utils.py
10Library ../Framework/restApi.py
11Variables ../Properties/RestApiProperties.py
12
13*** Keywords ***
14Verify 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
21CORD 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
32CORD 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
43CORD 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
54CORD 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
62Generate 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 Khalasicceec832018-08-10 15:46:50 -070074 {% if f.options.blank != "True" -%}
Kailash Khalasi72614802018-05-02 09:21:23 -070075 {% 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 Khalasi72090662018-08-13 17:50:46 -070082 {% 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 Khalasi72614802018-05-02 09:21:23 -070086 {% 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 Khalasi1aae9d12018-08-13 18:14:30 -070095 {% endif -%}
Kailash Khalasi72614802018-05-02 09:21:23 -070096 {% endfor -%}
Kailash Khalasif6aba282018-08-10 11:47:50 -070097 {% if m.name == "User" -%}
Kailash Khalasi4e813112018-08-10 12:32:51 -070098 ${json_user_email_tmp}= Generate Random Value string
Kailash Khalasifc74e1c2018-08-10 10:50:40 -070099 ${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 Khalasi72614802018-05-02 09:21:23 -0700102 {% 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 Khalasidb41afa2018-07-05 15:16:02 -0700112 {% 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 Khalasi19e57202018-07-13 10:21:41 -0700115 ${json_{{ m.name | lower}}_1}= Set Json Value ${json_{{ m.name | lower }}_1} /CellIndividualOffset "1"
Kailash Khalasidb41afa2018-07-05 15:16:02 -0700116 ${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 Khalasi19e57202018-07-13 10:21:41 -0700118 ${json_{{ m.name | lower}}_updated_1}= Set Json Value ${json_{{ m.name | lower }}_updated_1} /CellIndividualOffset "1"
Kailash Khalasidb41afa2018-07-05 15:16:02 -0700119 {% endif %}
Kailash Khalasi3dc40b82018-08-13 14:41:46 -0700120 {% 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 Khalasi62ab4032018-07-09 14:01:21 -0700124 {% endif %}
Kailash Khalasi56bbde22018-07-24 13:52:34 -0700125 {% 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 Khalasi72614802018-05-02 09:21:23 -0700130 ${json_{{ m.name | lower }}_1}= To JSON ${json_{{ m.name | lower }}_1}
131 ${json_{{ m.name | lower }}_updated_1}= To JSON ${json_{{ m.name | lower }}_updated_1}
132 Set Suite Variable ${json_{{ m.name | lower }}_1}
133 Set Suite Variable ${json_{{ m.name | lower }}_updated_1}
134 {% endif -%}
135 {% endfor %}
136
137{% for m in proto.messages %}
138{%- if m.name not in ['XOSBase'] -%}
139Create {{ m.name }}
140 ##Creating {{ m.name | lower }} object
141 ${json_{{ m.name | lower }}_tmp}= Set Variable { }
142 # set required fields for {{ m.name | lower }} object
143 {% for f in m.fields + xproto_base_fields(m, proto.message_table) -%}
144 {% if f.link -%}
145 {% if f.modifier == "required" -%}
Kailash Khalasicceec832018-08-10 15:46:50 -0700146 {% if f.options.blank != "True" -%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700147 # create dependent {{ f.options.model }}
148 ${dependent_{{ f.options.model | lower }}_id}= Create {{ f.options.model }}
149 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }}_id ${dependent_{{ f.options.model | lower }}_id}
150 {% endif -%}
151 {% endif -%}
152 {% else -%}
153 {% if f.modifier == "required" -%}
Kailash Khalasicceec832018-08-10 15:46:50 -0700154 {% if f.options.blank != "True" -%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700155 {% if not f.options.default -%}
Kailash Khalasifc74e1c2018-08-10 10:50:40 -0700156 {% if m.name == "User" and f.name == "email" -%}
157 ${json_user_email_tmp}= Generate Random Value {{ f.type }}
158 ${json_user_email_tmp}= Catenate SEPARATOR= ${json_user_email_tmp} @opencord.org
159 ${json_user_tmp}= Set Json Value ${json_user_tmp} /email "${json_user_email_tmp}"
160 {% else -%}
Kailash Khalasicceec832018-08-10 15:46:50 -0700161 {% if f.name == "created" or f.name == "amend" or f.name =="expires" or f.name =='granted' -%}
162 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value float
163 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
164 {% else -%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700165 ${json_{{ m.name | lower}}_{{ f.name }}_tmp}= Generate Random Value {{ f.type }}
166 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /{{ f.name }} "${json_{{ m.name | lower}}_{{ f.name }}_tmp}"
167 {% endif -%}
168 {% endif -%}
169 {% endif -%}
170 {% endif -%}
Kailash Khalasifc74e1c2018-08-10 10:50:40 -0700171 {% endif -%}
Kailash Khalasia92d5e22018-08-13 17:30:39 -0700172 {% endif -%}
Kailash Khalasi72614802018-05-02 09:21:23 -0700173 {% endfor -%}
174 {% if m.name == "Site" -%}
175 ${json_{{ m.name | lower}}_login_base_tmp}= Set Variable testloginbase
176 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /login_base "${json_{{ m.name | lower }}_login_base_tmp}"
177 {% endif -%}
178 {% if m.name == "Slice" -%}
179 ${json_{{ m.name | lower}}_name}= Generate Random Slice Name
180 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /name "${json_{{ m.name | lower }}_name}"
181 {% endif -%}
182 {% if m.name == "Network" -%}
183 ${json_{{ m.name | lower}}_tmp}= Set Json Value ${json_{{ m.name | lower }}_tmp} /permit_all_slices true
184 {% endif -%}
185 ${json_{{ m.name | lower }}_tmp}= To JSON ${json_{{ m.name | lower }}_tmp}
Kailash Khalasi9302c182018-05-07 13:46:15 -0600186 ${resp}= CORD Post /xosapi/v1/{{ xproto_unquote(m.options.app_label) }}/{{ xproto_pluralize(m) | lower}} ${json_{{ m.name | lower }}_tmp}
Kailash Khalasi72614802018-05-02 09:21:23 -0700187 ${id_{{ m.name | lower }}_tmp}= Get Json Value ${resp.content} /id
188 Append To List ${dependent_{{ m.name | lower }}_ids} ${id_{{ m.name | lower }}_tmp}
189 [Return] ${id_{{ m.name | lower }}_tmp}
190{% endif -%}
191{% endfor -%}
192
193Setup Tests
194 [Documentation] Find all dependent objects per model and create them and store them for later use
195 {% for m in proto.messages %}
196 {%- if m.name not in ['XOSBase'] -%}
197 ${model}= Set Variable {{ m.name | lower }}s
198 @{dependent_{{ m.name | lower }}_ids}= Create List ${model}
199 Set Suite Variable @{dependent_{{ m.name | lower }}_ids}
200 {% endif -%}
201 {% endfor -%}
202 @{dependent_models}= Create List
203 Set Suite Variable ${dependent_models}
204 ${auth} = Create List ${XOS_USER} ${XOS_PASSWD}
205 ${HEADERS} Create Dictionary Content-Type=application/json
206 Create Session ${SERVER_IP} http://${SERVER_IP}:${SERVER_PORT} auth=${AUTH} headers=${HEADERS}
207 Generate JSON Data
208
209Teardown Tests
210 [Documentation] Delete all dependent objects created in Setup
211 {% for m in proto.messages %}
212 {%- if m.name not in ['XOSBase'] -%}
213 ${len}= Get Length ${dependent_{{ m.name | lower }}_ids}
214 : FOR ${INDEX} IN RANGE 1 ${len}
215 \ 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}]}
216 {% endif -%}
217 {% endfor -%}
Kailash Khalasi2e0e3e12018-07-30 08:23:04 -0700218 Delete All Sessions