def main(): global options options = parse_args() if options.db_file: # FIXME - should do dupe checking response = requests.get('https://graph.facebook.com/me', params={'access_token': options.access_token}) if response.ok: user_id = response.json['id'] sql = 'INSERT INTO oauth_access_tokens(user_id, code, token) VALUES("%s", "asdf", "%s");' % (user_id, options.access_token) schemautil.get_db(options.db_file).executescript(sql) else: print >> sys.stderr, "There was a problem downloading the user info [%s]" % options.access_token if options.fql_schema: fql_schema = schemautil.FqlSchema() scrape_schema(fql_schema, options.fql_docs_url, FQL_COLUMN_RE) fql_schema.write() else: fql_schema = schemautil.FqlSchema.read() if options.fql_data: dataset = fetch_fql_data(fql_schema) dataset.write(db_file=options.db_file) if options.graph: ids = get_graph_ids() schema, dataset = fetch_graph_schema_and_data(ids) schema.write() dataset.write(db_file=options.db_file)
def setUp(self, *handler_classes): """Args: handler_classes: RequestHandlers to initialize """ super(HandlerTest, self).setUp() self.conn = schemautil.get_db(':memory:') for cls in handler_classes: cls.init(self.conn, self.ME) self.app = server.application()
def main(): global options options = parse_args() if options.db_file: # FIXME - should do dupe checking sql = 'INSERT INTO oauth_access_tokens(code, token) VALUES("asdf", "%s");' % options.access_token schemautil.get_db(options.db_file).executescript(sql) if options.fql_schema: fql_schema = schemautil.FqlSchema() scrape_schema(fql_schema, options.fql_docs_url, FQL_COLUMN_RE) fql_schema.write() else: fql_schema = schemautil.FqlSchema.read() if options.fql_data: dataset = fetch_fql_data(fql_schema) dataset.write(db_file=options.db_file) if options.graph: ids = get_graph_ids() schema, dataset = fetch_graph_schema_and_data(ids) schema.write() dataset.write(db_file=options.db_file)
def setUp(self): warnings.filterwarnings('ignore', 'tempnam is a potential security risk') self.db_filename = os.tempnam('/tmp', 'mockfacebook_test.') conn = schemautil.get_db(self.db_filename) fql_test.insert_test_data(conn) graph_test.insert_test_data(conn) conn.close() started = threading.Event() self.thread = threading.Thread( target=server.main, args=(['--db_file', self.db_filename, '--port', str(self.PORT), '--me', '1', ],), kwargs={'started': started}) self.thread.start() started.wait()
def main(args, started=None): """Args: args: list of string command line arguments started: an Event to set once the server has started. for testing. """ parse_args(args) print 'Options: %s' % options conn = schemautil.get_db(options.db_file) for cls in HANDLER_CLASSES: cls.init(conn, options.me) # must run after FqlHandler.init() since that reads the FQL schema warn_if_no_data(conn) global server # for server_test.ServerTest server = wsgiref.simple_server.make_server('', options.port, application()) print 'Serving on port %d...' % options.port if started: started.set() server.serve_forever(poll_interval=SERVER_POLL_INTERVAL)