add test case for modules sync view

This commit is contained in:
wh1te909 2020-09-30 21:37:17 +00:00
parent 4df20cce1e
commit 414e7bec99
1 changed files with 34 additions and 2 deletions

View File

@ -1,3 +1,35 @@
from django.test import TestCase
from tacticalrmm.test import TacticalTestCase
from unittest.mock import patch
# Create your tests here.
class TestAPIv2(TacticalTestCase):
def setUp(self):
self.authenticate()
self.setup_coresettings()
self.agent_setup()
@patch("agents.models.Agent.salt_api_cmd")
def test_sync_modules(self, mock_ret):
url = "/api/v2/saltminion/"
payload = {"agent_id": self.agent.agent_id}
mock_ret.return_value = "error"
r = self.client.patch(url, payload, format="json")
self.assertEqual(r.status_code, 400)
mock_ret.return_value = []
r = self.client.patch(url, payload, format="json")
self.assertEqual(r.status_code, 200)
self.assertEqual(r.data, "Modules are already in sync")
mock_ret.return_value = ["modules.win_agent"]
r = self.client.patch(url, payload, format="json")
self.assertEqual(r.status_code, 200)
self.assertEqual(r.data, "Successfully synced salt modules")
mock_ret.return_value = ["askdjaskdjasd", "modules.win_agent"]
r = self.client.patch(url, payload, format="json")
self.assertEqual(r.status_code, 200)
self.assertEqual(r.data, "Successfully synced salt modules")
self.check_not_authenticated("patch", url)