blob: 220c4b458bbd48d1e5a48f2483d6b1b6f5e2a6aa [file] [log] [blame]
Kailashbc5245f2019-03-26 13:40:19 -07001
Kailash16758312019-03-18 14:10:39 -07002# XOS Core Test
3#
4# This test will validate the xos-core's sync steps and model policies using the TestService
5#
6
7*** Settings ***
8Documentation Test migration of a Service in the core
9Library RequestsLibrary
10Library HttpLibrary.HTTP
11Library Collections
12Library String
13Library OperatingSystem
14Library DateTime
15Library ../../Framework/utils/utils.py
16Resource ../../Framework/utils/utils.robot
17Library ../../Framework/restApi.py
18Variables ../../Properties/RestApiProperties.py
19Suite Setup Setup
20Suite Teardown Teardown
21
22*** Variables ***
23${testservice_api} /xosapi/v1/testservice/testserviceservices
24${testservice_si} /xosapi/v1/testservice/testserviceserviceinstances
25${testservice_duplicate_si} /xosapi/v1/testservice/testserviceduplicateserviceinstances
26
27*** Test Cases ***
28Create Test Model with No Duplicate
29 [Documentation] Create a testservice service instance with no duplicate
30 [Tags] create
31 ${model_name}= Generate Random Value string
32 ${data}= Create Dictionary name=${model_name} create_duplicate=${false}
33 ${resp}= CORD Post ${testservice_si} ${data}
34 ${json_content}= To Json ${resp.content}
35 ${test_serviceinstance_id}= Get From Dictionary ${json_content} id
Kailashbc5245f2019-03-26 13:40:19 -070036 ${default_float}= Get From Dictionary ${json_content} optional_float_with_default
37 ${default_string}= Get From Dictionary ${json_content} optional_string_with_default
38 ${default_int}= Get From Dictionary ${json_content} optional_int_with_default
Kailash16758312019-03-18 14:10:39 -070039 Set Suite Variable ${test_serviceinstance_id}
40 Set Suite Variable ${model_name}
Kailashbc5245f2019-03-26 13:40:19 -070041 Set Suite Variable ${default_float}
42 Set Suite Variable ${default_string}
43 Set Suite Variable ${default_int}
Kailash16758312019-03-18 14:10:39 -070044 Repeat Keyword 10s Validate Duplicate Model false
45
Kailashbc5245f2019-03-26 13:40:19 -070046Replicate Model with Duplicate
47 [Tags] replicate
Kailash16758312019-03-18 14:10:39 -070048 CORD Put ${testservice_si} {'create_duplicate': ${true}} ${test_serviceinstance_id}
Kailashbc5245f2019-03-26 13:40:19 -070049 Wait Until Keyword Succeeds 15s 2s Validate Duplicate Model true
50
51Update Model Values and Validate on Duplicate
52 [Tags] update
53 ##create optional strings
54 @{choices}= Create List one two
55 ${optional_string}= Generate Random Value string max_length=50
56 ${optional_string_choice}= Evaluate random.choice($choices) random
57 ${optional_string_max_length}= Generate Random Value string max_length=32
58 ${optional_string_date}= Get Current Date result_format=%m-%d-%Y
59 ${optional_string_ip}= Generate Random Value ip_address
60 ##create optional ints
61 @{choices}= Create List one two
62 ${optional_integer_min}= Generate Random Value int32 min_int=100
63 ${optional_integer_max}= Generate Random Value int32 max_int=199
64 ${optional_string_choice}= Evaluate random.choice($choices) random
65 ${optional_string_max_length}= Generate Random Value string max_length=32
66 #${optional_string_max}= Get Substring ${optional_string_max_length} 0 32
67 ${optional_string_date}= Get Current Date result_format=%m-%d-%Y
68 ${optional_string_ip}= Generate Random Value ip_address
69 ##create optional float
70 ${optional_float}= Generate Random Value float
71 Set Suite Variable ${optional_string}
72 Set Suite Variable ${optional_string_choice}
73 Set Suite Variable ${optional_string_max_length}
74 Set Suite Variable ${optional_string_date}
75 Set Suite Variable ${optional_string_ip}
76 Set Suite Variable ${optional_integer_min}
77 Set Suite Variable ${optional_integer_max}
78 Set Suite Variable ${optional_float}
79 ${data}= Create Dictionary optional_string=${optional_string}
80 Set To Dictionary ${data} optional_string_with_choices=${optional_string_choice}
81 Set To Dictionary ${data} optional_string_max_length=${optional_string_max_length}
82 #Set To Dictionary ${data} optional_string_date=${optional_string_date}
83 Set To Dictionary ${data} optional_string_ip=${optional_string_ip}
84 Set To Dictionary ${data} optional_int_with_min=${optional_integer_min}
85 Set To Dictionary ${data} optional_int_with_max=${optional_integer_max}
86 Set To Dictionary ${data} optional_float=${optional_float}
87 CORD Put ${testservice_si} ${data} ${test_serviceinstance_id}
88 Wait Until Keyword Succeeds 60s 2s Validate Duplicate Model with Updates
Kailash16758312019-03-18 14:10:39 -070089
90Revert Model
Kailashbc5245f2019-03-26 13:40:19 -070091 [Tags] revert
Kailash16758312019-03-18 14:10:39 -070092 CORD Put ${testservice_si} {'create_duplicate': ${false}} ${test_serviceinstance_id}
93 Wait Until Keyword Succeeds 60s 2s Validate Duplicate Model false
94
95*** Keywords ***
96Setup
97 ${auth} = Create List ${XOS_USER} ${XOS_PASSWD}
98 ${HEADERS} Create Dictionary Content-Type=application/json allow_modify_feedback=True
99 Create Session ${server_ip} http://${server_ip}:${server_port} auth=${AUTH} headers=${HEADERS}
100 # create test-service
101 ${data}= Create Dictionary name=xos-core-test-service-test
102 ${resp}= CORD Post ${testservice_api} ${data}
103
104Teardown
105 [Documentation] Delete all https sessions
106 Clean Up Objects ${testservice_si}
107 Clean Up Objects ${testservice_duplicate_si}
108 Clean Up Objects ${testservice_api}
109 Delete All Sessions
110
111Validate Duplicate Model
112 [Documentation] Checks if 'testserviceduplicateserviceinstances' was created or not
113 [Arguments] ${exists}=false
114 ${resp}= Wait Until Keyword Succeeds 60s 2s CORD Get ${testservice_duplicate_si}
115 ${jsondata}= To Json ${resp.content}
116 Run Keyword If '${exists}' == 'false' Should Be Empty ${jsondata['items']} ELSE Verify Exists ${jsondata}
117
118Verify Exists
119 [Arguments] ${data}
120 ${dict}= Get From List ${data['items']} 0
121 Should Be Equal As Strings ${dict['name']} ${model_name}
Kailashbc5245f2019-03-26 13:40:19 -0700122 Should Be Equal As Strings ${dict['optional_float_with_default']} ${default_float}
123 Should Be Equal As Strings ${dict['optional_string_with_default']} ${default_string}
124 Should Be Equal As Strings ${dict['optional_int_with_default']} ${default_int}
125
126Validate Duplicate Model with Updates
127 ${resp}= CORD Get ${testservice_duplicate_si}
128 ${jsondata}= To Json ${resp.content}
129 ${dict}= Get From List ${jsondata['items']} 0
130 Should Be Equal As Strings ${dict['name']} ${model_name}
131 Should Be Equal As Strings ${dict['optional_float_with_default']} ${default_float}
132 Should Be Equal As Strings ${dict['optional_string_with_default']} ${default_string}
133 Should Be Equal As Strings ${dict['optional_int_with_default']} ${default_int}
134 Should Be Equal As Strings ${dict['optional_string']} ${optional_string}
135 Should Be Equal As Strings ${dict['optional_string_with_choices']} ${optional_string_choice}
136 Should Be Equal As Strings ${dict['optional_string_max_length']} ${optional_string_max_length}
137 Should Be Equal As Strings ${dict['optional_string_ip']} ${optional_string_ip}
138 Should Be Equal As Strings ${dict['optional_int_with_min']} ${optional_integer_min}
139 Should Be Equal As Strings ${dict['optional_int_with_max']} ${optional_integer_max}
140 ${float_diff}= Evaluate abs(${optional_float} - ${dict['optional_float']})
141 Should Be True ${float_diff} < .0005