Ejemplo n.º 1
0
    def test_body_invalid_json__responds_with_usage_msg(self, mock_boto3):
        mock_boto3.client.side_effect = self.mock_for_service_selector
        event['body'] = 'Hello'

        default_handler(event, None)

        self.mock_apigw.post_to_connection.assert_called_once()
        msg = self.mock_apigw.post_to_connection.call_args.kwargs[
            'Data'].decode('utf8')
        assert 'Send JSON object with program and input to run' in msg
Ejemplo n.º 2
0
    def test_program_with_invalid_mode__responds_with_error_message(
            self, mock_boto3):
        mock_boto3.client.side_effect = self.mock_for_service_selector
        event['body'] = json.dumps({'program': [301], 'input': []})

        default_handler(event, None)

        self.mock_apigw.post_to_connection.assert_called_once()
        msg = self.mock_apigw.post_to_connection.call_args.kwargs[
            'Data'].decode('utf8')
        assert 'Intcode program error' in msg
        assert 'Invalid mode' in msg
Ejemplo n.º 3
0
    def test_valid_body_missing_input__asks_for_input(self, mock_boto3):
        mock_boto3.client.side_effect = self.mock_for_service_selector
        event['body'] = json.dumps({
            'program': [3, 0, 3, 0, 99],
            'input': [42]
        })

        default_handler(event, None)

        msg = self.mock_apigw.post_to_connection.call_args_list[0].kwargs[
            'Data'].decode('utf8')
        assert 'Additional input required' in msg
Ejemplo n.º 4
0
    def test_valid_body__response_ends_with_program_completed_message(
            self, mock_boto3):
        mock_boto3.client.side_effect = self.mock_for_service_selector
        event['body'] = json.dumps({
            'program': [3, 0, 4, 0, 99],
            'input': [42]
        })

        default_handler(event, None)

        msg = self.mock_apigw.post_to_connection.call_args_list[-1].kwargs[
            'Data'].decode('utf8')
        assert msg == 'Program completed.'
Ejemplo n.º 5
0
 def ui ( self, context, parent        = None, 
                         kind          = None, 
                         view_elements = None, 
                         handler       = None ):
     """ Creates a UI user interface object.
     """
     if type( context ) is not dict:
         context = { 'object': context }
     ui = UI( view          = self,
              context       = context,
              handler       = handler or self.handler or default_handler(),
              view_elements = view_elements )
     if kind is None:
         kind = self.kind
     ui.ui( parent, kind )
     return ui
Ejemplo n.º 6
0
    def ui(self, context, parent=None, kind=None, view_elements=None, handler=None, id="", scrollable=None, args=None):
        """ Creates a **UI** object, which generates the actual GUI window or
            panel from a set of view elements.

            Parameters
            ----------
            context : object or dictionary
                A single object or a dictionary of string/object pairs, whose
                facet attributes are to be edited. If not specified, the current
                object is used.
            parent : window component
                The window parent of the View object's window
            kind : string
                The kind of window to create. See the **AKind** facet for
                details. If *kind* is unspecified or None, the **kind**
                attribute of the View object is used.
            view_elements : ViewElements object
                The set of Group, Item, and Include objects contained in the
                view. Do not use this parameter when calling this method
                directly.
            handler : Handler object
                A handler object used for event handling in the dialog box. If
                None, the default handler for Facets UI is used.
            id : string
                A unique ID for persisting preferences about this user
                interface, such as size and position. If not specified, no user
                preferences are saved.
            scrollable : Boolean
                Indicates whether the dialog box should be scrollable. When set
                to True, scroll bars appear on the dialog box if it is not large
                enough to display all of the items in the view at one time.

        """
        handler = handler or self.handler or default_handler()
        if not isinstance(handler, Handler):
            handler = handler()

        if args is not None:
            handler.set(**args)

        if not isinstance(context, dict):
            context = context.facet_context()

        context.setdefault("handler", handler)
        handler = context["handler"]

        if self.model_view is not None:
            context["object"] = self.model_view(context["object"])

        self_id = self.id
        if self_id != "":
            if id != "":
                id = "%s:%s" % (self_id, id)
            else:
                id = self_id

        if scrollable is None:
            scrollable = self.scrollable

        if kind is None:
            kind = self.kind

        ui = UI(
            view=self,
            context=context,
            handler=handler,
            view_elements=view_elements,
            title=self.title,
            id=id,
            kind=kind,
            scrollable=scrollable,
        )

        ui.ui(parent)

        return ui
Ejemplo n.º 7
0
    def ui(self,
           context,
           parent=None,
           kind=None,
           view_elements=None,
           handler=None,
           id='',
           scrollable=None,
           args=None):
        """ Creates a **UI** object, which generates the actual GUI window or
        panel from a set of view elements.
        
        Parameters
        ----------
        context : object or dictionary
            A single object or a dictionary of string/object pairs, whose trait
            attributes are to be edited. If not specified, the current object is
            used.
        parent : window component 
            The window parent of the View object's window
        kind : string
            The kind of window to create. See the **kind_trait** trait for 
            details. If *kind* is unspecified or None, the **kind** attribute
            of the View object is used.
        view_elements : ViewElements object 
            The set of Group, Item, and Include objects contained in the view.
            Do not use this parameter when calling this method directly.
        handler : Handler object
            A handler object used for event handling in the dialog box. If
            None, the default handler for Traits UI is used.
        id : string
            A unique ID for persisting preferences about this user interface,
            such as size and position. If not specified, no user preferences
            are saved.
        scrollable : Boolean
            Indicates whether the dialog box should be scrollable. When set to 
            True, scroll bars appear on the dialog box if it is not large enough
            to display all of the items in the view at one time.
        
        """
        handler = handler or self.handler or default_handler()
        if not isinstance(handler, Handler):
            handler = handler()
        if args is not None:
            handler.set(**args)

        if not isinstance(context, dict):
            context = context.trait_context()

        context.setdefault('handler', handler)

        if self.model_view is not None:
            context['object'] = self.model_view(context['object'])

        self_id = self.id
        if self_id != '':
            if id != '':
                id = '%s:%s' % (self_id, id)
            else:
                id = self_id

        if scrollable is None:
            scrollable = self.scrollable

        ui = UI(view=self,
                context=context,
                handler=handler,
                view_elements=view_elements,
                title=self.title,
                id=id,
                scrollable=scrollable)

        if kind is None:
            kind = self.kind

        ui.ui(parent, kind)

        return ui