Beispiel #1
0
 def _call(self, method, **kwargs):
     params = {}
     for key in kwargs:
         parsed_response = simplify_response(kwargs[key])
         params[key] = parsed_response
     whole_request = json.dumps({
                         "method" : method,
                         "params" : params
                     })
     avoid_sessionid = False
     if method == 'login':
         uopen = self.opener.open(self.url_login,data=whole_request)
     elif method in ('send_command', 'send_file', 'poll'):
         if self.remote_url is None:
             uopen = self.opener.open(self.url,data=whole_request)
         else:
             avoid_sessionid = True
             opener = urllib2.build_opener()
             opener.addheaders.append(('Cookie', 'weblabsessionid=%s' % self.remote_reservation_id.id.split(';')[1]))
             uopen = opener.open(self.remote_url + 'json/', data = whole_request)
     else:
         uopen = self.opener.open(self.url,data=whole_request)
     content = uopen.read()
     if not avoid_sessionid:
         cookies = [ c for c in self.cj if c.name == 'weblabsessionid' ]
         if len(cookies) > 0:
             self.weblabsessionid = cookies[0].value
     response = json.loads(content)
     if response.get('is_exception', False):
         raise Exception(response["message"])
     return response['result']
Beispiel #2
0
 def _check(self, msg, expected, limit=None):
     if limit is not None:
         simplified = simplify_response(msg, limit=limit)
     else:
         simplified = simplify_response(msg)
     self.assertEquals(simplified, expected)
Beispiel #3
0
 def _check(self, msg, expected, limit = None):
     if limit is not None:
         simplified = simplify_response(msg, limit = limit)
     else:
         simplified = simplify_response(msg)
     self.assertEquals(simplified, expected)