Fix integration tests for iotdm project
[integration/test.git] / csit / libraries / ciotdm.py
index 6f56bf936b9157f81cb6642aaff536f6e57dfad8..a513360c288b622f29e5436a4b1afe541d521969 100644 (file)
@@ -65,13 +65,13 @@ nod_payload = '''
 '''
 
 resources = {"m2m:ae", "m2m:cnt", "m2m:cin", "m2m:sub",
-             "m2m:acp", "m2m:nod", "m2m:grp"}
+             "m2m:acp", "m2m:nod", "m2m:grp", "m2m:cb", "ch"}
 
 payload_map = {1: acp_payload, 2: ae_payload, 3: con_payload,
                4: cin_payload, 14: nod_payload, 23: sub_payload}
 
 
-def find_key(response, key):
+def find_key(response, key, first=None):
     """Deserialize response, return value for key or None."""
     dic = response.json()
     key1 = list(dic.keys())
@@ -79,7 +79,20 @@ def find_key(response, key):
         raise ValueError("The response should be json object")
     if key1[0] not in resources:
         raise ValueError("The resource is not recognized")
-    return dic.get(key1[0], None).get(key, None)
+    if first is True:
+        return dic.get(key1[0], None)
+    else:
+        return dic.get(key1[0], None).get(key, None)
+
+
+def childResource(response):
+    """Return child resources from the response."""
+    return find_key(response, "ch")
+
+
+def childResourceFirst(response):
+    """Return child resources from the response."""
+    return find_key(response, "ch", True)
 
 
 def name(response):
@@ -92,6 +105,11 @@ def lastModifiedTime(response):
     return find_key(response, "lt")
 
 
+def stateTag(response):
+    """Return the state tag from the response."""
+    return find_key(response, "st")
+
+
 def resid(response):
     """Return the resource id in the response."""
     return find_key(response, "ri")
@@ -112,6 +130,26 @@ def restype(response):
     return find_key(response, "rty")
 
 
+def currentNumberOfInstances(response):
+    """Return current number of instances from the response."""
+    return find_key(response, "cni")
+
+
+def currentByteSize(response):
+    """Return current byte size from the response."""
+    return find_key(response, "cbs")
+
+
+def maxNumberOfInstances(response):
+    """Return max number of instances from the response."""
+    return find_key(response, "mni")
+
+
+def maxByteSize(response):
+    """Return max byte size from the response."""
+    return find_key(response, "mbs")
+
+
 def status(response):
     """Return the protocol status code in the response."""
     try:
@@ -161,7 +199,7 @@ class connect:
             # and until a proper defaulting initializer is in place
             # are hard-coded.
             'content-type': 'application/vnd.onem2m-res+json',
-            'X-M2M-Origin': '//localhost:10000',
+            'X-M2M-Origin': 'iotdm-robot-tests',
             'X-M2M-RI': '12345',
             'X-M2M-OT': 'NOW'
         }