def test_attachments(self):
    'Check attachments.'
    url = reverse('modoboa_webmail:index')
    response = self.client.get('{}?action=compose'.format(url))
    self.assertEqual(response.status_code, 200)
    self.assertIn('compose_mail', self.client.session)
    url = reverse('modoboa_webmail:attachment_list')
    response = self.client.get(url)
    self.assertEqual(response.status_code, 200)
    self.set_global_parameters({'max_attachment_size': '10'})
    with self.settings(MEDIA_ROOT=self.workdir):
        response = self.client.post(url, {'attachment': get_gif()})
    self.assertContains(response, 'Attachment is too big')
    self.set_global_parameters({'max_attachment_size': '10K'})
    with self.settings(MEDIA_ROOT=self.workdir):
        response = self.client.post(url, {'attachment': get_gif()})
    self.assertContains(response, 'upload_success')
    self.assertEqual(len(self.client.session['compose_mail']['attachments']), 1)
    name = self.client.session['compose_mail']['attachments'][0]['tmpname']
    path = '{}/webmail/{}'.format(self.workdir, name)
    self.assertTrue(os.path.exists(path))
    url = reverse('modoboa_webmail:attachment_delete')
    with self.settings(MEDIA_ROOT=self.workdir):
        self.ajax_get('{}?name={}'.format(url, name))
    self.assertFalse(os.path.exists(path))
Check attachments.
def test_attachments(self):
    
    url = reverse('modoboa_webmail:index')
    response = self.client.get('{}?action=compose'.format(url))
    self.assertEqual(response.status_code, 200)
    self.assertIn('compose_mail', self.client.session)
    url = reverse('modoboa_webmail:attachment_list')
    response = self.client.get(url)
    self.assertEqual(response.status_code, 200)
    self.set_global_parameters({'max_attachment_size': '10'})
    with self.settings(MEDIA_ROOT=self.workdir):
        response = self.client.post(url, {'attachment': get_gif()})
    self.assertContains(response, 'Attachment is too big')
    self.set_global_parameters({'max_attachment_size': '10K'})
    with self.settings(MEDIA_ROOT=self.workdir):
        response = self.client.post(url, {'attachment': get_gif()})
    self.assertContains(response, 'upload_success')
    self.assertEqual(len(self.client.session['compose_mail']['attachments']), 1)
    name = self.client.session['compose_mail']['attachments'][0]['tmpname']
    path = '{}/webmail/{}'.format(self.workdir, name)
    self.assertTrue(os.path.exists(path))
    url = reverse('modoboa_webmail:attachment_delete')
    with self.settings(MEDIA_ROOT=self.workdir):
        self.ajax_get('{}?name={}'.format(url, name))
    self.assertFalse(os.path.exists(path))