Exemplo n.º 1
0
def test_create_archive_files(taskmanager):
    zip_blob = models.Blob.create_from_file(ZIP_DOCX)
    listing_blob = archives.unarchive(zip_blob)

    zip_parent_dir = models.Directory.objects.create()
    zip_file = models.File.objects.create(
        name_bytes=JERRY_ZIP.name.encode('utf8'),
        parent_directory=zip_parent_dir,
        ctime=time_from_unix(0),
        mtime=time_from_unix(0),
        size=0,
        original=zip_blob,
        blob=zip_blob,
    )

    filesystem.create_archive_files(zip_file.pk, listing_blob)

    assert models.Directory.objects.count() == 2  # root and fake dir
    assert models.File.objects.count() == 3  # zip, docx and doc

    file_names = set(f.name for f in models.File.objects.all())
    assert file_names == {
        'jerry.zip', 'AppBody-Sample-English.docx', 'sample.doc'
    }

    assert models.Directory.objects.get(
        container_file__isnull=False).container_file == zip_file
Exemplo n.º 2
0
def test_unarchive_tar_gz(taskmanager):
    tar_gz_blob = models.Blob.create_from_file(TAR_GZ)
    listing_blob = archives.unarchive(tar_gz_blob)
    with listing_blob.open() as f:
        listing = json.load(f)

    [tar_file] = listing
    assert tar_file['type'] == 'file'

    tar_blob = models.Blob.objects.get(pk=tar_file['blob_pk'])
    listing_blob = archives.unarchive(tar_blob)
    with listing_blob.open() as f:
        listing = json.load(f)

    assert set(f['name'] for f in listing) == {
        'sample (1).doc',
        'Sample_BulletsAndNumberings.docx',
        'cap33.pdf',
    }
Exemplo n.º 3
0
def test_unarchive_rar(taskmanager):
    rar = models.Blob.create_from_file(RAR)
    listing_blob = archives.unarchive(rar)
    with listing_blob.open() as f:
        listing = json.load(f)

    assert set(f['name'] for f in listing) == {
        'sample (1).doc',
        'Sample_BulletsAndNumberings.docx',
        'cap33.pdf',
    }
Exemplo n.º 4
0
def test_unarchive_zip(taskmanager):
    zip_blob = models.Blob.create_from_file(JERRY_ZIP)
    listing_blob = archives.unarchive(zip_blob)
    with listing_blob.open() as f:
        listing = json.load(f)

    assert listing[0]['name'] == 'jerry'
    assert listing[0]['type'] == 'directory'
    assert ETC_DIR in listing[0]['children']
    assert PACKAGE_JSON in listing[0]['children']
    assert WHAT_DIR in listing[0]['children']
    assert MOUSE_DIR in listing[0]['children']
Exemplo n.º 5
0
def test_unarchive_mbox(taskmanager):
    mbox_blob = models.Blob.create_from_file(SHAPELIB_MBOX)
    listing_blob = archives.unarchive(mbox_blob)
    with listing_blob.open() as f:
        listing = json.load(f)

    assert len(listing) == 28
    assert listing[0] == {
         'children': [
            {'blob_pk': '7779d128a2cd425eba06693b56e1fc7351c1d66c2ee78c96dd4bd5649307f636',
             'name': '0716d9708d321ffb6a00818614779e779925365c.eml',
             'type': 'file'}],
         'name': '07',
         'type': 'directory'}
Exemplo n.º 6
0
def test_unarchive_pst(taskmanager):
    pst_blob = models.Blob.create_from_file(JANE_DOE_PST)
    listing_blob = archives.unarchive(pst_blob)
    with listing_blob.open() as f:
        listing = json.load(f)

    EML_NUMBER_5 = {
        "type": "file",
        "name": "5.eml",
        "blob_pk": "9c007ccf1720d6279fc64389321fd83e053c9c4abc885a1745e9bc6793d515c9"
    }

    [root_dir] = listing
    assert root_dir['name'] == '*****@*****.**'
    assert root_dir['type'] == 'directory'
    assert len(root_dir['children']) == 3