Example #1
0
 def test_multiple_file_upload(self):
     tmp_text_file = self._generate_text_file()
     tmp_img_file = self._generate_image_file()
     fur = FileUploadRequestData([tmp_text_file, tmp_img_file])
     response = yield self.as_client.fetch(self.upload_url, method='POST', body=fur.get_body(),
                                           headers=fur.get_headers())
     data = json.loads(response.body.decode())
Example #2
0
 def test_single_file_upload(self):
     tmp_text_file = self._generate_text_file()
     fur = FileUploadRequestData([tmp_text_file])
     response = yield self.as_client.fetch(self.upload_url, method='POST', body=fur.get_body(),
                                           headers=fur.get_headers())
     data = json.loads(response.body.decode())
     self.assertEqual(data['files'][0]['file_name'], tmp_text_file.name.split('/')[-1])
Example #3
0
 def test_create_with_file(self):
     tmp_text_file = self._generate_text_file()
     fur = FileUploadRequestData([tmp_text_file])
     response = yield self.as_client.fetch(self.upload_url, method='POST', body=fur.get_body(),
                                           headers=fur.get_headers())
     file_data = json.loads(response.body.decode())
     data = {
         'name': 'foo',
         'file': [file_data['files'][0]]
     }
     self.connection.call_verb('withfile-route', 'create', **data)
     last_data = self.connection.get_last_message()['data']
     self.assertGreater(len(last_data['file']), 0)
Example #4
0
    def test_create_with_multiple_files(self):
        tmp_text_file = self._generate_text_file()
        tmp_img_file = self._generate_image_file()
        fur = FileUploadRequestData([tmp_text_file, tmp_img_file])
        response = yield self.as_client.fetch(self.upload_url, method='POST', body=fur.get_body(),
                                              headers=fur.get_headers())
        file_data = json.loads(response.body.decode())
        data = {
            'text': 'foo',
            'files': [{'file': f} for f in file_data['files']]
        }

        self.connection.call_verb('multifile-route', 'create', **data)
        last_data = self.connection.get_last_message()['data']
        self.assertEqual(len(last_data['files']), 2)