Beispiel #1
0
 def root(self, request, **kwargs):
     try:
         name = kwargs.get('name', None)
         items = Item.lookup_list(name=name)
         return Ok([{'id': i.id, 'name': i.name} for i in items])
     except Exception as e:
         return BadRequest('Internal error: {}'.format(unicode(e)))
Beispiel #2
0
 def root(self, request):
     return Ok('<!DOCTYPE html>'
               '   <html>'
               '       <head><title>Dummy Root</title></head>'
               '       <body>'
               '           <h1>This is the Dummy Root. F**k yeah!</h1>'
               '       </body>'
               '   </html>')
Beispiel #3
0
    def test_send_back(self):

        request = DummyRequest(['/test'], '')
        result = Ok('Testing', {'content-type': 'application/json'})

        request = request
        result = yield self.c.sendback(result, request)

        self.assertEqual(result, None)
        self.assertEqual(request.written[0], 'Testing')
Beispiel #4
0
    def create(self, request, **kwargs):
        name = kwargs.get('name', None)

        if not name:
            return BadRequest('Name not filled')

        try:
            return Ok('{}'.format(Item.upsert(name=unicode(name))))
        except Exception as e:
            return BadRequest('Internal error: {}'.format(unicode(e)))
Beispiel #5
0
 def root_deferred(self, request, **kwargs):
     name = kwargs.get('name', None)
     d = ItemsManager.lookup_items(name=name)
     d.addCallback(lambda items: Ok([{
         'id': i.id,
         'name': i.name
     } for i in items]))
     d.addErrback(
         lambda e: BadRequest('Internal error: {}'.format(unicode(e))))
     return d
Beispiel #6
0
    def create_deferred(self, request, **kwargs):
        name = kwargs.get('name', None)

        if not name:
            return BadRequest('Name not filled')

        d = ItemsManager.upsert_item_with_name(name=unicode(name))
        d.addCallback(lambda res: Ok('{}'.format(res)))
        d.addErrback(
            lambda e: BadRequest('Internal error: {}'.format(unicode(e))))
        return d
Beispiel #7
0
 def hello(self, request, name, **kwargs):
     return Ok('Hello {}!'.format(name))
Beispiel #8
0
 def root(self, request, **kwargs):
     return Ok('I am the Hello, hello world!')
Beispiel #9
0
 def dummy_test(self, request):
     return Ok('<h1>Dummy Test</h1>', {'content-type': 'text/html'})