Skip to content

Commit

Permalink
Changed tests to use path spec factory #535 (#571)
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz authored May 24, 2021
1 parent f1a7a26 commit 58b3344
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 190 deletions.
32 changes: 18 additions & 14 deletions tests/mount/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

import unittest

from dfvfs.lib import definitions
from dfvfs.lib import errors
from dfvfs.mount import manager
from dfvfs.path import mount_path_spec
from dfvfs.path import os_path_spec
from dfvfs.path import qcow_path_spec
from dfvfs.path import tsk_path_spec
from dfvfs.path import factory as path_spec_factory
from dfvfs.resolver import context
from dfvfs.resolver import resolver

Expand All @@ -22,11 +20,13 @@ class MountPointManagerTest(shared_test_lib.BaseTestCase):
def setUp(self):
"""Sets up the needed objects used throughout the test."""
self._resolver_context = context.Context()
test_file = self._GetTestFilePath(['ext2.qcow2'])
self._SkipIfPathNotExists(test_file)
test_path = self._GetTestFilePath(['ext2.qcow2'])
self._SkipIfPathNotExists(test_path)

path_spec = os_path_spec.OSPathSpec(location=test_file)
self._qcow_path_spec = qcow_path_spec.QCOWPathSpec(parent=path_spec)
test_os_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
self._qcow_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_QCOW, parent=test_os_path_spec)

def testGetMountPoint(self):
"""Function to test the get mount point function."""
Expand All @@ -44,18 +44,22 @@ def testOpenFileObject(self):
"""Function to test mount point resolving."""
manager.MountPointManager.RegisterMountPoint('C', self._qcow_path_spec)

parent_path_spec = mount_path_spec.MountPathSpec(identifier='C')
path_spec = tsk_path_spec.TSKPathSpec(
location='/passwords.txt', parent=parent_path_spec)
parent_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_MOUNT, identifier='C')
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.PREFERRED_EXT_BACK_END, location='/passwords.txt',
parent=parent_path_spec)
file_object = resolver.Resolver.OpenFileObject(
path_spec, resolver_context=self._resolver_context)

self.assertIsNotNone(file_object)
self.assertEqual(file_object.get_size(), 116)

parent_path_spec = mount_path_spec.MountPathSpec(identifier='D')
path_spec = tsk_path_spec.TSKPathSpec(
location='/passwords.txt', parent=parent_path_spec)
parent_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_MOUNT, identifier='D')
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.PREFERRED_EXT_BACK_END, location='/passwords.txt',
parent=parent_path_spec)

with self.assertRaises(errors.MountPointError):
file_object = resolver.Resolver.OpenFileObject(
Expand Down
14 changes: 8 additions & 6 deletions tests/vfs/gzip_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import unittest

from dfvfs.path import gzip_path_spec
from dfvfs.path import os_path_spec
from dfvfs.lib import definitions
from dfvfs.path import factory as path_spec_factory
from dfvfs.resolver import context
from dfvfs.vfs import gzip_file_entry
from dfvfs.vfs import gzip_file_system
Expand All @@ -19,11 +19,13 @@ class GZIPFileEntryTest(shared_test_lib.BaseTestCase):
def setUp(self):
"""Sets up the needed objects used throughout the test."""
self._resolver_context = context.Context()
test_file = self._GetTestFilePath(['syslog.gz'])
self._SkipIfPathNotExists(test_file)
test_path = self._GetTestFilePath(['syslog.gz'])
self._SkipIfPathNotExists(test_path)

path_spec = os_path_spec.OSPathSpec(location=test_file)
self._gzip_path_spec = gzip_path_spec.GzipPathSpec(parent=path_spec)
test_os_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
self._gzip_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_GZIP, parent=test_os_path_spec)

self._file_system = gzip_file_system.GzipFileSystem(
self._resolver_context, self._gzip_path_spec)
Expand Down
66 changes: 38 additions & 28 deletions tests/vfs/os_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import unittest

from dfvfs.path import os_path_spec
from dfvfs.lib import definitions
from dfvfs.path import factory as path_spec_factory
from dfvfs.resolver import context
from dfvfs.vfs import os_file_entry
from dfvfs.vfs import os_file_system
Expand All @@ -18,10 +19,11 @@ class OSDirectoryTest(shared_test_lib.BaseTestCase):
def setUp(self):
"""Sets up the needed objects used throughout the test."""
self._resolver_context = context.Context()
test_file = self._GetTestFilePath(['testdir_os'])
self._SkipIfPathNotExists(test_file)
test_path = self._GetTestFilePath(['testdir_os'])
self._SkipIfPathNotExists(test_path)

self._os_path_spec = os_path_spec.OSPathSpec(location=test_file)
self._os_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)

self._file_system = os_file_system.OSFileSystem(
self._resolver_context, self._os_path_spec)
Expand Down Expand Up @@ -55,10 +57,11 @@ class OSFileEntryTest(shared_test_lib.BaseTestCase):
def setUp(self):
"""Sets up the needed objects used throughout the test."""
self._resolver_context = context.Context()
test_file = self._GetTestFilePath(['testdir_os'])
self._SkipIfPathNotExists(test_file)
test_path = self._GetTestFilePath(['testdir_os'])
self._SkipIfPathNotExists(test_path)

self._os_path_spec = os_path_spec.OSPathSpec(location=test_file)
self._os_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)

self._file_system = os_file_system.OSFileSystem(
self._resolver_context, self._os_path_spec)
Expand Down Expand Up @@ -141,10 +144,11 @@ def testGetFileEntryByPathSpec(self):

def testGetParentFileEntry(self):
"""Tests the GetParentFileEntry function."""
test_file = self._GetTestFilePath(['testdir_os', 'file1.txt'])
self._SkipIfPathNotExists(test_file)
test_path = self._GetTestFilePath(['testdir_os', 'file1.txt'])
self._SkipIfPathNotExists(test_path)

path_spec = os_path_spec.OSPathSpec(location=test_file)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
self.assertIsNotNone(file_entry)

Expand All @@ -156,10 +160,11 @@ def testGetParentFileEntry(self):

def testGetStat(self):
"""Tests the GetStat function."""
test_file = self._GetTestFilePath(['testdir_os', 'file1.txt'])
self._SkipIfPathNotExists(test_file)
test_path = self._GetTestFilePath(['testdir_os', 'file1.txt'])
self._SkipIfPathNotExists(test_path)

path_spec = os_path_spec.OSPathSpec(location=test_file)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
self.assertIsNotNone(file_entry)

Expand All @@ -176,10 +181,11 @@ def testGetStat(self):

def testIsFunctions(self):
"""Test the Is? functions."""
test_file = self._GetTestFilePath(['testdir_os', 'file1.txt'])
self._SkipIfPathNotExists(test_file)
test_path = self._GetTestFilePath(['testdir_os', 'file1.txt'])
self._SkipIfPathNotExists(test_path)

path_spec = os_path_spec.OSPathSpec(location=test_file)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
self.assertIsNotNone(file_entry)

Expand All @@ -194,10 +200,11 @@ def testIsFunctions(self):
self.assertFalse(file_entry.IsPipe())
self.assertFalse(file_entry.IsSocket())

test_file = self._GetTestFilePath(['testdir_os'])
self._SkipIfPathNotExists(test_file)
test_path = self._GetTestFilePath(['testdir_os'])
self._SkipIfPathNotExists(test_path)

path_spec = os_path_spec.OSPathSpec(location=test_file)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
self.assertIsNotNone(file_entry)

Expand Down Expand Up @@ -234,10 +241,11 @@ def testSubFileEntries(self):

def testDataStreams(self):
"""Test the data streams functionality."""
test_file = self._GetTestFilePath(['testdir_os', 'file1.txt'])
self._SkipIfPathNotExists(test_file)
test_path = self._GetTestFilePath(['testdir_os', 'file1.txt'])
self._SkipIfPathNotExists(test_path)

path_spec = os_path_spec.OSPathSpec(location=test_file)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
self.assertIsNotNone(file_entry)

Expand All @@ -249,10 +257,11 @@ def testDataStreams(self):

self.assertEqual(data_stream_names, [''])

test_file = self._GetTestFilePath(['testdir_os'])
self._SkipIfPathNotExists(test_file)
test_path = self._GetTestFilePath(['testdir_os'])
self._SkipIfPathNotExists(test_path)

path_spec = os_path_spec.OSPathSpec(location=test_file)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
self.assertIsNotNone(file_entry)

Expand All @@ -266,10 +275,11 @@ def testDataStreams(self):

def testGetDataStream(self):
"""Tests the GetDataStream function."""
test_file = self._GetTestFilePath(['testdir_os', 'file1.txt'])
self._SkipIfPathNotExists(test_file)
test_path = self._GetTestFilePath(['testdir_os', 'file1.txt'])
self._SkipIfPathNotExists(test_path)

path_spec = os_path_spec.OSPathSpec(location=test_file)
path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
file_entry = self._file_system.GetFileEntryByPathSpec(path_spec)
self.assertIsNotNone(file_entry)

Expand Down
72 changes: 40 additions & 32 deletions tests/vfs/sqlite_blob_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import unittest

from dfvfs.path import sqlite_blob_path_spec
from dfvfs.path import os_path_spec
from dfvfs.lib import definitions
from dfvfs.path import factory as path_spec_factory
from dfvfs.resolver import context
from dfvfs.vfs import sqlite_blob_file_entry
from dfvfs.vfs import sqlite_blob_file_system
Expand All @@ -19,22 +19,26 @@ class SQLiteBlobDirectoryTest(shared_test_lib.BaseTestCase):
def setUp(self):
"""Sets up the needed objects used throughout the test."""
self._resolver_context = context.Context()
test_file = self._GetTestFilePath(['blob.db'])
self._SkipIfPathNotExists(test_file)

path_spec = os_path_spec.OSPathSpec(location=test_file)
self._sqlite_blob_path_spec = sqlite_blob_path_spec.SQLiteBlobPathSpec(
table_name='myblobs', column_name='blobs',
row_condition=('name', '==', 'mmssms.db'), parent=path_spec)
self._sqlite_blob_path_spec_2 = sqlite_blob_path_spec.SQLiteBlobPathSpec(
table_name='myblobs', column_name='blobs',
row_index=2, parent=path_spec)
self._sqlite_blob_path_spec_3 = sqlite_blob_path_spec.SQLiteBlobPathSpec(
table_name='myblobs', column_name='blobs',
row_condition=('name', '==', 4), parent=path_spec)
test_path = self._GetTestFilePath(['blob.db'])
self._SkipIfPathNotExists(test_path)

test_os_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
self._sqlite_blob_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_SQLITE_BLOB, column_name='blobs',
parent=test_os_path_spec, row_condition=('name', '==', 'mmssms.db'),
table_name='myblobs')
self._sqlite_blob_path_spec_2 = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_SQLITE_BLOB, column_name='blobs',
parent=test_os_path_spec, row_index=2, table_name='myblobs')
self._sqlite_blob_path_spec_3 = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_SQLITE_BLOB, column_name='blobs',
parent=test_os_path_spec, row_condition=('name', '==', 4),
table_name='myblobs')
self._sqlite_blob_path_spec_directory = (
sqlite_blob_path_spec.SQLiteBlobPathSpec(
table_name='myblobs', column_name='blobs', parent=path_spec))
path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_SQLITE_BLOB, column_name='blobs',
table_name='myblobs', parent=test_os_path_spec))

self._file_system = sqlite_blob_file_system.SQLiteBlobFileSystem(
self._resolver_context, self._sqlite_blob_path_spec)
Expand Down Expand Up @@ -68,22 +72,26 @@ class SQLiteBlobFileEntryTest(shared_test_lib.BaseTestCase):
def setUp(self):
"""Sets up the needed objects used throughout the test."""
self._resolver_context = context.Context()
test_file = self._GetTestFilePath(['blob.db'])
self._SkipIfPathNotExists(test_file)

path_spec = os_path_spec.OSPathSpec(location=test_file)
self._sqlite_blob_path_spec = sqlite_blob_path_spec.SQLiteBlobPathSpec(
table_name='myblobs', column_name='blobs',
row_condition=('name', '==', 'mmssms.db'), parent=path_spec)
self._sqlite_blob_path_spec_2 = sqlite_blob_path_spec.SQLiteBlobPathSpec(
table_name='myblobs', column_name='blobs',
row_index=2, parent=path_spec)
self._sqlite_blob_path_spec_3 = sqlite_blob_path_spec.SQLiteBlobPathSpec(
table_name='myblobs', column_name='blobs',
row_condition=('name', '==', 4), parent=path_spec)
test_path = self._GetTestFilePath(['blob.db'])
self._SkipIfPathNotExists(test_path)

test_os_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_OS, location=test_path)
self._sqlite_blob_path_spec = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_SQLITE_BLOB, column_name='blobs',
parent=test_os_path_spec, row_condition=('name', '==', 'mmssms.db'),
table_name='myblobs')
self._sqlite_blob_path_spec_2 = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_SQLITE_BLOB, column_name='blobs',
parent=test_os_path_spec, row_index=2, table_name='myblobs')
self._sqlite_blob_path_spec_3 = path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_SQLITE_BLOB, column_name='blobs',
parent=test_os_path_spec, row_condition=('name', '==', 4),
table_name='myblobs')
self._sqlite_blob_path_spec_directory = (
sqlite_blob_path_spec.SQLiteBlobPathSpec(
table_name='myblobs', column_name='blobs', parent=path_spec))
path_spec_factory.Factory.NewPathSpec(
definitions.TYPE_INDICATOR_SQLITE_BLOB, column_name='blobs',
parent=test_os_path_spec, table_name='myblobs'))

self._file_system = sqlite_blob_file_system.SQLiteBlobFileSystem(
self._resolver_context, self._sqlite_blob_path_spec)
Expand Down
Loading

0 comments on commit 58b3344

Please sign in to comment.