-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move classes from conftest into separate module
The goal is to get rid of imports from tests/unit/conftest.py file. For this purpose FixPluginLegacy, DummyNotificationHandler and DummyLicensingHandler classes were moved from the conftest into a separate module mocks_and_helpers.py. Jira ticket: CMK-21864 Change-Id: I31c21eaf1b20199b73591d95f7c0a909f650715d
- Loading branch information
Showing
7 changed files
with
78 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (C) 2025 Checkmk GmbH - License: GNU General Public License v2 | ||
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and | ||
# conditions defined in the file COPYING, which is part of this source code package. | ||
|
||
from tests.testlib.common.repo import ( | ||
repo_path, | ||
) | ||
|
||
import cmk.ccc.debug | ||
from cmk.ccc import store | ||
|
||
import cmk.utils.caching | ||
import cmk.utils.paths | ||
from cmk.utils.licensing.handler import ( | ||
LicenseState, | ||
LicensingHandler, | ||
NotificationHandler, | ||
UserEffect, | ||
) | ||
|
||
import cmk.crypto.password_hashing | ||
from cmk.agent_based.legacy import discover_legacy_checks, FileLoader, find_plugin_files | ||
|
||
|
||
class FixPluginLegacy: | ||
"""Access legacy dicts like `check_info`""" | ||
|
||
def __init__(self) -> None: | ||
result = discover_legacy_checks( | ||
find_plugin_files(str(repo_path() / "cmk/base/legacy_checks")), | ||
FileLoader( | ||
precomile_path=cmk.utils.paths.precompiled_checks_dir, | ||
local_path="/not_relevant_for_test", | ||
makedirs=store.makedirs, | ||
), | ||
raise_errors=True, | ||
) | ||
self.check_info = {p.name: p for p in result.sane_check_info} | ||
|
||
|
||
class DummyNotificationHandler(NotificationHandler): | ||
def manage_notification(self) -> None: | ||
pass | ||
|
||
|
||
class DummyLicensingHandler(LicensingHandler): | ||
@classmethod | ||
def make(cls) -> "DummyLicensingHandler": | ||
return cls() | ||
|
||
@property | ||
def state(self) -> LicenseState: | ||
return LicenseState.LICENSED | ||
|
||
@property | ||
def message(self) -> str: | ||
return "" | ||
|
||
def effect_core(self, num_services: int, num_hosts_shadow: int) -> UserEffect: | ||
return UserEffect(header=None, email=None, block=None) | ||
|
||
def effect(self, licensing_settings_link: str | None = None) -> UserEffect: | ||
return UserEffect(header=None, email=None, block=None) | ||
|
||
@property | ||
def notification_handler(self) -> NotificationHandler: | ||
return DummyNotificationHandler(email_notification=None) |