예제 #1
0
파일: test_bukuDb.py 프로젝트: usm4n/Buku
def test_browse_by_index(low, high, index, is_range, empty_database):
    """test method."""
    n_low, n_high = (high, low) if low > high else (low, high)
    with mock.patch('buku.browse'):
        import buku
        bdb = buku.BukuDb()
        bdb.delete_rec_all()
        db_len = 0
        if not empty_database:
            bdb.add_rec("https://www.google.com/ncr", "?")
            db_len += 1
        res = bdb.browse_by_index(index=index,
                                  low=low,
                                  high=high,
                                  is_range=is_range)
        if is_range and (low < 0 or high < 0):
            assert not res
        elif is_range and 0 < n_low and 0 < n_high:
            assert res
        elif is_range:
            assert not res
        elif not is_range and index < 0:
            assert not res
        elif not is_range and index > db_len:
            assert not res
        elif not is_range and index >= 0 and empty_database:
            assert not res
        elif not is_range and 0 <= index <= db_len and not empty_database:
            assert res
        else:
            raise ValueError
        bdb.delete_rec_all()
예제 #2
0
def test_edit_update_rec_with_invalid_input(get_system_editor_retval, index, exp_res):
    """test method."""
    with mock.patch('buku.get_system_editor', return_value=get_system_editor_retval):
        import buku
        bdb = buku.BukuDb()
        res = bdb.edit_update_rec(index=index)
        assert res == exp_res
예제 #3
0
def test_load_chrome_database(chrome_db, add_pt):
    """test method."""
    # compatibility
    json_file = chrome_db[0]
    res_yaml_file = chrome_db[1] if add_pt else chrome_db[2]
    dump_data = False  # NOTE: change this value to dump data
    if not dump_data:
        with open(res_yaml_file, 'r') as f:
            try:
                res_yaml = yaml.load(f, Loader=yaml.FullLoader)
            except RuntimeError:
                res_yaml = yaml.load(f, Loader=PrettySafeLoader)
    # init
    import buku
    bdb = buku.BukuDb()
    bdb.add_rec = mock.Mock()
    bdb.load_chrome_database(json_file, None, add_pt)
    call_args_list_dict = dict(bdb.add_rec.call_args_list)
    # test
    if not dump_data:
        assert call_args_list_dict == res_yaml
    # dump data for new test
    if dump_data:
        with open(res_yaml_file, 'w') as f:
            yaml.dump(call_args_list_dict, f)
        print('call args list dict dumped to:{}'.format(res_yaml_file))
예제 #4
0
def test_update_rec_update_all_bookmark(caplog, read_in_retval):
    """test method."""
    if (sys.version_info.major, sys.version_info.minor) == (3, 8):
        caplog.set_level(logging.DEBUG)
    with mock.patch('buku.read_in', return_value=read_in_retval):
        import buku
        bdb = buku.BukuDb()
        res = bdb.update_rec(index=0, tags_in='tags1')
        if read_in_retval != 'y':
            assert not res
            return
        assert res
        try:
            if (sys.version_info.major, sys.version_info.minor) == (3, 8):
                assert caplog.records[0].getMessage() == \
                       'update_rec query: "UPDATE bookmarks SET tags = ?", args: [\',tags1,\']'
            else:
                assert caplog.records[0].getMessage() == \
                       'query: "UPDATE bookmarks SET tags = ?", args: [\',tags1\']'
            assert caplog.records[0].levelname == 'DEBUG'
        except IndexError as e:
            # TODO: fix test
            if (sys.version_info.major, sys.version_info.minor) in [(3, 4),
                                                                    (3, 5),
                                                                    (3, 6),
                                                                    (3, 7)]:
                print('caplog records: {}'.format(caplog.records))
                for idx, record in enumerate(caplog.records):
                    print('idx:{};{};message:{};levelname:{}'.format(
                        idx, record, record.getMessage(), record.levelname))
            else:
                raise e
예제 #5
0
def test_exclude_results_from_search(search_results, exclude_results, exp_res):
    """test method."""
    # init
    import buku
    bdb = buku.BukuDb()
    bdb.searchdb = mock.Mock(return_value=exclude_results)
    # test
    res = bdb.exclude_results_from_search(search_results, [], True)
    assert exp_res == res
예제 #6
0
def test_search_keywords_and_filter_by_tags(keyword_results, stag_results,
                                            exp_res):
    """test method."""
    # init
    import buku
    bdb = buku.BukuDb()
    bdb.searchdb = mock.Mock(return_value=keyword_results)
    bdb.search_by_tag = mock.Mock(return_value=stag_results)
    # test
    res = bdb.search_keywords_and_filter_by_tags(mock.Mock(), mock.Mock(),
                                                 mock.Mock(), mock.Mock(), [])
    assert exp_res == res
예제 #7
0
파일: test_bukuDb.py 프로젝트: usm4n/Buku
def test_update_rec_update_all_bookmark(caplog, read_in_retval):
    """test method."""
    with mock.patch('buku.read_in', return_value=read_in_retval):
        import buku
        bdb = buku.BukuDb()
        res = bdb.update_rec(index=0, tags_in='tags1')
        if read_in_retval != 'y':
            assert not res
            return
        assert res
        assert caplog.records[0].getMessage() == \
            'query: "UPDATE bookmarks SET tags = ?", args: [\',tags1\']'
        assert caplog.records[0].levelname == 'DEBUG'
예제 #8
0
파일: pinku.py 프로젝트: mosegontar/Pinku
 def __init__(self,
              api_key,
              filters=None,
              private_only=False,
              public_only=False,
              toread_only=False,
              read_only=False):
     self.buku = buku.BukuDb()
     self.pb = pinboard.Pinboard(api_key)
     self.filters = filters
     self.private_only = private_only
     self.public_only = public_only
     self.toread_only = toread_only
     self.read_only = read_only
예제 #9
0
파일: test_bukuDb.py 프로젝트: usm4n/Buku
def test_load_firefox_database(firefox_db, add_pt):
    # compatibility
    ff_db_path = firefox_db[0]

    res_pickle_file = firefox_db[1] if add_pt else firefox_db[2]
    with open(res_pickle_file, 'rb') as f:
        res_pickle = pickle.load(f)
    # init
    import buku
    bdb = buku.BukuDb()
    bdb.add_rec = mock.Mock()
    bdb.load_firefox_database(ff_db_path, None, add_pt)
    call_args_list_dict = dict(bdb.add_rec.call_args_list)
    # test
    assert call_args_list_dict == res_pickle
예제 #10
0
파일: test_bukuDb.py 프로젝트: usm4n/Buku
def test_load_chrome_database(chrome_db, add_pt):
    """test method."""
    # compatibility
    json_file = chrome_db[0]
    res_pickle_file = chrome_db[1] if add_pt else chrome_db[2]
    with open(res_pickle_file, 'rb') as f:
        res_pickle = pickle.load(f)
    # init
    import buku
    bdb = buku.BukuDb()
    bdb.add_rec = mock.Mock()
    bdb.load_chrome_database(json_file, None, add_pt)
    call_args_list_dict = dict(bdb.add_rec.call_args_list)
    # test
    assert call_args_list_dict == res_pickle
예제 #11
0
파일: poku.py 프로젝트: shanedabes/poku
def main():
    args = parse_args(sys.argv[1:])
    consumer_key = args.consumer

    # retrieve access token if not passed, otherwise use
    if not args.access:
        request_token = poku.pocket.get_request_token(consumer_key)
        auth_url = poku.pocket.generate_auth_url(request_token)
        print(f'Opening {auth_url} in browser')
        webbrowser.open(auth_url)
        input('Press Enter here once auth request is approved')
        access_token = poku.pocket.get_access_token(consumer_key,
                                                    request_token)
        print(f'Access token: {access_token}')
        print('Pass as argument or add to config to avoid this step in future')
    else:
        access_token = args.access

    # retrieve pocket items, ensure unique urls and sort
    pocket_items = [
        poku.pocket.item_to_dict(i)
        for i in poku.pocket.get_items(consumer_key, access_token)
    ]
    pocket_items = poku.utils.dict_list_ensure_unique(pocket_items)
    pocket_items = poku.utils.sort_dict_items(pocket_items)

    # retrieve buku items and sort
    bukudb = buku.BukuDb()
    buku_items = [poku.buku.item_to_dict(i) for i in bukudb.get_rec_all()]
    logging.info(f'{len(buku_items)} buku items retrieved')
    buku_items = poku.utils.sort_dict_items(buku_items)

    # Add new buku items
    new_buku_items = poku.utils.dict_list_difference(pocket_items, buku_items)
    print(f'Adding {len(new_buku_items)} new items to buku')
    for bi in new_buku_items:
        if args.tag:
            # Add custom tag to imported items
            bi['tags'] += [args.tag]

        bukudb.add_rec(bi['url'],
                       title_in=bi['title'],
                       tags_in=poku.buku.tags_to_tagstring(bi['tags']),
                       delay_commit=True,
                       fetch=False)
    bukudb.conn.commit()
예제 #12
0
파일: test_bukuDb.py 프로젝트: shv-q3/Buku
def test_load_firefox_database(firefox_db, add_pt):
    # compatibility
    ff_db_path = firefox_db[0]
    dump_data = False  # NOTE: change this value to dump data
    res_yaml_file = firefox_db[1] if add_pt else firefox_db[2]
    if not dump_data:
        with open(res_yaml_file, "r", encoding="utf8", errors="surrogateescape") as f:
            res_yaml = yaml.load(f, Loader=PrettySafeLoader)
    # init
    import buku

    bdb = buku.BukuDb()
    bdb.add_rec = mock.Mock()
    bdb.load_firefox_database(ff_db_path, None, add_pt)
    call_args_list_dict = dict(bdb.add_rec.call_args_list)
    # test
    if not dump_data:
        assert call_args_list_dict == res_yaml
    if dump_data:
        with open(res_yaml_file, "w", encoding="utf8", errors="surrogateescape") as f:
            yaml.dump(call_args_list_dict, f)
        print("call args list dict dumped to:{}".format(res_yaml_file))
예제 #13
0
def test_load_firefox_database(firefox_db, add_pt):
    # compatibility
    ff_db_path = firefox_db[0]
    dump_data = False  # NOTE: change this value to dump data
    res_yaml_file = firefox_db[1] if add_pt else firefox_db[2]
    if not dump_data:
        with open(res_yaml_file, 'r') as f:
            try:
                res_yaml = yaml.load(f)
            except RuntimeError:
                res_yaml = yaml.load(f, Loader=PrettySafeLoader)
    # init
    import buku
    bdb = buku.BukuDb()
    bdb.add_rec = mock.Mock()
    bdb.load_firefox_database(ff_db_path, None, add_pt)
    call_args_list_dict = dict(bdb.add_rec.call_args_list)
    # test
    if not dump_data:
        assert call_args_list_dict == res_yaml
    if dump_data:
        with open(res_yaml_file, 'w') as f:
            yaml.dump(call_args_list_dict, f)
        print('call args list dict dumped to:{}'.format(res_yaml_file))
예제 #14
0
#!/usr/bin/env python

import sys
import os
import buku

bukudb = buku.BukuDb()

fifo = os.getenv('QUTE_FIFO')
url = os.getenv('QUTE_URL')
title = os.getenv('QUTE_TITLE')

if len(sys.argv) > 1:
    taglist = ',{},'.format(sys.argv[1])
else:
    taglist = None

bukudb.add_rec(url, title_in=title, fetch=False, tags_in=taglist)

with open(fifo, 'w') as qp:
    qp.write(f'jseval "{url} saved to buku"')
예제 #15
0
 def __init__(self, api_key, filters=None, toread_only=False):
     self.buku = buku.BukuDb()
     self.pb = pinboard.Pinboard(api_key)
     self.filters = filters
     self.toread_only = toread_only