Skip to content

Commit

Permalink
conftest: Don't use MockFSOrganizer in scheduler tests
Browse files Browse the repository at this point in the history
There were two problems with this:
* It created a new temporary directory in __init__ which made it
impossible to have the same directory accross different fixtures
(e.g. analysis_scheduler and unpacking_scheduler)
* It didn't do anything different than the real FSOrganizer
(despite using a temporary directory, but we do this in the tests
anyways)

Also this commit makes the analysis_scheduler use the same
FSOrganizer as the unpacking_scheduler.
This is required since AnalysisPluginV0 are used.
  • Loading branch information
maringuu committed Jul 17, 2023
1 parent 57deb7f commit 4067c84
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from storage.unpacking_locks import UnpackingLockManager
from test.common_helper import clear_test_tables, setup_test_tables
from test.integration.common import MockDbInterface as BackEndDbInterfaceMock
from test.integration.common import MockFSOrganizer as FSOrganizerMock

T = TypeVar('T')

Expand Down Expand Up @@ -322,6 +321,7 @@ def analysis_scheduler( # noqa: PLR0913

with MonkeyPatch.context() as mkp:
mkp.setattr('plugins.base.ViewUpdater', test_config.view_updater_class)
mkp.setattr('scheduler.analysis.plugin.FSOrganizer', test_config.fs_organizer_class)
_analysis_scheduler = AnalysisScheduler(
post_analysis=lambda *_: None,
unpacking_locks=_unpacking_lock_manager,
Expand Down Expand Up @@ -498,7 +498,7 @@ class SchedulerTestConfig(BaseModel):
comparison_db_class: Type
#: Set the class that is used as :py:class:`~storage.fsorganizer.FSOrganizer`.
#: This can be either a mocked class or the actual :py:class:`~storage.fsorganizer.FSOrganizer`.
#: This is used by the :py:func:`unpacking_scheduler`
#: This is used by the :py:func:`unpacking_scheduler` and the :py:func:`analysis_scheduler`.
fs_organizer_class: Type
#: Set the class that is used as :py:class:`~storage.db_interface_view_sync.ViewUpdater`.
#: If you set this to the actual :py:class:`~storage.db_interface_view_sync.ViewUpdater` note that the fixture
Expand Down Expand Up @@ -526,7 +526,7 @@ def Integration(**kwargs): # noqa: N802
{
'backend_db_class': BackendDbInterface,
'comparison_db_class': ComparisonDbInterface,
'fs_organizer_class': FSOrganizerMock,
'fs_organizer_class': FSOrganizer,
'view_updater_class': ViewUpdater,
'pipeline': False,
'start_processes': True,
Expand All @@ -542,7 +542,7 @@ def Unit(**kwargs): # noqa: N802
{
'backend_db_class': BackEndDbInterfaceMock,
'comparison_db_class': ComparisonDbInterface,
'fs_organizer_class': FSOrganizerMock,
'fs_organizer_class': FSOrganizer,
'view_updater_class': ViewUpdaterMock,
'pipeline': False,
'start_processes': False,
Expand Down
3 changes: 1 addition & 2 deletions src/test/integration/scheduler/test_unpack_and_analyse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
from objects.firmware import Firmware
from test.common_helper import get_test_data_dir

from test.integration.common import MockDbInterface, MockFSOrganizer
from test.integration.common import MockDbInterface


class TestFileAddition:
@pytest.mark.SchedulerTestConfig(
pipeline=True,
backend_db_class=MockDbInterface,
fs_organizer_class=MockFSOrganizer,
)
def test_unpack_and_analyse(self, analysis_scheduler, unpacking_scheduler, post_analysis_queue):
test_fw = Firmware(file_path=f'{get_test_data_dir()}/container/test.zip')
Expand Down

0 comments on commit 4067c84

Please sign in to comment.