mirror of
https://github.com/onionshare/onionshare.git
synced 2025-05-19 06:40:22 -04:00
Move ZipWriter from common into web, because that's the only place it's used
This commit is contained in:
parent
73e7e2285f
commit
d2a11e696e
5 changed files with 143 additions and 111 deletions
|
@ -31,12 +31,10 @@ import pytest
|
|||
|
||||
from onionshare import common
|
||||
|
||||
DEFAULT_ZW_FILENAME_REGEX = re.compile(r'^onionshare_[a-z2-7]{6}.zip$')
|
||||
LOG_MSG_REGEX = re.compile(r"""
|
||||
^\[Jun\ 06\ 2013\ 11:05:00\]
|
||||
\ TestModule\.<function\ TestLog\.test_output\.<locals>\.dummy_func
|
||||
\ at\ 0x[a-f0-9]+>(:\ TEST_MSG)?$""", re.VERBOSE)
|
||||
RANDOM_STR_REGEX = re.compile(r'^[a-z2-7]+$')
|
||||
SLUG_REGEX = re.compile(r'^([a-z]+)(-[a-z]+)?-([a-z]+)(-[a-z]+)?$')
|
||||
|
||||
|
||||
|
@ -296,59 +294,3 @@ class TestSetDebug:
|
|||
def test_debug_false(self, set_debug_true):
|
||||
common.set_debug(False)
|
||||
assert common.debug is False
|
||||
|
||||
|
||||
class TestZipWriterDefault:
|
||||
@pytest.mark.parametrize('test_input', (
|
||||
'onionshare_{}.zip'.format(''.join(
|
||||
random.choice('abcdefghijklmnopqrstuvwxyz234567') for _ in range(6)
|
||||
)) for _ in range(50)
|
||||
))
|
||||
def test_default_zw_filename_regex(self, test_input):
|
||||
assert bool(DEFAULT_ZW_FILENAME_REGEX.match(test_input))
|
||||
|
||||
def test_zw_filename(self, default_zw):
|
||||
zw_filename = os.path.basename(default_zw.zip_filename)
|
||||
assert bool(DEFAULT_ZW_FILENAME_REGEX.match(zw_filename))
|
||||
|
||||
def test_zipfile_filename_matches_zipwriter_filename(self, default_zw):
|
||||
assert default_zw.z.filename == default_zw.zip_filename
|
||||
|
||||
def test_zipfile_allow_zip64(self, default_zw):
|
||||
assert default_zw.z._allowZip64 is True
|
||||
|
||||
def test_zipfile_mode(self, default_zw):
|
||||
assert default_zw.z.mode == 'w'
|
||||
|
||||
def test_callback(self, default_zw):
|
||||
assert default_zw.processed_size_callback(None) is None
|
||||
|
||||
def test_add_file(self, default_zw, temp_file_1024_delete):
|
||||
default_zw.add_file(temp_file_1024_delete)
|
||||
zipfile_info = default_zw.z.getinfo(
|
||||
os.path.basename(temp_file_1024_delete))
|
||||
|
||||
assert zipfile_info.compress_type == zipfile.ZIP_DEFLATED
|
||||
assert zipfile_info.file_size == 1024
|
||||
|
||||
def test_add_directory(self, temp_dir_1024_delete, default_zw):
|
||||
previous_size = default_zw._size # size before adding directory
|
||||
default_zw.add_dir(temp_dir_1024_delete)
|
||||
assert default_zw._size == previous_size + 1024
|
||||
|
||||
|
||||
class TestZipWriterCustom:
|
||||
@pytest.mark.parametrize('test_input', (
|
||||
common.random_string(
|
||||
random.randint(2, 50),
|
||||
random.choice((None, random.randint(2, 50)))
|
||||
) for _ in range(50)
|
||||
))
|
||||
def test_random_string_regex(self, test_input):
|
||||
assert bool(RANDOM_STR_REGEX.match(test_input))
|
||||
|
||||
def test_custom_filename(self, custom_zw):
|
||||
assert bool(RANDOM_STR_REGEX.match(custom_zw.zip_filename))
|
||||
|
||||
def test_custom_callback(self, custom_zw):
|
||||
assert custom_zw.processed_size_callback(None) == 'custom_callback'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue