Exemplo n.º 1
0
    def test_call_success(self, m):
        method = RPCMethod("some_rpc_method",
                           RPCHost("user", "password", "host", 18443, False))
        m.register_uri(
            'POST',
            'http://*****:*****@host:18443/',
            request_headers={"content-type": "application/json"},
            additional_matcher=lambda req: req.text == json.dumps(
                {
                    "method": "some_rpc_method",
                    "params": ["arg1", 2],
                    "jsonrpc": "2.0"
                }),
            json=json.loads('{"result": true, "error": null}'),
            status_code=200,
        )
        self.assertEqual(method("arg1", 2), True)

        method = RPCMethod("other_rpc_method",
                           RPCHost("user", "password", "host", 18443, False))
        m.register_uri(
            'POST',
            'http://*****:*****@host:18443/',
            request_headers={"content-type": "application/json"},
            additional_matcher=lambda req: req.text == json.dumps(
                {
                    "method": "other_rpc_method",
                    "params": [[0], "arg2", "arg3"],
                    "jsonrpc": "2.0"
                }),
            json=json.loads('{"result": true, "error": null}'),
            status_code=500,
        )
        self.assertEqual(method([0], "arg2", "arg3"), True)
Exemplo n.º 2
0
 def test_call_fails_status_code(self, m):
     method = RPCMethod("some_rpc_method",
                        RPCHost("user", "password", "host", 18443, False))
     m.register_uri('POST',
                    'http://*****:*****@host:18443/',
                    status_code=201,
                    reason="testing failing status code")
     with pytest.raises(bit.exceptions.BitcoinNodeException):
         method()
Exemplo n.º 3
0
 def test_call_fails_unsupported_command(self, m):
     method = RPCMethod("some_rpc_method",
                        RPCHost("user", "password", "host", 18443, False))
     m.register_uri('POST',
                    'http://*****:*****@host:18443/',
                    json=json.loads('{"result": false, "error": true}'),
                    status_code=200,
                    reason="testing failing return value")
     with pytest.raises(bit.exceptions.BitcoinNodeException):
         method()
Exemplo n.º 4
0
 def test_subcall(self):
     method = RPCMethod("some_rpc_method", None)
     sub_method = method.sub_cmd
     assert sub_method._rpc_method == "some_rpc_method.sub_cmd"
     assert sub_method._host is None
Exemplo n.º 5
0
 def test_call_fails_connection(self):
     method = RPCMethod(
         "some_rpc_method",
         RPCHost("user", "password", "some_invalid_host", 18443, False))
     with pytest.raises(ConnectionError):
         method()
Exemplo n.º 6
0
 def test_init(self):
     method = RPCMethod("some_rpc_method", None)
     assert method._rpc_method == "some_rpc_method"
     assert method._host is None