def test_special_chars_removing_from_tag_tree(): tags_tree_service = TagTreeService( tags=[ 'tAg1', 'tAg1,\n\r\ttag2', 'tag2.\ntag3', ] ) text = 'tag1 tag2 tag3' assert set(tags_tree_service.get_tags_by_text(text=text)) == { 'tag1', 'tag1 tag2', 'tag2 tag3' }
async def create_app(args): app = web.Application() with open(args.tag_file_path) as file: csv_reader = csv.reader(file, delimiter='\n') tags = (title[0] for title in csv_reader) app['tag_tree_service'] = TagTreeService(tags=tags) app.router.add_route('POST', '/text', request_handler) return app
def test_special_chars_removing(tags_tree_service: TagTreeService): tags = tags_tree_service.get_tags_by_text( text='tag1 \n tag5, tag6. \r\t\n tag2' ) assert set(tags) == { 'tag1', 'tag1 tag2', 'tag5 tag6' }
def test_upper_case(tags_tree_service: TagTreeService): tags = tags_tree_service.get_tags_by_text( text='Tag1 tAg5 taG6 TAG2' ) assert set(tags) == { 'Tag1', 'Tag1 TAG2', 'tAg5 taG6' }
def test_nested_tags_search(tags_tree_service: TagTreeService): tags = tags_tree_service.get_tags_by_text( text='tag1 tag5 tag6 tag2' ) assert set(tags) == { 'tag1', 'tag1 tag2', 'tag5 tag6' }
def test_all_tags_search(tags_tree_service: TagTreeService): tags = tags_tree_service.get_tags_by_text( text='tag1 tag2 tag3 tag4 tag2' ) assert set(tags) == { 'tag1', 'tag1 tag2', 'tag2 tag3', 'tag2 tag3 tag4' }
def tags_tree_service(): return TagTreeService( tags=[ 'tag1', 'tag1 tag2', 'tag2 tag3', 'tag2 tag3 tag4', 'tag5 tag6' ] )
def create_app(loop): app = web.Application(loop=loop) app.router.add_route('POST', '/text', request_handler) app['tag_tree_service'] = TagTreeService( tags=[ 'test1', 'test2', 'test3', 'test1 test2 test 3' ] ) return app
def test_tags_tree_build(): tags_tree_service = TagTreeService( tags=[ 'tag1', 'tag1 tag2', 'tag2 tag3', 'tag2 tag4', 'tag2 tag3 tag4', 'tag5 tag6' ] ) assert tags_tree_service.tags_tree == { 'tag1': { 'is_leaf': True, 'childs': {'tag2': {'is_leaf': True, 'childs': {}}} }, 'tag2': { 'is_leaf': False, 'childs': { 'tag3': { 'is_leaf': True, 'childs': { 'tag4': { 'is_leaf': True, 'childs': {} } } }, 'tag4': { 'is_leaf': True, 'childs': {} } } }, 'tag5': { 'is_leaf': False, 'childs': { 'tag6': { 'is_leaf': True, 'childs': {} } } } }
def test_no_tags_text_search(tags_tree_service: TagTreeService): tags = tags_tree_service.get_tags_by_text( text='test test test test' ) assert set(tags) == set()
def test_finding_multiple_tags_with(tags_tree_service: TagTreeService): tags = tags_tree_service.get_tags_by_text( text='tag2 tag3 tag4' ) assert set(tags) == {'tag2 tag3 tag4', 'tag2 tag3'}
def test_tag_search_with_two_word_beetween_tags(tags_tree_service: TagTreeService): tags = tags_tree_service.get_tags_by_text( text='test tag1 test test tag2' ) assert set(tags) == {'tag1', 'tag1 tag2'}
def test_tag_search(tags_tree_service: TagTreeService): tags = tags_tree_service.get_tags_by_text( text='test test tag1 tag2 test test' ) assert set(tags) == {'tag1', 'tag1 tag2'}