def test_search_by_tags_exclusion(self): # adding bookmarks for bookmark in self.bookmarks: self.bdb.add_rec(*bookmark) new_bookmark = ['https://newbookmark.com', 'New Bookmark', parse_tags(['test,old,new']), 'additional bookmark to test multiple tag search'] self.bdb.add_rec(*new_bookmark) with mock.patch('buku.prompt'): # search for bookmarks matching ANY of the supplied tags # while excluding bookmarks from results that match a given tag results = self.bdb.search_by_tag('test, old - est') # Expect a list of five-element tuples containing all bookmark data # db index, URL, title, tags, description expected = [ (1, 'http://slashdot.org', 'SLASHDOT', parse_tags([',news,old,']), "News for old nerds, stuff that doesn't matter"), (4, 'https://newbookmark.com', 'New Bookmark', parse_tags([',test,old,new,']), 'additional bookmark to test multiple tag search') ] self.assertEqual(results, expected)
def test_replace_tag(self): bdb = BukuDb() indices = [] for bookmark in self.bookmarks: # adding bookmark, getting index bdb.add_bookmark(*bookmark) index = bdb.get_bookmark_index(bookmark[0]) indices += [index] # replacing tags bdb.replace_tag("news", ["__01"]) bdb.replace_tag("zażółć", ["__02,__03"]) # replacing tag which is also a substring of other tag bdb.replace_tag("es", ["__04"]) # removing tags bdb.replace_tag("gęślą") bdb.replace_tag("old") # removing nonexistent tag bdb.replace_tag("_") # removing nonexistent tag which is also a substring of other tag bdb.replace_tag("e") for url, title, _, _ in self.bookmarks: # retrieving from db index = bdb.get_bookmark_index(url) from_db = bdb.get_bookmark_by_index(index) # asserting tags were replaced if title == "SLASHDOT": self.assertEqual(from_db[3], parse_tags(["__01"])) elif title == "ZAŻÓŁĆ": self.assertEqual(from_db[3], parse_tags(["__02,__03,jaźń"])) elif title == "test": self.assertEqual(from_db[3], parse_tags(["test,tes,est,__04"]))
def test_list_tags(capsys, setup): bdb = BukuDb() # adding bookmarks bdb.add_bookmark("http://one.com", "", parse_tags(['cat,ant,bee,1']), "") bdb.add_bookmark("http://two.com", "", parse_tags(['Cat,Ant,bee,1']), "") bdb.add_bookmark("http://three.com", "", parse_tags(['Cat,Ant,3,Bee,2']), "") # listing tags, asserting output out, err = capsys.readouterr() bdb.list_tags() out, err = capsys.readouterr() assert out == " 1. 1\n 2. 2\n 3. 3\n 4. Ant\n 5. ant\n 6. bee\n 7. Bee\n 8. Cat\n 9. cat\n" assert err == ''
def test_list_tags(capsys, setup): bdb = BukuDb() # adding bookmarks bdb.add_rec("http://one.com", "", parse_tags(['cat,ant,bee,1']), "") bdb.add_rec("http://two.com", "", parse_tags(['Cat,Ant,bee,1']), "") bdb.add_rec("http://three.com", "", parse_tags(['Cat,Ant,3,Bee,2']), "") # listing tags, asserting output out, err = capsys.readouterr() prompt(bdb, None, True, subprompt=True) out, err = capsys.readouterr() assert out == " 1. 1 (2)\n 2. 2 (1)\n 3. 3 (1)\n 4. ant (3)\n 5. bee (3)\n 6. cat (3)\n\n" assert err == ''
def test_parse_tags(self): # call with None parsed = parse_tags(None) self.assertIsNone(parsed) # call with empty list parsed = parse_tags([]) self.assertEqual(parsed, ",") # empty tags parsed = parse_tags([",,,,,"]) self.assertEqual(parsed, ",") # sorting tags parsed = parse_tags(["z_tag,a_tag,n_tag"]) self.assertEqual(parsed, ",a_tag,n_tag,z_tag,") # whitespaces parsed = parse_tags([" a tag , , , ,\t,\n,\r,\x0b,\x0c"]) self.assertEqual(parsed, ",a tag,") # duplicates, excessive spaces parsed = parse_tags(["tag,tag, tag, tag,tag , tag "]) self.assertEqual(parsed, ",tag,") # escaping quotes parsed = parse_tags(["\"tag\",\'tag\',tag"]) self.assertEqual(parsed, ",\"tag\",\'tag\',tag,") # combo parsed = parse_tags([",,z_tag, a tag ,\t,,, ,n_tag ,n_tag, a_tag, \na tag ,\r, \"a_tag\""]) self.assertEqual(parsed, ",\"a_tag\",a tag,a_tag,n_tag,z_tag,")
def test_parse_tags(keywords, exp_res): """test func.""" import buku if keywords is None: pass elif not keywords: exp_res = buku.DELIM res = buku.parse_tags(keywords) assert res == exp_res
def test_search_by_tags_enforces_space_seprations_exclusion(self): bookmark1 = [ 'https://bookmark1.com', 'Bookmark One', parse_tags(['tag, two,tag+two']), "test case for bookmark with '+' in tag" ] bookmark2 = [ 'https://bookmark2.com', 'Bookmark Two', parse_tags(['tag,two, tag-two']), "test case for bookmark with hyphenated tag" ] bookmark3 = [ 'https://bookmark3.com', 'Bookmark Three', parse_tags(['tag, tag three']), "second test case for bookmark with hyphenated tag" ] self.bdb.add_rec(*bookmark1) self.bdb.add_rec(*bookmark2) self.bdb.add_rec(*bookmark3) with mock.patch('buku.prompt'): # check that space separation for ' - ' operator is enforced results = self.bdb.search_by_tag('tag-two') # Expect a list of five-element tuples containing all bookmark data # db index, URL, title, tags, description expected = [ (2, 'https://bookmark2.com', 'Bookmark Two', parse_tags([',tag,two,tag-two,']), "test case for bookmark with hyphenated tag"), ] self.assertEqual(results, expected) results = self.bdb.search_by_tag('tag - two') # Expect a list of five-element tuples containing all bookmark data # db index, URL, title, tags, description expected = [ (3, 'https://bookmark3.com', 'Bookmark Three', parse_tags([',tag,tag three,']), "second test case for bookmark with hyphenated tag"), ] self.assertEqual(results, expected)
def test_replace_tag(self): indices = [] for bookmark in self.bookmarks: # adding bookmark, getting index self.bdb.add_rec(*bookmark) index = self.bdb.get_rec_id(bookmark[0]) indices += [index] # replacing tags with mock.patch('builtins.input', return_value='y'): self.bdb.replace_tag("news", ["__01"]) with mock.patch('builtins.input', return_value='y'): self.bdb.replace_tag("zażółć", ["__02,__03"]) # replacing tag which is also a substring of other tag with mock.patch('builtins.input', return_value='y'): self.bdb.replace_tag("es", ["__04"]) # removing tags with mock.patch('builtins.input', return_value='y'): self.bdb.replace_tag("gęślą") with mock.patch('builtins.input', return_value='y'): self.bdb.replace_tag("old") # removing non-existent tag with mock.patch('builtins.input', return_value='y'): self.bdb.replace_tag("_") # removing nonexistent tag which is also a substring of other tag with mock.patch('builtins.input', return_value='y'): self.bdb.replace_tag("e") for url, title, _, _ in self.bookmarks: # retrieving from db index = self.bdb.get_rec_id(url) from_db = self.bdb.get_rec_by_id(index) # asserting tags were replaced if title == "SLASHDOT": self.assertEqual(from_db[3], parse_tags(["__01"])) elif title == "ZAŻÓŁĆ": self.assertEqual(from_db[3], parse_tags(["__02,__03,jaźń"])) elif title == "test": self.assertEqual(from_db[3], parse_tags(["test,tes,est,__04"]))
def test_search_by_tags_enforces_space_seprations_exclusion(self): bookmark1 = ['https://bookmark1.com', 'Bookmark One', parse_tags(['tag, two,tag+two']), "test case for bookmark with '+' in tag"] bookmark2 = ['https://bookmark2.com', 'Bookmark Two', parse_tags(['tag,two, tag-two']), "test case for bookmark with hyphenated tag"] bookmark3 = ['https://bookmark3.com', 'Bookmark Three', parse_tags(['tag, tag three']), "second test case for bookmark with hyphenated tag"] self.bdb.add_rec(*bookmark1) self.bdb.add_rec(*bookmark2) self.bdb.add_rec(*bookmark3) with mock.patch('buku.prompt'): # check that space separation for ' - ' operator is enforced results = self.bdb.search_by_tag('tag-two') # Expect a list of five-element tuples containing all bookmark data # db index, URL, title, tags, description expected = [ (2, 'https://bookmark2.com', 'Bookmark Two', parse_tags([',tag,two,tag-two,']), "test case for bookmark with hyphenated tag"), ] self.assertEqual(results, expected) results = self.bdb.search_by_tag('tag - two') # Expect a list of five-element tuples containing all bookmark data # db index, URL, title, tags, description expected = [ (3, 'https://bookmark3.com', 'Bookmark Three', parse_tags([',tag,tag three,']), "second test case for bookmark with hyphenated tag"), ] self.assertEqual(results, expected)
def test_print_rec(capsys, caplog, setup): bdb = BukuDb() out, err = capsys.readouterr() # calling with nonexistent index bdb.print_rec(1) out, err = capsys.readouterr() for record in caplog.records(): assert record.levelname == "ERROR" assert record.getMessage() == "No matching index 1" assert (out, err) == ('', '') # adding bookmarks bdb.add_rec("http://full-bookmark.com", "full", parse_tags(['full,bookmark']), "full bookmark") bdb.add_rec("http://blank-title.com", "", parse_tags(['blank,title']), "blank title") bdb.add_rec("http://empty-tags.com", "empty tags", parse_tags(['']), "empty tags") bdb.add_rec("http://all-empty.com", "", parse_tags(['']), "all empty") out, err = capsys.readouterr() # printing first bookmark bdb.print_rec(1) out, err = capsys.readouterr() assert out == "\x1b[93;1m1. \x1b[0;92mhttp://full-bookmark.com\x1b[0m\n \x1b[91m>\x1b[0m full\n \x1b[91m+\x1b[0m full bookmark\n \x1b[91m#\x1b[0m bookmark,full\n\n" assert err == '' # printing all bookmarks bdb.print_rec(0) out, err = capsys.readouterr() assert out == "\x1b[93;1m1. \x1b[0;92mhttp://full-bookmark.com\x1b[0m\n \x1b[91m>\x1b[0m full\n \x1b[91m+\x1b[0m full bookmark\n \x1b[91m#\x1b[0m bookmark,full\n\n\x1b[93;1m2. \x1b[0;92mhttp://blank-title.com\x1b[0m\n \x1b[91m+\x1b[0m blank title\n \x1b[91m#\x1b[0m blank,title\n\n\x1b[93;1m3. \x1b[0;92mhttp://empty-tags.com\x1b[0m\n \x1b[91m>\x1b[0m empty tags\n \x1b[91m+\x1b[0m empty tags\n\n\x1b[93;1m4. \x1b[0;92mhttp://all-empty.com\x1b[0m\n \x1b[91m+\x1b[0m all empty\n\n" assert err == '' # printing all bookmarks with empty fields results = bdb.searchdb(['blank'], True) prompt(bdb, results, True) out, err = capsys.readouterr() assert out == "\x1b[93;1m1. \x1b[0;92mhttp://blank-title.com\x1b[0;1m [2]\x1b[0m\n \x1b[91m+\x1b[0m blank title\n \x1b[91m#\x1b[0m blank,title\n\n\x1b[93;1m2. \x1b[0;92mhttp://empty-tags.com\x1b[0;1m [3]\x1b[0m\n \x1b[91m>\x1b[0m empty tags\n \x1b[91m+\x1b[0m empty tags\n\n\x1b[93;1m3. \x1b[0;92mhttp://all-empty.com\x1b[0;1m [4]\x1b[0m\n \x1b[91m+\x1b[0m all empty\n\n" assert err == ''
def test_search_by_multiple_tags_search_all(self): # adding bookmarks for bookmark in self.bookmarks: self.bdb.add_rec(*bookmark) new_bookmark = [ 'https://newbookmark.com', 'New Bookmark', parse_tags(['test,old,new']), 'additional bookmark to test multiple tag search' ] self.bdb.add_rec(*new_bookmark) with mock.patch('buku.prompt'): # search for bookmarks matching ALL of the supplied tags results = self.bdb.search_by_tag('test + old') # Expect a list of five-element tuples containing all bookmark data # db index, URL, title, tags, description expected = [(4, 'https://newbookmark.com', 'New Bookmark', parse_tags([',test,old,new,']), 'additional bookmark to test multiple tag search')] self.assertEqual(results, expected)
def test_print_bookmark(capsys, caplog, setup): bdb = BukuDb() out, err = capsys.readouterr() # calling with nonexistent index bdb.print_bookmark(1) out, err = capsys.readouterr() for record in caplog.records(): assert record.levelname == "ERROR" assert record.getMessage() == "No matching index" assert (out, err) == ('', '') # adding bookmarks bdb.add_bookmark("http://full-bookmark.com", "full", parse_tags(['full,bookmark']), "full bookmark") bdb.add_bookmark("http://blank-title.com", "", parse_tags(['blank,title']), "blank title") bdb.add_bookmark("http://empty-tags.com", "empty tags", parse_tags(['']), "empty tags") bdb.add_bookmark("http://all-empty.com", "", parse_tags(['']), "all empty") out, err = capsys.readouterr() # printing first bookmark bdb.print_bookmark(1) out, err = capsys.readouterr() assert out == "\x1b[1m\x1b[93m1. \x1b[0m\x1b[92mhttp://full-bookmark.com\x1b[0m\n \x1b[91m>\x1b[0m full\n \x1b[91m+\x1b[0m full bookmark\n \x1b[91m#\x1b[0m bookmark,full\n\n" assert err == '' # printing all bookmarks bdb.print_bookmark(0) out, err = capsys.readouterr() assert out == "\x1b[1m\x1b[93m1. \x1b[0m\x1b[92mhttp://full-bookmark.com\x1b[0m\n \x1b[91m>\x1b[0m full\n \x1b[91m+\x1b[0m full bookmark\n \x1b[91m#\x1b[0m bookmark,full\n\n\x1b[1m\x1b[93m2. \x1b[0m\x1b[92mhttp://blank-title.com\x1b[0m\n \x1b[91m+\x1b[0m blank title\n \x1b[91m#\x1b[0m blank,title\n\n\x1b[1m\x1b[93m3. \x1b[0m\x1b[92mhttp://empty-tags.com\x1b[0m\n \x1b[91m>\x1b[0m empty tags\n \x1b[91m+\x1b[0m empty tags\n\n\x1b[1m\x1b[93m4. \x1b[0m\x1b[92mhttp://all-empty.com\x1b[0m\n \x1b[91m+\x1b[0m all empty\n\n" assert err == '' # printing all bookmarks with empty fields bdb.print_bookmark(0, empty=True) out, err = capsys.readouterr() assert out == "\x1b[1m3 records found\x1b[21m\n\n\x1b[1m\x1b[93m2. \x1b[0m\x1b[92mhttp://blank-title.com\x1b[0m\n \x1b[91m+\x1b[0m blank title\n \x1b[91m#\x1b[0m blank,title\n\n\x1b[1m\x1b[93m3. \x1b[0m\x1b[92mhttp://empty-tags.com\x1b[0m\n \x1b[91m>\x1b[0m empty tags\n \x1b[91m+\x1b[0m empty tags\n\n\x1b[1m\x1b[93m4. \x1b[0m\x1b[92mhttp://all-empty.com\x1b[0m\n \x1b[91m+\x1b[0m all empty\n\n" assert err == ''
def test_search_by_tags_exclusion(self): # adding bookmarks for bookmark in self.bookmarks: self.bdb.add_rec(*bookmark) new_bookmark = [ "https://newbookmark.com", "New Bookmark", parse_tags(["test,old,new"]), "additional bookmark to test multiple tag search", ] self.bdb.add_rec(*new_bookmark) with mock.patch("buku.prompt"): # search for bookmarks matching ANY of the supplied tags # while excluding bookmarks from results that match a given tag results = self.bdb.search_by_tag("test, old - est") # Expect a list of five-element tuples containing all bookmark data # db index, URL, title, tags, description expected = [ ( 4, "https://newbookmark.com", "New Bookmark", parse_tags([",test,old,new,"]), "additional bookmark to test multiple tag search", 0, ), ( 1, "http://slashdot.org", "SLASHDOT", parse_tags([",news,old,"]), "News for old nerds, stuff that doesn't matter", 0, ), ] self.assertEqual(results, expected)
def test_search_by_multiple_tags_search_all(self): # adding bookmarks for bookmark in self.bookmarks: self.bdb.add_rec(*bookmark) new_bookmark = ['https://newbookmark.com', 'New Bookmark', parse_tags(['test,old,new']), 'additional bookmark to test multiple tag search'] self.bdb.add_rec(*new_bookmark) with mock.patch('buku.prompt'): # search for bookmarks matching ALL of the supplied tags results = self.bdb.search_by_tag('test + old') # Expect a list of five-element tuples containing all bookmark data # db index, URL, title, tags, description expected = [ (4, 'https://newbookmark.com', 'New Bookmark', parse_tags([',test,old,new,']), 'additional bookmark to test multiple tag search') ] self.assertEqual(results, expected)
def test_print_bookmark(capsys, caplog, setup): bdb = BukuDb() out, err = capsys.readouterr() # calling with nonexistent index bdb.print_bookmark(1) out, err = capsys.readouterr() for record in caplog.records: assert record.levelname == "ERROR" assert record.getMessage() == "No matching index" assert (out, err) == ('', '') # adding bookmarks bdb.add_bookmark("http://full-bookmark.com", "full", parse_tags(['full,bookmark']), "full bookmark") bdb.add_bookmark("http://blank-title.com", "", parse_tags(['blank,title']), "blank title") bdb.add_bookmark("http://empty-tags.com", "empty tags", parse_tags(['']), "empty tags") bdb.add_bookmark("http://all-empty.com", "", parse_tags(['']), "all empty") out, err = capsys.readouterr() # printing first bookmark bdb.print_bookmark(1) out, err = capsys.readouterr() assert out == "\x1b[1m\x1b[93m1. \x1b[0m\x1b[92mhttp://full-bookmark.com\x1b[0m\n \x1b[91m>\x1b[0m full\n \x1b[91m+\x1b[0m full bookmark\n \x1b[91m#\x1b[0m bookmark,full\n\n" assert err == '' # printing all bookmarks bdb.print_bookmark(0) out, err = capsys.readouterr() assert out == "\x1b[1m\x1b[93m1. \x1b[0m\x1b[92mhttp://full-bookmark.com\x1b[0m\n \x1b[91m>\x1b[0m full\n \x1b[91m+\x1b[0m full bookmark\n \x1b[91m#\x1b[0m bookmark,full\n\n\x1b[1m\x1b[93m2. \x1b[0m\x1b[92mhttp://blank-title.com\x1b[0m\n \x1b[91m+\x1b[0m blank title\n \x1b[91m#\x1b[0m blank,title\n\n\x1b[1m\x1b[93m3. \x1b[0m\x1b[92mhttp://empty-tags.com\x1b[0m\n \x1b[91m>\x1b[0m empty tags\n \x1b[91m+\x1b[0m empty tags\n\n\x1b[1m\x1b[93m4. \x1b[0m\x1b[92mhttp://all-empty.com\x1b[0m\n \x1b[91m+\x1b[0m all empty\n\n" assert err == '' # printing all bookmarks with empty fields bdb.print_bookmark(0, empty=True) out, err = capsys.readouterr() assert out == "\x1b[1m3 records found\x1b[21m\n\n\x1b[1m\x1b[93m2. \x1b[0m\x1b[92mhttp://blank-title.com\x1b[0m\n \x1b[91m+\x1b[0m blank title\n \x1b[91m#\x1b[0m blank,title\n\n\x1b[1m\x1b[93m3. \x1b[0m\x1b[92mhttp://empty-tags.com\x1b[0m\n \x1b[91m>\x1b[0m empty tags\n \x1b[91m+\x1b[0m empty tags\n\n\x1b[1m\x1b[93m4. \x1b[0m\x1b[92mhttp://all-empty.com\x1b[0m\n \x1b[91m+\x1b[0m all empty\n\n" assert err == ''
def test_print_rec_hypothesis(caplog, setup, index, low, high, is_range): """test when index, low or high is less than 0.""" bdb = BukuDb() if high < low: n_high, n_low = low, high else: n_high, n_low = high, low bdb.add_rec("http://one.com", "", parse_tags(['cat,ant,bee,1']), "") db_len = 1 bdb.print_rec(index=index, low=low, high=high, is_range=is_range) check_print = False err_msg = ['Actual log:'] err_msg.extend( ['{}:{}'.format(x.levelname, x.getMessage()) for x in caplog.records]) # negative index/range if (is_range and any([low < 0, high < 0])): assert any(x.levelname == "ERROR" for x in caplog.records) assert any([x.getMessage() == "Negative range boundary" for x in caplog.records]), \ '\n'.join(err_msg) # is_range elif is_range: check_print = True # is_range == False elif not is_range and 0 <= index <= db_len: check_print = True # no matching index else: assert any([x.levelname == "ERROR" for x in caplog.records]), \ '\n'.join(err_msg) assert any([x.getMessage().startswith("No matching index") for x in caplog.records]), \ '\n'.join(err_msg) if check_print: assert not any([x.levelname == "ERROR" for x in caplog.records]), \ '\n'.join(err_msg) # teardown bdb.delete_rec(index=1) caplog.handler.records.clear() caplog.records.clear()
def test_add_and_retrieve_bookmark(self): URL = 'http://slashdot.org' TITLE = 'SLASHDOT' TAGS = ['old', 'news'] DESC = "News for old nerds, stuff that doesn't matter" # start from clean slate if exists(TEST_TEMP_DBFILE_PATH): os.remove(TEST_TEMP_DBFILE_PATH) bdb = BukuDb() bdb.add_bookmark(URL, tag_manual=parse_tags(TAGS), title_manual=TITLE, desc=DESC) index = bdb.get_bookmark_index(URL) self.assertEqual(1, index)
def test_print_rec_hypothesis(caplog, setup, index, low, high, is_range): """test when index, low or high is less than 0.""" # setup caplog.handler.records.clear() caplog.records.clear() bdb = BukuDb() # clear all record first before testing bdb.delete_rec_all() bdb.add_rec("http://one.com", "", parse_tags(['cat,ant,bee,1']), "") db_len = 1 bdb.print_rec(index=index, low=low, high=high, is_range=is_range) check_print = False err_msg = ['Actual log:'] err_msg.extend(['{}:{}'.format(x.levelname, x.getMessage()) for x in caplog.records]) if index < 0 or (0 <= index <= db_len and not is_range): check_print = True # negative index/range on is_range elif (is_range and any([low < 0, high < 0])): assert any([x.levelname == "ERROR" for x in caplog.records]), \ '\n'.join(err_msg) assert any([x.getMessage() == "Negative range boundary" for x in caplog.records]), \ '\n'.join(err_msg) elif is_range: check_print = True else: assert any([x.levelname == "ERROR" for x in caplog.records]), \ '\n'.join(err_msg) assert any([x.getMessage().startswith("No matching index") for x in caplog.records]), \ '\n'.join(err_msg) if check_print: assert not any([x.levelname == "ERROR" for x in caplog.records]), \ '\n'.join(err_msg) # teardown bdb.delete_rec(index=1) caplog.handler.records.clear() caplog.records.clear()
def test_parse_tags(self): # call without arguments parsed = parse_tags() self.assertIsNone(parsed) # empty tags parsed = parse_tags([",,,,,"]) self.assertEqual(parsed, ",") # sorting tags parsed = parse_tags(["z_tag,a_tag,n_tag"]) self.assertEqual(parsed, ",a_tag,n_tag,z_tag,") # whitespaces parsed = parse_tags([" a tag , , , ,\t,\n,\r,\x0b,\x0c"]) self.assertEqual(parsed, ",a tag,") # duplicates, excessive spaces parsed = parse_tags(["tag,tag, tag, tag,tag , tag "]) self.assertEqual(parsed, ",tag,") # escaping quotes parsed = parse_tags(["\"tag\",\'tag\',tag"]) self.assertEqual(parsed, ",\"tag\",\'tag\',tag,") # combo parsed = parse_tags([",,z_tag, a tag ,\t,,, ,n_tag ,n_tag, a_tag, \na tag ,\r, \"a_tag\""]) self.assertEqual(parsed, ",\"a_tag\",a tag,a_tag,n_tag,z_tag,")
def update_model(self, form: forms.BookmarkForm, model: Namespace): res = False try: form.populate_obj(model) self._on_model_change(form, model, False) res = self.bukudb.update_rec( model.id, url=model.url, title_in=model.title, tags_in=buku.parse_tags([model.tags]), desc=model.description, ) except Exception as ex: if not self.handle_view_exception(ex): msg = "Failed to update record." flash( gettext("%(msg)s %(error)s", msg=msg, error=str(ex)), "error", ) LOG.exception(msg) return False else: self.after_model_change(form, model, False) return res
from unittest import mock as mock import pytest import unittest from buku import BukuDb, parse_tags, prompt TEST_TEMP_DIR_OBJ = TemporaryDirectory(prefix='bukutest_') TEST_TEMP_DIR_PATH = TEST_TEMP_DIR_OBJ.name TEST_TEMP_DBDIR_PATH = os.path.join(TEST_TEMP_DIR_PATH, 'buku') TEST_TEMP_DBFILE_PATH = os.path.join(TEST_TEMP_DBDIR_PATH, 'bookmarks.db') MAX_SQLITE_INT = int(math.pow(2, 63) - 1) TEST_BOOKMARKS = [ [ 'http://slashdot.org', 'SLASHDOT', parse_tags(['old,news']), "News for old nerds, stuff that doesn't matter" ], [ 'http://www.zażółćgęśląjaźń.pl/', 'ZAŻÓŁĆ', parse_tags(['zażółć,gęślą,jaźń']), "Testing UTF-8, zażółć gęślą jaźń." ], [ 'https://test.com:8080', 'test', parse_tags(['test,tes,est,es']), "a case for replace_tag test" ], ] only_python_3_5 = pytest.mark.skipif(sys.version_info < (3, 5), reason="requires Python 3.5 or later")
def test_parse_tags_no_args(): import buku assert buku.parse_tags() == DELIM
import unittest, pytest from os.path import join, expanduser import sqlite3 buku = imp.load_source('buku', '../buku') TEST_TEMP_DIR_OBJ = TemporaryDirectory(prefix='bukutest_') TEST_TEMP_DIR_PATH = TEST_TEMP_DIR_OBJ.name TEST_TEMP_DBDIR_PATH = join(TEST_TEMP_DIR_PATH, 'buku') TEST_TEMP_DBFILE_PATH = join(TEST_TEMP_DBDIR_PATH, 'bookmarks.db') from buku import BukuDb, parse_tags TEST_BOOKMARKS = [ ['http://slashdot.org', 'SLASHDOT', parse_tags(['old,news']), "News for old nerds, stuff that doesn't matter", ], ['http://www.zażółćgęśląjaźń.pl/', 'ZAŻÓŁĆ', parse_tags(['zażółć,gęślą,jaźń']), "Testing UTF-8, zażółć gęślą jaźń.", ], ['https://test.com:8080', 'test', parse_tags(['test,tes,est,es']), "a case for replace_tag test", ], ]
from unittest import mock from os.path import join, expanduser import sqlite3 buku = imp.load_source('buku', '../buku') TEST_TEMP_DIR_OBJ = TemporaryDirectory(prefix='bukutest_') TEST_TEMP_DIR_PATH = TEST_TEMP_DIR_OBJ.name TEST_TEMP_DBDIR_PATH = join(TEST_TEMP_DIR_PATH, 'buku') TEST_TEMP_DBFILE_PATH = join(TEST_TEMP_DBDIR_PATH, 'bookmarks.db') from buku import BukuDb, parse_tags TEST_BOOKMARKS = [ ['http://slashdot.org', 'SLASHDOT', parse_tags(['old,news']), "News for old nerds, stuff that doesn't matter", ], ['http://www.zażółćgęśląjaźń.pl/', 'ZAŻÓŁĆ', parse_tags(['zażółć,gęślą,jaźń']), "Testing UTF-8, zażółć gęślą jaźń.", ], ['https://test.com:8080', 'test', parse_tags(['test,tes,est,es']), "a case for replace_tag test", ], ]
from buku import BukuDb, parse_tags, prompt logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from vcrpy vcr_log = logging.getLogger("vcr") vcr_log.setLevel(logging.INFO) def get_temp_dir_path(): with TemporaryDirectory(prefix="bukutest_") as dir_obj: return dir_obj TEST_TEMP_DIR_PATH = get_temp_dir_path() TEST_TEMP_DBDIR_PATH = os.path.join(TEST_TEMP_DIR_PATH, "buku") TEST_TEMP_DBFILE_PATH = os.path.join(TEST_TEMP_DBDIR_PATH, "bookmarks.db") MAX_SQLITE_INT = int(math.pow(2, 63) - 1) TEST_PRINT_REC = ("https://example.com", "", parse_tags(["cat,ant,bee,1"]), "") TEST_BOOKMARKS = [ [ "http://slashdot.org", "SLASHDOT", parse_tags(["old,news"]), "News for old nerds, stuff that doesn't matter", ], [ "http://www.zażółćgęśląjaźń.pl/", "ZAŻÓŁĆ", parse_tags(["zażółć,gęślą,jaźń"]), "Testing UTF-8, zażółć gęślą jaźń.", ], [