Add test cases for field mode

Resolves openbmc/openbmc-test-automation#1032

Change-Id: Idaa467b79241fc135ae01a8eaa7a4103ba4689c9
Signed-off-by: Charles Paul Hofer <Charles.Hofer@ibm.com>
diff --git a/lib/rest_client.robot b/lib/rest_client.robot
index 83fb049..67170d9 100644
--- a/lib/rest_client.robot
+++ b/lib/rest_client.robot
@@ -178,13 +178,41 @@
     ${content}=     To Json    ${resp.content}
     [Return]    ${content["data"]}
 
+
 Write Attribute
-    [Arguments]    ${uri}      ${attr}    ${timeout}=10    &{kwargs}
-    ${base_uri}=    Catenate    SEPARATOR=    ${DBUS_PREFIX}    ${uri}
-    ${resp}=  openbmc put request  ${base_uri}/attr/${attr}
+    [Documentation]  Write a D-Bus attribute with REST.
+    [Arguments]  ${uri}  ${attr}  ${timeout}=10  ${verify}=${FALSE}
+    ...  ${expected_value}=${EMPTY}  &{kwargs}
+
+    # Description of argument(s):
+    # uri               URI of the object that the attribute lives on
+    #                   (e.g. '/xyz/openbmc_project/software/').
+    # attr              Name of the attribute (e.g. 'FieldModeEnabled').
+    # timeout           Timeout for the REST call.
+    # verify            If set to ${TRUE}, the attribute will be read back to
+    #                   ensure that its value is set to ${verify_attr}.
+    # expected_value    Only used if verify is set to ${TRUE}. The value that
+    #                   ${attr} should be set to. This defaults to
+    #                   ${kwargs['data']. There are cases where the caller
+    #                   expects some other value in which case this value can
+    #                   be explicitly specified.
+    # kwargs            Arguments passed to the REST call. This should always
+    #                   contain the value to set the property to at the 'data'
+    #                   key (e.g. data={"data": 1}).
+
+    ${base_uri}=  Catenate  SEPARATOR=  ${DBUS_PREFIX}  ${uri}
+    ${resp}=  Openbmc Put Request  ${base_uri}/attr/${attr}
     ...  timeout=${timeout}  &{kwargs}
-    should be equal as strings      ${resp.status_code}     ${HTTP_OK}
-    ${json}=   to json         ${resp.content}
+    Should Be Equal As Strings  ${resp.status_code}  ${HTTP_OK}
+
+    # Verify the attribute was set correctly if the caller requested it.
+    Return From Keyword If  ${verify} == ${FALSE}
+
+    ${expected_value}=  Set Variable If  '${expected_value}' == '${EMPTY}'
+    ...  ${kwargs['data']['data']}
+    ${value}=  Read Attribute  ${uri}  ${attr}
+    Should Be Equal  ${value}  ${expected_value}
+
 
 Read Properties
     [Arguments]  ${uri}  ${timeout}=10  ${quiet}=${QUIET}