def post_response(self):
     """Return the response generated from a generic POST request. Do basic
     validation on the response."""
     response = self.req.post('/tag',
                              headers={"Content-Type": 'application/json'},
                              data=dumps({u'name': u'Jeff Knupp'}))
     assert response.status_code == 201
     assert loads(response.data)[u'name'] == u'Jeff Knupp'
     return response
 def test_put_existing_resource(self):
     """Send HTTP PUT for an existing resource (should be updated)."""
     self.post_response()
     response = self.req.put('/tag/1',
                             headers={"Content-Type": 'application/json'},
                             data=dumps({u'name': u'Jeff Knupp2'}))
     assert response.status_code == 200
     response = self.get_response('/tag/1', 200)
     assert loads(response.data)[u'name'] == u'Jeff Knupp2'
     assert loads(response.data)[u'id'] == 1
Beispiel #3
0
 def on_error(self, request, error):
     if isinstance(request, JsonRpcNotification):
         return
     if not isinstance(error, JsonRpcError):
         data = {'exception': '%s' % error}
         error = JsonRpcInternalError(data=data)
     if request:
         error.id = request.id
     data = dumps(error.marshal(), encoding=self.server.encoding)
     self.send_http_result(data)
 def test_put_new_resource(self):
     """Send HTTP PUT for a resource which doesn't exist (should be
     created)."""
     response = self.req.put('/tag/2',
                             headers={"Content-Type": 'application/json'},
                             data=dumps({
                                 u'id': 2,
                                 u'name': u'Jeff Knupp'
                             }))
     assert response.status_code == 201
     assert loads(response.data)['name'] == u'Jeff Knupp'
Beispiel #5
0
 def con_update(cls, session, ctx, ea, dictionary):
     result = ((session.id,ctx,ea,base.dumps(v),k) for k,v in dictionary.iteritems())  # XXX
     q = 'replace into content (session,context,address,tag,value) select ?,?,?,tag.id,? from tag where tag.name=?'
     return session.database.executemany(q, result).rowcount