Example #1
0
 def test_return_response(self):
     context = Mock()
     r = Response.Return(123, context)
     self.assertEquals(123, r.id_)
     self.assertEquals("Return", r.type_)
     self.assertEquals(context, r.context)
     self.assertIsNone(r.fields["value"])
     r = Response.Return(123, Mock(), {"key": "value"})
     self.assertEquals({"key": "value"}, r.fields["value"])
Example #2
0
 def test_init(self):
     id_ = 123
     context = Mock()
     r = Response(id_, context)
     self.assertEquals(id_, r.id_)
     self.assertEquals(None, r.typeid)
     self.assertEquals(context, r.context)
Example #3
0
    def test_Error(self):
        context = Mock()
        r = Response.Error(123, context, "Test Error")

        self.assertEquals(123, r.id_)
        self.assertEquals("Error", r.type_)
        self.assertEquals(context, r.context)
Example #4
0
 def test_return_response_to_dict(self):
     context = Mock()
     r = Response.Return(123, context)
     expected = OrderedDict()
     expected["id"] = 123
     expected["type"] = "Return"
     expected["value"] = None
     self.assertEquals(expected, r.to_dict())
Example #5
0
 def test_init(self):
     id_ = 123
     type_ = "Return"
     context = Mock()
     r = Response(id_, context, type_)
     self.assertEquals(id_, r.id_)
     self.assertEquals(type_, r.type_)
     self.assertEquals(context, r.context)
Example #6
0
 def test_from_dict(self):
     serialized = {"id": 123, "type": "Return", "extra_1": "abc",
                   "extra_2": {"field": "data"}}
     response = Response.from_dict(serialized)
     self.assertEquals(123, response.id_)
     self.assertEquals("Return", response.type_)
     self.assertEquals("abc", response.fields["extra_1"])
     self.assertEquals({"field": "data"}, response.fields["extra_2"])
     self.assertIsNone(response.context)
Example #7
0
    def respond_with_error(self, message):
        """
        Create an Error Response object to handle the request

        Args:
            message(str): Message explaining error
        """

        response = Response.Error(self.id_, self.context, message=message)
        self.response_queue.put(response)
Example #8
0
    def respond_with_return(self, value=None):
        """
        Create a Return Response object to handle the request

        Args:
            value(): Value to set endpoint to
        """

        response = Response.Return(self.id_, self.context, value=value)
        self.response_queue.put(response)
Example #9
0
 def test_from_dict(self):
     serialized = {
         "id": 123,
         "type": "Return",
         "extra_1": "abc",
         "extra_2": {
             "field": "data"
         }
     }
     response = Response.from_dict(serialized)
     self.assertEquals(123, response.id_)
     self.assertEquals("Return", response.type_)
     self.assertEquals("abc", response.fields["extra_1"])
     self.assertEquals({"field": "data"}, response.fields["extra_2"])
     self.assertIsNone(response.context)
Example #10
0
 def test_init(self):
     r = Response(123)
     assert r.id == 123
Example #11
0
 def test_repr(self):
     r = Response(123, Mock())
     s = r.__repr__()
     self.assertTrue(isinstance(s, str))
     self.assertIn("123", s)
     self.assertIn("id", s)
Example #12
0
 def test_to_dict(self):
     r = Response(123, Mock(), "Return")
     expected = OrderedDict()
     expected["id"] = 123
     expected["type"] = "Return"
     self.assertEquals(expected, r.to_dict())
Example #13
0
 def test_getattr(self):
     r = Response.Return(22, None, "bar")
     self.assertEquals(r.value, "bar")
     self.assertRaises(KeyError, lambda: r.ffff)
Example #14
0
 def test_to_dict(self):
     r = Response(123, Mock(), "Return")
     expected = OrderedDict()
     expected["id"] = 123
     expected["type"] = "Return"
     self.assertEquals(expected, r.to_dict())