Example #1
0
 def test_CallActionThrowsExceptionWhenMethodIsWrong(self):
     service = mock()
     service.api = {
         0: 'method_0',
         1: 'method_1'
     }
     when(common.Call).getService().thenReturn(service)
     action = common.Call('Service.method')
     self.assertRaises(ServiceError, action.execute().get)
Example #2
0
    def test_CallActionThrowsExceptionWhenWrongArgsSyntax(self):
        service = mock()
        method = mock()
        callableMethod = CallableMock(method)

        service.api = {
            0: 'method_0',
            1: 'method_1'
        }
        when(common.Call).getService().thenReturn(service)
        when(common.Call).getMethod(any(object)).thenReturn(callableMethod)

        action = common.Call('S.M(WrongArgs)')
        self.assertRaises(ServiceCallError, action.execute().get)
Example #3
0
    def test_CallActionWhenArgumentsIsNotNecessary(self):
        service = mock()
        method = mock()
        callableMethod = CallableMock(method)

        service._service_api = {
            0: 'method_0',
            1: 'method_1'
        }
        when(common.Call).getService().thenReturn(service)
        when(common.Call).getMethod(any(object)).thenReturn(callableMethod)

        action = common.Call("S.M()")
        when(method).__call__().thenReturn('Ok')
        action.execute().get()

        verify(method).__call__()
Example #4
0
    def test_CallAction(self):
        service = mock()
        method = mock()
        callableMethod = CallableMock(method)

        service.api = {
            0: 'method_0',
            1: 'method_1'
        }
        when(common.Call).getService().thenReturn(service)
        when(common.Call).getMethod(any(object)).thenReturn(callableMethod)

        action = common.Call("Service.method_0(1, 2, {'key': 'value'})")
        when(method).__call__(1, 2, {'key': 'value'}).thenReturn('Ok')
        action.execute().get()

        verify(method).__call__(1, 2, {'key': 'value'})
Example #5
0
    def test_CallActionReturnsApiWhenMethodIsNotSpecified(self):
        service = mock()
        service.api = {
            0: 'method_0',
            1: 'method_1'
        }
        when(common.Call).getService().thenReturn(service)
        action = common.Call('Service', '', 0)
        actual = action.execute().get()

        expected = {
            'service': 'Service',
            'request': 'api',
            'response': {
                0: 'method_0',
                1: 'method_1'
            }
        }
        self.assertEqual(expected, actual)
Example #6
0
    def test_CallActionParser(self):
        action = common.Call('S.m()', '', 0)
        self.assertEqual((), action.parseArguments())

        action = common.Call('S.m(1)', '', 0)
        self.assertEqual((1,), action.parseArguments())

        action = common.Call('S.m(1, 2)', '', 0)
        self.assertEqual((1, 2), action.parseArguments())

        action = common.Call('S.m("string")', '', 0)
        self.assertEqual(('string',), action.parseArguments())

        action = common.Call('S.m((1, 2))', '', 0)
        self.assertEqual((1, 2), action.parseArguments())

        action = common.Call('S.m([1, 2])', '', 0)
        self.assertEqual(([1, 2],), action.parseArguments())

        action = common.Call('S.m({1: 2})', '', 0)
        self.assertEqual(({1: 2},), action.parseArguments())

        action = common.Call("S.m({'Echo': 'EchoProfile'})", '', 0)
        self.assertEqual(({'Echo': 'EchoProfile'},), action.parseArguments())

        action = common.Call('S.m(True, False)', '', 0)
        self.assertEqual((True, False), action.parseArguments())

        action = common.Call("S.m(1, 2, {'key': 'value'})", '', 0)
        self.assertEqual((1, 2, {'key': 'value'}), action.parseArguments())

        action = common.Call("S.m(1, 2, (3, 4), [5, 6], {'key': 'value'})", '', 0)
        self.assertEqual((1, 2, (3, 4), [5, 6], {'key': 'value'}), action.parseArguments())
Example #7
0
 def test_CallActionThrowsExceptionWhenServiceIsNotAvailable(self):
     action = common.Call('Service')
     self.assertRaises(ServiceCallError, action.execute().get)