/core/users Test: Test fail, XOS issue
Change-Id: I0adc4e3f1e86b210aefd20783652ae472bc98914
diff --git a/src/test/cord-api/Framework/restApi.py b/src/test/cord-api/Framework/restApi.py
index dd8b7ad..68c1d18 100644
--- a/src/test/cord-api/Framework/restApi.py
+++ b/src/test/cord-api/Framework/restApi.py
@@ -112,6 +112,7 @@
def ApiDelete(self, key, urlSuffix=""):
url = self.getURL(key) + str(urlSuffix)
+ print "url",url
resp = requests.delete(url, auth=(self.user, self.password))
passed = self.checkResult(resp, requests.codes.no_content)
return passed
@@ -132,8 +133,19 @@
time.sleep(5)
result = test.ApiDelete(key, urlSuffix)
'''
-'''
test = restApi()
+#key = "UTILS_SYNCHRONIZER"
+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.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)
@@ -141,4 +153,3 @@
#jsonResponse = test.ApiPost(key,{"name":"test-2"})
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 34de843..85508a5 100644
--- a/src/test/cord-api/Framework/utils/utils.py
+++ b/src/test/cord-api/Framework/utils/utils.py
@@ -71,9 +71,19 @@
key_value, found = self.search_dictionary(input_dict[key],search_key)
if found == True:
break
+ elif type(input_dict[key]) == list:
+ if not input_dict[key]:
+ found = False
+ break
+ for item in input_dict[key]:
+ if isinstance(item, dict):
+ key_value, found = self.search_dictionary(item, search_key)
+ if found == True:
+ break
return key_value,found
'''
- @method getDictFromGetJsonList
+ @method getDictFromListOfDict
+ return key_value,found
@Description: Searches for the dictionary in the provided list of dictionaries
that matches the value of the key provided
@params : List of dictionaries(getResponse Data from the URL),
@@ -119,20 +129,23 @@
@Returns: Returns the value of the Key that was provided
'''
def getFieldValueFromDict(self,search_dict, field):
- fields_found = []
results = ''
found = False
input_keys = search_dict.keys()
for key in input_keys:
if key == field:
results = search_dict[key]
- found = True
- break
+ if not results:
+ found = True
+ break
elif type(search_dict[key]) == dict:
results, found = self.search_dictionary(search_dict[key],field)
if found == True:
break
elif type(search_dict[key]) == list:
+ if not search_dict[key]:
+ found = False
+ break
for item in search_dict[key]:
if isinstance(item, dict):
results, found = self.search_dictionary(item, field)
@@ -147,6 +160,8 @@
#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)
print "finalllllll result....", result
'''
diff --git a/src/test/cord-api/Properties/RestApiProperties.py b/src/test/cord-api/Properties/RestApiProperties.py
index 143f65a..aedaa36 100644
--- a/src/test/cord-api/Properties/RestApiProperties.py
+++ b/src/test/cord-api/Properties/RestApiProperties.py
@@ -1,7 +1,9 @@
#!/usr/bin/env python
-SERVER_IP = 'localhost'
-SERVER_PORT = '8001'
+SERVER_IP = '10.128.100.9'
+SERVER_PORT = '8888'
USER = 'padmin@vicci.org'
PASSWD = 'letmein'
TENANT_SUBSCRIBER = '/api/tenant/cord/subscriber/'
UTILS_SYNCHRONIZER = '/api/utility/synchronizer/'
+UTILS_LOGIN = '/api/utility/login/'
+CORE_USERS = '/api/core/users/'
diff --git a/src/test/cord-api/Tests/Users.txt b/src/test/cord-api/Tests/Users.txt
new file mode 100644
index 0000000..3f50a39
--- /dev/null
+++ b/src/test/cord-api/Tests/Users.txt
@@ -0,0 +1,84 @@
+*** Settings ***
+Documentation Test suite for Utility Synchronizer API
+Suite Setup Read InputFile
+Test Template Verify User 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/CoreUsers.json
+
+*** Test Cases *** TYPE LISTINDEX
+Test Add User-1 CREATE 0
+
+Test Get User-1 RETRIEVE 0
+
+Test Delete User-1 DELETE 0
+
+Test Add Synchronizer-2
+ CREATE 1
+
+Test Get Synchronizer-2
+ RETRIEVE 1
+
+Test Delete Synchronizer-2
+ DELETE 1
+
+Test Add Synchronizer-3
+ CREATE 2
+
+Test Get Synchronizer-3
+ RETRIEVE 2
+
+Test Delete Synchronizer-3
+ DELETE 2
+
+*** Keywords ***
+Read InputFile
+ ${userList} = utils.jsonToList ${PATHFILE} UserInfo
+ Set Suite Variable ${uList} ${userList}
+
+Verify User functionality
+ [Arguments] ${type} ${listIndex}
+ Run Keyword If "${type}" == "CREATE" Test Post Users API ${listIndex}
+ Run Keyword If "${type}" == "RETRIEVE" Test Get Users API ${listIndex}
+ Run Keyword If "${type}" == "DELETE" Test Delete Users API ${listIndex}
+
+Test Post Users API
+ [Arguments] ${listIndex}
+ ${userList} = Get Variable Value ${uList}
+ ${userDict}= utils.listToDict ${userList} ${listIndex}
+ ${api_result}= restApi.ApiPost CORE_USERS ${userDict}
+ Should Be True ${api_result}
+
+Test Get Users API
+ [Arguments] ${listIndex}
+ ${json_result}= restApi.ApiGet CORE_USERS
+ Log ${json_result}
+ ${userList}= Get Variable Value ${uList}
+ ${inputDict}= utils.listToDict ${userList} ${listIndex}
+ ${email}= utils.getFieldValueFromDict ${inputDict} email
+ ${getJsonDict}= utils.getDictFromListOfDict ${json_result} email ${email}
+ ${test_result}= utils.compare_dict ${inputDict} ${getJsonDict}
+ Should Be True ${json_result}
+
+Test Delete Users API
+ [Arguments] ${listIndex}
+ ${json_getresult}= restApi.ApiGet CORE_USERS
+ ${userList}= Get Variable Value ${uList}
+ ${userDict}= utils.listToDict ${uList} ${listIndex}
+ ${email}= utils.getFieldValueFromDict ${userDict} email
+ Log ${email}
+ ${getUserDict}= utils.getDictFromListofDict ${json_getresult} email ${email}
+ Log ${getUserDict}
+ ${userID}= utils.getFieldValueFromDict ${getUserDict} id
+ Log ${userID}
+ ${test_result}= restApi.ApiDelete CORE_USERS ${userID}
+ Should be True ${test_result}
diff --git a/src/test/cord-api/Tests/data/CoreUsers.json b/src/test/cord-api/Tests/data/CoreUsers.json
new file mode 100644
index 0000000..caa8b93
--- /dev/null
+++ b/src/test/cord-api/Tests/data/CoreUsers.json
@@ -0,0 +1,26 @@
+{
+ "UserInfo": [
+ {
+ "firstname" : "TestUser001",
+ "lastname" : "User001",
+ "password" : "TestUser001",
+ "email" : "TestUser001@onlab.us",
+ "site": "http://localhost:8000/api/core/sites/1/"
+ },
+ {
+ "firstname" : "TestUser002",
+ "lastname" : "User002",
+ "password" : "TestUser002",
+ "email" : "TestUser002@onlab.us",
+ "site": "http://localhost:8000/api/core/sites/1/"
+ },
+ {
+ "firstname" : "TestUser003",
+ "lastname" : "User003",
+ "password" : "TestUser003",
+ "email" : "TestUser003@onlab.us",
+ "site": "http://localhost:8000/api/core/sites/1/"
+ }
+ ]
+}
+