def test_direct(self): (RouteId('test_direct') .process(set_body('test_direct_success'))) #yapf: disable ((Any() .assert_('test_direct_0', self.assertEqual, body(), 'boo') .to(direct('test_direct')) .assert_('test_direct_1', self.assertEqual, body(), 'test_direct_success')) ).send_to_sync(Exchange('boo')) #yapf: disable (RouteId('test_direct_blank')) ((Any() .to(direct('test_direct_blank')) .assert_('test_direct_blank_1', self.assertEqual, body(), 'bar')) ).send_to_sync(Exchange('bar')) #yapf: disable (RouteId('test_direct_nest_first').to(direct('test_direct_nest_second'))) #yapf: disable (RouteId('test_direct_nest_second').to(direct('test_direct_nest_third'))) #yapf: disable (RouteId('test_direct_nest_third').process(set_body('nest_success'))) #yapf: disable ((Any().to(direct('test_direct_nest_first')) .assert_('test_direct_nest_0', self.assertEqual, body(), 'nest_success')) ).send_to_sync() #yapf: disable
def test_cache(self): from cachetools import LRUCache (RouteId('test_cache_request') .process(set_header('process_flag', True)) .process(set_body('response'))) #yapf: disable route = (Any().to(cache({ 'to': To(direct('test_cache_request')), 'keys': [header('key')], 'cache_object': LRUCache(maxsize=1000) })))#yapf: disable ex1 = route.send_to_sync(Exchange(header={'key': 'foo'})) self.assertEqual(ex1.get_body(), 'response') self.assertEqual(ex1.get_header('process_flag'), True) ex2 = route.send_to_sync(Exchange(header={'key': 'foo'})) self.assertEqual(ex2.get_body(), 'response') self.assertEqual(ex2.get_header('process_flag'), None) ex3 = route.send_to_sync(Exchange(header={'key': 'bar'})) self.assertEqual(ex3.get_body(), 'response') self.assertEqual(ex3.get_header('process_flag'), True)
#yapf:disable (Aiohttp('/ameblo-images') .validate({ 'rule': lambda ex: re.match('^https://ameblo.jp/.+/$', ex.get_header('url','')), 'message':'urlパラメータに有効なameblo urlをセットしてください。書式: https://ameblo.jp/{userid}/'}) .to(cache({ 'cache_object': ameblo_cache, 'keys': [header('url')], 'to': Any() .throttle(1) .to(cache({ 'cache_object': ameblo_cache, 'keys': [header('url')], 'to': To(direct('ameblo_images_main')) })) })) ) #yapf:disable (RouteId('ameblo_images_main') .validate({ 'process_rule': To(aiohttp_request({'url': header('url'), 'isValid': True})), 'message': 'amebloサーバーからのレスポンスに問題があるため、処理を中断しました。ameblo idおよびamebloサーバーのステータスを確認してください。' }) .to(log({'name':'ameblo_images_main_start','header':True, 'body': False})) # get entrylist last url: max=10 .to(aiohttp_request({'url':lambda ex: '{}entrylist-10.html'.format(ex.get_header('url'))})) .to(soup(lambda soup:(soup.find('a', class_='pagingPrev') or
#yapf:disable (Aiohttp('/futaboard-images') .validate({ 'rule': lambda ex: re.match('^http://board.futakuro.com/jk2/res/\d+.htm$', ex.get_header('url','')), 'message':'urlパラメータに有効なふたボード urlをセットしてください。書式: http://board.futakuro.com/jk2/res/{id}.htm$'}) .to(cache({ 'cache_object': futaboard_cache, 'keys': [header('url')], 'to': Any() .throttle(1) .to(cache({ 'cache_object': futaboard_cache, 'keys': [header('url')], 'to': To(direct('futaboard_images_main')) })) })) ) #yapf:disable (RouteId('futaboard_images_main') .validate({ 'process_rule': To(aiohttp_request({'url': header('url'), 'isValid': True})), 'message': 'futaboardサーバーからのレスポンスに問題があるため、処理を中断しました。urlおよびfutaboardサーバーのステータスを確認してください。' }) .to(log({'name':'futaboard_images_main_start','header':True, 'body': False})) .to(aiohttp_request({'url': header('url')})) .to(soup(lambda soup:[span.find('a').get('href') if 'http://' in span.find('a').get('href') else 'http://board.futakuro.com/jk2/' + span.find('a').get('href') for span in soup.find_all('span', class_='s10')])) # open zipfile
exchange.set_body('success') return exchange (RouteId('common_post_processing') .process(sort_func) .to(cache_set_processor) .to(merge_item) ) #yapf: disable (Context('create-item') .to(cache_get_processor) .process(lambda ex: ex.set_header('id', max([item.get('id', 0) for item in ex.get_body()]) + 1)) .process(lambda ex: ex.set_body( [calc_date_from_span({**(ex.get_headers(['id', 'name', 'url', 'memo', 'decide', 'span'])), 'start': get_now("%m/%d")(ex)}, True)] + ex.get_body())) .to(direct('common_post_processing')) ) #yapf: disable (Context('click-current-item-no-finish') .to(cache_get_processor) .to(simple_update_success_count) .to(simple_update_next()) .to(simple_update_time) .to(direct('common_post_processing')) ) #yapf: disable (Context('click-current-item-to-finish') .to(cache_get_processor) .to(complete_item) .to(direct('common_post_processing')) ) #yapf: disable