How to use the responses.mock.add_callback function in responses

To help you get started, we’ve selected a few responses examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pawamoy / aria2p / tests / test_client.py View on Github external
def test_does_not_insert_secret_with_unknown_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"]

        # call function and assert result
        resp = client.call("other.method", params, insert_secret=True)
        assert secret not in resp
github pawamoy / aria2p / tests / test_client.py View on Github external
def test_multicall2(self):
        client = Client()

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

        # create params
        params_1 = ["2089b05ecca3d829"]
        params_2 = ["2fa07b6e85c40205"]
        calls = [(client.REMOVE, params_1), (client.REMOVE, params_2)]
        # copy params and insert secret
        expected_params = [
            [
                {"methodName": client.REMOVE, "params": deepcopy(params_1)},
                {"methodName": client.REMOVE, "params": deepcopy(params_2)},
            ]
        ]

        # call function and assert result
        resp = client.multicall2(calls)
        assert resp == expected_params
github pawamoy / aria2p / tests / test_client.py View on Github external
def test_insert_secret_with_batch_call(self):
        # create client with secret
        secret = "hello"
        client = Client(secret=secret)

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

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

        # call function and assert result
        resp = client.batch_call(
            [(client.ADD_URI, params_1, 0), (client.ADD_METALINK, params_2, 1)], insert_secret=True
        )
        assert resp == expected_params
github pawamoy / aria2p / tests / test_client.py View on Github external
def test_insert_secret_with_multicall2(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_1 = ["2089b05ecca3d829"]
        params_2 = ["2fa07b6e85c40205"]
        calls = [(client.REMOVE, params_1), (client.REMOVE, params_2)]
        # copy params and insert secret
        expected_params = [
            [
                {"methodName": client.REMOVE, "params": deepcopy(params_1)},
                {"methodName": client.REMOVE, "params": deepcopy(params_2)},
            ]
        ]
        for param in expected_params[0]:
            param["params"].insert(0, f"token:{secret}")

        # call function and assert result
github ascoderu / opwen-cloudserver / tests / opwen_email_server / services / test_sendgrid.py View on Github external
def test_retries_request_when_creation_failed(self):
        mock_responses.add(mock_responses.GET,
                           'https://api.sendgrid.com/v3/user/webhooks/parse/settings/my-domain',
                           status=404)
        mock_responses.add_callback(mock_responses.POST,
                                    'https://api.sendgrid.com/v3/user/webhooks/parse/settings',
                                    callback=MockResponses([(500, '', ''), (200, '', '')]))

        action = SetupSendgridMailbox('my-key', max_retries=3, retry_interval_seconds=0.001)

        action('my-client-id', 'my-domain')

        self.assertEqual(len(mock_responses.calls), 4)
github pawamoy / aria2p / tests / test_client.py View on Github external
def test_batch_call(self):
        client = Client()

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

        # create params
        params_1 = ["param1", "param2"]
        params_2 = ["param3", "param4"]
        # copy params and insert secret
        expected_params = [params_1, params_2]

        # call function and assert result
        resp = client.batch_call([(client.ADD_URI, params_1, 0), (client.ADD_METALINK, params_2, 1)])
        assert resp == expected_params
github pawamoy / aria2p / tests / test_client.py View on Github external
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
github ascoderu / opwen-cloudserver / tests / opwen_email_server / services / test_auth.py View on Github external
def test_with_correct_password(self):
        mock_responses.add_callback(
            mock_responses.POST,
            github.GRAPHQL_URL,
            callback=MockResponses([
                '''{
                       "data": {
                           "viewer": {
                               "login": "user",
                               "organization": {
                                   "teams": {
                                       "edges": [
                                           {"cursor": "cursor1"},
                                           {"cursor": "cursor2"}
                                       ],
                                       "nodes": [
                                           {"slug": "team1"},
                                           {"slug": "team2"}
github pawamoy / aria2p / tests / test_client.py View on Github external
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, f"token:{secret}")

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