Ejemplo n.º 1
0
    def test_upload(self):
        #   Pretend to upload a file
        file_data = "here is some test data"
        file_size = len(file_data)
        handler = MemoryFileUploadHandler()
        handler.handle_raw_input(file_data, None, file_size, None)
        try:
            handler.new_file('test', 'test_file.txt', 'text/plain', file_size)
        except StopFutureHandlers:
            pass
        file = handler.file_complete(file_size)
        media = Media(friendly_name = 'Test QSD Media')
        media.handle_file(file, file.name)
        media.save()

        #   Check that the file can be downloaded from the proper link
        url = '/download/%s' % media.hashed_name
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)

        #   Delete the QSD Media object
        media.delete()

        #   Check that the file can no longer be downloaded
        response = self.client.get(url)
        self.assertEqual(response.status_code, 404)
Ejemplo n.º 2
0
    def test_upload(self):
        #   Pretend to upload a file
        file_data = "here is some test data"
        file_size = len(file_data)
        handler = MemoryFileUploadHandler()
        handler.handle_raw_input(file_data, None, file_size, None)
        try:
            handler.new_file('test', 'test_file.txt', 'text/plain', file_size)
        except StopFutureHandlers:
            pass
        file = handler.file_complete(file_size)
        media = Media(friendly_name='Test QSD Media')
        media.handle_file(file, file.name)
        media.save()

        #   Check that the file can be downloaded from the proper link
        url = '/download/%s' % media.hashed_name
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)

        #   Delete the QSD Media object
        media.delete()

        #   Check that the file can no longer be downloaded
        response = self.client.get(url)
        self.assertEqual(response.status_code, 404)
Ejemplo n.º 3
0
 def new_file(self, field_name, file_name, content_type, *args, **kwargs):
     if content_type == WavUploadHander.mimeType:
         MemoryFileUploadHandler.new_file(self, field_name, file_name,
                                          content_type, *args, **kwargs)
     else:
         raise TypeError(
             f"Audio file has wrong format, {content_type}. Requires a Wav file instead"
         )