Exemple #1
0
    def test_jsonrpc(self):
        with patch('uiautomator.JsonRPCMethod') as JsonRPCMethod:
            client = JsonRPCClient(self.url, self.timeout)
            JsonRPCMethod.return_value = "Ok"
            self.assertEqual(client.ping, "Ok")
            JsonRPCMethod.assert_called_once_with(self.url, "ping", timeout=self.timeout)

            JsonRPCMethod.return_value = {"width": 10, "height": 20}
            self.assertEqual(client.info, {"width": 10, "height": 20})
            JsonRPCMethod.assert_called_with(self.url, "info", timeout=self.timeout)
        def _JsonRPCMethod(url, method, timeout, restart=True):
            _method_obj = JsonRPCMethod(url, method, timeout)

            def wrapper(*args, **kwargs):
                URLError = urllib3.exceptions.HTTPError if os.name == "nt" else urllib2.URLError
                try:
                    return _method_obj(*args, **kwargs)
                except (URLError, socket.error, HTTPException) as e:
                    if restart:
                        server.stop()
                        server.start()
                        return _JsonRPCMethod(url, method, timeout,
                                              False)(*args, **kwargs)
                    else:
                        raise
                except JsonRPCError as e:
                    if e.code >= ERROR_CODE_BASE - 2:
                        server.stop()
                        server.start()
                        print "i am here & do something in this place will work!"
                        Exception_analyze.analysis_crash()
                        return _method_obj(*args, **kwargs)
                    raise

            return wrapper
Exemple #3
0
 def setUp(self):
     self.url = "http://localhost/jsonrpc"
     self.timeout = 20
     self.method_name = "ping"
     self.id = "fGasV62G"
     self.method = JsonRPCMethod(self.url, self.method_name, self.timeout)
     self.method.id = MagicMock()
     self.method.id.return_value = self.id
     self.urlopen_patch = patch('requests.post')
     self.urlopen = self.urlopen_patch.start()
 def setUp(self):
     self.os_name = os.name
     os.name = "nt"
     self.url = "http://localhost/jsonrpc"
     self.timeout = 20
     self.method_name = "ping"
     self.id = "fGasV62G"
     self.method = JsonRPCMethod(self.url, self.method_name, self.timeout)
     self.method.pool = MagicMock()
     self.method.id = MagicMock()
     self.method.id.return_value = self.id
 def setUp(self):
     self.url = "http://localhost/jsonrpc"
     self.timeout = 20
     self.method_name = "ping"
     self.id = "fGasV62G"
     self.method = JsonRPCMethod(self.url, self.method_name, self.timeout)
     self.method.id = MagicMock()
     self.method.id.return_value = self.id
     try:
         import urllib2
         self.urlopen_patch = patch('urllib2.urlopen')
     except:
         self.urlopen_patch = patch('urllib.request.urlopen')
     finally:
         self.urlopen = self.urlopen_patch.start()
 def test_id(self):
     method = JsonRPCMethod("", "method", 30)
     self.assertTrue(isinstance(method.id(), str))
     self.assertTrue(len(method.id()) > 0)
     for i in range(100):
         self.assertNotEqual(method.id(), method.id())
Exemple #7
0
 def test_id(self):
     method = JsonRPCMethod("", "method", 30)
     self.assertTrue(isinstance(method.id(), str))
     self.assertTrue(len(method.id()) > 0)
     for i in range(100):
         self.assertNotEqual(method.id(), method.id())