Add Tests for policy relations
This commit is contained in:
parent
3129d34500
commit
1e8456a268
|
@ -317,3 +317,40 @@ class TestPolicyViews(BaseTestCase):
|
|||
self.assertEqual(resp.status_code, 400)
|
||||
|
||||
self.check_not_authenticated("patch", url)
|
||||
|
||||
|
||||
class TestPolicyTasks(BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
||||
# Generates 5 clients with 5 sites each with 5 agents each
|
||||
self.generate_agents(5, 5, 5)
|
||||
|
||||
def test_policy_related(self):
|
||||
|
||||
agent = self.agents[50]
|
||||
client = agent.client
|
||||
site = agent.site
|
||||
|
||||
policy = Policy.objects.create(
|
||||
name="Policy Relate Tests", desc="my awesome policy", active=True,
|
||||
)
|
||||
|
||||
# Add Client to Policy
|
||||
policy.clients.add(client)
|
||||
|
||||
resp = self.client.get(f"/automation/policies/{policy.pk}/related/", format="json")
|
||||
|
||||
self.assertEquals(len(resp.data.clients), 1)
|
||||
self.assertEquals(len(resp.data.sites), 5)
|
||||
self.assertEquals(len(resp.data.agents), 25)
|
||||
|
||||
# Add Site to Policy and the agents and sites length shouldn't change
|
||||
policy.sites.add(site)
|
||||
self.assertEquals(len(resp.data.sites), 5)
|
||||
self.assertEquals(len(resp.data.agents), 25)
|
||||
|
||||
# Add Agent to Policy and the agents length shouldn't change
|
||||
policy.agents.add(agent)
|
||||
self.assertEquals(len(resp.data.agents), 25)
|
||||
|
|
@ -24,59 +24,7 @@ class BaseTestCase(TestCase):
|
|||
self.client.force_authenticate(user=self.john)
|
||||
|
||||
self.coresettings = CoreSettings.objects.create()
|
||||
|
||||
self.agent = Agent.objects.create(
|
||||
operating_system="Windows 10",
|
||||
plat="windows",
|
||||
plat_release="windows-Server2019",
|
||||
hostname="DESKTOP-TEST123",
|
||||
local_ip="10.0.25.188",
|
||||
agent_id="71AHC-AA813-HH1BC-AAHH5-00013|DESKTOP-TEST123",
|
||||
services=[
|
||||
{
|
||||
"pid": 880,
|
||||
"name": "AeLookupSvc",
|
||||
"status": "stopped",
|
||||
"binpath": "C:\\Windows\\system32\\svchost.exe -k netsvcs",
|
||||
"username": "localSystem",
|
||||
"start_type": "manual",
|
||||
"description": "Processes application compatibility cache requests for applications as they are launched",
|
||||
"display_name": "Application Experience",
|
||||
},
|
||||
{
|
||||
"pid": 812,
|
||||
"name": "ALG",
|
||||
"status": "stopped",
|
||||
"binpath": "C:\\Windows\\System32\\alg.exe",
|
||||
"username": "NT AUTHORITY\\LocalService",
|
||||
"start_type": "manual",
|
||||
"description": "Provides support for 3rd party protocol plug-ins for Internet Connection Sharing",
|
||||
"display_name": "Application Layer Gateway Service",
|
||||
},
|
||||
],
|
||||
public_ip="74.13.24.14",
|
||||
total_ram=16,
|
||||
used_ram=33,
|
||||
disks={
|
||||
"C:": {
|
||||
"free": "42.3G",
|
||||
"used": "17.1G",
|
||||
"total": "59.5G",
|
||||
"device": "C:",
|
||||
"fstype": "NTFS",
|
||||
"percent": 28,
|
||||
}
|
||||
},
|
||||
boot_time=8173231.4,
|
||||
logged_in_username="John",
|
||||
client="Google",
|
||||
site="Main Office",
|
||||
monitoring_type="server",
|
||||
description="Test PC",
|
||||
mesh_node_id="abcdefghijklmnopAABBCCDD77443355##!!AI%@#$%#*",
|
||||
last_seen=djangotime.now(),
|
||||
)
|
||||
|
||||
self.agent = self.create_agent("DESKTOP-TEST123", "Google", "Main Office")
|
||||
self.update_policy = WinUpdatePolicy.objects.create(agent=self.agent)
|
||||
|
||||
Client.objects.create(client="Google")
|
||||
|
@ -126,8 +74,63 @@ class BaseTestCase(TestCase):
|
|||
r = switch.get(method)
|
||||
self.assertEqual(r.status_code, 401)
|
||||
|
||||
def create_agent(self, hostname, client, site):
|
||||
return Agent.objects.create(
|
||||
operating_system="Windows 10",
|
||||
plat="windows",
|
||||
plat_release="windows-Server2019",
|
||||
hostname=f"{hostname}",
|
||||
local_ip="10.0.25.188",
|
||||
agent_id="71AHC-AA813-HH1BC-AAHH5-00013|DESKTOP-TEST123",
|
||||
services=[
|
||||
{
|
||||
"pid": 880,
|
||||
"name": "AeLookupSvc",
|
||||
"status": "stopped",
|
||||
"binpath": "C:\\Windows\\system32\\svchost.exe -k netsvcs",
|
||||
"username": "localSystem",
|
||||
"start_type": "manual",
|
||||
"description": "Processes application compatibility cache requests for applications as they are launched",
|
||||
"display_name": "Application Experience",
|
||||
},
|
||||
{
|
||||
"pid": 812,
|
||||
"name": "ALG",
|
||||
"status": "stopped",
|
||||
"binpath": "C:\\Windows\\System32\\alg.exe",
|
||||
"username": "NT AUTHORITY\\LocalService",
|
||||
"start_type": "manual",
|
||||
"description": "Provides support for 3rd party protocol plug-ins for Internet Connection Sharing",
|
||||
"display_name": "Application Layer Gateway Service",
|
||||
},
|
||||
],
|
||||
public_ip="74.13.24.14",
|
||||
total_ram=16,
|
||||
used_ram=33,
|
||||
disks={
|
||||
"C:": {
|
||||
"free": "42.3G",
|
||||
"used": "17.1G",
|
||||
"total": "59.5G",
|
||||
"device": "C:",
|
||||
"fstype": "NTFS",
|
||||
"percent": 28,
|
||||
}
|
||||
},
|
||||
boot_time=8173231.4,
|
||||
logged_in_username="John",
|
||||
client=f"{client}",
|
||||
site=f"{site}",
|
||||
monitoring_type="server",
|
||||
description="Test PC",
|
||||
mesh_node_id="abcdefghijklmnopAABBCCDD77443355##!!AI%@#$%#*",
|
||||
last_seen=djangotime.now(),
|
||||
)
|
||||
|
||||
def generate_agents(self, numOfAgents, numOfClients, numOfSites):
|
||||
|
||||
self.agents = None
|
||||
|
||||
for c in range(numOfClients):
|
||||
client = Client.objects.create(
|
||||
client=f"Client{c}"
|
||||
|
@ -141,54 +144,6 @@ class BaseTestCase(TestCase):
|
|||
|
||||
for a in range(numOfAgents):
|
||||
|
||||
Agent.objects.create(
|
||||
operating_system="Windows 10",
|
||||
plat="windows",
|
||||
plat_release="windows-Server2019",
|
||||
hostname=f"Agent{a}",
|
||||
local_ip="10.0.25.188",
|
||||
agent_id=f"71AHC-AA813-HH1BC-AAHH5-00013|Agent{a}",
|
||||
services=[
|
||||
{
|
||||
"pid": 880,
|
||||
"name": "AeLookupSvc",
|
||||
"status": "stopped",
|
||||
"binpath": "C:\\Windows\\system32\\svchost.exe -k netsvcs",
|
||||
"username": "localSystem",
|
||||
"start_type": "manual",
|
||||
"description": "Processes application compatibility cache requests for applications as they are launched",
|
||||
"display_name": "Application Experience",
|
||||
},
|
||||
{
|
||||
"pid": 812,
|
||||
"name": "ALG",
|
||||
"status": "stopped",
|
||||
"binpath": "C:\\Windows\\System32\\alg.exe",
|
||||
"username": "NT AUTHORITY\\LocalService",
|
||||
"start_type": "manual",
|
||||
"description": "Provides support for 3rd party protocol plug-ins for Internet Connection Sharing",
|
||||
"display_name": "Application Layer Gateway Service",
|
||||
},
|
||||
],
|
||||
public_ip="74.13.24.14",
|
||||
total_ram=16,
|
||||
used_ram=33,
|
||||
disks={
|
||||
"C:": {
|
||||
"free": "42.3G",
|
||||
"used": "17.1G",
|
||||
"total": "59.5G",
|
||||
"device": "C:",
|
||||
"fstype": "NTFS",
|
||||
"percent": 28,
|
||||
}
|
||||
},
|
||||
boot_time=8173231.4,
|
||||
logged_in_username="John",
|
||||
client=client.client,
|
||||
site=site.site,
|
||||
monitoring_type="server",
|
||||
description="Test PC",
|
||||
mesh_node_id="abcdefghijklmnopAABBCCDD77443355##!!AI%@#$%#*",
|
||||
last_seen=djangotime.now(),
|
||||
self.agents.append(
|
||||
self.create_agent(f"Agent{a}", f"Client{c}", f"Site{s}")
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue