API test cases for /core/sites

Change-Id: I98f0d3070169cf8eca09382d92ce4997139681da
diff --git a/src/test/cord-api/Properties/RestApiProperties.py b/src/test/cord-api/Properties/RestApiProperties.py
index f1cd6ee..1ace0b6 100644
--- a/src/test/cord-api/Properties/RestApiProperties.py
+++ b/src/test/cord-api/Properties/RestApiProperties.py
@@ -17,3 +17,4 @@
 CORE_SANITY_NODES = '/api/core/nodes/?no_hyperlinks=1'
 CORE_NODES = '/api/core/nodes/'
 CORE_FLAVORS = '/api/core/flavors/'
+CORE_SITES = '/api/core/sites/'
diff --git a/src/test/cord-api/Tests/SiteTest.txt b/src/test/cord-api/Tests/SiteTest.txt
new file mode 100644
index 0000000..21f4357
--- /dev/null
+++ b/src/test/cord-api/Tests/SiteTest.txt
@@ -0,0 +1,94 @@
+*** Settings ***
+Documentation     Test suite for Site verification
+Suite Setup       Read InputFile
+Test Template     Verify Site functionality
+Library           Collections
+Library           String
+Library           OperatingSystem
+Library           XML
+Library           RequestsLibrary
+Library           ../Framework/utils/utils.py
+Library           ../Framework/restApi.py
+
+*** Variables ***
+${USER}           admin
+${PASSWORD}       admin
+${PATHFILE}       ${CURDIR}/data/Site.json
+${PATHFILE2}      ${CURDIR}/data/putSite.json
+
+*** Test Cases ***      TYPE        LISTINDEX
+Test Post Site-1        CREATE      0
+
+Test Get Site-1         RETRIEVE    0
+
+Test Edit Site-1        PUT         0
+
+Test Delete Site-1      DELETE      0
+
+Test Post Site-2        CREATE      1
+
+Test Get Site-2         RETRIEVE    1
+
+Test Edit Site-2        PUT         1
+
+Test Delete Site-2      DELETE      1
+
+*** Keywords ***
+Read InputFile
+    ${siteList}=    utils.jsonToList    ${PATHFILE}    SiteInfo
+    Set Suite Variable    ${slist}    ${siteList}
+    ${putSiteList}=    utils.jsonToList    ${PATHFILE2}    SiteInfo
+    Set Suite Variable    ${putList}    ${putSiteList}
+
+Verify Site functionality
+    [Arguments]    ${type}    ${listIndex}
+    Run Keyword If    "${type}" == "CREATE"    Test Post Site API    ${listIndex}
+    Run Keyword If    "${type}" == "RETRIEVE"    Test Get Site API    ${listIndex}
+    Run Keyword If    "${type}" == "PUT"    Test Edit Site API    ${listIndex}
+    Run Keyword If    "${type}" == "DELETE"    Test Delete Site API    ${listIndex}
+
+Test Post Site API
+    [Arguments]    ${listIndex}
+    ${siteList} =    Get Variable Value    ${slist}
+    ${siteDict}=    utils.listToDict    ${siteList}    ${listIndex}
+    ${api_result}=    restApi.ApiPost    CORE_SITES    ${siteDict}
+    Should Be True    ${api_result}
+
+Test Get Site API
+    [Arguments]    ${listIndex}
+    ${json_result}=    restApi.ApiGet   CORE_SITES
+    Log    ${json_result}
+    ${siteList}=    Get Variable Value    ${slist}
+    ${siteDict}=    utils.listToDict    ${siteList}    ${listIndex}
+    ${name}=    utils.getFieldValueFromDict    ${siteDict}   name
+    ${getJsonDict}=    utils.getDictFromListOfDict    ${json_result}    name    ${name}
+    ${test_result}=    utils.compare_dict    ${siteDict}    ${getJsonDict}
+    Should Be True    ${test_result}
+
+Test Edit Site API
+    [Arguments]    ${listIndex}
+    ${get_result}=    restApi.ApiGet    CORE_SITES
+    ${putSiteList}=    Get Variable Value    ${putList}
+    ${putSiteDict}=    utils.listToDict    ${putSiteList}    ${listIndex}
+    ${name}=    utils.getFieldValueFromDict    ${putSiteDict}    name
+    ${siteDict}=    utils.getDictFromListofDict    ${get_result}    name    ${name}
+    ${siteID}=    utils.getFieldValueFromDict    ${siteDict}    id
+    ${api_result}=    restApi.ApiPut    CORE_SITES    ${putSiteDict}    ${siteID}
+    Should Be True    ${api_result}
+    ${getResultAfterPut}=    restApi.ApiGet    CORE_SITES    ${siteID}
+    ${test_result}=    utils.compare_dict    ${putSiteDict}    ${getResultAfterPut}
+    Should Be True    ${test_result}
+
+Test Delete Site API
+    [Arguments]    ${listIndex}
+    ${json_result}=    restApi.ApiGet    CORE_SITES
+    ${siteList}=    Get Variable Value    ${slist}
+    ${siteDict}=    utils.listToDict    ${siteList}    ${listIndex}
+    ${name}=    utils.getFieldValueFromDict    ${siteDict}    name
+    Log    ${name}
+    ${siteDict}=    utils.getDictFromListofDict    ${json_result}    name  ${name}
+    Log    ${siteDict}
+    ${siteId}=    utils.getFieldValueFromDict    ${siteDict}    id
+    Log    ${siteId}
+    ${test_result}=    restApi.ApiDelete    CORE_SITES    ${siteId}
+    Should Be True    ${test_result}
diff --git a/src/test/cord-api/Tests/data/Site.json b/src/test/cord-api/Tests/data/Site.json
new file mode 100644
index 0000000..feffe3b
--- /dev/null
+++ b/src/test/cord-api/Tests/data/Site.json
@@ -0,0 +1,15 @@
+{
+    "SiteInfo":
+    [
+        {
+            "name": "test-site-1",
+            "login_base":"testsite1",
+            "abbreviated_name":"ts1"
+        },
+        {
+            "name": "test-site-2",
+            "login_base":"testsite2",
+            "abbreviated_name":"ts2"
+        }
+    ]
+}
diff --git a/src/test/cord-api/Tests/data/putSite.json b/src/test/cord-api/Tests/data/putSite.json
new file mode 100644
index 0000000..6e1e4b3
--- /dev/null
+++ b/src/test/cord-api/Tests/data/putSite.json
@@ -0,0 +1,15 @@
+{
+    "SiteInfo":
+    [
+        {
+            "name": "test-site-1",
+            "login_base":"testsite1",
+            "abbreviated_name":"ts1 - edited"
+        },
+        {
+            "name": "test-site-2",
+            "login_base":"testsite2",
+            "abbreviated_name":"ts2 - edited"
+        }
+    ]
+}