def main(argv): """ Start with:: python -m restorm.examples.mock.library_serv [port or address:port] """ ip_address = '127.0.0.1' port = 8000 # This is an example. Your should do argument checking. if len(argv) == 1: ip_address_port = argv[0].split(':', 1) if len(ip_address_port) == 1: port = ip_address_port[0] else: ip_address, port = ip_address_port # Create a playground HTTP server that handles requests from the # ``LibraryApiClient``. api = LibraryApiClient('http://%s:%s/api/' % (ip_address, port)) server = api.create_server(ip_address, int(port)) print 'Mock library webservice is running at http://%s:%s/api/' % ( ip_address, port) print 'Quit the server with CTRL-C.' try: server.serve_forever() except KeyboardInterrupt: print 'Closing server...' server.socket.close()
def setUp(self): self.client = LibraryApiClient()
def setUp(self): RestormAppSetup() self.client = LibraryApiClient()
def setUp(self): RestormAppSetup() self.client = LibraryApiClient() class Author(Resource): id = fields.IntegerField(primary_key=True) name = fields.CharField() class Meta: resource_name = 'author' list = (r'^author/$', 'author_set') item = r'^author/(?P<id>\d)$' client = self.client verbose_name = 'Author' verbose_name_plural = 'Authors' self.author_resource = Author class BookManager(ResourceManager): def filter_on_author(self, author_resource): return self.all(query=[('author', author_resource), ]) self.book_manager = BookManager def get_author_id(data, resource): return { 'id': data.split('/')[-1] } class Book(Resource): some_class_attribute = 'foobar' isbn = fields.CharField(primary_key=True) title = fields.CharField() author = fields.ToOneField('author', Author, get_author_id) objects = BookManager() class Meta: resource_name = 'book' list = r'^book/$' item = r'^book/(?P<isbn>\d)$' client = self.client def __init__(self, *args, **kwargs): self.some_instance_attribute_before_init = 'foobar' super(Book, self).__init__(*args, **kwargs) self.some_instance_attribute_after_init = 'foobar' def get_title(self): return self.title.title() self.book_resource = Book class Store(Resource): id = fields.IntegerField(primary_key=True) name = fields.CharField() class Meta: resource_name = 'store' list = r'^store/$' item = r'^store/(?P<id>\d)$' client = self.client verbose_name = 'Storage' verbose_name_plural = 'Storages' self.store_resource = Store