Instance Validation tests, Added README.md files
Change-Id: Ie37545eb62d1ccd1e3db2c383b68a774d6c8be0e
diff --git a/src/test/cord-api/Framework/restApi.py b/src/test/cord-api/Framework/restApi.py
index 789bb6f..1889f21 100644
--- a/src/test/cord-api/Framework/restApi.py
+++ b/src/test/cord-api/Framework/restApi.py
@@ -154,8 +154,8 @@
#jsonGetData = test.ApiGet(key)
print "========="
#print jsonGetData
-#jsonEdit = test.ApiPut(key,{"c_tag" : "666","s_tag" : "123"},"7")
-jsonO = test.ApiDelete(key,"36")
+jsonEdit = test.ApiPut(key,{"c_tag" : "666","s_tag" : "123"},"30")
+#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")
diff --git a/src/test/cord-api/Framework/utils/utils.py b/src/test/cord-api/Framework/utils/utils.py
index 04c94f9..7bedeff 100644
--- a/src/test/cord-api/Framework/utils/utils.py
+++ b/src/test/cord-api/Framework/utils/utils.py
@@ -139,16 +139,13 @@
@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
@@ -174,6 +171,29 @@
input_dict[field]=field_value
return input_dict
+ '''
+ @method getAllFieldValues
+ @params : getJsonDataDictList - List of dictionaries to be searched
+ fieldName - Key to be searched for (ex: instance_id)
+ @Returns: Returns the unique value of the Key that was provided
+ '''
+
+ def getAllFieldValues(self, getJsonDataDictList, fieldName):
+ value_list = []
+ uniqValue = ''
+ uniq_list = []
+ for data in getJsonDataDictList:
+ fieldValue = ''
+ fieldValue = self.getFieldValueFromDict(data, fieldName)
+ value_list.append(fieldValue)
+ uniq_list = sorted(set(value_list))
+ if len(uniq_list) == 1:
+ uniqValue = uniq_list[0]
+ else:
+ print "list of values found for ", fieldName, ";", uniq_list
+ return fieldValue
+
+
'''
#Test
dict_list = {
@@ -203,6 +223,7 @@
#result = test.getDictFromListOfDict(dict_list,"email",21)
#result = test.getFieldValueFromDict(dict_list,"id")
#result = test.getDictFromListOfDict(dict_list,"account_num",21)
-result = test.setFieldValueInDict(input_dict,"subscriber",new_value)
+#result = test.setFieldValueInDict(input_dict,"subscriber",new_value)
+result = test.getAllFieldValues(list1,"instance_name")
print "finalllllll result....", result
'''
diff --git a/src/test/cord-api/Properties/RestApiProperties.py b/src/test/cord-api/Properties/RestApiProperties.py
index 9cc30be..25eebe0 100644
--- a/src/test/cord-api/Properties/RestApiProperties.py
+++ b/src/test/cord-api/Properties/RestApiProperties.py
@@ -9,3 +9,4 @@
UTILS_LOGIN = '/api/utility/login/'
CORE_USERS = '/api/core/users/'
CORE_SERVICES = '/api/core/services/'
+CORE_INSTANCES = '/api/core/instances/'
diff --git a/src/test/cord-api/README.md b/src/test/cord-api/README.md
new file mode 100644
index 0000000..ae94ada
--- /dev/null
+++ b/src/test/cord-api/README.md
@@ -0,0 +1,29 @@
+## CORD API TESTS
+
+This module contains tests using XOS APIs.
+Testcases are written in RobotFramework utilizing some automated python library framework.
+
+## Prerequisites:
+
+ * Robot Framework
+
+## Install Robot Framework:
+```bash
+ $ sudo pip install robotframework
+ $ sudo pip install pygments
+ $ sudo apt-get install python-wxgtk2.8
+ $ sudo pip install robotframework-ride
+```
+ - To bring up IDE for the robot framework
+```bash
+ $ ride.py
+```
+## Execute testcases:
+ * Testcases can be run using ride.py IDE
+ * Or From the command line
+```bash
+ $ cd cord-tester/src/test/cord-api/Tests
+ $ pybot <testcase.txt>
+```
+## Input Files for the testcases
+* Input files for the testcases are present in the "Tests/data" directory, a set of input files to run the testcases
diff --git a/src/test/cord-api/Tests/SingleInstanceTest.txt b/src/test/cord-api/Tests/SingleInstanceTest.txt
new file mode 100644
index 0000000..209f09c
--- /dev/null
+++ b/src/test/cord-api/Tests/SingleInstanceTest.txt
@@ -0,0 +1,88 @@
+*** Settings ***
+Documentation Test suite for Instance creation for multiple subscribers with same "s_tag"
+Suite Setup Read InputFile
+Test Template Verify Instance 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/Subscriber.json
+${PATHFILE2} ${CURDIR}/data/SingleInstance_VoltTenant.json
+
+*** Test Cases *** TYPE LISTINDEX
+Test Create Instance-1
+ SUBSCRIBER_CREATE 0
+
+Test Create Subscriber-2
+ SUBSCRIBER_CREATE 1
+
+Test Create Subscriber-3
+ SUBSCRIBER_CREATE 2
+
+Test Create Tenant-1
+ TENANT_CREATE 0
+
+Test Create Tenant-2
+ TENANT_CREATE 1
+
+Test Create Tenant-3
+ TENANT_CREATE 2
+
+Test Instance creation validation
+ INSTANCE_VALIDATE 0
+
+*** Keywords ***
+Read InputFile
+ ${subscriberList} = utils.jsonToList ${PATHFILE} SubscriberInfo
+ Set Suite Variable ${slist} ${subscriberList}
+ ${voltList}= utils.jsonToList ${PATHFILE2} voltSubscriberInfo
+ Set Suite Variable ${vlist} ${voltList}
+
+Verify Instance functionality
+ [Arguments] ${type} ${listIndex}
+ Run Keyword If "${type}" == "SUBSCRIBER_CREATE" Test Post Subscriber Create ${listIndex}
+ Run Keyword If "${type}" == "TENANT_CREATE" Test Post volt Tenant Create ${listIndex}
+ Run Keyword If "${type}" == "INSTANCE_VALIDATE" Test Instance Validation ${listIndex}
+
+Test Post Subscriber Create
+ [Arguments] ${listIndex}
+ ${subscriberList} = Get Variable Value ${slist}
+ ${subscriberDict}= utils.listToDict ${subscriberList} ${listIndex}
+ ${api_result}= restApi.ApiPost TENANT_SUBSCRIBER ${subscriberDict}
+ Should Be True ${api_result}
+
+Test Post volt Tenant Create
+ [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}
+
+Test Instance Validation
+ [Arguments] ${listIndex}
+ ${get_result}= restApi.ApiGet TENANT_SUBSCRIBER
+ ${instance_id_fromvolt}= utils.getAllFieldValues ${get_result} instance_id
+ ${instance_name}= utils.getAllFieldValues ${get_result} instance_name
+ ${instance_id_name}= Catenate SEPARATOR=- ${instance_name} ${instance_id_fromvolt}
+ ${get_instanceresult}= restApi.ApiGet CORE_INSTANCES
+ ${instanceDict}= utils.getDictFromListofDict ${get_instanceresult} instance_name ${instance_id_name}
+ ${instance_id_fromCore}= utils.getFieldValueFromDict ${instanceDict} id
+ Should Be Equal As Strings ${instance_id_fromvolt} ${instance_id_fromCore}
diff --git a/src/test/cord-api/Tests/data/SingleInstance_VoltTenant.json b/src/test/cord-api/Tests/data/SingleInstance_VoltTenant.json
new file mode 100644
index 0000000..7bf5b73
--- /dev/null
+++ b/src/test/cord-api/Tests/data/SingleInstance_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
+ }
+ ]
+}