Ejemplo n.º 1
0
    def test_deserialize_type(self):
        ttype = load_module().ExampleStruct
        data = {'test_string': 'Hello World', 'test_bool': False}

        expected = load_module().ExampleStruct(test_string='Hello World',
                                               test_bool=False)

        self.assertEqual(expected, deserialize(data, ttype))
Ejemplo n.º 2
0
class FileTestSuite(TestCase):

    thrift_module = load_module()

    def test_thrift_module(self):
        struct = self.thrift_module.ExampleStruct(test_string="hello",
                                                  test_bool=True)
        self.assertEqual(struct.test_string, "hello")
        self.assertTrue(struct.test_bool)

    def test_default_thrift_module(self):
        struct = self.thrift_module.ExampleStruct(test_string="hello")
        self.assertEqual(struct.test_string, "hello")
        self.assertTrue(struct.test_bool)

    def test_not_default(self):
        thrift = load_module('non-default')
        struct = thrift.Secondary(val=64)
        self.assertEqual(struct.val, 64)

    def test_load_service_default(self):
        expected_func_args = [
            'multiVarArgument_args', 'pingPong_args', 'pong_args',
            'simple_args', 'complex_args'
        ]
        service = load_service()
        self.assertTrue(all([hasattr(service, x) for x in expected_func_args]))

    def test_load_service_key(self):
        expected_func_args = ['deadFunction_args']
        service = load_service(key='non-default')
        self.assertTrue(all([hasattr(service, x) for x in expected_func_args]))
Ejemplo n.º 3
0
def setup_test_env(settings_key='default'):
    """Allows easier integration testing by creating RPC and HTTP clients

    :param settings_key: Desired server to use
    :return: Tuple of RPC client, HTTP client, and thrift module
    """
    return RpcClient(handler), HttpClient(), load_module(settings_key)
Ejemplo n.º 4
0
    def test_inner_struct_type(self):
        module = load_module()
        ttype = module.ContainedStruct
        data = {'some_string': 'Hello World', 'innerStruct': {'val': 123}}

        expected = ttype(some_string='Hello World',
                         innerStruct=module.InnerStruct(val=123))

        self.assertEqual(expected, deserialize(data, ttype))
Ejemplo n.º 5
0
def handle_complex(val):
    module = load_module()

    validator = ComplexValidator(val)
    if not validator.is_valid():
        raise module.ExampleException(error=validator.error_str())

    return module.ContainedStruct(innerStruct=module.InnerStruct(val=234),
                                  some_string='Hello World')
Ejemplo n.º 6
0
    def test_invalid_key_given(self):
        module = load_module()
        ttype = module.ContainedStruct
        data = {
            'some_string': 'Hello World',
            'innerStruct': {
                'val': 123
            },
            'invalid_key': 'What am I doing here?'
        }

        with self.assertRaises(KeyError):
            deserialize(data, ttype)
Ejemplo n.º 7
0
    def test_object_serializer(self):
        module = load_module()

        expected = {
            'some_string': 'hello world',
            'innerStruct': {
                'val': 123,
            }
        }
        test_struct = module.ContainedStruct(some_string='hello world',
                                             innerStruct=module.InnerStruct(
                                                 val=123, ))

        result = serialize(test_struct)
        self.assertEqual(result, expected)
Ejemplo n.º 8
0
 def test_not_default(self):
     thrift = load_module('non-default')
     struct = thrift.Secondary(val=64)
     self.assertEqual(struct.val, 64)