blob: 6d9c1183782bbc3c1b941f65c810917a36a0ee7d [file] [log] [blame]
hwchiu01e51172020-01-16 22:29:13 +00001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15*** Settings ***
16Documentation Library for Digital Loggers Web Power Switch
17 ... Official Document: https://www.digital-loggers.com/rest.html
18Library Collections
19Library RequestsLibrary
20
21*** Variables ***
22${timeout} 60s
23${alias_name} Switch Outlet
24${restapi_uri} restapi/relay/outlets/
25
26*** Keywords ***
27Power Switch Connection Suite
28 [Arguments] ${ip} ${username} ${password}
29 [Documentation] Setup The HTTP Session To Web Power Switch
30 ${auth}= Create List ${username} ${password}
31 ${headers}= Create Dictionary
32 Set To Dictionary ${headers} X-CSRF x
33 Set To Dictionary ${headers} Content-Type application/x-www-form-urlencoded
34 Create Digest Session alias=${alias_name} url=http://${ip}/${restapi_uri}
35 ... auth=${auth} headers=${headers}
36
37Enable Switch Outlet
38 [Arguments] ${outlet_number}
39 [Documentation] Enable specific outlet of the Web Power Switch
40 ${resp}= Put Request alias=${alias_name} uri==${outlet_number}/state/ data=value=true
41 Should Be Equal As Strings ${resp.status_code} 207
42 Wait Until Keyword Succeeds ${timeout} 2s
43 ... Check Expected Switch Outlet Status ${outlet_number} true
44
45Disable Switch Outlet
46 [Arguments] ${outlet_number}
47 [Documentation] Disable specific outlet of the Web Power Switch
48 ${resp}= Put Request alias=${alias_name} uri==${outlet_number}/state/ data=value=false
49 Should Be Equal As Strings ${resp.status_code} 207
50 Wait Until Keyword Succeeds ${timeout} 2s
51 ... Check Expected Switch Outlet Status ${outlet_number} false
52
53Check Expected Switch Outlet Status
54 [Arguments] ${outlet_number} ${status}
55 [Documentation] Succeeds if the status of the desired switch outlet is expected
56 ${resp}= Get Request alias=${alias_name} uri==${outlet_number}/state/
57 Should Be Equal As Strings ${resp.text} [${status}]