Finish refactor of the new compressed file class support. Closes GitLab issue #7.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
BIN
mayan/apps/common/tests/contrib/test_file.tar
Normal file
BIN
mayan/apps/common/tests/contrib/test_file.tar
Normal file
Binary file not shown.
BIN
mayan/apps/common/tests/contrib/test_file.tar.bz2
Normal file
BIN
mayan/apps/common/tests/contrib/test_file.tar.bz2
Normal file
Binary file not shown.
BIN
mayan/apps/common/tests/contrib/test_file.tar.gz
Normal file
BIN
mayan/apps/common/tests/contrib/test_file.tar.gz
Normal file
Binary file not shown.
BIN
mayan/apps/common/tests/contrib/test_file.zip
Normal file
BIN
mayan/apps/common/tests/contrib/test_file.zip
Normal file
Binary file not shown.
1
mayan/apps/common/tests/contrib/test_file1.txt
Normal file
1
mayan/apps/common/tests/contrib/test_file1.txt
Normal file
@@ -0,0 +1 @@
|
||||
TEST FILE 1
|
||||
1
mayan/apps/common/tests/contrib/test_file2.txt
Normal file
1
mayan/apps/common/tests/contrib/test_file2.txt
Normal file
@@ -0,0 +1 @@
|
||||
TEST FILE 2
|
||||
1
mayan/apps/common/tests/contrib/test_file3.txt
Normal file
1
mayan/apps/common/tests/contrib/test_file3.txt
Normal file
@@ -0,0 +1 @@
|
||||
TEST FILE 3
|
||||
@@ -1,5 +1,38 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
TEST_ERROR_LOG_ENTRY_RESULT = 'test_error_log_entry_result_text'
|
||||
TEST_VIEW_NAME = 'test view name'
|
||||
TEST_VIEW_URL = 'test-view-url'
|
||||
|
||||
# Filenames
|
||||
TEST_FILENAME1 = 'test_file1.txt'
|
||||
TEST_FILENAME2 = 'test_file2.txt'
|
||||
TEST_FILENAME3 = 'test_file3.txt'
|
||||
TEST_FILE_CONTENTS_1 = 'TEST FILE 1\n'
|
||||
TEST_FILE_CONTENTS_2 = 'TEST FILE 2\n'
|
||||
TEST_TAR_BZ2_FILE = 'test_file.tar.bz2'
|
||||
TEST_TAR_FILE = 'test_file.tar'
|
||||
TEST_TAR_GZ_FILE = 'test_file.tar.gz'
|
||||
TEST_ZIP_FILE = 'test_file.zip'
|
||||
TEST_COMPRESSED_FILE_CONTENTS = [TEST_FILENAME1, TEST_FILENAME2]
|
||||
|
||||
# File paths
|
||||
TEST_FILE3_PATH = os.path.join(
|
||||
settings.BASE_DIR, 'apps', 'common', 'tests', 'contrib', TEST_FILENAME3
|
||||
)
|
||||
TEST_TAR_BZ2_FILE_PATH = os.path.join(
|
||||
settings.BASE_DIR, 'apps', 'common', 'tests', 'contrib', TEST_TAR_BZ2_FILE
|
||||
)
|
||||
TEST_TAR_FILE_PATH = os.path.join(
|
||||
settings.BASE_DIR, 'apps', 'common', 'tests', 'contrib', TEST_TAR_FILE
|
||||
)
|
||||
TEST_TAR_GZ_FILE_PATH = os.path.join(
|
||||
settings.BASE_DIR, 'apps', 'common', 'tests', 'contrib', TEST_TAR_GZ_FILE
|
||||
)
|
||||
TEST_ZIP_FILE_PATH = os.path.join(
|
||||
settings.BASE_DIR, 'apps', 'common', 'tests', 'contrib', TEST_ZIP_FILE
|
||||
)
|
||||
|
||||
70
mayan/apps/common/tests/test_compressed_files.py
Normal file
70
mayan/apps/common/tests/test_compressed_files.py
Normal file
@@ -0,0 +1,70 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from common.tests import BaseTestCase
|
||||
from django.test import override_settings
|
||||
|
||||
from ..compressed_files import Archive, TarArchive, ZipArchive
|
||||
|
||||
from .literals import (
|
||||
TEST_COMPRESSED_FILE_CONTENTS, TEST_FILE_CONTENTS_1, TEST_FILE_CONTENTS_2,
|
||||
TEST_FILE3_PATH, TEST_FILENAME1, TEST_FILENAME2, TEST_FILENAME3,
|
||||
TEST_TAR_BZ2_FILE_PATH, TEST_TAR_FILE_PATH, TEST_TAR_GZ_FILE_PATH,
|
||||
TEST_ZIP_FILE_PATH
|
||||
)
|
||||
|
||||
|
||||
class TarArchiveClassTestCase(BaseTestCase):
|
||||
archive_path = TEST_TAR_FILE_PATH
|
||||
cls = TarArchive
|
||||
filename = TEST_FILENAME3
|
||||
file_path = TEST_FILE3_PATH
|
||||
members_list = TEST_COMPRESSED_FILE_CONTENTS
|
||||
member_name = TEST_FILENAME1
|
||||
member_contents = TEST_FILE_CONTENTS_1
|
||||
|
||||
def test_add_file(self):
|
||||
archive = self.cls()
|
||||
archive.create()
|
||||
with open(self.file_path) as file_object:
|
||||
archive.add_file(file_object=file_object, filename=self.filename)
|
||||
self.assertTrue(archive.members(), [self.filename])
|
||||
|
||||
def test_open(self):
|
||||
with open(self.archive_path) as file_object:
|
||||
archive = Archive.open(file_object=file_object)
|
||||
self.assertTrue(isinstance(archive, self.cls))
|
||||
|
||||
def test_members(self):
|
||||
with open(self.archive_path) as file_object:
|
||||
archive = Archive.open(file_object=file_object)
|
||||
self.assertEqual(archive.members(), self.members_list)
|
||||
|
||||
def test_member_contents(self):
|
||||
with open(self.archive_path) as file_object:
|
||||
archive = Archive.open(file_object=file_object)
|
||||
self.assertEqual(
|
||||
archive.member_contents(filename=self.member_name), self.member_contents
|
||||
)
|
||||
|
||||
def test_open_member(self):
|
||||
with open(self.archive_path) as file_object:
|
||||
archive = Archive.open(file_object=file_object)
|
||||
file_object = archive.open_member(filename=self.member_name)
|
||||
self.assertEqual(
|
||||
file_object.read(), self.member_contents
|
||||
)
|
||||
|
||||
|
||||
class ZipArchiveClassTestCase(TarArchiveClassTestCase):
|
||||
archive_path = TEST_ZIP_FILE_PATH
|
||||
cls = ZipArchive
|
||||
|
||||
|
||||
class TarGzArchiveClassTestCase(TarArchiveClassTestCase):
|
||||
archive_path = TEST_TAR_GZ_FILE_PATH
|
||||
cls = TarArchive
|
||||
|
||||
|
||||
class TarBz2ArchiveClassTestCase(TarArchiveClassTestCase):
|
||||
archive_path = TEST_TAR_BZ2_FILE_PATH
|
||||
cls = TarArchive
|
||||
Reference in New Issue
Block a user