Kailash | bc5245f | 2019-03-26 13:40:19 -0700 | [diff] [blame] | 1 | |
Kailash | 1675831 | 2019-03-18 14:10:39 -0700 | [diff] [blame] | 2 | # 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 *** |
| 8 | Documentation Test migration of a Service in the core |
| 9 | Library RequestsLibrary |
| 10 | Library HttpLibrary.HTTP |
| 11 | Library Collections |
| 12 | Library String |
| 13 | Library OperatingSystem |
| 14 | Library DateTime |
| 15 | Library ../../Framework/utils/utils.py |
| 16 | Resource ../../Framework/utils/utils.robot |
| 17 | Library ../../Framework/restApi.py |
| 18 | Variables ../../Properties/RestApiProperties.py |
| 19 | Suite Setup Setup |
| 20 | Suite 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 *** |
| 28 | Create 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 |
Kailash | bc5245f | 2019-03-26 13:40:19 -0700 | [diff] [blame] | 36 | ${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 |
Kailash | 1675831 | 2019-03-18 14:10:39 -0700 | [diff] [blame] | 39 | Set Suite Variable ${test_serviceinstance_id} |
| 40 | Set Suite Variable ${model_name} |
Kailash | bc5245f | 2019-03-26 13:40:19 -0700 | [diff] [blame] | 41 | Set Suite Variable ${default_float} |
| 42 | Set Suite Variable ${default_string} |
| 43 | Set Suite Variable ${default_int} |
Kailash | 1675831 | 2019-03-18 14:10:39 -0700 | [diff] [blame] | 44 | Repeat Keyword 10s Validate Duplicate Model false |
| 45 | |
Kailash | bc5245f | 2019-03-26 13:40:19 -0700 | [diff] [blame] | 46 | Replicate Model with Duplicate |
| 47 | [Tags] replicate |
Kailash | 1675831 | 2019-03-18 14:10:39 -0700 | [diff] [blame] | 48 | CORD Put ${testservice_si} {'create_duplicate': ${true}} ${test_serviceinstance_id} |
Kailash | bc5245f | 2019-03-26 13:40:19 -0700 | [diff] [blame] | 49 | Wait Until Keyword Succeeds 15s 2s Validate Duplicate Model true |
| 50 | |
| 51 | Update 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 |
Kailash | 1675831 | 2019-03-18 14:10:39 -0700 | [diff] [blame] | 89 | |
| 90 | Revert Model |
Kailash | bc5245f | 2019-03-26 13:40:19 -0700 | [diff] [blame] | 91 | [Tags] revert |
Kailash | 1675831 | 2019-03-18 14:10:39 -0700 | [diff] [blame] | 92 | CORD Put ${testservice_si} {'create_duplicate': ${false}} ${test_serviceinstance_id} |
| 93 | Wait Until Keyword Succeeds 60s 2s Validate Duplicate Model false |
| 94 | |
| 95 | *** Keywords *** |
| 96 | Setup |
| 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 | |
| 104 | Teardown |
| 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 | |
| 111 | Validate 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 | |
| 118 | Verify Exists |
| 119 | [Arguments] ${data} |
| 120 | ${dict}= Get From List ${data['items']} 0 |
| 121 | Should Be Equal As Strings ${dict['name']} ${model_name} |
Kailash | bc5245f | 2019-03-26 13:40:19 -0700 | [diff] [blame] | 122 | 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 | |
| 126 | Validate 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 |