add tests
This commit is contained in:
@@ -6,7 +6,6 @@ include = *.py
|
||||
omit =
|
||||
*/__pycache__/*
|
||||
*/env/*
|
||||
*/management/*
|
||||
*/migrations/*
|
||||
*/static/*
|
||||
manage.py
|
||||
|
||||
51
api/tacticalrmm/agents/tests/test_mgmt_commands.py
Normal file
51
api/tacticalrmm/agents/tests/test_mgmt_commands.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from typing import TYPE_CHECKING
|
||||
from unittest.mock import call, patch
|
||||
|
||||
from django.core.management import call_command
|
||||
from model_bakery import baker
|
||||
|
||||
from tacticalrmm.constants import AgentMonType, AgentPlat
|
||||
from tacticalrmm.test import TacticalTestCase
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from clients.models import Client, Site
|
||||
|
||||
|
||||
class TestBulkRestartAgents(TacticalTestCase):
|
||||
def setUp(self) -> None:
|
||||
self.authenticate()
|
||||
self.setup_coresettings()
|
||||
self.client1: "Client" = baker.make("clients.Client")
|
||||
self.site1: "Site" = baker.make("clients.Site", client=self.client1)
|
||||
|
||||
@patch("core.management.commands.bulk_restart_agents.sleep")
|
||||
@patch("agents.models.Agent.recover")
|
||||
@patch("core.management.commands.bulk_restart_agents.get_mesh_ws_url")
|
||||
def test_bulk_restart_agents_mgmt_cmd(
|
||||
self, get_mesh_ws_url, recover, mock_sleep
|
||||
) -> None:
|
||||
get_mesh_ws_url.return_value = "https://mesh.example.com/test"
|
||||
|
||||
baker.make_recipe(
|
||||
"agents.online_agent",
|
||||
site=self.site1,
|
||||
monitoring_type=AgentMonType.SERVER,
|
||||
plat=AgentPlat.WINDOWS,
|
||||
)
|
||||
|
||||
baker.make_recipe(
|
||||
"agents.online_agent",
|
||||
site=self.site1,
|
||||
monitoring_type=AgentMonType.SERVER,
|
||||
plat=AgentPlat.LINUX,
|
||||
)
|
||||
|
||||
calls = [
|
||||
call("tacagent", "https://mesh.example.com/test", wait=False),
|
||||
call("mesh", "", wait=False),
|
||||
]
|
||||
|
||||
call_command("bulk_restart_agents")
|
||||
|
||||
recover.assert_has_calls(calls)
|
||||
mock_sleep.assert_called_with(10)
|
||||
@@ -11,7 +11,7 @@ from rest_framework.authtoken.models import Token
|
||||
from agents.models import Agent
|
||||
from core.utils import get_core_settings
|
||||
from logs.models import PendingAction
|
||||
from tacticalrmm.constants import CustomFieldModel, PAAction, PAStatus
|
||||
from tacticalrmm.constants import CustomFieldModel, PAAction, PAStatus, CONFIG_MGMT_CMDS
|
||||
from tacticalrmm.test import TacticalTestCase
|
||||
|
||||
from .consumers import DashInfo
|
||||
@@ -430,26 +430,8 @@ class TestCoreMgmtCommands(TacticalTestCase):
|
||||
self.setup_coresettings()
|
||||
|
||||
def test_get_config(self):
|
||||
names = (
|
||||
"api",
|
||||
"version",
|
||||
"webversion",
|
||||
"meshver",
|
||||
"natsver",
|
||||
"frontend",
|
||||
"djangoadmin",
|
||||
"setuptoolsver",
|
||||
"wheelver",
|
||||
"dbname",
|
||||
"dbuser",
|
||||
"dbpw",
|
||||
"dbport",
|
||||
"meshsite",
|
||||
"meshuser",
|
||||
"meshtoken",
|
||||
)
|
||||
for name in names:
|
||||
call_command("get_config", name)
|
||||
for cmd in CONFIG_MGMT_CMDS:
|
||||
call_command("get_config", cmd)
|
||||
|
||||
|
||||
class TestCorePermissions(TacticalTestCase):
|
||||
|
||||
@@ -401,3 +401,23 @@ DEMO_NOT_ALLOWED = [
|
||||
{"name": "PendingActions", "methods": ["DELETE"]},
|
||||
{"name": "clear_cache", "methods": ["GET"]},
|
||||
]
|
||||
|
||||
CONFIG_MGMT_CMDS = (
|
||||
"api",
|
||||
"version",
|
||||
"webversion",
|
||||
"meshver",
|
||||
"natsver",
|
||||
"frontend",
|
||||
"djangoadmin",
|
||||
"setuptoolsver",
|
||||
"wheelver",
|
||||
"dbname",
|
||||
"dbuser",
|
||||
"dbhost",
|
||||
"dbpw",
|
||||
"dbport",
|
||||
"meshsite",
|
||||
"meshuser",
|
||||
"meshtoken",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user