Пример #1
0
    def testEncode(self):
        encoder = ParameterHandler()
        ioc.initialize(encoder)

        service = typeFor(IService).service
        for call in service.calls:
            if call.name == 'get': break
        invoker = InvokerCall(Service(), call)

        resolve = encoder.encodeInvoker(invoker)
        context = dict(converter=ConverterPath(), normalizer=ConverterPath())

        args = {'offset': 20, 'limit':0}
        self.assertEqual([('offset', '20'), ('limit', '0')], list(resolve(value=args, **context)))

        q = QMainModel(name='Gabriel')
        q.name.ascending = True
        q.name.priority = 1
        q.when.ascending = False
        q.when.priority = 2
        args = {'q': q}
        self.assertEqual([('name', 'Gabriel'), ('asc', 'name'), ('desc', 'when')], list(resolve(value=args, **context)))

        q = QMainModel()
        q.name.ascending = True
        q.name.priority = 1
        q.when.ascending = True
        q.when.priority = 2
        args = {'q': q}
        self.assertEqual([('asc', 'name,when')], list(resolve(value=args, **context)))

        qa = QAModel()
        qa.name.like = 'Gabriel'
        qa.name.ascending = False
        qa.name.priority = 1
        qa.something.start = 'startAndEnd'
        qa.something.end = 'startAndEnd'
        qa.something.until = 'until'
        args = {'qa': qa}
        self.assertEqual([('qa.something', 'startAndEnd'), ('qa.something.until', 'until'), ('qa.name', 'Gabriel'),
                          ('desc', 'qa.name')], list(resolve(value=args, **context)))

        args = {'offset': 20, 'limit':0, 'q': q, 'qa': qa}
        self.assertEqual([('qa.something', 'startAndEnd'), ('qa.something.until', 'until'), ('qa.name', 'Gabriel'),
                          ('offset', '20'), ('limit', '0'), ('asc', 'name'), ('desc', 'qa.name'), ('asc', 'when')],
                         list(resolve(value=args, **context)))

        self.assertTrue(len(resolve(value=SAMPLE, **context)) > 10)

        for call in service.calls:
            if call.name == 'insert': break
        invoker = InvokerCall(Service(), call)

        resolve = encoder.encodeInvoker(invoker)

        self.assertFalse(resolve(value=SAMPLE, **context))
Пример #2
0
    def testMethodInvoker(self):
        handler = MethodInvokerHandler()
        ioc.initialize(handler)
        request, response = Request(), Response()
        
        node = NodeRoot()
        request.method, request.path = HTTP_GET, Path([], node)

        def callProcess(chain, **keyargs): handler.process(**keyargs)
        chain = Chain([callProcess])
        chain.process(request=request, response=response).doAll()

        self.assertEqual(response.allows, [])
        self.assertTrue(response.isSuccess is False)
Пример #3
0
 def testConfigurationParser(self):
     ''' '''
     assemblyScanning = Assembly('Files scanner')
     registerListeners = RegisterListeners()
     registerListeners.patterns = ['file:///home/mihaigociu/Work/notifier_test/test1.txt',
                                   'file:///home/mihaigociu/Work/*/test1.txt']
     
     assemblyScanning.add(initialize(registerListeners), initialize(FileSystemScanner()))
     # assemblyScanning.add(initialize(RegisterListeners()))
     
     proc = assemblyScanning.create()
     assert isinstance(proc, Processing)
     
     proc.execute(FILL_ALL)
Пример #4
0
 def testPerformance(self):
     from babel import localedata, core
     # Babel FIX: We need to adjust the dir name for locales since they need to be outside the .egg file
     localedata._dirname = localedata._dirname.replace('.egg', '')
     core._filename = core._filename.replace('.egg', '')
 
     languageService = LanguageServiceBabelAlchemy()
     ioc.initialize(languageService)
     
     profile = Profile()
     qlang = QLanguage(name='rom%')
     try:
         profile = profile.runctx("languageService.getAllAvailable(['en'], 0, 10, qlang)", globals(), locals())
     except SystemExit: pass
     pstats.Stats(profile).sort_stats('time', 'cum').print_stats()
Пример #5
0
    def testTextConversion(self):
        handler = ConversionSetHandler()
        handler.normalizer = Normalizer()
        handler.converter = Converter()
        ioc.initialize(handler)

        requestCnt, response = Content(), Content()
        def callProcess(chain, **keyargs): handler.process(**keyargs)
        chain = Chain([callProcess])
        chain.process(requestCnt=requestCnt, response=response).doAll()

        self.assertEqual(handler.normalizer, requestCnt.normalizer)
        self.assertEqual(handler.normalizer, response.normalizer)

        self.assertEqual(handler.converter, response.converter)
        self.assertEqual(handler.converter, response.converter)
Пример #6
0
    def testMethodInvoker(self):
        handler = MethodInvokerHandler()
        ioc.initialize(handler)
        request, response = Request(), Response()

        node = NodeRoot()
        request.method, request.path = HTTP_GET, Path([], node)

        def callProcess(chain, **keyargs):
            handler.process(**keyargs)

        chain = Chain([callProcess])
        chain.process(request=request, response=response).doAll()

        self.assertEqual(response.allows, [])
        self.assertTrue(response.isSuccess is False)
Пример #7
0
    def testMethodInvoker(self):
        resourcesLocator = DummyResourceLocator()

        handler = MethodInvokerHandler()
        ioc.initialize(handler)

        request, response = Request(), Response()

        node = NodeRoot()
        request.method, request.path = GET, Path(resourcesLocator, [], node)

        def callProcess(chain, **keyargs): handler.process(**keyargs)
        chain = Chain([callProcess])
        chain.process(request=request, response=response).doAll()

        self.assertEqual(response.allows, 0)
        self.assertTrue(not response.code.isSuccess)
Пример #8
0
    def testConfigurationParser(self):
        ''' '''
        assemblyScanning = Assembly('Files scanner')
        registerListeners = RegisterListeners()
        registerListeners.patterns = [
            'file:///home/mihaigociu/Work/notifier_test/test1.txt',
            'file:///home/mihaigociu/Work/*/test1.txt'
        ]

        assemblyScanning.add(initialize(registerListeners),
                             initialize(FileSystemScanner()))
        # assemblyScanning.add(initialize(RegisterListeners()))

        proc = assemblyScanning.create()
        assert isinstance(proc, Processing)

        proc.execute(FILL_ALL)
Пример #9
0
    def testDecode(self):
        transformer = CreateDecoderHandler()
        ioc.initialize(transformer)

        typeModel = typeFor(ModelId)
        assert isinstance(typeModel, TypeModel)
        resolve = transformer.decoderFor('model', typeModel)

        context = dict(converter=ConverterPath(), converterId=ConverterPath(), normalizer=ConverterPath())

        args = {}
        self.assertTrue(resolve(path=deque(('Id',)), value='12', target=args, **context))
        self.assertTrue('model' in args)
        m = args['model']
        self.assertIsInstance(m, ModelId)
        assert isinstance(m, ModelId)
        self.assertTrue(m.Id == 12)

        args = {}
        self.assertTrue(resolve(path=deque(('ModelId', 'Id')), value='23', target=args, **context))
        self.assertTrue('model' in args)
        m = args['model']
        self.assertIsInstance(m, ModelId)
        assert isinstance(m, ModelId)
        self.assertTrue(m.Id == 23)

        self.assertTrue(resolve(path=deque(('ModelKey', 'Key')), value='The key', target=args, **context))
        self.assertTrue(m.ModelKey == 'The key')

        self.assertTrue(resolve(path=deque(('Name',)), value='Uau Name', target=args, **context))
        self.assertTrue(resolve(path=deque(('Flags',)), value=['1', '2', '3'], target=args, **context))
        self.assertTrue(m.Name == 'Uau Name')
        self.assertTrue(m.Flags == ['1', '2', '3'])

        args = {}
        self.assertTrue(resolve(path=deque(('Flags',)), value='3', target=args, **context))
        self.assertTrue(resolve(path=deque(('Flags',)), value='1', target=args, **context))
        self.assertTrue(resolve(path=deque(('Flags',)), value='2', target=args, **context))
        self.assertTrue('model' in args)
        m = args['model']
        self.assertIsInstance(m, ModelId)
        self.assertTrue(m.Flags == ['3', '1', '2'])

        self.assertRaises(InputError, resolve, path=deque(('ModelKey', 'Name')), value='The name',
                          target=args, **context)
Пример #10
0
    def testPerformance(self):
        from babel import localedata, core
        # Babel FIX: We need to adjust the dir name for locales since they need to be outside the .egg file
        localedata._dirname = localedata._dirname.replace('.egg', '')
        core._filename = core._filename.replace('.egg', '')

        languageService = LanguageServiceBabelAlchemy()
        ioc.initialize(languageService)

        profile = Profile()
        qlang = QLanguage(name='rom%')
        try:
            profile = profile.runctx(
                "languageService.getAllAvailable(0, 10, qlang, None)",
                globals(), locals())
        except SystemExit:
            pass
        pstats.Stats(profile).sort_stats('time', 'cum').print_stats()
Пример #11
0
    def testTextConversion(self):
        handler = ConversionSetHandler()
        handler.normalizer = Normalizer()
        handler.converter = Converter()
        ioc.initialize(handler)

        requestCnt, response = Content(), Content()

        def callProcess(chain, **keyargs):
            handler.process(**keyargs)

        chain = Chain([callProcess])
        chain.process(requestCnt=requestCnt, response=response).doAll()

        self.assertEqual(handler.normalizer, requestCnt.normalizer)
        self.assertEqual(handler.normalizer, response.normalizer)

        self.assertEqual(handler.converter, response.converter)
        self.assertEqual(handler.converter, response.converter)
Пример #12
0
 def createAssemplyParsing(self):
     parser = ParserHandler()
     parser.rootNode = RuleRoot()
     
     anonymous = parser.rootNode.addRule(GroupRule(), 'Config/Anonymous')
     captcha = parser.rootNode.addRule(GroupRule(), 'Config/Captcha')
     right = parser.rootNode.addRule(RightRule('name', 'inherits'), 'Config/Right')
     right.addRule(DescriptionRule(), 'Description')
     
     #allows = anonymous.addRule(AccessRule(), 'Allows')
     allows = Node('Allows')
     allows.addRule(AccessRule())
     #allows.addRule(MethodRule(fromAttributes=True))
     allows.addRule(URLRule(), 'URL')
     allows.addRule(MethodRule(), 'Method')
     
     action = Node('Action')
     action.addRule(ActionRule())
     action.childrens['Action'] = action
     
     actions = Node('Actions')
     actions.childrens['Action'] = action
     
     anonymous.childrens['Actions'] = actions
     anonymous.childrens['Action'] = action
     anonymous.childrens['Allows'] = allows
     
     #no actions for captcha
     captcha.childrens['Allows'] = allows
     
     right.childrens['Actions'] = actions
     right.childrens['Action'] = action
     right.childrens['Allows'] = allows
     
     assemblyParsing = Assembly('Parsing XML')
     assemblyParsing.add(initialize(parser))
     return assemblyParsing
Пример #13
0
    def testEncode(self):
        transformer = CreateEncoderHandler()
        ioc.initialize(transformer)

        resolve = Resolve(transformer.encoderFor(typeFor(ModelId)))
        render = RenderToObject()
        context = dict(render=render,
                       converter=ConverterPath(),
                       converterId=ConverterPath(),
                       normalizer=ConverterPath())

        model = ModelId()
        model.Id = 12
        render.obj = None
        resolve.request(value=model, **context).doAll()
        self.assertEqual({'Id': '12'}, render.obj)

        model.ModelKey = 'The key'
        render.obj = None
        resolve.request(value=model, **context).doAll()
        self.assertEqual({
            'Id': '12',
            'ModelKey': {
                'Key': 'The key'
            }
        }, render.obj)

        model.Name = 'Uau Name'
        model.Flags = ['1', '2', '3']
        render.obj = None
        resolve.request(value=model, **context).doAll()
        self.assertEqual(
            {
                'ModelKey': {
                    'Key': 'The key'
                },
                'Flags': {
                    'Flags': ['1', '2', '3']
                },
                'Id': '12',
                'Name': 'Uau Name'
            }, render.obj)

        transformer = CreateEncoderHandler()
        ioc.initialize(transformer)

        resolve = Resolve(transformer.encoderFor(typeFor(List(ModelId))))

        render.obj = None
        resolve.request(value=[model], **context).doAll()

        self.assertEqual(
            {
                'ModelIdList': [{
                    'ModelKey': {
                        'Key': 'The key'
                    },
                    'Flags': {
                        'Flags': ['1', '2', '3']
                    },
                    'Id': '12',
                    'Name': 'Uau Name'
                }]
            }, render.obj)

        render.obj = None
        resolve.request(value=[model, model, model], **context)
        resolve.do()
        self.assertEqual({'ModelIdList': []}, render.obj)
        resolve.do()
        self.assertEqual(
            {
                'ModelIdList': [{
                    'ModelKey': {
                        'Key': 'The key'
                    },
                    'Flags': {
                        'Flags': ['1', '2', '3']
                    },
                    'Id': '12',
                    'Name': 'Uau Name'
                }]
            }, render.obj)
        resolve.do()
        self.assertEqual(
            {
                'ModelIdList': [{
                    'ModelKey': {
                        'Key': 'The key'
                    },
                    'Flags': {
                        'Flags': ['1', '2', '3']
                    },
                    'Id': '12',
                    'Name': 'Uau Name'
                }, {
                    'ModelKey': {
                        'Key': 'The key'
                    },
                    'Flags': {
                        'Flags': ['1', '2', '3']
                    },
                    'Id': '12',
                    'Name': 'Uau Name'
                }]
            }, render.obj)
        resolve.do()
        self.assertEqual(
            {
                'ModelIdList': [{
                    'ModelKey': {
                        'Key': 'The key'
                    },
                    'Flags': {
                        'Flags': ['1', '2', '3']
                    },
                    'Id': '12',
                    'Name': 'Uau Name'
                }, {
                    'ModelKey': {
                        'Key': 'The key'
                    },
                    'Flags': {
                        'Flags': ['1', '2', '3']
                    },
                    'Id': '12',
                    'Name': 'Uau Name'
                }, {
                    'ModelKey': {
                        'Key': 'The key'
                    },
                    'Flags': {
                        'Flags': ['1', '2', '3']
                    },
                    'Id': '12',
                    'Name': 'Uau Name'
                }]
            }, render.obj)
        resolve.do()
        self.assertFalse(resolve.has())
Пример #14
0
    def testDecode(self):
        decoder = ParameterHandler()
        ioc.initialize(decoder)

        service = typeFor(IService).service
        invoker = InvokerCall(Service(), service.calls['get'])

        resolve = decoder.decodeInvoker(invoker)
        context = dict(converter=ConverterPath(), normalizer=ConverterPath())

        args = {}
        self.assertTrue(
            resolve(path='offset', value='20', target=args, **context))
        self.assertTrue(
            resolve(path='limit', value='0', target=args, **context))
        self.assertEqual(args, {'limit': 0, 'offset': 20})

        args = {}
        self.assertTrue(
            resolve(path='name', value='Gabriel', target=args, **context))
        self.assertTrue(
            resolve(path='asc', value='name', target=args, **context))
        self.assertTrue(
            resolve(path='desc', value='when', target=args, **context))
        self.assertTrue('q' in args)
        q = args['q']
        self.assertIsInstance(q, QMainModel)
        assert isinstance(q, QMainModel)
        self.assertTrue(q.name.like == 'Gabriel')
        self.assertTrue(q.name.ascending == True and q.name.priority == 1)
        self.assertTrue(q.when.ascending == False and q.when.priority == 2)

        args = {}
        self.assertTrue(
            resolve(path='asc', value='name, when', target=args, **context))
        self.assertTrue('q' in args)
        q = args['q']
        self.assertIsInstance(q, QMainModel)
        assert isinstance(q, QMainModel)
        self.assertTrue(q.name.ascending == True and q.name.priority == 1)
        self.assertTrue(q.when.ascending == True and q.when.priority == 2)

        args = {}
        self.assertTrue(
            resolve(path='qa.name', value='Gabriel', target=args, **context))
        self.assertTrue(
            resolve(path='desc', value='qa.name', target=args, **context))
        self.assertTrue(
            resolve(path='qa.something',
                    value='startAndEnd',
                    target=args,
                    **context))
        self.assertTrue(
            resolve(path='qa.something.until',
                    value='until',
                    target=args,
                    **context))
        self.assertTrue('qa' in args)
        qa = args['qa']
        self.assertIsInstance(qa, QAModel)
        assert isinstance(qa, QAModel)
        self.assertTrue(qa.name.like == 'Gabriel')
        self.assertTrue(qa.name.ascending == False and q.name.priority == 1)
        self.assertTrue(qa.something.start == 'startAndEnd'
                        and qa.something.end == 'startAndEnd')
        self.assertTrue(qa.something.until == 'until')

        args = {}
        self.assertFalse(
            resolve(path='mainId', value='not', target=args, **context))
        self.assertFalse(
            resolve(path='scheme', value='not', target=args, **context))
        self.assertFalse(
            resolve(path='locale', value='not', target=args, **context))
        self.assertFalse(
            resolve(path='another', value='not', target=args, **context))
        self.assertFalse(
            resolve(path='name.ascending',
                    value='False',
                    target=args,
                    **context))
        self.assertFalse(
            resolve(path='qa.name.priority', value='1', target=args,
                    **context))

        invoker = InvokerCall(Service(), service.calls['insert'])

        resolve = decoder.decodeInvoker(invoker)

        self.assertFalse(
            resolve(path='offset', value='20', target=args, **context))
        self.assertFalse(
            resolve(path='limit', value='0', target=args, **context))
Пример #15
0
    def testEncode(self):
        encoder = ParameterHandler()
        ioc.initialize(encoder)

        service = typeFor(IService).service
        invoker = InvokerCall(Service(), service.calls['get'])

        resolve = encoder.encodeInvoker(invoker)
        context = dict(converter=ConverterPath(), normalizer=ConverterPath())

        args = {'offset': 20, 'limit': 0}
        self.assertEqual([('offset', '20'), ('limit', '0')],
                         list(resolve(value=args, **context)))

        q = QMainModel(name='Gabriel')
        q.name.ascending = True
        q.name.priority = 1
        q.when.ascending = False
        q.when.priority = 2
        args = {'q': q}
        self.assertEqual([('name', 'Gabriel'), ('asc', 'name'),
                          ('desc', 'when')],
                         list(resolve(value=args, **context)))

        q = QMainModel()
        q.name.ascending = True
        q.name.priority = 1
        q.when.ascending = True
        q.when.priority = 2
        args = {'q': q}
        self.assertEqual([('asc', 'name,when')],
                         list(resolve(value=args, **context)))

        qa = QAModel()
        qa.name.like = 'Gabriel'
        qa.name.ascending = False
        qa.name.priority = 1
        qa.something.start = 'startAndEnd'
        qa.something.end = 'startAndEnd'
        qa.something.until = 'until'
        args = {'qa': qa}
        self.assertEqual([('qa.something', 'startAndEnd'),
                          ('qa.something.until', 'until'),
                          ('qa.name', 'Gabriel'), ('desc', 'qa.name')],
                         list(resolve(value=args, **context)))

        args = {'offset': 20, 'limit': 0, 'q': q, 'qa': qa}
        self.assertEqual([('qa.something', 'startAndEnd'),
                          ('qa.something.until', 'until'),
                          ('qa.name', 'Gabriel'), ('offset', '20'),
                          ('limit', '0'), ('asc', 'name'), ('desc', 'qa.name'),
                          ('asc', 'when')], list(resolve(value=args,
                                                         **context)))

        self.assertTrue(len(resolve(value=SAMPLE, **context)) > 10)

        invoker = InvokerCall(Service(), service.calls['insert'])

        resolve = encoder.encodeInvoker(invoker)

        self.assertFalse(resolve(value=SAMPLE, **context))
Пример #16
0
    def testDecode(self):
        decoder = ParameterHandler()
        ioc.initialize(decoder)

        service = typeFor(IService).service
        for call in service.calls:
            if call.name == 'get': break
        invoker = InvokerCall(Service(), call)

        resolve = decoder.decodeInvoker(invoker)
        context = dict(converter=ConverterPath(), normalizer=ConverterPath())

        args = {}
        self.assertTrue(resolve(path='offset', value='20', target=args, **context))
        self.assertTrue(resolve(path='limit', value='0', target=args, **context))
        self.assertEqual(args, {'limit': 0, 'offset': 20})

        args = {}
        self.assertTrue(resolve(path='name', value='Gabriel', target=args, **context))
        self.assertTrue(resolve(path='asc', value='name', target=args, **context))
        self.assertTrue(resolve(path='desc', value='when', target=args, **context))
        self.assertTrue('q' in args)
        q = args['q']
        self.assertIsInstance(q, QMainModel)
        assert isinstance(q, QMainModel)
        self.assertTrue(q.name.like == 'Gabriel')
        self.assertTrue(q.name.ascending == True and q.name.priority == 1)
        self.assertTrue(q.when.ascending == False and q.when.priority == 2)

        args = {}
        self.assertTrue(resolve(path='asc', value='name, when', target=args, **context))
        self.assertTrue('q' in args)
        q = args['q']
        self.assertIsInstance(q, QMainModel)
        assert isinstance(q, QMainModel)
        self.assertTrue(q.name.ascending == True and q.name.priority == 1)
        self.assertTrue(q.when.ascending == True and q.when.priority == 2)

        args = {}
        self.assertTrue(resolve(path='qa.name', value='Gabriel', target=args, **context))
        self.assertTrue(resolve(path='desc', value='qa.name', target=args, **context))
        self.assertTrue(resolve(path='qa.something', value='startAndEnd', target=args, **context))
        self.assertTrue(resolve(path='qa.something.until', value='until', target=args, **context))
        self.assertTrue('qa' in args)
        qa = args['qa']
        self.assertIsInstance(qa, QAModel)
        assert isinstance(qa, QAModel)
        self.assertTrue(qa.name.like == 'Gabriel')
        self.assertTrue(qa.name.ascending == False and q.name.priority == 1)
        self.assertTrue(qa.something.start == 'startAndEnd' and qa.something.end == 'startAndEnd')
        self.assertTrue(qa.something.until == 'until')

        args = {}
        self.assertFalse(resolve(path='mainId', value='not', target=args, **context))
        self.assertFalse(resolve(path='scheme', value='not', target=args, **context))
        self.assertFalse(resolve(path='locale', value='not', target=args, **context))
        self.assertFalse(resolve(path='another', value='not', target=args, **context))
        self.assertFalse(resolve(path='name.ascending', value='False', target=args, **context))
        self.assertFalse(resolve(path='qa.name.priority', value='1', target=args, **context))

        for call in service.calls:
            if call.name == 'insert': break
        invoker = InvokerCall(Service(), call)

        resolve = decoder.decodeInvoker(invoker)

        self.assertFalse(resolve(path='offset', value='20', target=args, **context))
        self.assertFalse(resolve(path='limit', value='0', target=args, **context))
Пример #17
0
    def testEncode(self):
        transformer = CreateEncoderHandler()
        ioc.initialize(transformer)

        resolve = Resolve(transformer.encoderFor(typeFor(ModelId)))
        render = RenderToObject()
        context = dict(render=render, converter=ConverterPath(), converterId=ConverterPath(), normalizer=ConverterPath())

        model = ModelId()
        model.Id = 12
        render.obj = None
        resolve.request(value=model, **context).doAll()
        self.assertEqual({'Id':'12'}, render.obj)

        model.ModelKey = 'The key'
        render.obj = None
        resolve.request(value=model, **context).doAll()
        self.assertEqual({'Id':'12', 'ModelKey': {'Key': 'The key'}}, render.obj)

        model.Name = 'Uau Name'
        model.Flags = ['1', '2', '3']
        render.obj = None
        resolve.request(value=model, **context).doAll()
        self.assertEqual({'ModelKey': {'Key': 'The key'}, 'Flags': {'Flags': ['1', '2', '3']}, 'Id': '12',
                          'Name': 'Uau Name'}, render.obj)

        transformer = CreateEncoderHandler()
        ioc.initialize(transformer)

        resolve = Resolve(transformer.encoderFor(typeFor(List(ModelId))))

        render.obj = None
        resolve.request(value=[model], **context).doAll()

        self.assertEqual({'ModelIdList':
                [{'ModelKey': {'Key': 'The key'}, 'Flags': {'Flags': ['1', '2', '3']}, 'Id': '12', 'Name': 'Uau Name'}]},
                render.obj)

        render.obj = None
        resolve.request(value=[model, model, model], **context)
        resolve.do()
        self.assertEqual({'ModelIdList': []}, render.obj)
        resolve.do()
        self.assertEqual({'ModelIdList':
                  [
                   {'ModelKey': {'Key': 'The key'}, 'Flags': {'Flags': ['1', '2', '3']}, 'Id': '12', 'Name': 'Uau Name'}
                   ]}, render.obj)
        resolve.do()
        self.assertEqual({'ModelIdList':
                  [
                   {'ModelKey': {'Key': 'The key'}, 'Flags': {'Flags': ['1', '2', '3']}, 'Id': '12', 'Name': 'Uau Name'},
                   {'ModelKey': {'Key': 'The key'}, 'Flags': {'Flags': ['1', '2', '3']}, 'Id': '12', 'Name': 'Uau Name'}
                   ]}, render.obj)
        resolve.do()
        self.assertEqual({'ModelIdList':
                  [
                   {'ModelKey': {'Key': 'The key'}, 'Flags': {'Flags': ['1', '2', '3']}, 'Id': '12', 'Name': 'Uau Name'},
                   {'ModelKey': {'Key': 'The key'}, 'Flags': {'Flags': ['1', '2', '3']}, 'Id': '12', 'Name': 'Uau Name'},
                   {'ModelKey': {'Key': 'The key'}, 'Flags': {'Flags': ['1', '2', '3']}, 'Id': '12', 'Name': 'Uau Name'}
                   ]}, render.obj)
        resolve.do()
        self.assertFalse(resolve.has())
Пример #18
0
    def testEncode(self):
        encoder = ParameterHandler()
        ioc.initialize(encoder)

        service = typeFor(IService).service
        invoker = InvokerCall(Service(), service.calls["get"])

        resolve = encoder.encodeInvoker(invoker)
        context = dict(converter=ConverterPath(), normalizer=ConverterPath())

        args = {"offset": 20, "limit": 0}
        self.assertEqual([("offset", "20"), ("limit", "0")], list(resolve(value=args, **context)))

        q = QMainModel(name="Gabriel")
        q.name.ascending = True
        q.name.priority = 1
        q.when.ascending = False
        q.when.priority = 2
        args = {"q": q}
        self.assertEqual([("name", "Gabriel"), ("asc", "name"), ("desc", "when")], list(resolve(value=args, **context)))

        q = QMainModel()
        q.name.ascending = True
        q.name.priority = 1
        q.when.ascending = True
        q.when.priority = 2
        args = {"q": q}
        self.assertEqual([("asc", "name,when")], list(resolve(value=args, **context)))

        qa = QAModel()
        qa.name.like = "Gabriel"
        qa.name.ascending = False
        qa.name.priority = 1
        qa.something.start = "startAndEnd"
        qa.something.end = "startAndEnd"
        qa.something.until = "until"
        args = {"qa": qa}
        self.assertEqual(
            [
                ("qa.something", "startAndEnd"),
                ("qa.something.until", "until"),
                ("qa.name", "Gabriel"),
                ("desc", "qa.name"),
            ],
            list(resolve(value=args, **context)),
        )

        args = {"offset": 20, "limit": 0, "q": q, "qa": qa}
        self.assertEqual(
            [
                ("qa.something", "startAndEnd"),
                ("qa.something.until", "until"),
                ("qa.name", "Gabriel"),
                ("offset", "20"),
                ("limit", "0"),
                ("asc", "name"),
                ("desc", "qa.name"),
                ("asc", "when"),
            ],
            list(resolve(value=args, **context)),
        )

        self.assertTrue(len(resolve(value=SAMPLE, **context)) > 10)

        invoker = InvokerCall(Service(), service.calls["insert"])

        resolve = encoder.encodeInvoker(invoker)

        self.assertFalse(resolve(value=SAMPLE, **context))
Пример #19
0
    def testDecode(self):
        decoder = ParameterHandler()
        ioc.initialize(decoder)

        service = typeFor(IService).service
        invoker = InvokerCall(Service(), service.calls["get"])

        resolve = decoder.decodeInvoker(invoker)
        context = dict(converter=ConverterPath(), normalizer=ConverterPath())

        args = {}
        self.assertTrue(resolve(path="offset", value="20", target=args, **context))
        self.assertTrue(resolve(path="limit", value="0", target=args, **context))
        self.assertEqual(args, {"limit": 0, "offset": 20})

        args = {}
        self.assertTrue(resolve(path="name", value="Gabriel", target=args, **context))
        self.assertTrue(resolve(path="asc", value="name", target=args, **context))
        self.assertTrue(resolve(path="desc", value="when", target=args, **context))
        self.assertTrue("q" in args)
        q = args["q"]
        self.assertIsInstance(q, QMainModel)
        assert isinstance(q, QMainModel)
        self.assertTrue(q.name.like == "Gabriel")
        self.assertTrue(q.name.ascending == True and q.name.priority == 1)
        self.assertTrue(q.when.ascending == False and q.when.priority == 2)

        args = {}
        self.assertTrue(resolve(path="asc", value="name, when", target=args, **context))
        self.assertTrue("q" in args)
        q = args["q"]
        self.assertIsInstance(q, QMainModel)
        assert isinstance(q, QMainModel)
        self.assertTrue(q.name.ascending == True and q.name.priority == 1)
        self.assertTrue(q.when.ascending == True and q.when.priority == 2)

        args = {}
        self.assertTrue(resolve(path="qa.name", value="Gabriel", target=args, **context))
        self.assertTrue(resolve(path="desc", value="qa.name", target=args, **context))
        self.assertTrue(resolve(path="qa.something", value="startAndEnd", target=args, **context))
        self.assertTrue(resolve(path="qa.something.until", value="until", target=args, **context))
        self.assertTrue("qa" in args)
        qa = args["qa"]
        self.assertIsInstance(qa, QAModel)
        assert isinstance(qa, QAModel)
        self.assertTrue(qa.name.like == "Gabriel")
        self.assertTrue(qa.name.ascending == False and q.name.priority == 1)
        self.assertTrue(qa.something.start == "startAndEnd" and qa.something.end == "startAndEnd")
        self.assertTrue(qa.something.until == "until")

        args = {}
        self.assertFalse(resolve(path="mainId", value="not", target=args, **context))
        self.assertFalse(resolve(path="scheme", value="not", target=args, **context))
        self.assertFalse(resolve(path="locale", value="not", target=args, **context))
        self.assertFalse(resolve(path="another", value="not", target=args, **context))
        self.assertFalse(resolve(path="name.ascending", value="False", target=args, **context))
        self.assertFalse(resolve(path="qa.name.priority", value="1", target=args, **context))

        invoker = InvokerCall(Service(), service.calls["insert"])

        resolve = decoder.decodeInvoker(invoker)

        self.assertFalse(resolve(path="offset", value="20", target=args, **context))
        self.assertFalse(resolve(path="limit", value="0", target=args, **context))