keystore tests
@@ -8,8 +8,8 @@ from model_bakery import baker
from tacticalrmm.test import TacticalTestCase
from .consumers import DashInfo
-from .models import CoreSettings, CustomField
-from .serializers import CustomFieldSerializer
+from .models import CoreSettings, CustomField, GlobalKVStore
+from .serializers import CustomFieldSerializer, KeyStoreSerializer
from .tasks import core_maintenance_tasks
@@ -273,3 +273,61 @@ class TestCoreTasks(TacticalTestCase):
self.assertFalse(CustomField.objects.filter(pk=custom_field.id).exists()) # type: ignore
self.check_not_authenticated("delete", url)
+
+ def test_get_keystore(self):
+ url = "/core/keystore/"
+
+ # setup
+ keys = baker.make("core.GlobalKVStore", _quantity=2)
+
+ r = self.client.get(url)
+ serializer = KeyStoreSerializer(keys, many=True)
+ self.assertEqual(r.status_code, 200)
+ self.assertEqual(len(r.data), 2) # type: ignore
+ self.assertEqual(r.data, serializer.data) # type: ignore
+
+ self.check_not_authenticated("get", url)
+
+ def test_add_keystore(self):
+ url = "/core/keystore/"
+
+ data = {"name": "test", "value": "text"}
+ r = self.client.post(url, data)
+ self.assertEqual(r.status_code, 200)
+
+ self.check_not_authenticated("post", url)
+
+ def test_update_keystore(self):
+ # setup
+ key = baker.make("core.GlobalKVStore")
+
+ # test not found
+ r = self.client.put("/core/keystore/500/")
+ self.assertEqual(r.status_code, 404)
+
+ url = f"/core/keystore/{key.id}/" # type: ignore
+ data = {"name": "test", "value": "text"}
+ r = self.client.put(url, data)
+ self.assertEqual(r.status_code, 200)
+
+ new_key = GlobalKVStore.objects.get(pk=key.id) # type: ignore
+ self.assertEqual(new_key.name, data["name"])
+ self.assertEqual(new_key.value, data["value"])
+
+ self.check_not_authenticated("put", url)
+
+ def test_delete_keystore(self):
+ # setup
+ key = baker.make("core.GlobalKVStore")
+
+ # test not found
+ r = self.client.delete("/core/keystore/500/")
+ self.assertEqual(r.status_code, 404)
+
+ url = f"/core/keystore/{key.id}/" # type: ignore
+ r = self.client.delete(url)
+ self.assertEqual(r.status_code, 200)
+
+ self.assertFalse(GlobalKVStore.objects.filter(pk=key.id).exists()) # type: ignore
+
+ self.check_not_authenticated("delete", url)
\ No newline at end of file
