fix/add tests

This commit is contained in:
Josh 2020-12-01 15:55:16 +00:00
parent a2963ed7bb
commit 584254e6ca
3 changed files with 52 additions and 2 deletions

View File

@ -1056,6 +1056,8 @@ class TestPolicyTasks(TacticalTestCase):
from .tasks import update_policy_task_fields_task
from autotasks.models import AutomatedTask
nats_cmd.return_value = "ok"
# setup data
policy = baker.make("automation.Policy", active=True)
tasks = baker.make(

View File

@ -31,3 +31,36 @@ class TestCoreTasks(TacticalTestCase):
self.assertEqual(r.status_code, 200)
self.check_not_authenticated("get", url)
def test_ui_maintenance_actions(self):
url = "/core/servermaintenance/"
# test with empty data
r = self.client.post(url, {})
self.assertEqual(r.status_code, 400)
# test with invalid action
data = {"action": "invalid_action"}
r = self.client.post(url, data)
self.assertEqual(r.status_code, 400)
# test reload nats action
data = {"action": "reload_nats"}
r = self.client.post(url, data)
self.assertEqual(r.status_code, 200)
# test prune db with no tables
data = {"action": "prune_db"}
r = self.client.post(url, data)
self.assertEqual(r.status_code, 400)
# test prune db with tables
data = {
"action": "prune_db",
"prune_tables": ["audit_logs", "agent_outages", "pending_actions"],
}
r = self.client.post(url, data)
self.assertEqual(r.status_code, 200)
self.check_not_authenticated("post", url)

View File

@ -122,10 +122,25 @@ class TestAuditViews(TacticalTestCase):
{"filter": {"clientFilter": [site.client.id]}, "count": 23},
]
pagination = {
"rowsPerPage": 25,
"page": 1,
"sortBy": "entry_time",
"descending": True,
}
for req in data:
resp = self.client.patch(url, req["filter"], format="json")
resp = self.client.patch(
url, {**req["filter"], "pagination": pagination}, format="json"
)
self.assertEqual(resp.status_code, 200)
self.assertEqual(len(resp.data), req["count"])
self.assertEqual(
len(resp.data["audit_logs"]),
pagination["rowsPerPage"]
if req["count"] > pagination["rowsPerPage"]
else req["count"],
)
self.assertEqual(resp.data["total"], req["count"])
self.check_not_authenticated("patch", url)