From 414e7bec994db4c451d8a2f4f1210b0d8b689005 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Wed, 30 Sep 2020 21:37:17 +0000 Subject: [PATCH] add test case for modules sync view --- api/tacticalrmm/apiv2/tests.py | 36 ++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/api/tacticalrmm/apiv2/tests.py b/api/tacticalrmm/apiv2/tests.py index 7ce503c2..41f137c8 100644 --- a/api/tacticalrmm/apiv2/tests.py +++ b/api/tacticalrmm/apiv2/tests.py @@ -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)