Beispiel #1
0
 def test_call_raises_custom_error(self):
     client = Client()
     responses.add(
         responses.POST, client.server, json={"error": {"code": 1, "message": "Custom message"}}, status=200
     )
     with pytest.raises(ClientException, match=r"Custom message") as e:
         client.call("aria2.method")
         assert e.code == 1
Beispiel #2
0
 def test_call_raises_known_error(self):
     client = Client()
     responses.add(
         responses.POST,
         client.server,
         json={"error": {"code": JSONRPC_PARSER_ERROR, "message": "Custom message"}},
         status=200,
     )
     with pytest.raises(ClientException, match=rf"{JSONRPC_CODES[JSONRPC_PARSER_ERROR]}\nCustom message") as e:
         client.call("aria2.method")
         assert e.code == JSONRPC_PARSER_ERROR
Beispiel #3
0
    def test_insert_secret_with_system_multicall(self):
        # create client with secret
        secret = "hello"
        client = Client(secret=secret)

        responses.add_callback(responses.POST,
                               client.server,
                               callback=self.call_params_callback)

        # create params
        params = [[
            {
                "methodName": client.ADD_URI,
                "params": ["param1", "param2"]
            },
            {
                "methodName": client.ADD_URI,
                "params": ["param3", "param4"]
            },
        ]]
        # copy params and insert secret
        expected_params = deepcopy(params)
        for param in expected_params[0]:
            param["params"].insert(0, f"token:{secret}")

        # call function and assert result
        resp = client.call(client.MULTICALL, params, insert_secret=True)
        assert resp == expected_params
Beispiel #4
0
    def test_does_not_insert_secret_if_told_so(self):
        # create client with secret
        secret = "hello"
        client = Client(secret=secret)

        responses.add_callback(responses.POST, client.server, callback=self.call_params_callback)

        # create params
        params = ["param1", "param2"]

        # call function and assert result
        resp = client.call("other.method", params, insert_secret=False)
        assert secret not in resp
Beispiel #5
0
    def test_insert_secret_with_aria2_method_call(self):
        # create client with secret
        secret = "hello"
        client = Client(secret=secret)

        responses.add_callback(responses.POST, client.server, callback=self.call_params_callback)

        # create params
        params = ["param1", "param2"]
        # copy params and insert secret
        expected_params = deepcopy(params)
        expected_params.insert(0, secret)

        # call function and assert result
        resp = client.call(client.ADD_URI, params, insert_secret=True)
        assert resp == expected_params