def compare_tags_and_feeds(self, shelf): for tag in alltags.get_tags(): for item in alltags.tags[tag]: URL = dict_id(item)["URL"] id = dict_id(item)["ID"] feed = allfeeds.get_feed(dict_id(item)["URL"]) if tag.startswith("maintag:") and tag[8:] == feed.name: continue for entry in shelf[feed.URL]["entries"]: if id == entry["id"] and tag not in entry["canto-tags"]: raise Exception("Tag %s has no source: %s / %s!" % (tag, feed.name, entry))
def check(self): content = { "title": "Title %d", "link": TEST_URL + "%d/", } update_content = { "title": "Title %d updated", "link": TEST_URL + "%d/updated", } self.banner("sanity") # Index basic sanity checks (should write to shelf, should populate tags) # All internal to the baseline generator. f, s, u = self.generate_baseline("Test Feed", "http://example.com", 100, content, time.time()) self.banner("discard") now = time.time() test_feed, test_shelf, first_update = self.generate_baseline( "Test Feed", TEST_URL, 100, content, now - (DEF_KEEP_TIME + 1)) second_update = self.generate_update_contents(100, update_content, now) # Keep some items from the first update second_update["entries"].extend(first_update["entries"][:5]) test_feed.index(second_update) self.compare_feed_and_tags(test_shelf) tag = alltags.tags["maintag:Test Feed"] nitems = len(tag) if nitems != 105: raise Exception("Wrong number of items in tag! %d - %s" % (nitems, tag)) if dict_id(tag[100])["ID"] != "http://example.com/0/": raise Exception("Failed to keep order got id = %s" % dict_id(tag[100])["ID"]) self.banner("keep_time") test_feed, test_shelf, first_update = self.generate_baseline( "Test Feed", TEST_URL, 100, content, now - 300) test_feed.index(second_update) self.compare_feed_and_tags(test_shelf) tag = alltags.tags["maintag:Test Feed"] nitems = len(tag) if nitems != 200: raise Exception("Wrong number of items in tag! %d - %s" % (nitems, tag)) if dict_id(tag[0])["ID"] != "http://example.com/0/updated": raise Exception("Failed to keep order got id = %s" % dict_id(tag[0])["ID"]) if dict_id(tag[100])["ID"] != "http://example.com/0/": raise Exception("Failed to keep order got id = %s" % dict_id(tag[100])["ID"]) if dict_id(tag[199])["ID"] != "http://example.com/99/": raise Exception("Failed to keep order got id = %s" % dict_id(tag[199])["ID"]) self.banner("keep_unread") now = time.time() test_feed, test_shelf, first_update = self.generate_baseline( "Test Feed", TEST_URL, 100, content, now - (DEF_KEEP_TIME + 1)) test_feed.keep_unread = True # Mark five that aren't keep_unread protected, but are too young to discard for i in range(5): test_shelf[TEST_URL]["entries"][i]["canto_update"] = now - 300 test_shelf[TEST_URL]["entries"][i]["canto-state"] = ["read"] # Mark 25 that should be discarded for i in range(25, 50): test_shelf[TEST_URL]["entries"][i]["canto-state"] = ["read"] second_update = self.generate_update_contents(100, update_content, now) test_feed.index(second_update) self.compare_feed_and_tags(test_shelf) tag = alltags.tags["maintag:Test Feed"] nitems = len(tag) if nitems != 175: raise Exception("Wrong number of items in tag! %d - %s" % (nitems, tag)) self.banner("save all items on empty new content") test_feed, test_shelf, first_update = self.generate_baseline( "Test Feed", TEST_URL, 100, content, now - (DEF_KEEP_TIME + 1)) test_feed.index(self.generate_update_contents(0, update_content, now)) tag = alltags.tags["maintag:Test Feed"] nitems = len(tag) if nitems != 100: raise Exception("Wrong number of items in tag! %d - %s" % (nitems, tag)) return True
def check(self): content = { "title" : "Title %d", "link" : TEST_URL + "%d/", } update_content = { "title" : "Title %d updated", "link" : TEST_URL + "%d/updated", } self.banner("sanity") # Index basic sanity checks (should write to shelf, should populate tags) # All internal to the baseline generator. f, s, u = self.generate_baseline("Test Feed", "http://example.com", 100, content, time.time()) self.banner("discard") now = time.time() test_feed, test_shelf, first_update = self.generate_baseline("Test Feed", TEST_URL, 100, content, now - (DEF_KEEP_TIME + 1)) second_update = self.generate_update_contents(100, update_content, now) # Keep some items from the first update second_update["entries"].extend(first_update["entries"][:5]) test_feed.index(second_update) self.compare_feed_and_tags(test_shelf) tag = alltags.tags["maintag:Test Feed"] nitems = len(tag) if nitems != 105: raise Exception("Wrong number of items in tag! %d - %s" % (nitems, tag)) if dict_id(tag[100])["ID"] != "http://example.com/0/": raise Exception("Failed to keep order got id = %s" % dict_id(tag[100])["ID"]) self.banner("keep_time") test_feed, test_shelf, first_update = self.generate_baseline("Test Feed", TEST_URL, 100, content, now - 300) test_feed.index(second_update) self.compare_feed_and_tags(test_shelf) tag = alltags.tags["maintag:Test Feed"] nitems = len(tag) if nitems != 200: raise Exception("Wrong number of items in tag! %d - %s" % (nitems, tag)) if dict_id(tag[0])["ID"] != "http://example.com/0/updated": raise Exception("Failed to keep order got id = %s" % dict_id(tag[0])["ID"]) if dict_id(tag[100])["ID"] != "http://example.com/0/": raise Exception("Failed to keep order got id = %s" % dict_id(tag[100])["ID"]) if dict_id(tag[199])["ID"] != "http://example.com/99/": raise Exception("Failed to keep order got id = %s" % dict_id(tag[199])["ID"]) self.banner("keep_unread") now = time.time() test_feed, test_shelf, first_update = self.generate_baseline("Test Feed", TEST_URL, 100, content, now - (DEF_KEEP_TIME + 1)) test_feed.keep_unread = True # Mark five that aren't keep_unread protected, but are too young to discard for i in range(5): test_shelf[TEST_URL]["entries"][i]["canto_update"] = now - 300 test_shelf[TEST_URL]["entries"][i]["canto-state"] = [ "read" ] # Mark 25 that should be discarded for i in range(25, 50): test_shelf[TEST_URL]["entries"][i]["canto-state"] = [ "read" ] second_update = self.generate_update_contents(100, update_content, now) test_feed.index(second_update) self.compare_feed_and_tags(test_shelf) tag = alltags.tags["maintag:Test Feed"] nitems = len(tag) if nitems != 175: raise Exception("Wrong number of items in tag! %d - %s" % (nitems, tag)) self.banner("save all items on empty new content") test_feed, test_shelf, first_update = self.generate_baseline("Test Feed", TEST_URL, 100, content, now - (DEF_KEEP_TIME + 1)) test_feed.index(self.generate_update_contents(0, update_content, now)) tag = alltags.tags["maintag:Test Feed"] nitems = len(tag) if nitems != 100: raise Exception("Wrong number of items in tag! %d - %s" % (nitems, tag)) return True