def _chrome_data_test(self): """Test that we find the correct Chrome bmark data after import""" res = Bmark.query.all() self.assertEqual(len(res), 4, "We should have 4 results, we got: " + str(len(res))) # Verify we can find a bookmark by url and check tags, etc check_url = 'https://addons.mozilla.org/en-US/firefox/bookmarks/' check_url_hashed = generate_hash(check_url) found = Bmark.query.filter(Bmark.hash_id == check_url_hashed).one() self.assertTrue(found.hashed.url == check_url, "The url should match our search") self.assertEqual( len(found.tags), 2, "We should have gotten 2 tags, got: " + str(len(found.tags))) # and check we have a right tag or two self.assertTrue( 'imported-from-firefox' in found.tag_string(), 'imported-from-firefox should be a valid tag in the bookmark') # and check the timestamp is correct # relative to user's timezone date_should_be = datetime.fromtimestamp(1350353334) self.assertEqual(date_should_be, found.stored)
def _delicious_xml_data_test(self): """Test that we find the correct google bmark data after import""" res = Bmark.query.all() self.assertEqual( len(res), 25, "We should have 25 results, we got: " + str(len(res))) # verify we can find a bookmark by url and check tags, etc check_url = 'http://jekyllrb.com/' check_url_hashed = generate_hash(check_url) found = Bmark.query.filter(Bmark.hash_id == check_url_hashed).one() self.assertTrue( found.hashed.url == check_url, "The url should match our search") self.assertEqual( len(found.tags), 6, "We should have gotten 6 tags, got: " + str(len(found.tags))) # and check we have a right tag or two self.assertTrue( 'ruby' in found.tag_string(), 'ruby should be a valid tag in the bookmark') # and check the long description field self.assertTrue( 'added for test' in found.extended, "'added for test' should be in the extended description")
def save_bookmark(self, url, desc, ext, tags, dt=None): """Save the bookmark to the db :param url: bookmark url :param desc: one line description :param ext: extended description/notes :param tags: The string of tags to store with this bmark :param mark: Instance of Bmark that we're storing to db """ # we should make sure that this url isn't already bookmarked before # adding it...if the hash matches, you must skip! check_hash = generate_hash(url) if check_hash not in self.hash_list: bmark = BmarkMgr.store( url, self.username, desc, ext, tags, dt=dt, inserted_by=IMPORTED) # add this hash to the list so that we can skip dupes in the same # import set self.hash_list.add(check_hash) return bmark else: return None
def _google_data_test(self): """Test that we find the correct google bmark data after import""" res = Bmark.query.all() self.assertEqual( len(res), 9, "We should have 9 results, we got: " + str(len(res))) # verify we can find a bookmark by url and check tags, etc check_url = 'http://www.alistapart.com/' check_url_hashed = generate_hash(check_url) found = Bmark.query.filter(Bmark.hash_id == check_url_hashed).one() self.assertTrue( found.hashed.url == check_url, "The url should match our search") self.assertEqual( len(found.tags), 4, "We should have gotten 4 tags, got: " + str(len(found.tags))) # and check we have a right tag or two self.assertTrue( 'html' in found.tag_string(), 'html should be a valid tag in the bookmark') # and check the long description field self.assertTrue( "make websites" in found.extended, "'make websites' should be in the extended description")
def save_bookmark(self, url, desc, ext, tags, dt=None): """Save the bookmark to the db :param url: bookmark url :param desc: one line description :param ext: extended description/notes :param tags: The string of tags to store with this bmark :param mark: Instance of Bmark that we're storing to db """ # we should make sure that this url isn't already bookmarked before # adding it...if the hash matches, you must skip! check_hash = generate_hash(url) if check_hash not in self.hash_list: BmarkMgr.store(url, self.username, desc, ext, tags, dt=dt, inserted_by=IMPORTED) # add this hash to the list so that we can skip dupes in the same # import set self.hash_list.add(check_hash)
def _delicious_data_test(): """Test that we find the correct set of declicious data after import""" # blatant copy/paste, but I'm ona plane right now so oh well # now let's do some db sanity checks res = Bmark.query.all() eq_(len(res), 19, "We should have 19 results, we got: " + str(len(res))) # verify we can find a bookmark by url and check tags, etc check_url = 'http://www.ndftz.com/nickelanddime.png' check_url_hashed = generate_hash(check_url) found = Bmark.query.filter(Bmark.hash_id == check_url_hashed).one() ok_(found.hashed.url == check_url, "The url should match our search") eq_(len(found.tags), 7, "We should have gotten 7 tags, got: " + str(len(found.tags))) eq_('importer', found.inserted_by, "The bookmark should have come from importing: " + found.inserted_by) # and check we have a right tag or two ok_('canonical' in found.tag_string(), 'Canonical should be a valid tag in the bookmark') # and check the long description field ok_("description" in found.extended, "The extended attrib should have a nice long string in it")
def _google_data_test(self): """Test that we find the correct google bmark data after import""" res = Bmark.query.all() self.assertEqual(len(res), 9, "We should have 9 results, we got: " + str(len(res))) # verify we can find a bookmark by url and check tags, etc check_url = 'http://www.alistapart.com/' check_url_hashed = generate_hash(check_url) found = Bmark.query.filter(Bmark.hash_id == check_url_hashed).one() self.assertTrue(found.hashed.url == check_url, "The url should match our search") self.assertEqual( len(found.tags), 4, "We should have gotten 4 tags, got: " + str(len(found.tags))) # and check we have a right tag or two self.assertTrue('html' in found.tag_string(), 'html should be a valid tag in the bookmark') # and check the long description field self.assertTrue( "make websites" in found.extended, "'make websites' should be in the extended description")
def _delicious_xml_data_test(self): """Test that we find the correct google bmark data after import""" res = Bmark.query.all() self.assertEqual(len(res), 25, "We should have 25 results, we got: " + str(len(res))) # verify we can find a bookmark by url and check tags, etc check_url = 'http://jekyllrb.com/' check_url_hashed = generate_hash(check_url) found = Bmark.query.filter(Bmark.hash_id == check_url_hashed).one() self.assertTrue(found.hashed.url == check_url, "The url should match our search") self.assertEqual( len(found.tags), 6, "We should have gotten 6 tags, got: " + str(len(found.tags))) # and check we have a right tag or two self.assertTrue('ruby' in found.tag_string(), 'ruby should be a valid tag in the bookmark') # and check the long description field self.assertTrue( 'added for test' in found.extended, "'added for test' should be in the extended description")
def _delicious_data_test(self): """Test that we find the correct set of declicious data after import""" # Blatant copy/paste, but I'm on a plane right now so oh well. # Now let's do some db sanity checks. res = Bmark.query.all() self.assertEqual(len(res), 19, "We should have 19 results, we got: " + str(len(res))) # verify we can find a bookmark by url and check tags, etc check_url = u'http://www.ndftz.com/nickelanddime.png' check_url_hashed = generate_hash(check_url) found = Bmark.query.filter(Bmark.hash_id == check_url_hashed).one() self.assertTrue(found.hashed.url == check_url, "The url should match our search") self.assertEqual( len(found.tags), 7, "We should have gotten 7 tags, got: " + str(len(found.tags))) self.assertEqual( 'importer', found.inserted_by, "The bookmark should have imported: " + found.inserted_by) # and check we have a right tag or two self.assertTrue('canonical' in found.tag_string(), 'Canonical should be a valid tag in the bookmark') # and check the long description field self.assertTrue( "description" in found.extended, "The extended attrib should have a nice long string in it")
def _chrome_data_test(self): """Test that we find the correct Chrome bmark data after import""" res = Bmark.query.all() self.assertEqual( len(res), 4, "We should have 4 results, we got: " + str(len(res))) # Verify we can find a bookmark by url and check tags, etc check_url = 'https://addons.mozilla.org/en-US/firefox/bookmarks/' check_url_hashed = generate_hash(check_url) found = Bmark.query.filter(Bmark.hash_id == check_url_hashed).one() self.assertTrue( found.hashed.url == check_url, "The url should match our search") self.assertEqual( len(found.tags), 2, "We should have gotten 2 tags, got: " + str(len(found.tags))) # and check we have a right tag or two self.assertTrue( 'imported-from-firefox' in found.tag_string(), 'imported-from-firefox should be a valid tag in the bookmark') # and check the timestamp is correct # relative to user's timezone date_should_be = datetime.fromtimestamp(1350353334) self.assertEqual(date_should_be, found.stored)
def save_bookmark(self, url, desc, ext, tags, dt=None): """Save the bookmark to the db :param url: bookmark url :param desc: one line description :param ext: extended description/notes :param tags: The string of tags to store with this bmark :param mark: Instance of Bmark that we're storing to db """ # If a bookmark has the tag "private" then we ignore it to prevent # leaking user data. if tags and "private" in tags.lower().split(" "): return None check_hash = generate_hash(url) # We should make sure that this url isn't already bookmarked before # adding it...if the hash matches, you must skip! if check_hash not in self.hash_list: bmark = BmarkMgr.store(url, self.username, desc, ext, tags, dt=dt, inserted_by=IMPORTED) # Add this hash to the list so that we can skip dupes in the # same import set. self.hash_list.add(check_hash) return bmark # If we don't store a bookmark then just return None back to the # importer. return None
def edit(request): """Manual add a bookmark to the user account Can pass in params (say from a magic bookmarklet later) url description extended tags """ rdict = request.matchdict params = request.params new = False with ReqAuthorize(request, username=rdict['username']): if 'hash_id' in rdict: hash_id = rdict['hash_id'] elif 'hash_id' in params: hash_id = params['hash_id'] else: hash_id = None if hash_id: bmark = BmarkMgr.get_by_hash(hash_id, request.user.username) if bmark is None: return HTTPNotFound() else: # hash the url and make sure that it doesn't exist url = params.get('url', u"") if url != u"": new_url_hash = generate_hash(url) test_exists = BmarkMgr.get_by_hash(new_url_hash, request.user.username) if test_exists: location = request.route_url( 'user_bmark_edit', hash_id=new_url_hash, username=request.user.username) return HTTPFound(location) new = True desc = params.get('description', None) bmark = Bmark(url, request.user.username, desc=desc) tag_suggest = TagMgr.suggestions( url=bmark.hashed.url, username=request.user.username ) return { 'new': new, 'bmark': bmark, 'user': request.user, 'tag_suggest': tag_suggest, }
def test_hash_url(self): """Hashes base url correctly""" url = u'http://google.com' hashed = generate_hash(url) self.assertEqual('aa2239c17609b2', hashed)
def __init__(self, url): """We'll auto hash the id for them and set this up""" cleaned_url = str(unidecode(url)) self.hash_id = generate_hash(cleaned_url) self.url = url
def test_unicode_url(self): """Hashes with unicode correctly""" url = u'http://www.bizrevolution.com.br/bizrevolution/2011/02/somos-t\xe3o-jovens-no-campus-party-.html' hashed = generate_hash(url) self.assertEqual('bd846e7222adf2', hashed)