Update iotdm library and tests.
[integration/test.git] / csit / libraries / criotdm.py
index 804f9db376f0736322e3d1fecb45ce21b9cff09f..85bb13719a41ffb35f839d2477ea016a506fd700 100644 (file)
@@ -8,75 +8,78 @@ def connect_to_iotdm(host, user, password, prot):
         user, password), protocol=prot)
 
 
-def create_resource(connection, parent, restype, attribute=None, name=None):
+def modify_headers_origin(connection, new_origin):
+    """Replace the headers origin with the neworigin to test ACP."""
+    connection.modify_headers_origin(new_origin)
+
+
+def create_resource(connection, parent, restype, attribute=None):
     """Create resource without command."""
-    restype = int(restype)
-    response = connection.create(parent, restype, attribute, name=name)
-    Check_Response(response, "create")
-    return response
+    connection.create(parent, restype, attribute)
+    check_response(connection.response, "create")
+    return connection.response
 
 
 def create_resource_with_command(connection, parent, restype,
-                                 command, attribute=None, name=None):
+                                 command, attribute=None):
     """According to command in the header, create the resource."""
-    restype = int(restype)
-    response = connection.createWithCommand(parent, restype,
-                                            command, attribute, name=name)
-    Check_Response(response, "create")
-    return response
+    connection.create_with_command(parent, restype,
+                                   command, attribute)
+    check_response(connection.response, "create")
+    return connection.response
 
 
 def create_subscription(connection, parent, ip, port):
     """Create subscription."""
     uri = "http://%s:%d" % (ip, int(port))
-    response = connection.create(parent, "subscription", {
+    connection.create(parent, "subscription", {
         "notificationURI": uri,
         "notificationContentType": "wholeResource"})
-    Check_Response(response, "create")
-    return response
+    check_response(connection.response, "create")
+    return connection.response
 
 
 def retrieve_resource(connection, resid):
     """Retrieve resource according to resourceID."""
-    response = connection.retrieve(resid)
-    Check_Response(response, "retrieve")
-    return response
+    connection.retrieve(resid)
+    check_response(connection.response, "retrieve")
+    return connection.response
 
 
 def retrieve_resource_with_command(connection, resid, command):
     """According to command, retrieve source with the resourceID."""
-    response = connection.retrieveWithCommand(resid, command)
-    Check_Response(response, "retrieve")
-    return response
+    connection.retrieve_with_command(resid, command)
+    check_response(connection.response, "retrieve")
+    return connection.response
 
 
-def update_resource(connection, resid, restype, attr, nm=None):
+def update_resource(connection, resid, restype, attr):
     """According to resourceID, update resource."""
-    response = connection.update(resid, restype, attr, nm)
-    Check_Response(response, "update")
-    return response
+    connection.update(resid, restype, attr)
+    check_response(connection.response, "update")
+    return connection.response
 
 
 def update_resource_with_command(connection, resid,
-                                 restype, command, attr, nm=None):
+                                 restype, command, attr):
     """According to command, update resource with resourceID."""
-    response = connection.updateWithCommand(resid, restype, command, attr, nm)
-    Check_Response(response, "update")
-    return response
+    connection.update_with_command(resid, restype, command, attr)
+    check_response(connection.response, "update")
+    return connection.response
 
 
 def delete_resource(connection, resid):
     """According to resourceID, delete the resource."""
-    response = connection.delete(resid)
-    Check_Response(response, "delete")
-    return response
+    connection.delete(resid)
+    check_response(connection.response, "delete")
+    return connection.response
 
 
 def delete_resource_with_command(connection, resid, command):
     """According to command, delete the resource with resourceID."""
-    response = connection.deleteWithCommand(resid, command)
-    Check_Response(response, "delete")
-    return response
+    connection.delete_with_command(resid, command)
+    check_response(connection.response, "delete")
+    return connection.response
 
 
 def resid(response):
@@ -86,10 +89,10 @@ def resid(response):
 
 def name(response):
     """Return resourceName."""
-    resourceName = ciotdm.name(response)
-    if resourceName is None:
+    resource_name = ciotdm.name(response)
+    if resource_name is None:
         raise AssertionError('Cannot find this resource')
-    return resourceName
+    return resource_name
 
 
 def text(response):
@@ -97,7 +100,7 @@ def text(response):
     return response.text
 
 
-def lastModifiedTime(response):
+def last_modified_time(response):
     """Return resource lastModifiedTime."""
     return ciotdm.lastModifiedTime(response)
 
@@ -117,14 +120,19 @@ def elapsed(response):
     return response.elapsed.total_seconds()
 
 
-def kill_the_tree(host, CSEID, username, password):
+def location(response):
+    """Return response content-location."""
+    return response.headers['Content-Location']
+
+
+def kill_the_tree(host, cseid, username, password):
     """Delete the whole tree."""
-    connection = ciotdm.connect(host, base=CSEID,
+    connection = ciotdm.connect(host, base=cseid,
                                 auth=(username, password), protocol="http")
     connection.kill()
 
 
-def Check_Response(response, operation):
+def check_response(response, operation):
     """Check whether the connection is none."""
     if response is None:
         raise AssertionError('Cannot %s this resource') % (operation)