'A call to /json/user_uploads should return a uri and actually create an
entry in the database. This entry will be marked unclaimed till a message
refers it.'

def test_file_upload_authed(self):

    self.login(self.example_email('hamlet'))
    fp = StringIO('zulip!')
    fp.name = 'zulip.txt'
    result = self.client_post('/json/user_uploads', {'file': fp})
    self.assert_json_success(result)
    json = ujson.loads(result.content)
    self.assertIn('uri', json)
    uri = json['uri']
    base = '/user_uploads/'
    self.assertEqual(base, uri[:len(base)])
    self.assert_url_serves_contents_of_file(uri, 'zulip!')
    entry = Attachment.objects.get(file_name='zulip.txt')
    self.assertEqual(entry.is_claimed(), False)
    self.subscribe_to_stream(self.example_email('hamlet'), 'Denmark')
    body = (('First    message    ...[zulip.txt](http://localhost:9991' + uri) + ')')
    self.send_message(self.example_email('hamlet'), 'Denmark', Recipient.STREAM, body, 'test')
    self.assertIn('title="zulip.txt"', self.get_last_message().rendered_content)
