How to use the pysoa.client.client.Client function in pysoa

To help you get started, we’ve selected a few pysoa 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 eventbrite / pysoa / tests / integration / test_send_receive.py View on Github external
def setUp(self):
        self.client = Client({
            'service_1': {
                'transport': {
                    'path': 'pysoa.test.stub_service:StubClientTransport',
                    'kwargs': {
                        'action_map': {
                            'action_1': {'body': {'foo': 'bar'}},
                            'action_2': {'body': {'baz': 3}},
                        },
                    },
                },
            },
            'service_2': {
                'transport': {
                    'path': 'pysoa.test.stub_service:StubClientTransport',
                    'kwargs': {
                        'action_map': {
github eventbrite / pysoa / tests / integration / test_send_receive.py View on Github external
"""Client.call_actions raises CallActionError when any action response is an error."""
        action_request = [
            {
                'action': 'action_1',
                'body': {'foo': 'bar'},
            },
            {
                'action': 'action_2',
                'body': {},
            },
        ]  # type: List[Dict[six.text_type, Any]]
        error_expected = Error(code=ERROR_CODE_INVALID, message='Invalid input', field='foo')
        self.client_settings[SERVICE_NAME]['transport']['kwargs']['action_map']['action_1'] = {
            'errors': [error_expected],
        }
        client = Client(self.client_settings)

        for actions in (action_request, [ActionRequest(**a) for a in action_request]):
            with self.assertRaises(Client.CallActionError) as e:
                client.call_actions(SERVICE_NAME, actions)  # type: ignore
            self.assertEqual(len(e.exception.actions), 1)
            self.assertEqual(e.exception.actions[0].action, 'action_1')
            error_response = e.exception.actions[0].errors
            self.assertEqual(len(error_response), 1)
            self.assertEqual(error_response[0].code, error_expected.code)
            self.assertEqual(error_response[0].message, error_expected.message)
            self.assertEqual(error_response[0].field, error_expected.field)
github eventbrite / pysoa / tests / integration / test_send_receive.py View on Github external
def test_call_actions_future_success(self, mock_present_sounds):
        client = Client({})

        future = client.call_actions_future(
            'future_service',
            [{'action': 'present_sounds', 'body': {'foo': 'bar'}}],
        )

        mock_present_sounds.assert_called_once_with({'foo': 'bar'})

        assert future.exception() is None

        response = future.result()

        assert response.errors == []
        assert response.actions[0].errors == []
        assert response.actions[0].body == {'baz': 'qux'}
        assert response.context == {}
github eventbrite / pysoa / tests / integration / test_send_receive.py View on Github external
def test_call_actions_future_error(self, mock_present_sounds):
        client = Client({})

        future = client.call_actions_future(
            'future_service',
            [{'action': 'present_sounds', 'body': {'foo': 'bar'}}],
        )

        mock_present_sounds.assert_called_once_with({'foo': 'bar'})

        with self.assertRaises(client.CallActionError) as error_context:
            raise future.exception()  # type: ignore

        first_exception = error_context.exception

        assert len(error_context.exception.actions[0].errors) == 1

        error = error_context.exception.actions[0].errors[0]
github eventbrite / pysoa / tests / integration / test_expansions.py View on Github external
'kwargs': {
                        'action_map': address_transport_action_map,
                    }
                }
            },
            'automaker_info_service': {
                'transport': {
                    'path': 'pysoa.test.stub_service:StubClientTransport',
                    'kwargs': {
                        'action_map': automaker_transport_action_map,
                    }
                }
            },
        }

        self.client = Client(config=config, expansion_config=expansion_config)
github eventbrite / pysoa / tests / integration / test_send_receive.py View on Github external
def test_call_jobs_parallel_future_error(self, mock_present_sounds, mock_past_sounds):
        client = Client({})

        future = client.call_jobs_parallel_future(
            [
                {'service_name': 'future_service', 'actions': [
                    {'action': 'present_sounds', 'body': {'where': 'here'}},
                ]},
                {'service_name': 'future_service', 'actions': [
                    {'action': 'past_sounds', 'body': {'where': 'there'}},
                ]},
            ],
        )

        mock_present_sounds.assert_called_once_with({'where': 'here'})
        mock_past_sounds.assert_called_once_with({'where': 'there'})

        with self.assertRaises(client.CallActionError) as error_context:
github eventbrite / pysoa / tests / integration / test_send_receive.py View on Github external
def create_client(*middleware):
        return Client({
            SERVICE_NAME: {
                'transport': {
                    'path': 'pysoa.test.stub_service:StubClientTransport',
                    'kwargs': {
                        'action_map': {
                            'action_1': {'body': {}},
                        },
                    },
                },
                'middleware': [
                    {'path': 'tests.integration.test_send_receive:{}'.format(m)} for m in middleware
                ],
github eventbrite / pysoa / tests / integration / test_send_receive.py View on Github external
def test_call_actions_suppress_response_is_ignored(self):
        """Client.call_actions sends a valid request and returns a valid response without errors."""
        action_request = [
            {
                'action': 'action_1',
                'body': {},
            },
            {
                'action': 'action_2',
                'body': {},
            },
        ]  # type: List[Dict[six.text_type, Any]]
        client = Client(self.client_settings)

        for actions in (action_request, [ActionRequest(**a) for a in action_request]):
            with pytest.raises(TypeError):
                # noinspection PyArgumentList
                client.call_actions(SERVICE_NAME, actions, timeout=2, suppress_response=True)  # type: ignore
github eventbrite / pysoa / tests / integration / test_send_receive.py View on Github external
def test_call_actions_parallel_future_success(self, mock_present_sounds, mock_past_sounds):
        client = Client({})

        future = client.call_actions_parallel_future(
            'future_service',
            [
                {'action': 'present_sounds', 'body': {'where': 'here'}},
                {'action': 'past_sounds', 'body': {'where': 'there'}},
            ],
        )

        mock_present_sounds.assert_called_once_with({'where': 'here'})
        mock_past_sounds.assert_called_once_with({'where': 'there'})

        assert isinstance(future.result(), types.GeneratorType)

        responses = list(future.result())
github eventbrite / pysoa / tests / integration / test_send_receive.py View on Github external
def test_call_action(self):
        """Client.call_action sends a valid request and returns a valid response without errors."""
        client = Client(self.client_settings)
        response = client.call_action(SERVICE_NAME, 'action_1')
        self.assertTrue(isinstance(response, ActionResponse))
        self.assertEqual(response.action, 'action_1')
        self.assertEqual(response.body['foo'], 'bar')