def test_general(gm_client, login, msgs, patch): stdout = check_output('mlr -h', shell=True) assert b'Mailur CLI' in stdout stdout = check_output('mlr icons', shell=True) assert b'assets/font/icons.less updated\n' in stdout gm_client.add_emails([{}, {}], fetch=False, parse=False) assert [i['uid'] for i in msgs(local.SRC)] == [] assert [i['uid'] for i in msgs()] == [] cli.main('gmail %s --parse' % login.user1) assert [i['uid'] for i in msgs(local.SRC)] == ['1', '2'] assert [i['uid'] for i in msgs()] == ['1', '2'] local.link_threads(['1', '2']) assert [i['uid'] for i in msgs(local.SRC)] == ['1', '2', '3'] assert [i['uid'] for i in msgs()] == ['1', '2', '3'] cli.main('update-links %s' % login.user1) assert [i['uid'] for i in msgs(local.SRC)] == ['1', '2', '4'] assert [i['uid'] for i in msgs()] == ['1', '2', '4'] with patch('mailur.cli.local') as m: cli.main('update-metadata %s' % login.user1) assert m.save_addrs.called assert m.save_msgids.called assert m.save_uid_pairs.called
def test_link_threads_part3(gm_client, msgs): gm_client.add_emails([ {}, {'refs': '<none-two@mlr>'}, {'refs': '<none@mlr>'}, {'refs': '<none@mlr> <102@mlr>'} ]) refs = [ '<*****@*****.**>', '<*****@*****.**> <none-two@mlr>', '<*****@*****.**> <none@mlr>', '<*****@*****.**> <none@mlr> <102@mlr>' ] assert local.search_thrs('all') == ['4', '3', '1'] assert local.data_threads.get()[1] == { '1': ['1'], '3': ['3'], '4': ['2', '4'] } res = msgs(local.SRC) assert [i['body']['references'] for i in res] == [ None, '<none-two@mlr>', '<none@mlr>', '<none@mlr> <102@mlr>', ] res = msgs() assert [i['body']['references'] for i in res] == refs local.link_threads(['1', '3', '4']) assert local.search_thrs('all') == ['4'] assert local.data_threads.get()[1] == {'4': ['1', '2', '3', '4']} res = msgs() assert [i['body']['references'] for i in res] == refs assert local.search_thrs('uid 1') == [i[0] for i in local.thrs_info(['1'])]
def test_clean_flags(gm_client, msgs, login): gm_client.add_emails([{}] * 2) local.link_threads(['1', '2']) assert [i['flags'] for i in msgs(local.SRC)] == ['', '', '\\Seen #link'] assert [i['flags'] for i in msgs()] == ['', '#latest', '\\Seen #link'] con_src = local.client(local.SRC, readonly=False) con_all = local.client(local.ALL, readonly=False) con_src.store('3', '-FLAGS', '#link \\Seen') con_src.store('1', '+FLAGS', '#latest') con_src.store('2', '+FLAGS', '#dup') con_all.store('3', '-FLAGS', '#link \\Seen') con_all.store('2', '-FLAGS', '#latest') assert [i['flags'] for i in msgs(local.SRC)] == ['#latest', '#dup', ''] assert [i['flags'] for i in msgs()] == ['', '', ''] local.clean_flags() assert [i['flags'] for i in msgs(local.SRC)] == ['', '', '\\Seen #link'] assert [i['flags'] for i in msgs()] == ['', '#latest', '\\Seen #link'] con_src.store('3', '-FLAGS', '#link \\Seen') con_src.store('2', '+FLAGS', '#err') con_all.store('3', '-FLAGS', '#link \\Seen') con_all.store('2', '-FLAGS', '#latest') assert [i['flags'] for i in msgs(local.SRC)] == ['', '#err', ''] assert [i['flags'] for i in msgs()] == ['', '', ''] cli.main('clean-flags %s' % login.user1) assert [i['flags'] for i in msgs(local.SRC)] == ['', '', '\\Seen #link'] assert [i['flags'] for i in msgs()] == ['', '#latest', '\\Seen #link']
def test_link_threads_part3(gm_client, msgs): gm_client.add_emails([ {}, {'refs': '<none-two@mlr>'}, {'refs': '<none@mlr>'}, {'refs': '<none@mlr> <102@mlr>'} ]) refs = [ '<*****@*****.**>', '<*****@*****.**> <none-two@mlr>', '<*****@*****.**> <none@mlr>', '<*****@*****.**> <none@mlr> <102@mlr>' ] assert local.search_thrs('all') == ['4', '3', '1'] assert local.data_threads.get()[1] == { '1': ['1'], '3': ['3'], '4': ['2', '4'] } res = msgs(local.SRC) assert [i['body']['references'] for i in res] == [ None, '<none-two@mlr>', '<none@mlr>', '<none@mlr> <102@mlr>', ] res = msgs() assert [i['body']['references'] for i in res] == refs local.link_threads(['1', '3', '4']) assert local.search_thrs('all') == ['4'] assert local.data_threads.get()[1] == {'4': ['1', '2', '3', '4']} res = msgs() assert [i['body']['references'] for i in res] == refs assert local.search_thrs('uid 1') == [i[0] for i in local.thrs_info(['1'])]
def test_general(gm_client, login, msgs, patch, call): stdout = check_output('mlr -h', shell=True) assert b'Mailur CLI' in stdout gm_client.add_emails([{}, {}], fetch=False, parse=False) assert [i['uid'] for i in msgs(local.SRC)] == [] assert [i['uid'] for i in msgs()] == [] cli.main('%s remote --parse' % login.user1) assert [i['uid'] for i in msgs(local.SRC)] == ['1', '2'] assert [i['uid'] for i in msgs()] == ['1', '2'] with patch('mailur.cli.local') as m: cli.main('%s metadata' % login.user1) assert m.update_metadata.called cli.main('%s metadata' % login.user1) with local.client() as con: con.copy(['1', '2'], local.ALL) puids = con.search('ALL') con.select(local.SRC) ouids = con.search('ALL') assert len(puids) == (2 * len(ouids)) cli.main('%s metadata' % login.user1) con.select(local.ALL) all_puids = con.search('ALL') assert len(all_puids) == 4 local.link_threads(ouids) cli.main('%s parse --fix-duplicates' % login.user1) cli.main('%s metadata' % login.user1) con.select(local.ALL) puids = con.search('ALL') con.select(local.SRC) ouids = con.search('ALL') assert len(puids) == len(ouids) puids_from_msgs = sorted(local.data_msgs.get()) puids_from_pairs = sorted(local.data_uidpairs.get().values()) assert puids_from_msgs == puids_from_pairs with patch('mailur.cli.remote.fetch_folder') as m: cli.main('%s remote' % login.user1) opts = {'batch': 1000, 'threads': 2} assert m.call_args_list == [ call(tag='\\All', **opts), call(tag='\\Junk', **opts), call(tag='\\Trash', **opts), ] m.reset_mock() cli.main('%s remote --tag=\\All' % login.user1) assert m.call_args_list == [call(tag='\\All', **opts)] m.reset_mock() cli.main('%s remote --box=All' % login.user1) assert m.call_args_list == [call(box='All', **opts)]
def test_link_threads_part3(gm_client, msgs): gm_client.add_emails([{}, { 'refs': '<non-exist-two@mlr>' }, { 'refs': '<non-exist@mlr>' }, { 'refs': '<non-exist@mlr> <102@mlr>' }]) res = msgs(local.SRC) assert thread() == ( ('1', ), ('3', ), ('2', '4'), ) assert [i['flags'] for i in res] == ['', '', '', ''] assert [i['body']['references'] for i in res] == [ None, '<non-exist-two@mlr>', '<non-exist@mlr>', '<non-exist@mlr> <102@mlr>', ] res = msgs() assert [i['uid'] for i in res] == ['1', '2', '3', '4'] assert [i['flags'] for i in res] == ['#latest', '', '#latest', '#latest'] assert [i['body']['references'] for i in res] == [ '<*****@*****.**>', '<*****@*****.**>', '<*****@*****.**>', '<102@mlr>' ] local.link_threads(['1', '3', '4']) res = msgs(local.SRC) assert [i['flags'] for i in res] == ['', '', '', '', '\\Seen #link'] assert [i['body']['references'] for i in res] == [ None, '<non-exist-two@mlr>', '<non-exist@mlr>', '<non-exist@mlr> <102@mlr>', ('<*****@*****.**> <101@mlr> ' '<*****@*****.**> <102@mlr> ' '<*****@*****.**> <103@mlr> ' '<104@mlr>') ] res = msgs() assert [i['uid'] for i in res] == ['1', '2', '3', '4', '5'] assert [i['flags'] for i in res] == ['', '', '', '#latest', '\\Seen #link'] assert [i['body']['references'] for i in res] == [ '<*****@*****.**>', '<*****@*****.**>', '<*****@*****.**>', '<102@mlr>', ('<*****@*****.**> <101@mlr> ' '<*****@*****.**> <102@mlr> ' '<*****@*****.**> <103@mlr> ' '<104@mlr>') ] assert local.search_thrs('uid 1') == [i[0] for i in local.thrs_info(['1'])]
def test_link_threads_part2(clean_users, gm_client, msgs): gm_client.add_emails([{}, { 'refs': '<101@mlr>' }, {}, { 'refs': '<103@mlr>' }]) res = msgs(local.SRC) assert thread() == (('1', '2'), ('3', '4')) assert [i['flags'] for i in res] == ['', '', '', ''] assert [i['body']['references'] for i in res] == [None, '<101@mlr>', None, '<103@mlr>'] res = msgs() assert [i['uid'] for i in res] == ['1', '2', '3', '4'] assert [i['flags'] for i in res] == ['', '#latest', '', '#latest'] assert [i['body']['references'] for i in res] == [None, '<101@mlr>', None, '<103@mlr>'] local.link_threads(['1', '3']) res = msgs(local.SRC) assert thread() == (('1', '2', '3', '4', '5'), ) assert [i['flags'] for i in res] == ['', '', '', '', '#link'] assert [i['body']['references'] for i in res] == [ None, '<101@mlr>', None, '<103@mlr>', '<101@mlr> <102@mlr> <103@mlr> <104@mlr>' ] res = msgs() assert [i['uid'] for i in res] == ['1', '2', '3', '4', '5'] assert [i['flags'] for i in res] == ['', '', '', '#latest', '#link'] assert [i['body']['references'] for i in res] == [ None, '<101@mlr>', None, '<103@mlr>', '<101@mlr> <102@mlr> <103@mlr> <104@mlr>' ] gm_client.add_emails([{'refs': '<non-exist@mlr> <102@mlr>'}]) res = msgs(local.SRC) assert thread() == (('1', '2', '3', '4', '5', '6'), ) assert [i['flags'] for i in res] == ['', '', '', '', '#link', ''] assert [i['body']['references'] for i in res] == [ None, '<101@mlr>', None, '<103@mlr>', '<101@mlr> <102@mlr> <103@mlr> <104@mlr>', '<non-exist@mlr> <102@mlr>' ] res = msgs() assert [i['uid'] for i in res] == ['1', '2', '3', '4', '5', '6'] assert [i['flags'] for i in res] == ['', '', '', '', '#link', '#latest'] assert [i['body']['references'] for i in res] == [ None, '<101@mlr>', None, '<103@mlr>', '<101@mlr> <102@mlr> <103@mlr> <104@mlr>', '<102@mlr>' ]
def test_update_metadata(gm_client, msgs, patch, call): gm_client.add_emails([{}, {}]) assert ['1', '2'] == [i['uid'] for i in msgs(local.SRC)] local.link_threads(['1', '2']) thrids, thrs = local.data_threads.get() assert {'1': '2', '2': '2'} == thrids # emulate that metadata wasn't updated when messages were re-parsed with patch.object(local, 'update_metadata') as m: local.parse('1:*') m.assert_called_with('3:*') # refresh metadata local.update_metadata('1:*') thrids, thrs = local.data_threads.get() assert {'3': '4', '4': '4'} == thrids
def test_clean_flags(gm_client, msgs, login): gm_client.add_emails([{}] * 2) local.link_threads(['1', '2']) assert [i['flags'] for i in msgs(local.SRC)] == ['', ''] assert [i['flags'] for i in msgs()] == ['', ''] con_src = local.client(local.SRC, readonly=False) con_all = local.client(local.ALL, readonly=False) con_src.store('1', '+FLAGS', '#tag1') con_src.store('2', '+FLAGS', '#tag2 #tag3') con_all.store('1', '+FLAGS', '#tag1 #tag3') con_all.store('2', '+FLAGS', '#tag2') assert [i['flags'] for i in msgs(local.SRC)] == ['#tag1', '#tag2 #tag3'] assert [i['flags'] for i in msgs()] == ['#tag1 #tag3', '#tag2'] cli.main('clean-flags %s #tag1' % login.user1) assert [i['flags'] for i in msgs(local.SRC)] == ['', '#tag2 #tag3'] assert [i['flags'] for i in msgs()] == ['#tag3', '#tag2'] cli.main('clean-flags %s #tag2 #tag3' % login.user1) assert [i['flags'] for i in msgs(local.SRC)] == ['', ''] assert [i['flags'] for i in msgs()] == ['', '']
def test_clean_flags(gm_client, msgs, login): gm_client.add_emails([{}] * 2) local.link_threads(['1', '2']) assert [i['flags'] for i in msgs(local.SRC)] == ['', ''] assert [i['flags'] for i in msgs()] == ['', ''] con_src = local.client(local.SRC, readonly=False) con_all = local.client(local.ALL, readonly=False) con_src.store('1', '+FLAGS', '#tag1') con_src.store('2', '+FLAGS', '#tag2 #tag3') con_all.store('1', '+FLAGS', '#tag1 #tag3') con_all.store('2', '+FLAGS', '#tag2') assert [i['flags'] for i in msgs(local.SRC)] == ['#tag1', '#tag2 #tag3'] assert [i['flags'] for i in msgs()] == ['#tag1 #tag3', '#tag2'] cli.main('clean-flags %s #tag1' % login.user1) assert [i['flags'] for i in msgs(local.SRC)] == ['', '#tag2 #tag3'] assert [i['flags'] for i in msgs()] == ['#tag3', '#tag2'] cli.main('clean-flags %s #tag2 #tag3' % login.user1) assert [i['flags'] for i in msgs(local.SRC)] == ['', ''] assert [i['flags'] for i in msgs()] == ['', '']
def test_link_threads_part1(clean_users, gm_client, msgs): gm_client.add_emails([{}, {}]) res = msgs() assert ['1', '2'] == [i['uid'] for i in res] assert ['#latest', '#latest'] == [i['flags'] for i in res] assert [i['body']['references'] for i in res] == [None, None] local.link_threads(['1', '2']) res = msgs(local.SRC) assert (('1', '2', '3'), ) == thread() assert ['', '', '#link'] == [i['flags'] for i in res] assert [i['body']['references'] for i in res] == [None, None, '<101@mlr> <102@mlr>'] res = msgs() assert ['1', '2', '3'] == [i['uid'] for i in res] assert ['', '#latest', '#link'] == [i['flags'] for i in res] assert [i['body']['references'] for i in res] == [None, None, '<101@mlr> <102@mlr>'] local.parse('all') res = msgs(local.SRC) assert (('1', '2', '3'), ) == thread() assert ['', '', '#link'] == [i['flags'] for i in res] res = msgs() assert ['4', '5', '6'] == [i['uid'] for i in res] assert ['', '#latest', '#link'] == [i['flags'] for i in res] assert [i['body']['references'] for i in res] == [None, None, '<101@mlr> <102@mlr>'] gm_client.add_emails([{}]) local.link_threads(['4', '7']) res = msgs(local.SRC) assert (('1', '2', '4', '5', '3'), ) == thread() assert ['1', '2', '3', '4', '5'] == [i['uid'] for i in res] assert [i['flags'] for i in res] == ['', '', '\\Deleted #link', '', '#link'] assert [i['body']['references'] for i in res] == [ None, None, '<101@mlr> <102@mlr>', None, '<101@mlr> <102@mlr> <103@mlr>' ] res = msgs() assert ['4', '5', '7', '8'] == [i['uid'] for i in res] assert ['', '', '#latest', '#link'] == [i['flags'] for i in res] assert [i['body']['references'] for i in res ] == [None, None, None, '<101@mlr> <102@mlr> <103@mlr>'] gm_client.add_emails([{'refs': '<101@mlr>'}]) res = msgs(local.SRC) assert (('1', '2', '4', '5', '3', '6'), ) == thread() assert ['1', '2', '3', '4', '5', '6'] == [i['uid'] for i in res] assert [i['flags'] for i in res] == ['', '', '\\Deleted #link', '', '#link', ''] assert [i['body']['references'] for i in res] == [ None, None, '<101@mlr> <102@mlr>', None, '<101@mlr> <102@mlr> <103@mlr>', '<101@mlr>' ] res = msgs() assert ['4', '5', '7', '8', '9'] == [i['uid'] for i in res] assert ['', '', '', '#link', '#latest'] == [i['flags'] for i in res] assert [i['body']['references'] for i in res] == [ None, None, None, '<101@mlr> <102@mlr> <103@mlr>', '<101@mlr>' ]
def test_link_threads_part1(gm_client, msgs): gm_client.add_emails([{}, {}]) res = msgs() assert ['1', '2'] == [i['uid'] for i in res] assert ['#latest', '#latest'] == [i['flags'] for i in res] assert [i['body']['references'] for i in res] == [ '<*****@*****.**>', '<*****@*****.**>' ] local.link_threads(['1', '2']) res = msgs(local.SRC) assert (('1', '2', '3'), ) == thread() assert ['', '', '\\Seen #link'] == [i['flags'] for i in res] assert [i['body']['references'] for i in res] == [ None, None, ('<*****@*****.**> <101@mlr> ' '<*****@*****.**> <102@mlr>') ] res = msgs() assert ['1', '2', '3'] == [i['uid'] for i in res] assert ['', '#latest', '\\Seen #link'] == [i['flags'] for i in res] assert [i['body']['references'] for i in res] == [ '<*****@*****.**>', '<*****@*****.**>', ('<*****@*****.**> <101@mlr> ' '<*****@*****.**> <102@mlr>') ] local.parse('all') res = msgs(local.SRC) assert (('1', '2', '3'), ) == thread() assert ['', '', '\\Seen #link'] == [i['flags'] for i in res] res = msgs() assert ['4', '5', '6'] == [i['uid'] for i in res] assert ['', '#latest', '\\Seen #link'] == [i['flags'] for i in res] assert [i['body']['references'] for i in res] == [ '<*****@*****.**>', '<*****@*****.**>', ('<*****@*****.**> <101@mlr> ' '<*****@*****.**> <102@mlr>') ] gm_client.add_emails([{}]) local.link_threads(['4', '7']) res = msgs(local.SRC) assert (('1', '2', '4', '5'), ) == thread() assert ['1', '2', '4', '5'] == [i['uid'] for i in res] assert [i['flags'] for i in res] == ['', '', '', '\\Seen #link'] assert [i['body']['references'] for i in res] == [ None, None, None, ('<*****@*****.**> <101@mlr> ' '<*****@*****.**> <102@mlr> ' '<*****@*****.**> <103@mlr>') ] res = msgs() assert ['4', '5', '7', '8'] == [i['uid'] for i in res] assert ['', '', '#latest', '\\Seen #link'] == [i['flags'] for i in res] assert [i['body']['references'] for i in res] == [ '<*****@*****.**>', '<*****@*****.**>', '<*****@*****.**>', ('<*****@*****.**> <101@mlr> ' '<*****@*****.**> <102@mlr> ' '<*****@*****.**> <103@mlr>') ] gm_client.add_emails([{'refs': '<101@mlr>'}]) res = msgs(local.SRC) assert (('1', '2', '4', '5', '6'), ) == thread() assert ['1', '2', '4', '5', '6'] == [i['uid'] for i in res] assert [i['flags'] for i in res] == ['', '', '', '\\Seen #link', ''] assert [i['body']['references'] for i in res] == [ None, None, None, ('<*****@*****.**> <101@mlr> ' '<*****@*****.**> <102@mlr> ' '<*****@*****.**> <103@mlr>'), '<101@mlr>' ] res = msgs() assert ['4', '5', '7', '8', '9'] == [i['uid'] for i in res] assert [i['flags'] for i in res] == ['', '', '', '\\Seen #link', '#latest'] assert [i['body']['references'] for i in res] == [ '<*****@*****.**>', '<*****@*****.**>', '<*****@*****.**>', ('<*****@*****.**> <101@mlr> ' '<*****@*****.**> <102@mlr> ' '<*****@*****.**> <103@mlr>'), '<101@mlr>' ] assert local.search_thrs('uid 4') == [i[0] for i in local.thrs_info(['4'])] local.update_links() res = msgs(local.SRC) assert (('1', '2', '4', '6', '7'), ) == thread() assert ['1', '2', '4', '6', '7'] == [i['uid'] for i in res] assert [i['flags'] for i in res] == ['', '', '', '', '\\Seen #link'] res = msgs() assert ['4', '5', '7', '9', '10'] == [i['uid'] for i in res] assert [i['flags'] for i in res] == ['', '', '', '#latest', '\\Seen #link']