Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1te909 committed Nov 27, 2023
1 parent 6d39a7f commit e12dc93
Showing 1 changed file with 14 additions and 43 deletions.
57 changes: 14 additions & 43 deletions api/tacticalrmm/autotasks/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def test_create_win_task_schedule(self, nats_cmd):
"pk": task1.pk,
"type": "rmm",
"name": task1.win_task_name,
"overwrite_task": False,
"overwrite_task": True,
"enabled": True,
"trigger": "daily",
"multiple_instances": 1,
Expand All @@ -431,7 +431,7 @@ def test_create_win_task_schedule(self, nats_cmd):
"day_interval": 1,
},
},
timeout=5,
timeout=10,
)
nats_cmd.reset_mock()
self.assertEqual(
Expand Down Expand Up @@ -470,7 +470,7 @@ def test_create_win_task_schedule(self, nats_cmd):
"pk": task1.pk,
"type": "rmm",
"name": task1.win_task_name,
"overwrite_task": False,
"overwrite_task": True,
"enabled": True,
"trigger": "weekly",
"multiple_instances": 2,
Expand All @@ -490,7 +490,7 @@ def test_create_win_task_schedule(self, nats_cmd):
"days_of_week": 127,
},
},
timeout=5,
timeout=10,
)
nats_cmd.reset_mock()

Expand Down Expand Up @@ -518,7 +518,7 @@ def test_create_win_task_schedule(self, nats_cmd):
"pk": task1.pk,
"type": "rmm",
"name": task1.win_task_name,
"overwrite_task": False,
"overwrite_task": True,
"enabled": True,
"trigger": "monthly",
"multiple_instances": 1,
Expand All @@ -538,7 +538,7 @@ def test_create_win_task_schedule(self, nats_cmd):
"months_of_year": 1024,
},
},
timeout=5,
timeout=10,
)
nats_cmd.reset_mock()

Expand All @@ -562,7 +562,7 @@ def test_create_win_task_schedule(self, nats_cmd):
"pk": task1.pk,
"type": "rmm",
"name": task1.win_task_name,
"overwrite_task": False,
"overwrite_task": True,
"enabled": True,
"trigger": "monthlydow",
"multiple_instances": 1,
Expand All @@ -578,7 +578,7 @@ def test_create_win_task_schedule(self, nats_cmd):
"weeks_of_month": 3,
},
},
timeout=5,
timeout=10,
)
nats_cmd.reset_mock()

Expand All @@ -600,7 +600,7 @@ def test_create_win_task_schedule(self, nats_cmd):
"pk": task1.pk,
"type": "rmm",
"name": task1.win_task_name,
"overwrite_task": False,
"overwrite_task": True,
"enabled": True,
"trigger": "runonce",
"multiple_instances": 1,
Expand All @@ -613,39 +613,10 @@ def test_create_win_task_schedule(self, nats_cmd):
"start_min": int(task1.run_time_date.strftime("%-M")),
},
},
timeout=5,
timeout=10,
)
nats_cmd.reset_mock()

# test runonce with date in the past
task1 = baker.make(
"autotasks.AutomatedTask",
agent=agent,
name="test task 3",
task_type=TaskType.RUN_ONCE,
run_asap_after_missed=True,
run_time_date=djangotime.datetime(2018, 6, 1, 23, 23, 23),
)
nats_cmd.return_value = "ok"
create_win_task_schedule(pk=task1.pk)
nats_cmd.assert_called()

# check if task is scheduled for at most 5min in the future
_, args, _ = nats_cmd.mock_calls[0]

current_minute = int(djangotime.now().strftime("%-M"))

if current_minute >= 55 and current_minute < 60:
self.assertLess(
args[0]["schedtaskpayload"]["start_min"],
int(djangotime.now().strftime("%-M")),
)
else:
self.assertGreater(
args[0]["schedtaskpayload"]["start_min"],
int(djangotime.now().strftime("%-M")),
)

# test checkfailure task
nats_cmd.reset_mock()
check = baker.make_recipe("checks.diskspace_check", agent=agent)
Expand All @@ -665,15 +636,15 @@ def test_create_win_task_schedule(self, nats_cmd):
"pk": task1.pk,
"type": "rmm",
"name": task1.win_task_name,
"overwrite_task": False,
"overwrite_task": True,
"enabled": True,
"trigger": "manual",
"multiple_instances": 1,
"delete_expired_task_after": False,
"start_when_available": False,
},
},
timeout=5,
timeout=10,
)
nats_cmd.reset_mock()

Expand All @@ -692,15 +663,15 @@ def test_create_win_task_schedule(self, nats_cmd):
"pk": task1.pk,
"type": "rmm",
"name": task1.win_task_name,
"overwrite_task": False,
"overwrite_task": True,
"enabled": True,
"trigger": "manual",
"multiple_instances": 1,
"delete_expired_task_after": False,
"start_when_available": False,
},
},
timeout=5,
timeout=10,
)


Expand Down

0 comments on commit e12dc93

Please sign in to comment.