def testViaAgent(self):
"""
This is a manual check of a POST to /objects which uses
L{twisted.web.client.Agent} to make the request. We do not use
txFluidDB because we need to check that a Location header is
received and that we receive both a 'URI' and an 'id' in the JSON
response payload.
"""
URI = self.txEndpoint.getRootURL() + defaults.httpObjectCategoryName
basicAuth = 'Basic %s' % b64encode('%s:%s' % ('testuser1', 'secret'))
headers = Headers({'accept': ['application/json'],
'authorization': [basicAuth]})
agent = Agent(reactor)
response = yield agent.request('POST', URI, headers)
self.assertEqual(http.CREATED, response.code)
self.assertTrue(response.headers.hasHeader('location'))
d = defer.Deferred()
bodyGetter = ResponseGetter(d)
response.deliverBody(bodyGetter)
body = yield d
responseDict = json.loads(body)
self.assertIn('URI', responseDict)
self.assertIn('id', responseDict)
评论列表
文章目录