def test_upload_content_filename(self): grab = self.prepare_form_grab() data = b'foo' upload_data = UploadContent(data, filename='avatar.jpg') grab.doc.set_input('image', upload_data) grab.doc.submit(make_request=False) post = dict(grab.config['multipart_post']) self.assertTrue(isinstance(post['image'], UploadContent)) grab.doc.submit() self.assertEqual(data, self.server.request['files']['image'][0]['body']) self.assertEqual('avatar.jpg', self.server.request['files']['image'][0]['filename']) self.assertEqual( 'image/jpeg', self.server.request['files']['image'][0]['content_type'])
def test_upload_content_random_filename(self): grab = self.prepare_form_grab() data = b'foo' upload_data = UploadContent(data) grab.doc.set_input('image', upload_data) grab.doc.submit(make_request=False) post = dict(grab.config['multipart_post']) self.assertTrue(isinstance(post['image'], UploadContent)) grab.doc.submit() self.assertEqual(data, self.server.request['files']['image'][0]['body']) self.assertEqual( 10, len(self.server.request['files']['image'][0]['filename'])) self.assertEqual( 'application/octet-stream', self.server.request['files']['image'][0]['content_type'])
def test(self): fc = UploadContent('a') self.assertEqual(fc, 'xxx') self.g.set_input('image', fc)