'This test tries to claim the same attachment twice. The messages field in
the Attachment model should have both the messages in its entry.'

def test_multiple_claim_attachments(self):

    self.login(self.example_email('hamlet'))
    d1 = StringIO('zulip!')
    d1.name = 'dummy_1.txt'
    result = self.client_post('/json/user_uploads', {'file': d1})
    json = ujson.loads(result.content)
    uri = json['uri']
    d1_path_id = re.sub('/user_uploads/', '', uri)
    self.subscribe_to_stream(self.example_email('hamlet'), 'Denmark')
    body = (('First    message    ...[zulip.txt](http://localhost:9991/user_uploads/' + d1_path_id) + ')')
    self.send_message(self.example_email('hamlet'), 'Denmark', Recipient.STREAM, body, 'test')
    body = (('Second    message    ...[zulip.txt](http://localhost:9991/user_uploads/' + d1_path_id) + ')')
    self.send_message(self.example_email('hamlet'), 'Denmark', Recipient.STREAM, body, 'test')
    self.assertEqual(Attachment.objects.get(path_id=d1_path_id).messages.count(), 2)
