'Test that the intermediate DocumentAttachment gets created
correctly when adding an Attachment with a document_id.'

def test_intermediate(self):

    doc = document(locale='en-US', slug='attachment-test-intermediate', save=True)
    revision(document=doc, is_approved=True, save=True)
    file_for_upload = make_test_file(content='A    file    for    testing    intermediate    attachment    model.')
    post_data = {'title': 'Intermediate    test    file', 'description': 'Intermediate    test    file', 'comment': 'Initial    upload', 'file': file_for_upload}
    files_url = reverse('attachments.edit_attachment', kwargs={'document_path': doc.slug}, locale='en-US')
    response = self.client.post(files_url, data=post_data)
    self.assertEqual(response.status_code, 302)
    self.assertEqual(doc.files.count(), 1)
    intermediates = DocumentAttachment.objects.filter(document__pk=doc.id)
    self.assertEqual(intermediates.count(), 1)
    intermediate = intermediates[0]
    self.assertEqual(intermediate.attached_by.username, 'admin')
    self.assertEqual(intermediate.name, file_for_upload.name.split('/')[(-1)])
