def setUp(self): super(CreateChannelTestCase, self).setUp() self.topic = cc.ContentKind.objects.get(kind='topic') self.license = cc.License.objects.all()[0] self.fileobj_audio = create_temp_file("abc", preset='audio', ext='mp3') self.fileobj_video = create_temp_file("def", preset='high_res_video', ext='mp4') self.fileobj_document = create_temp_file("ghi", preset='document', ext='pdf') self.fileobj_exercise = create_temp_file("jkl", preset='exercise', ext='perseus')
def test_file_upload(self): file_data = create_temp_file("Just some data.") f = SimpleUploadedFile(file_data['name'], file_data['data']) response = self.post(self.file_upload_url, {'file': f}, format='multipart') assert response.status_code == 200, "Call failed:\n output: {}".format( response.content)
def upload_temp_file(self, data, preset='document', ext='pdf'): """ Uploads a file to the server using an authorized client. """ fileobj_temp = testdata.create_temp_file(data, preset=preset, ext=ext) name = fileobj_temp['name'] f = SimpleUploadedFile(name, data) file_upload_url = str(reverse_lazy('api_file_upload')) return fileobj_temp, self.admin_client().post(file_upload_url, {"file": f})
def _add_temp_file_to_content_node(self, node): new_file = create_temp_file('mybytes') db_file = new_file['db_file'] assert node.files.filter(checksum=db_file.checksum).count() == 0 db_file.contentnode = node db_file.save() node.changed = True node.save() return db_file
def test_file_upload(self): file_data = create_temp_file("Just some data.") f = SimpleUploadedFile(file_data['name'], file_data['data']) response = self.post(self.file_upload_url, {'file': f}, format='multipart') assert response.status_code == 200, "Call failed:\n output: {}".format(response.content)
def test_file_upload_bad_hash(self): file_data = create_temp_file("Just some data.") f = SimpleUploadedFile("myfile.txt", file_data['data']) response = self.post(self.file_upload_url, {'file': f}, format='multipart') assert response.status_code == 500