'Tests the /api/v1/user_uploads api endpoint. Here a single file is uploaded
and downloaded using a username and api_key'

def test_rest_endpoint(self):

    fp = StringIO('zulip!')
    fp.name = 'zulip.txt'
    auth_headers = self.api_auth(self.example_email('hamlet'))
    result = self.client_post('/api/v1/user_uploads', {'file': fp}, **auth_headers)
    json = ujson.loads(result.content)
    self.assertIn('uri', json)
    uri = json['uri']
    base = '/user_uploads/'
    self.assertEqual(base, uri[:len(base)])
    self.logout()
    response = self.client_get(uri, **auth_headers)
    data = ''.join(response.streaming_content)
    self.assertEqual('zulip!', data)
    self.login(self.example_email('hamlet'))
    self.assert_url_serves_contents_of_file(uri, 'zulip!')
