add tests

This commit is contained in:
wh1te909
2022-06-01 19:14:30 +00:00
parent c540f802b0
commit 312774e472
4 changed files with 74 additions and 22 deletions

View File

@@ -6,7 +6,6 @@ include = *.py
omit =
*/__pycache__/*
*/env/*
*/management/*
*/migrations/*
*/static/*
manage.py

View 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)

View File

@@ -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):

View File

@@ -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",
)