blob: b7c9ed4c221a9f472c42332792a73bf5cd97891f [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
Kailash16758312019-03-18 14:10:39 -070010Library Collections
11Library String
12Library OperatingSystem
13Library DateTime
Zack Williams821c5022020-01-15 15:11:46 -070014Library CORDRobot
15Library ImportResource resources=CORDRobot
Kailash16758312019-03-18 14:10:39 -070016Variables ../../Properties/RestApiProperties.py
17Suite Setup Setup
18Suite Teardown Teardown
19
20*** Variables ***
21${testservice_api} /xosapi/v1/testservice/testserviceservices
22${testservice_si} /xosapi/v1/testservice/testserviceserviceinstances
23${testservice_duplicate_si} /xosapi/v1/testservice/testserviceduplicateserviceinstances
24
25*** Test Cases ***
26Create Test Model with No Duplicate
27 [Documentation] Create a testservice service instance with no duplicate
28 [Tags] create
29 ${model_name}= Generate Random Value string
30 ${data}= Create Dictionary name=${model_name} create_duplicate=${false}
31 ${resp}= CORD Post ${testservice_si} ${data}
32 ${json_content}= To Json ${resp.content}
33 ${test_serviceinstance_id}= Get From Dictionary ${json_content} id
Kailashbc5245f2019-03-26 13:40:19 -070034 ${default_float}= Get From Dictionary ${json_content} optional_float_with_default
35 ${default_string}= Get From Dictionary ${json_content} optional_string_with_default
36 ${default_int}= Get From Dictionary ${json_content} optional_int_with_default
Kailash16758312019-03-18 14:10:39 -070037 Set Suite Variable ${test_serviceinstance_id}
38 Set Suite Variable ${model_name}
Kailashbc5245f2019-03-26 13:40:19 -070039 Set Suite Variable ${default_float}
40 Set Suite Variable ${default_string}
41 Set Suite Variable ${default_int}
Kailash16758312019-03-18 14:10:39 -070042 Repeat Keyword 10s Validate Duplicate Model false
43
Kailashbc5245f2019-03-26 13:40:19 -070044Replicate Model with Duplicate
45 [Tags] replicate
Kailash16758312019-03-18 14:10:39 -070046 CORD Put ${testservice_si} {'create_duplicate': ${true}} ${test_serviceinstance_id}
Kailashbc5245f2019-03-26 13:40:19 -070047 Wait Until Keyword Succeeds 15s 2s Validate Duplicate Model true
48
49Update Model Values and Validate on Duplicate
50 [Tags] update
51 ##create optional strings
52 @{choices}= Create List one two
53 ${optional_string}= Generate Random Value string max_length=50
54 ${optional_string_choice}= Evaluate random.choice($choices) random
55 ${optional_string_max_length}= Generate Random Value string max_length=32
56 ${optional_string_date}= Get Current Date result_format=%m-%d-%Y
57 ${optional_string_ip}= Generate Random Value ip_address
58 ##create optional ints
59 @{choices}= Create List one two
60 ${optional_integer_min}= Generate Random Value int32 min_int=100
61 ${optional_integer_max}= Generate Random Value int32 max_int=199
62 ${optional_string_choice}= Evaluate random.choice($choices) random
63 ${optional_string_max_length}= Generate Random Value string max_length=32
64 #${optional_string_max}= Get Substring ${optional_string_max_length} 0 32
65 ${optional_string_date}= Get Current Date result_format=%m-%d-%Y
66 ${optional_string_ip}= Generate Random Value ip_address
67 ##create optional float
68 ${optional_float}= Generate Random Value float
69 Set Suite Variable ${optional_string}
70 Set Suite Variable ${optional_string_choice}
71 Set Suite Variable ${optional_string_max_length}
72 Set Suite Variable ${optional_string_date}
73 Set Suite Variable ${optional_string_ip}
74 Set Suite Variable ${optional_integer_min}
75 Set Suite Variable ${optional_integer_max}
76 Set Suite Variable ${optional_float}
77 ${data}= Create Dictionary optional_string=${optional_string}
78 Set To Dictionary ${data} optional_string_with_choices=${optional_string_choice}
79 Set To Dictionary ${data} optional_string_max_length=${optional_string_max_length}
80 #Set To Dictionary ${data} optional_string_date=${optional_string_date}
81 Set To Dictionary ${data} optional_string_ip=${optional_string_ip}
82 Set To Dictionary ${data} optional_int_with_min=${optional_integer_min}
83 Set To Dictionary ${data} optional_int_with_max=${optional_integer_max}
84 Set To Dictionary ${data} optional_float=${optional_float}
85 CORD Put ${testservice_si} ${data} ${test_serviceinstance_id}
86 Wait Until Keyword Succeeds 60s 2s Validate Duplicate Model with Updates
Kailash16758312019-03-18 14:10:39 -070087
88Revert Model
Kailashbc5245f2019-03-26 13:40:19 -070089 [Tags] revert
Kailash16758312019-03-18 14:10:39 -070090 CORD Put ${testservice_si} {'create_duplicate': ${false}} ${test_serviceinstance_id}
91 Wait Until Keyword Succeeds 60s 2s Validate Duplicate Model false
92
93*** Keywords ***
94Setup
95 ${auth} = Create List ${XOS_USER} ${XOS_PASSWD}
96 ${HEADERS} Create Dictionary Content-Type=application/json allow_modify_feedback=True
97 Create Session ${server_ip} http://${server_ip}:${server_port} auth=${AUTH} headers=${HEADERS}
98 # create test-service
99 ${data}= Create Dictionary name=xos-core-test-service-test
100 ${resp}= CORD Post ${testservice_api} ${data}
101
102Teardown
103 [Documentation] Delete all https sessions
104 Clean Up Objects ${testservice_si}
105 Clean Up Objects ${testservice_duplicate_si}
106 Clean Up Objects ${testservice_api}
107 Delete All Sessions
108
109Validate Duplicate Model
110 [Documentation] Checks if 'testserviceduplicateserviceinstances' was created or not
111 [Arguments] ${exists}=false
112 ${resp}= Wait Until Keyword Succeeds 60s 2s CORD Get ${testservice_duplicate_si}
113 ${jsondata}= To Json ${resp.content}
114 Run Keyword If '${exists}' == 'false' Should Be Empty ${jsondata['items']} ELSE Verify Exists ${jsondata}
115
116Verify Exists
117 [Arguments] ${data}
118 ${dict}= Get From List ${data['items']} 0
119 Should Be Equal As Strings ${dict['name']} ${model_name}
Kailashbc5245f2019-03-26 13:40:19 -0700120 Should Be Equal As Strings ${dict['optional_float_with_default']} ${default_float}
121 Should Be Equal As Strings ${dict['optional_string_with_default']} ${default_string}
122 Should Be Equal As Strings ${dict['optional_int_with_default']} ${default_int}
123
124Validate Duplicate Model with Updates
125 ${resp}= CORD Get ${testservice_duplicate_si}
126 ${jsondata}= To Json ${resp.content}
127 ${dict}= Get From List ${jsondata['items']} 0
128 Should Be Equal As Strings ${dict['name']} ${model_name}
129 Should Be Equal As Strings ${dict['optional_float_with_default']} ${default_float}
130 Should Be Equal As Strings ${dict['optional_string_with_default']} ${default_string}
131 Should Be Equal As Strings ${dict['optional_int_with_default']} ${default_int}
132 Should Be Equal As Strings ${dict['optional_string']} ${optional_string}
133 Should Be Equal As Strings ${dict['optional_string_with_choices']} ${optional_string_choice}
134 Should Be Equal As Strings ${dict['optional_string_max_length']} ${optional_string_max_length}
135 Should Be Equal As Strings ${dict['optional_string_ip']} ${optional_string_ip}
136 Should Be Equal As Strings ${dict['optional_int_with_min']} ${optional_integer_min}
137 Should Be Equal As Strings ${dict['optional_int_with_max']} ${optional_integer_max}
138 ${float_diff}= Evaluate abs(${optional_float} - ${dict['optional_float']})
139 Should Be True ${float_diff} < .0005