Fix pep8 violations in csit/libraries/SettingsLibrary.py
authorThanh Ha <thanh.ha@linuxfoundation.org>
Sun, 15 Mar 2015 21:02:17 +0000 (17:02 -0400)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Mon, 16 Mar 2015 01:04:04 +0000 (21:04 -0400)
- Fix pep8 violations
- Refactor templates using triple quoted block strings

Change-Id: I88dee761205e8d1bc9ec57d4accb878f0fe15c2b
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
test/csit/libraries/SettingsLibrary.py

index d98a263219a553ea4b7f0f38cfcbc379cbedcea9..a66f27f6c3fa5f64effafd8f8e1aee0482d2c1ed 100644 (file)
@@ -6,114 +6,132 @@ __email__ = "syedbahm@cisco.com"
 from string import Template
 
 # helps in taking the hostname entered by the user
-#global hostname
-#global port
+# global hostname
+# global port
 
-#def setHostname(host):
+# def setHostname(host):
 #     hostname=host
 
-#def getServer():
-#    return hostname +":"+"8080"
+# def getServer():
+#     return hostname +":"+"8080"
 
-#Cars resource URL for GET
-def getCarsUrl(hostname,port):
 
-    return "http://"+hostname+":"+port+"/restconf/config/car:cars"
+def getCarsUrl(hostname, port):
+    """Cars resource URL for GET"""
+    return "http://" + hostname + ":" + port + "/restconf/config/car:cars"
 
-#People resouce URL for GET
-def getPersonsUrl(hostname,port):
 
-    return "http://"+hostname+":"+port+"/restconf/config/people:people"
+def getPersonsUrl(hostname, port):
+    """People resouce URL for GET"""
+    return "http://" + hostname + ":" + port + "/restconf/config/people:people"
 
-#GET cars persons mapping resource URL
-def getCarPersonUrl(hostname,port):
 
-    return "http://"+hostname+":"+port+"/restconf/config/car-people:car-people"
+def getCarPersonUrl(hostname, port):
+    """GET cars persons mapping resource URL"""
+    return "http://" + hostname + ":" + port + "/restconf/config/car-people:car-people"
 
-#POST or DELETE URL
-def getAddCarUrl(hostname,port):
-    return "http://"+hostname+":"+port+"/restconf/config"
-#POST or DELETE URL
-def getAddPersonUrl(hostname,port):
-    return "http://"+hostname+":"+port+"/restconf/config"
 
-#POST URL -using rpc
-def getAddPersonRpcUrl(hostname,port):
-    return "http://"+hostname+":"+port+"/restconf/operations/people:add-person"
+def getAddCarUrl(hostname, port):
+    """POST or DELETE URL"""
+    return "http://" + hostname + ":" + port + "/restconf/config"
 
-#POST URL for car person mapping
-def getAddCarPersonUrl(hostname,port):
-   return "http://"+hostname+":"+port+"/restconf/config"
-#POST URL for buy car rpc
-def getBuyCarRpcUrl(hostname,port):
-    return "http://"+hostname+":"+port+"/restconf/operations/car-purchase:buy-car"
 
-#GET URL for jolokia
-def getJolokiaURL(hostname,port, shardIndex,shardName):
-    return "http://"+ hostname + ":"+ port+"/jolokia/read/org.opendaylight.controller:Category=Shards,name=member-"+shardIndex+"-"+shardName+",type=DistributedConfigDatastore"
+def getAddPersonUrl(hostname, port):
+    """POST or DELETE URL"""
+    return "http://" + hostname + ":" + port + "/restconf/config"
 
 
-# Template for Car resource payload
-add_car_payload_template = Template( '{\"car:cars\":{'
-    '\"car-entry\": ['
-        '{'
-            '\"id\": \"$id\",'
-            '\"category\": \"$category\",'
-            '\"model\": \"$model\",'
-            '\"manufacturer\": \"$manufacturer\",'
-            '\"year\": \"$year\"'
-        '}'
-    ']'
-'}'
-'}')
+def getAddPersonRpcUrl(hostname, port):
+    """POST URL -using rpc"""
+    return "http://" + hostname + ":" + port + "/restconf/operations/people:add-person"
 
-# Template for Person resource payload
-add_person_payload_template =  Template( '{\"people:people":{'
-    '\"person\": ['
-        '{'
-            '\"id\": \"$personId\",'
-            '\"gender\": \"$gender\",'
-            '\"age\": \"$age\",'
-            '\"address\": \"$address\",'
-            '\"contactNo\":\"$contactNo\"'
-        '}'
-            ']'
-     '}}')
 
-# Template for Car Person mapping  payload
-add_car_person_template = Template('{\"car-people:car-people\":{'
-    '\"car-person\": ['
-        '{'
-           ' \"car-id\": \"$Id\",'
-            '\"person-id\": \"$personId\"'
-        '}'
-    ']'
-'}'
-'}')
+def getAddCarPersonUrl(hostname, port):
+    """POST URL for car person mapping"""
+    return "http://" + hostname + ":" + port + "/restconf/config"
 
-# Template for adding person using RPC
-add_person_rpc_payload_template = Template ( '{'
-                                                 '\"input\":'
-                                                     '{'
-                                                         '\"people:id\" : \"$personId\",'
-                                                         '\"people:gender\":\"$gender\",'
-                                                         '\"people:address\" : \"$address\",'
-                                                         '\"people:contactNo\":\"$contactNo\",'
-                                                         '\"people:age\":\"$age\"'
-                                                     '}'
-                                             '}')
 
-# Template for buing car rpc
-buy_car_rpc_template = Template ( '{'
-    '\"input\" :'
-        '{'
-            '\"car-purchase:person\" : \"/people:people/people:person[people:id=\'$personId\']\",'
-            '\"car-purchase:person-id\" : \"$personId\",'
-            '\"car-purchase:car-id\" : \"$carId\"'
-        '}'
-'}')
+def getBuyCarRpcUrl(hostname, port):
+    """POST URL for buy car rpc"""
+    return "http://" + hostname + ":" + port + "/restconf/operations/car-purchase:buy-car"
 
 
+def getJolokiaURL(hostname, port, shardIndex, shardName):
+    """GET URL for jolokia"""
+    return "http://" + hostname + ":" + port + \
+        "/jolokia/read/org.opendaylight.controller:Category=Shards,name=member-" + \
+        shardIndex + "-" + shardName + ", type=DistributedConfigDatastore"
 
 
+# Template for Car resource payload
+add_car_payload_template = Template(
+    """
+    {"car:cars":{
+        "car-entry": [
+            {
+                "id": "$id",
+                "category": "$category",
+                "model": "$model",
+                "manufacturer": "$manufacturer",
+                "year": "$year"
+            }
+        ]
+    }}
+    """)
 
+# Template for Person resource payload
+add_person_payload_template = Template(
+    """
+    {"people:people":{
+        "person": [
+            {
+                "id": "$personId",
+                "gender": "$gender",
+                "age": "$age",
+                "address": "$address",
+                "contactNo":"$contactNo"
+            }
+        ]
+    }}
+    """)
+
+# Template for Car Person mapping  payload
+add_car_person_template = Template(
+    """
+    {"car-people:car-people":{
+        "car-person": [
+            {
+                "car-id": "$Id",
+                "person-id": "$personId"
+            }
+        ]
+    }}
+    """)
+
+# Template for adding person using RPC
+add_person_rpc_payload_template = Template(
+    """
+    {
+        "input":
+            {
+                "people:id" : "$personId",
+                "people:gender":"$gender",
+                "people:address" : "$address",
+                "people:contactNo":"$contactNo",
+                "people:age":"$age"
+            }
+    }
+    """)
+
+# Template for buing car rpc
+buy_car_rpc_template = Template(
+    """
+    {
+        "input" :
+        {
+            "car-purchase:person" : "/people:people/people:person[people:id='$personId']",
+            "car-purchase:person-id" : "$personId",
+            "car-purchase:car-id" : "$carId"
+        }
+    }
+    """)