Skip to content

Instantly share code, notes, and snippets.

@cansadadeserfeliz
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cansadadeserfeliz/f9dc7b342664e4990409 to your computer and use it in GitHub Desktop.
Save cansadadeserfeliz/f9dc7b342664e4990409 to your computer and use it in GitHub Desktop.
File attachments for Django test
from django.core.files.uploadedfile import SimpleUploadedFile
class UploadTestCase(TestCase):
def test_can_upload_file(self):
self.client.logout()
self.client.login(username='demo@demo.com', password='demo')
attachment = SimpleUploadedFile('attachment.pdf', 'file_content', content_type='application/pdf')
response = self.client.post(
reverse(
'contract:contract_update',
args=(contract.id,)
), {
'attachment_file': attachment,
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment