def test_temporary_file(self):
        a = SecureTemporaryFile(Settings.tmp_path)
        antani = "0123456789"
        with a.open('w') as f:
            for _ in range(1000):
                f.write(antani)
            f.finalize_write()

        with a.open('r') as f:
            for x in range(1000):
                self.assertTrue(antani == f.read(10))
    def test_temporary_file(self):
        a = SecureTemporaryFile(Settings.tmp_path)
        antani = "0123456789"
        with a.open('w') as f:
            for _ in range(1000):
                f.write(antani)
            f.finalize_write()

        with a.open('r') as f:
            for x in range(1000):
                self.assertTrue(antani == text_type(f.read(10), 'utf-8'))
Beispiel #3
0
def get_dummy_file(filename=None, content=None):
    global files_count
    files_count += 1

    if filename is None:
        filename = ''.join(six.unichr(x) for x in range(0x400, 0x40A)).join('-%d' % files_count)

    content_type = u'application/octet'

    if content is None:
        content = base64.b64decode(VALID_BASE64_IMG)

    temporary_file = SecureTemporaryFile(Settings.tmp_path)

    with temporary_file.open('w') as f:
        f.write(content)
        f.finalize_write()

    State.TempUploadFiles[os.path.basename(temporary_file.filepath)] = temporary_file

    return {
        'date': datetime_now(),
        'name': filename,
        'description': 'description',
        'body': temporary_file,
        'size': len(content),
        'filename': os.path.basename(temporary_file.filepath),
        'type': content_type,
        'submission': False
    }
Beispiel #4
0
def get_dummy_file(filename=None, content=None):
    global files_count
    files_count += 1

    if filename is None:
        filename = ''.join(six.unichr(x) for x in range(0x400, 0x40A)).join('-%d' % files_count)

    content_type = u'application/octet'

    if content is None:
        content = base64.b64decode(VALID_BASE64_IMG)

    temporary_file = SecureTemporaryFile(Settings.tmp_path)

    with temporary_file.open('w') as f:
        f.write(content)
        f.finalize_write()

    State.TempUploadFiles[os.path.basename(temporary_file.filepath)] = temporary_file

    return {
        'date': datetime_now(),
        'name': filename,
        'description': 'description',
        'body': temporary_file,
        'size': len(content),
        'filename': os.path.basename(temporary_file.filepath),
        'type': content_type,
        'submission': False
    }
Beispiel #5
0
def get_dummy_file(content=None):
    filename = generateRandomKey()

    content_type = 'application/octet'

    if content is None:
        content = base64.b64decode(VALID_BASE64_IMG)

    temporary_file = SecureTemporaryFile(Settings.tmp_path)

    with temporary_file.open('w') as f:
        f.write(content)
        f.finalize_write()

    State.TempUploadFiles[os.path.basename(
        temporary_file.filepath)] = temporary_file

    return {
        'id': filename,
        'date': datetime_now(),
        'name': filename,
        'description': 'description',
        'body': temporary_file,
        'size': len(content),
        'filename': os.path.basename(temporary_file.filepath),
        'type': content_type,
        'submission': False
    }