-
-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
76 changed files
with
1,294 additions
and
195 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
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
18 changes: 18 additions & 0 deletions
18
api/tacticalrmm/agents/migrations/0059_alter_agenthistory_id.py
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,18 @@ | ||
# Generated by Django 4.2.10 on 2024-02-19 05:57 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("agents", "0058_alter_agent_time_zone"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="agenthistory", | ||
name="id", | ||
field=models.BigAutoField(primary_key=True, serialize=False), | ||
), | ||
] |
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,61 @@ | ||
from unittest.mock import patch | ||
|
||
from model_bakery import baker | ||
|
||
from agents.models import Agent | ||
from tacticalrmm.constants import AgentMonType | ||
from tacticalrmm.test import TacticalTestCase | ||
|
||
|
||
class AgentSaveTestCase(TacticalTestCase): | ||
def setUp(self): | ||
self.client1 = baker.make("clients.Client") | ||
self.client2 = baker.make("clients.Client") | ||
self.site1 = baker.make("clients.Site", client=self.client1) | ||
self.site2 = baker.make("clients.Site", client=self.client2) | ||
self.site3 = baker.make("clients.Site", client=self.client2) | ||
self.agent = baker.make( | ||
"agents.Agent", | ||
site=self.site1, | ||
monitoring_type=AgentMonType.SERVER, | ||
) | ||
|
||
@patch.object(Agent, "set_alert_template") | ||
def test_set_alert_template_called_on_mon_type_change( | ||
self, mock_set_alert_template | ||
): | ||
self.agent.monitoring_type = AgentMonType.WORKSTATION | ||
self.agent.save() | ||
mock_set_alert_template.assert_called_once() | ||
|
||
@patch.object(Agent, "set_alert_template") | ||
def test_set_alert_template_called_on_site_change(self, mock_set_alert_template): | ||
self.agent.site = self.site2 | ||
self.agent.save() | ||
mock_set_alert_template.assert_called_once() | ||
|
||
@patch.object(Agent, "set_alert_template") | ||
def test_set_alert_template_called_on_site_and_montype_change( | ||
self, mock_set_alert_template | ||
): | ||
print(f"before: {self.agent.monitoring_type} site: {self.agent.site_id}") | ||
self.agent.site = self.site3 | ||
self.agent.monitoring_type = AgentMonType.WORKSTATION | ||
self.agent.save() | ||
mock_set_alert_template.assert_called_once() | ||
print(f"after: {self.agent.monitoring_type} site: {self.agent.site_id}") | ||
|
||
@patch.object(Agent, "set_alert_template") | ||
def test_set_alert_template_not_called_without_changes( | ||
self, mock_set_alert_template | ||
): | ||
self.agent.save() | ||
mock_set_alert_template.assert_not_called() | ||
|
||
@patch.object(Agent, "set_alert_template") | ||
def test_set_alert_template_not_called_on_non_relevant_field_change( | ||
self, mock_set_alert_template | ||
): | ||
self.agent.hostname = "abc123" | ||
self.agent.save() | ||
mock_set_alert_template.assert_not_called() |
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
Oops, something went wrong.