Esempio n. 1
0
 def test_put_with_binary_data(self):
     # Putting binary data should fail.
     request = testing.DummyRequest()
     request.matchdict = {"username": "******"}
     request.body = "\x00" * 4
     request.content_length = 4
     request.content_type = "image/jpeg"
     self.assertRaises(HTTPUnsupportedMediaType, put_key, request)
     # Sending any text type will succeed.
     request = testing.DummyRequest()
     request.matchdict = {"username": "******"}
     request.body = '{ "hello": "world" }'
     request.content_length = len(request.body)
     request.content_type = "text/json"
     res = put_key(request)
     self.assertEquals(res.status_int, 204)
     # But it's gonna come back as text/plain.
     request = testing.DummyRequest()
     request.matchdict = {"username": "******"}
     res = get_key(request)
     self.assertEquals(res.status_int, 200)
     self.assertEquals(res.body, '{ "hello": "world" }')
     self.assertEquals(res.content_type, "text/plain")
Esempio n. 2
0
 def test_get_put_delete_cycle(self):
     # Initially there should be no data
     request = testing.DummyRequest()
     request.matchdict = {"username": "******"}
     self.assertRaises(HTTPNotFound, get_key, request)
     # Put some data.
     request = testing.DummyRequest()
     request.matchdict = {"username": "******"}
     request.body = "TEST"
     request.content_length = 4
     request.content_type = "text/plain"
     res = put_key(request)
     self.assertEquals(res.status_int, 204)
     # Now we can retrieve it.
     request = testing.DummyRequest()
     request.matchdict = {"username": "******"}
     res = get_key(request)
     self.assertEquals(res.status_int, 200)
     self.assertEquals(res.body, "TEST")
     # But only by using the correct username.
     request = testing.DummyRequest()
     request.matchdict = {"username": "******"}
     self.assertRaises(HTTPNotFound, get_key, request)
     # Delete the data.
     request = testing.DummyRequest()
     request.matchdict = {"username": "******"}
     res = delete_key(request)
     self.assertEquals(res.status_int, 204)
     # And now it's gone.
     request = testing.DummyRequest()
     request.matchdict = {"username": "******"}
     self.assertRaises(HTTPNotFound, get_key, request)
     # We can't delete it again.
     request = testing.DummyRequest()
     request.matchdict = {"username": "******"}
     self.assertRaises(HTTPNotFound, delete_key, request)