def should_perform_assynchronous_requests(self): barrier = Semaphore(0) def callback(response): body = response.body try: assert "Response for" in body assert "/hello" in body finally: barrier.release() Restfulie.at("http://localhost:20144/hello").async(callback).get() barrier.acquire()
def should_perform_assynchronous_requests_with_arguments_to_the_callback_function(self): barrier = Semaphore(0) def callback(response, extra1, extra2): body = response.body try: assert "Response for" in body assert "/hello" in body assert extra1 == "first" assert extra2 == "second" finally: barrier.release() Restfulie.at("http://localhost:20144/hello").async(callback, args=("first", "second")).get() barrier.acquire()
def should_perform_async_requests_with_arguments_to_the_callback(self): barrier = Semaphore(0) def callback(response, extra1, extra2): body = response.body assert "Response for" in body assert "/hello" in body assert extra1 == "first" assert extra2 == "second" barrier.release() r = Restfulie.at("http://localhost:20144/hello") r = r. async (callback, args=("first", "second")).get() barrier.acquire() assert "Response for" in r.body assert "/hello" in r.body
def should_return_a_dsl_object(self): assert type(Restfulie.at("www.caelum.com.br")) == Configuration
from restfulie.restfulie import Restfulie response = Restfulie.at("http://localhost:8080").accepts("application/json").get() r = response.resource print r.status print r.servertime print r.link('self') a = response.links.follow().get() for link in a.links: print link print a
def should_perform_ordinary_requests(self): body = Restfulie.at("http://localhost:20144/hello").get().body assert "Response for" in body assert "/hello" in body
def should_perform_ordinary_requests_with_simple_auth(self): r = Restfulie.at("http://localhost:20144/auth").auth('test', 'test') response = r.get() body = response.body assert "worked" in body
def should_perform_requests_with_parameters_as_dict(self): d = {"action": "test"} response = Restfulie.at("http://localhost:20144").post(**d) print response.body body = response.body assert "This is a test" in body
def should_perform_requests_with_parameters_as_kwargs(self): response = Restfulie.at("http://localhost:20144").post(action="test") print response.body body = response.body assert "This is a test" in body
from tornado.ioloop import IOLoop found = False visited = {} steps = 0 def solve(current): global found global visited if not found and not current.link('exit'): directions = ["start", "east", "west", "south", "north"] for direction in directions: link = current.link(direction) if not found and link and not visited.get(link.href): visited[link.href] = True link.follow().get(callback=solve) else: IOLoop.instance().stop() print "FOUND!" found = True # syncronous invoke current = Restfulie.at('http://amundsen.com/examples/mazes/2d/five-by-five/').accepts("application/xml").get() # async invoke solve(current) # start IOLoop IOLoop.instance().start()
def should_perform_async_requests_without_callback(self): r = Restfulie.at("http://localhost:20144/hello").async().get() assert "Response for" in r.body assert "/hello" in r.body