def runTest(self): """Make sure bittorrent table works as expected""" connection = sqlite3.connect(":memory:") connection.row_factory = sqlite3.Row table_bittorrent.create(connection) table_bittorrent.create(connection) v = map(None, ResultIterator()) for d in v: table_bittorrent.insert(connection, d, override_timestamp=False) v1 = table_bittorrent.listify(connection) self.assertEquals(sorted(v), sorted(v1)) since = utils.timestamp() - 7 * 24 * 60 * 60 until = utils.timestamp() - 3 * 24 * 60 * 60 v2 = table_bittorrent.listify(connection, since=since, until=until) self.assertTrue(len(v2) < len(v)) table_bittorrent.prune(connection, until) self.assertTrue(len(table_bittorrent.listify(connection)) < len(v1))
def _api_bittorrent(self, stream, request, query): since, until = -1, -1 dictionary = cgi.parse_qs(query) if dictionary.has_key("since"): since = int(dictionary["since"][0]) if dictionary.has_key("until"): until = int(dictionary["until"][0]) indent, mimetype, sort_keys = None, "application/json", False if "debug" in dictionary and utils.intify(dictionary["debug"][0]): indent, mimetype, sort_keys = 4, "text/plain", True response = Message() lst = table_bittorrent.listify(DATABASE.connection(), since, until) s = json.dumps(lst, indent=indent, sort_keys=sort_keys) stringio = StringIO.StringIO(s) response.compose(code="200", reason="Ok", body=stringio, mimetype=mimetype) stream.send_response(request, response)