voltTenant tests: enhanced subscriber tests

Change-Id: Id28389dc9d77c5e5eb2b76cbd81a1c29fa8de17f
diff --git a/src/test/cord-api/Framework/restApi.py b/src/test/cord-api/Framework/restApi.py
index 68c1d18..789bb6f 100644
--- a/src/test/cord-api/Framework/restApi.py
+++ b/src/test/cord-api/Framework/restApi.py
@@ -133,23 +133,31 @@
     time.sleep(5)
     result = test.ApiDelete(key, urlSuffix)
 '''
+'''
 test = restApi()
 #key = "UTILS_SYNCHRONIZER"
-key = "CORE_USERS"
-key2 = "UTILS_LOGIN"
+#key = "CORE_USERS"
+#key2 = "UTILS_LOGIN"
 #key = "TENANT_SUBSCRIBER"
 #jsonGetData = test.ApiGet(key)
-#jsonResponse = test.ApiPut(key,{"identity":{"name":"My House 22"}},"71")
-jsonResponse = test.ApiPost(key,{"firstname":"Test002","lastname":"User002","email":"test002@onlab.us","password":"TestUser002","site": "http://localhost:8000/api/core/sites/1/"})
+#jsonResponse = test.ApiPost(key,{"identity":{"name":"My House 22"}})
+#jsonResponse = test.ApiPost(key,{"firstname":"Test002","lastname":"User002","email":"test002@onlab.us","password":"TestUser002","site": "http://localhost:8000/api/core/sites/1/"})
 #jsonResponse = test.ApiDelete(key,15)
 #jsonResponse = test.ApiPut(key,{"firstname":"Test002","lastname":"User002","email":"test002update@onlab.us","password":"TestUser002","site": "http://localhost:8000/api/core/sites/1/"},14)
 #jsonResponse = test.ApiPost(key2,{"username":"test002update@onlab.us","password":"TestUser002"})
 #jsonResponse = test.ApiPost(key2,{"username":"padmin@vicci.org","password":"letmein"})
 #jsonResponse = test.ApiPut(key,{"username":"testuser","password":"TestUser001"},"9")
-key = "UTILS_SYNCHRONIZER"
-#key = "TENANT_SUBSCRIBER"
-jsonGetData = test.ApiGet(key)
+#key = "UTILS_SYNCHRONIZER"
+key = "TENANT_VOLT"
+#input_dict = { "s_tag" : "111", "c_tag" : "222", "subscriber" : 23}
+#jsonResponse = test.ApiPost(key,input_dict)
+#jsonGetData = test.ApiGet(key)
+print "========="
+#print jsonGetData
+#jsonEdit = test.ApiPut(key,{"c_tag" : "666","s_tag" : "123"},"7")
+jsonO = test.ApiDelete(key,"36")
 #jsonResponse = test.ApiPut(key,{"identity":{"name":"My House 22"}},"71")
 #jsonResponse = test.ApiPost(key,{"name":"test-2"})
-jsonResponse = test.ApiPut(key,{"name":"test1-changed"},"9")
+#jsonResponse = test.ApiPut(key,{"name":"test1-changed"},"9")
 print "========="
+'''
diff --git a/src/test/cord-api/Framework/utils/utils.py b/src/test/cord-api/Framework/utils/utils.py
index 85508a5..c807189 100644
--- a/src/test/cord-api/Framework/utils/utils.py
+++ b/src/test/cord-api/Framework/utils/utils.py
@@ -129,12 +129,16 @@
     @Returns: Returns the value of the Key that was provided
     '''
     def getFieldValueFromDict(self,search_dict, field):
+        print "search_dict", search_dict, "field...", field
         results = ''
         found = False
         input_keys = search_dict.keys()
         for key in input_keys:
+            print "key...", key
             if key == field:
+               print "entered if..."
                results = search_dict[key]
+               print "results...", results
                if not results:
                   found = True
                   break
@@ -151,17 +155,44 @@
                         results, found = self.search_dictionary(item, field)
                         if found == True:
                            break
+            if results:
+               break
 
         return results
 
+    def setFieldValueInDict(self,input_dict,field,field_value):
+        input_dict[field]=field_value
+        return input_dict
+
 '''
 #Test
+dict_list = {
+ "humanReadableName": "cordSubscriber-17",
+        "id": 17,
+        "features": {
+            "uplink_speed": 1000000000,
+            "downlink_speed": 1000000000,
+            "status": "enabled"
+        },
+        "identity": {
+            "account_num": "20",
+            "name": "My House"
+        },
+        "related": {}
+    }
+input_dict = {
+ "s_tag" : "111",
+ "c_tag" : "222",
+ "subscriber" : ""
+ }
+new_value = 3
 test = utils()
 #data=test.jsonToList("Subscribers.json","SubscriberInfo")
 #print  test.jsonToList("Subscribers.json","SubscriberInfo")
 #print "index 1...",test.listToDict(data,1)
 #result = test.getDictFromListOfDict(dict_list,"email",21)
-result = test.getFieldValueFromDict(dict_list,"id")
-result = test.getDictFromListOfDict(dict_list,"account_num",21)
+#result = test.getFieldValueFromDict(dict_list,"id")
+#result = test.getDictFromListOfDict(dict_list,"account_num",21)
+result = test.setFieldValueInDict(input_dict,"subscriber",new_value)
 print "finalllllll result....", result
 '''
diff --git a/src/test/cord-api/Properties/RestApiProperties.py b/src/test/cord-api/Properties/RestApiProperties.py
index aedaa36..8daa483 100644
--- a/src/test/cord-api/Properties/RestApiProperties.py
+++ b/src/test/cord-api/Properties/RestApiProperties.py
@@ -4,6 +4,7 @@
 USER = 'padmin@vicci.org'
 PASSWD = 'letmein'
 TENANT_SUBSCRIBER = '/api/tenant/cord/subscriber/'
+TENANT_VOLT = '/api/tenant/cord/volt/'
 UTILS_SYNCHRONIZER = '/api/utility/synchronizer/'
 UTILS_LOGIN = '/api/utility/login/'
 CORE_USERS = '/api/core/users/'
diff --git a/src/test/cord-api/Tests/Robot-TemplateTest.txt b/src/test/cord-api/Tests/Robot-TemplateTest.txt
deleted file mode 100644
index ec0f5d2..0000000
--- a/src/test/cord-api/Tests/Robot-TemplateTest.txt
+++ /dev/null
@@ -1,51 +0,0 @@
-*** Settings ***
-Documentation     Test suite for Subscriber verification
-Suite Setup       Read InputFile
-Test Template     Verify Subscriber functionality
-Library           Collections
-Library           String
-Library           OperatingSystem
-Library           XML
-Library           RequestsLibrary
-Library           ../Framework/restapi/RestApiTest.py
-Library           ../Framework/restapi/utils.py
-
-*** Variables ***
-${USER}           admin
-${PASSWORD}       admin
-${PATHFILE}       ${CURDIR}/../Framework/restapi/Subscribers.json
-
-*** Test Cases ***    TYPE        LISTINDEX
-Test Subscriber-1     CREATEP     0
-
-Test Get_Subscriber-1
-                      RETRIEVE    0
-
-Test Subscriber-2     CREATEP     1
-
-Test Get_Subscriber-2
-                      RETRIEVE    1
-
-*** Keywords ***
-Read InputFile
-    ${subscriberList} =    utils.jsonToList    ${PATHFILE}    SubscriberInfo
-    Set Suite Variable    ${slist}    ${subscriberList}
-
-Verify Subscriber functionality
-    [Arguments]    ${type}    ${listIndex}
-    Run Keyword If    "${type}" == "CREATEP"    Test Post Subscriber API    ${listIndex}
-    Run Keyword If    "${type}" == "RETRIEVE"    Test Get Subscriber API    ${listIndex}
-
-Test Post Subscriber API
-    [Arguments]    ${listIndex}
-    ${subscriberList} =    Get Variable Value    ${slist}
-    ${subscriberDict}=    utils.listToDict    ${subscriberList}    ${listIndex}
-    ${api_result}=    RestApiTest.TestPost    ${subscriberDict}
-    Should Be True    ${api_result}
-
-Test Get Subscriber API
-    [Arguments]    ${listIndex}
-    ${json_result}=    RestApiTest.TestGet
-    Log    ${json_result}
-    #${actual_json}=    Get From Dictionary    ${subscriber.json}    Subscriber
-    #Dictionaries Should Be Equal    ${json_result}    ${actual_json}
diff --git a/src/test/cord-api/Tests/SubscriberTest.txt b/src/test/cord-api/Tests/SubscriberTest.txt
index 4df3faf..d69181e 100644
--- a/src/test/cord-api/Tests/SubscriberTest.txt
+++ b/src/test/cord-api/Tests/SubscriberTest.txt
@@ -17,7 +17,8 @@
 ${PATHFILE2}      ${CURDIR}/data/putSubscriber.json
 
 *** Test Cases ***    TYPE        LISTINDEX
-Test Subscriber-1     CREATE      0
+Test Create Subscriber-1
+                      CREATE      0
 
 Test Get_Subscriber-1
                       RETRIEVE    0
@@ -25,21 +26,17 @@
 Test Edit Subscriber-1
                       PUT         0
 
-Test Delete Subscriber Data-1
-                      DELETE      0
-
-Test Subscriber-2     CREATE      1
+Test Create Subscriber-2
+                      CREATE      1
 
 Test Get_Subscriber-2
                       RETRIEVE    1
 
-Test Edit Subscriber Data-2
+Test Edit Subscriber-2
                       PUT         1
 
-Test Delete Subscriber-2
-                      DELETE      1
-
-Test Subscriber-3     CREATE      2
+Test Create Subscriber-3
+                      CREATE      2
 
 Test Get_Subcriber-3
                       RETRIEVE    2
@@ -47,9 +44,6 @@
 Test Edit Subscriber-3
                       PUT         2
 
-Test Delete Subscriber-3
-                      DELETE      2
-
 *** Keywords ***
 Read InputFile
     ${subscriberList} =    utils.jsonToList    ${PATHFILE}    SubscriberInfo
diff --git a/src/test/cord-api/Tests/SubscriberVolt_Delete.txt b/src/test/cord-api/Tests/SubscriberVolt_Delete.txt
new file mode 100644
index 0000000..5621b24
--- /dev/null
+++ b/src/test/cord-api/Tests/SubscriberVolt_Delete.txt
@@ -0,0 +1,55 @@
+*** Settings ***
+Documentation     Test suite for Deletion of Subscribers and voltTenants
+Suite Setup       Read InputFile
+Test Template     Verify Deletion of Subscriber and volt Tenant 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/VoltTenant.json
+
+*** Test Cases ***    TYPE      LISTINDEX
+Test Delete Subscriber and volt_tenant-1
+                      DELETE    0
+
+Test Delete Subscriber and volt_tenant-2
+                      DELETE    1
+
+Test Delete Subscriber and volt_tenant-3
+                      DELETE    2
+
+*** Keywords ***
+Read InputFile
+    ${voltList} =    utils.jsonToList    ${PATHFILE}    voltSubscriberInfo
+    Set Suite Variable    ${vlist}    ${voltList}
+
+Verify Deletion of Subscriber and volt Tenant functionality
+    [Arguments]    ${type}    ${listIndex}
+    Run Keyword If    "${type}" == "DELETE"    Test Delete Subscriber and voltTenant    ${listIndex}
+
+Test Delete Subscriber and voltTenant
+    [Arguments]    ${listIndex}
+    ${getSubscriber_result}=    restApi.ApiGet    TENANT_SUBSCRIBER
+    ${getVoltTenant_result}=    restApi.ApiGet    TENANT_VOLT
+    ${voltList}=    Get Variable Value    ${vlist}
+    ${voltTenantDict}=    utils.listToDict    ${voltList}    ${listIndex}
+    ${voltDict}=    Get From Dictionary    ${voltTenantDict}    voltTenant
+    ${account_num}=    Get From Dictionary    ${voltTenantDict}    account_num
+    ${subscriberDict}=    utils.getDictFromListofDict    ${getSubscriber_result}    account_num    ${account_num}
+    Log    ${subscriberDict}
+    ${subscriberId}=    utils.getFieldValueFromDict    ${subscriberDict}    id
+    Log    ${subscriberId}
+    ${subscriber_delete_result}=    restApi.ApiDelete    TENANT_SUBSCRIBER    ${subscriberId}
+    Should Be True    ${subscriber_delete_result}
+    # Deletion of volt Tenants
+    ${getVoltDict}=    utils.getDictFromListOfDict    ${getVoltTenant_result}    subscriber    ${subscriberId}
+    ${voltID}=    utils.getFieldValueFromDict    ${getVoltDict}    id
+    ${volt_delete_result}=    restApi.ApiDelete    TENANT_VOLT    ${voltID}
+    Should Be True    ${volt_delete_result}
diff --git a/src/test/cord-api/Tests/VoltTenant.txt b/src/test/cord-api/Tests/VoltTenant.txt
new file mode 100644
index 0000000..136cae6
--- /dev/null
+++ b/src/test/cord-api/Tests/VoltTenant.txt
@@ -0,0 +1,65 @@
+*** Settings ***
+Documentation     Test suite for volt Tenant Verification
+Suite Setup       Read InputFile
+Test Template     Verify volt Tenant 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/VoltTenant.json
+${PATHFILE2}      ${CURDIR}/data/putVoltTenant.json
+
+*** Test Cases ***    TYPE      LISTINDEX
+Test volt Tenant-1    CREATE    0
+
+Test volt Tenant-2    CREATE    1
+
+Test volt Tenant-3    CREATE    2
+
+*** Keywords ***
+Read InputFile
+    ${voltList} =    utils.jsonToList    ${PATHFILE}    voltSubscriberInfo
+    Set Suite Variable    ${vlist}    ${voltList}
+    ${putvoltList}=    utils.jsonToList    ${PATHFILE2}    voltSubscriberInfo
+    Set Suite Variable    ${putList}    ${putvoltList}
+
+Verify volt Tenant Functionality
+    [Arguments]    ${type}    ${listIndex}
+    Run Keyword If    "${type}" == "CREATE"    Test Post volt Tenant API    ${listIndex}
+
+Test Post volt Tenant API
+    [Arguments]    ${listIndex}
+    ${voltTenantList} =    Get Variable Value    ${vlist}
+    ${voltTenantDict}=    utils.listToDict    ${voltTenantList}    ${listIndex}
+    ${voltDict}=    Get From Dictionary    ${voltTenantDict}    voltTenant
+    ${account_num}=    Get From Dictionary    ${voltTenantDict}    account_num
+    ${get_result}=    restApi.ApiGet    TENANT_SUBSCRIBER
+    ${subscriberDict}=    utils.getDictFromListofDict    ${get_result}    account_num    ${account_num}
+    ${subscriberID}=    utils.getFieldValueFromDict    ${subscriberDict}    id
+    ${updatedVoltDict}=    utils.setFieldValueInDict    ${voltDict}    subscriber    ${subscriberID}
+    ${api_result}=    restApi.ApiPost    TENANT_VOLT    ${updatedVoltDict}
+    Should Be True    ${api_result}
+    # Verifying Get operation after POST
+    ${getVolt_result}=    restApi.ApiGet    TENANT_VOLT
+    ${getJsonDict}=    utils.getDictFromListOfDict    ${getVolt_result}    subscriber    ${subscriberID}
+    ${test_result}=    utils.compare_dict    ${voltDict}    ${getJsonDict}
+    Should Be True    ${test_result}
+    # Verifying PUT operation
+    ${putvoltList}=    Get Variable Value    ${putList}
+    ${putVoltDict}=    utils.listToDict    ${putvoltList}    ${listIndex}
+    ${putvoltTenantDict}=    Get From Dictionary    ${putVoltDict}    voltTenant
+    ${voltID}=    utils.getFieldValueFromDict    ${getJsonDict}    id
+    ${put_result}=    restApi.ApiPut    TENANT_VOLT    ${putvoltTenantDict}    ${voltID}
+    Should Be True    ${put_result}
+    # Verifying Get after PUT operation
+    ${getVolt_afterPut}=    restApi.ApiGet    TENANT_VOLT
+    ${getVoltDict}=    utils.getDictFromListofDict    ${getVolt_afterPut}    id    ${voltID}
+    ${result_afterPut}=    utils.compare_dict    ${putvoltTenantDict}    ${getVoltDict}
+    Should Be True    ${result_afterPut}
diff --git a/src/test/cord-api/Tests/data/Subscriber.json b/src/test/cord-api/Tests/data/Subscriber.json
index 8605026..d36453c 100644
--- a/src/test/cord-api/Tests/data/Subscriber.json
+++ b/src/test/cord-api/Tests/data/Subscriber.json
@@ -1,8 +1,6 @@
 {
     "SubscriberInfo" : [
     {
-        "humanReadableName": "cordSubscriber-2",
-        "id": 2,
         "features": {
             "cdn": true,
             "uplink_speed": 1000000000,
@@ -16,8 +14,6 @@
         }
     },
     {
-        "humanReadableName": "cordSubscriber-3",
-        "id": 3,
         "features": {
             "cdn": false,
             "uplink_speed": 500000000,
diff --git a/src/test/cord-api/Tests/data/VoltTenant.json b/src/test/cord-api/Tests/data/VoltTenant.json
new file mode 100644
index 0000000..7bf5b73
--- /dev/null
+++ b/src/test/cord-api/Tests/data/VoltTenant.json
@@ -0,0 +1,31 @@
+{
+    "voltSubscriberInfo" : [
+    {
+      "voltTenant" : 
+       {
+         "s_tag" : "111",
+         "c_tag" : "222",
+         "subscriber" : ""
+       },
+       "account_num" : 20
+    },
+    {
+     "voltTenant" : 
+      {
+        "s_tag" : "111",
+        "c_tag" : "333",
+        "subscriber" : ""
+      },
+      "account_num" : 21
+    },
+    {
+     "voltTenant" :
+      {
+        "s_tag" : "111",
+        "c_tag" : "444",
+        "subscriber" : ""
+      },
+     "account_num" : 22
+    }
+ ]
+} 
diff --git a/src/test/cord-api/Tests/data/putVoltTenant.json b/src/test/cord-api/Tests/data/putVoltTenant.json
new file mode 100644
index 0000000..78a4c25
--- /dev/null
+++ b/src/test/cord-api/Tests/data/putVoltTenant.json
@@ -0,0 +1,28 @@
+{
+    "voltSubscriberInfo" : [
+    {
+      "voltTenant" : 
+       {
+         "s_tag" : "111",
+         "c_tag" : "221"
+       },
+       "account_num" : 20
+    },
+    {
+     "voltTenant" : 
+      {
+        "s_tag" : "112",
+        "c_tag" : "331"
+      },
+      "account_num" : 21
+    },
+    {
+     "voltTenant" :
+      {
+        "s_tag" : "112",
+        "c_tag" : "442"
+      },
+      "account_num" : 22
+    }
+ ]
+}