Browse Source

Testcase for handle_many function in sendalerts management command.

pull/10/head
Pēteris Caune 9 years ago
parent
commit
0512e8a7c5
1 changed files with 33 additions and 0 deletions
  1. +33
    -0
      hc/api/tests/test_sendalerts.py

+ 33
- 0
hc/api/tests/test_sendalerts.py View File

@ -0,0 +1,33 @@
from datetime import datetime
from mock import patch
from django.contrib.auth.models import User
from django.test import TestCase
from hc.api.models import Check
from hc.api.management.commands.sendalerts import handle_many
class SendAlertsTestCase(TestCase):
@patch("hc.api.management.commands.sendalerts.handle_one")
def test_it_handles_few(self, mock):
alice = User(username="alice")
alice.save()
names = ["Check %d" % d for d in range(0, 10)]
for name in names:
check = Check(user=alice, name=name)
check.alert_after = datetime(2000, 1, 1)
check.status = "up"
check.save()
result = handle_many()
assert result, "handle_many should return True"
handled_names = []
for args, kwargs in mock.call_args_list:
handled_names.append(args[0].name)
assert set(names) == set(handled_names)

Loading…
Cancel
Save