How to use the pysoa.server.types.EnrichedActionRequest 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 / unit / server / action / test_switched.py View on Github external
def test_action_one_switch_twelve(self):
        settings = {'foo': 'bar'}

        action = SwitchedActionOne(cast(ServerSettings, settings))

        response = action(EnrichedActionRequest(action='one', body={'planet': 'Mars'}, switches=[12]))

        self.assertEqual([], response.errors)
        self.assertEqual({'planet_response': 'Mars', 'settings': settings}, response.body)
github eventbrite / pysoa / tests / unit / server / action / test_base.py View on Github external
def setUp(self):
        self.action = TestAction()
        self.action._return = {'boolean_field': True}
        self.action_request = EnrichedActionRequest(
            action='test_action',
            body={
                'string_field': 'a unicode string',
            },
github eventbrite / pysoa / tests / unit / server / action / test_switched.py View on Github external
def test_action_one_switch_five(self):
        settings = {'foo': 'bar'}

        action = SwitchedActionOne(cast(ServerSettings, settings))

        response = action(EnrichedActionRequest(action='one', body={'animal': 'cat'}, switches=[5]))

        self.assertEqual([], response.errors)
        self.assertEqual({'animal_response': 'cat', 'settings': settings}, response.body)
github eventbrite / pysoa / tests / unit / server / test_types.py View on Github external
def test_call_local_action_standard_request(self):
        action = mock.MagicMock()
        action.return_value.side_effect = ActionError([Error('FOO', 'Foo error')])

        server = mock.MagicMock()
        server.settings = {'a_setting': 'a_value'}
        server.action_class_map = {'other_foo': action}

        r = EnrichedActionRequest(action='foo', body={'bar': 'baz'})
        r._server = server

        with pytest.raises(ActionError) as error_context:
            r.call_local_action('other_foo', {'color': 'red'})

        assert error_context.value.errors[0].code == 'FOO'

        action.assert_called_once_with(server.settings)
        assert action.return_value.call_count == 1

        other_r = action.return_value.call_args[0][0]
        assert other_r is not r
        assert other_r != r
        assert other_r.action == 'other_foo'
        assert other_r.body == {'color': 'red'}
        assert other_r.context == {}
github eventbrite / pysoa / tests / unit / server / action / test_switched.py View on Github external
def test_action_one_switches_twelve_and_five(self):
        settings = {'baz': 'qux'}

        action = SwitchedActionOne(cast(ServerSettings, settings))

        response = action(EnrichedActionRequest(action='one', body={'planet': 'Jupiter'}, switches=[12, 5]))

        self.assertEqual([], response.errors)
        self.assertEqual({'planet_response': 'Jupiter', 'settings': settings}, response.body)
github eventbrite / pysoa / tests / unit / server / action / test_introspection.py View on Github external
def test_whole_server_complex(self):
        action = IntrospectionAction(FakeServerTwo())

        response = action(EnrichedActionRequest(action='introspect', body={}))

        self.assertEqual([], response.errors)
        self.assertEqual(
            {
                'documentation': 'Instead, we should get this documentation',
                'action_names': ['introspect', 'one', 'status', 'two'],
                'actions': {
                    'introspect': {
                        'documentation': IntrospectionAction.description,
                        'request_schema': IntrospectionAction.request_schema.introspect(),
                        'response_schema': IntrospectionAction.response_schema.introspect(),
                    },
                    'status': {
                        'documentation': BaseStatusAction.description,
                        'request_schema': BaseStatusAction.request_schema.introspect(),
                        'response_schema': BaseStatusAction.response_schema.introspect(),
github eventbrite / pysoa / tests / unit / server / test_types.py View on Github external
)

import logging

import attr
import pytest

from pysoa.common.errors import Error
from pysoa.common.types import ActionResponse
from pysoa.server.errors import ActionError
from pysoa.server.types import EnrichedActionRequest
from pysoa.test.compatibility import mock


@attr.s
class SuperEnrichedActionRequest(EnrichedActionRequest):
    metrics = attr.ib(default=None)
    analytics_logger = attr.ib(default=None)


class TestEnrichedActionRequest(object):
    def test_call_local_action_no_server(self):
        r = EnrichedActionRequest(action='foo', body={'bar': 'baz'})

        with pytest.raises(ActionError) as error_context:
            r.call_local_action('other_foo', {'color': 'red'})

        assert error_context.value.errors[0].code == 'SERVER_ERROR'

        response = r.call_local_action('other_foo', {'color': 'red'}, raise_action_errors=False)
        assert response.action == 'other_foo'
        assert response.errors
github eventbrite / pysoa / tests / unit / server / action / test_status.py View on Github external
def test_complex_status_body_none_works(self):
        action_request = EnrichedActionRequest(action='status', body={})

        response = _ComplexStatusAction()(action_request)

        self.assertIsInstance(response, ActionResponse)
        self.assertEqual(
            {
                'build': 'complex_service-28381-7.8.9-16_04',
                'conformity': six.text_type(conformity.__version__),
                'healthcheck': {
                    'diagnostics': {'check_good_called': True},
                    'errors': [('ANOTHER_CODE', 'This is an error')],
                    'warnings': [('FIRST_CODE', 'First warning'), ('SECOND_CODE', 'Second warning')],
                },
                'pysoa': six.text_type(pysoa.__version__),
                'python': six.text_type(platform.python_version()),
                'version': '7.8.9',
github eventbrite / pysoa / tests / unit / server / action / test_introspection.py View on Github external
def test_single_action_simple(self):
        action = IntrospectionAction(FakeServerOne())

        response = action(EnrichedActionRequest(action='introspect', body={'action_name': 'one'}))

        self.assertEqual([], response.errors)
        self.assertEqual(
            {
                'action_names': ['one'],
                'actions': {
                    'one': {
                        'documentation': 'The real documentation',
                        'request_schema': None,
                        'response_schema': None,
                    },
                },
            },
            response.body,
        )