mirror of https://github.com/status-im/cabot.git
Use freezegun for testing alert acknowledgements
This commit is contained in:
parent
b490459925
commit
c969d99e7f
|
@ -24,6 +24,7 @@ from django.core.urlresolvers import reverse
|
|||
from django.test.client import Client
|
||||
from django.test.utils import override_settings
|
||||
from django.utils import timezone
|
||||
from freezegun import freeze_time
|
||||
from mock import Mock, patch
|
||||
from rest_framework import status, HTTP_HEADER_ENCODING
|
||||
from rest_framework.reverse import reverse as api_reverse
|
||||
|
@ -225,6 +226,7 @@ class TestCheckRun(LocalTestCase):
|
|||
|
||||
@patch('cabot.cabotapp.models.send_alert')
|
||||
@patch('cabot.cabotapp.models.send_alert_update')
|
||||
@freeze_time('2017-03-02 10:30:43.714759')
|
||||
def test_alert_acknowledgement(self, fake_send_alert_update, fake_send_alert):
|
||||
self.assertEqual(self.service.overall_status, Service.PASSING_STATUS)
|
||||
self.most_recent_result.succeeded = False
|
||||
|
@ -235,18 +237,28 @@ class TestCheckRun(LocalTestCase):
|
|||
Service.CALCULATED_FAILING_STATUS)
|
||||
self.service.update_status()
|
||||
fake_send_alert.assert_called_with(self.service, duty_officers=[])
|
||||
|
||||
fake_send_alert.reset_mock()
|
||||
self.service.last_alert_sent = timezone.now() - timedelta(minutes=30)
|
||||
self.service.update_status()
|
||||
fake_send_alert.assert_called_with(self.service, duty_officers=[])
|
||||
|
||||
fake_send_alert.reset_mock()
|
||||
with freeze_time(timezone.now() + timedelta(minutes=30)):
|
||||
self.service.update_status()
|
||||
fake_send_alert.assert_called_with(self.service, duty_officers=[])
|
||||
fake_send_alert.reset_mock()
|
||||
|
||||
self.service.acknowledge_alert(user=self.user)
|
||||
self.service.last_alert_sent = timezone.now() - timedelta(minutes=30)
|
||||
self.service.update_status()
|
||||
self.assertEqual(self.service.unexpired_acknowledgement().user, self.user)
|
||||
fake_send_alert_update.assert_called_with(self.service, duty_officers=[])
|
||||
self.assertFalse(fake_send_alert_update.called)
|
||||
|
||||
with freeze_time(timezone.now() + timedelta(minutes=60)):
|
||||
self.service.update_status()
|
||||
self.assertEqual(self.service.unexpired_acknowledgement(), None)
|
||||
fake_send_alert.assert_called_with(self.service, duty_officers=[])
|
||||
|
||||
with freeze_time(timezone.now() + timedelta(minutes=90)):
|
||||
self.service.acknowledge_alert(user=self.user)
|
||||
self.service.update_status()
|
||||
self.assertEqual(self.service.unexpired_acknowledgement().user, self.user)
|
||||
fake_send_alert_update.assert_called_with(self.service, duty_officers=[])
|
||||
|
||||
@patch('cabot.cabotapp.graphite.requests.get', fake_graphite_response)
|
||||
def test_graphite_run(self):
|
||||
|
|
|
@ -1,32 +1,33 @@
|
|||
Django>=1.8,<1.9
|
||||
Markdown==2.5
|
||||
PyJWT==0.1.2
|
||||
amqp<2.0
|
||||
anyjson==0.3.3
|
||||
argparse==1.2.1
|
||||
celery[redis]==3.1.23
|
||||
dj-database-url==0.4.2
|
||||
django-appconf==1.0.2
|
||||
django-auth-ldap==1.2.6
|
||||
django-celery==3.1.17
|
||||
django-compressor==2.1.1
|
||||
django-filter==0.13
|
||||
django-jsonify==0.3.0
|
||||
django-mptt==0.6.0
|
||||
django-polymorphic==0.7.2
|
||||
Django>=1.8,<1.9
|
||||
djangorestframework==2.4.8
|
||||
gunicorn==19.6.0
|
||||
freezegun==0.3.8
|
||||
gevent==1.0.1
|
||||
gunicorn==19.6.0
|
||||
httplib2==0.7.7
|
||||
icalendar==3.2
|
||||
Markdown==2.5
|
||||
ndg-httpsclient==0.4.2
|
||||
psycogreen==1.0
|
||||
psycopg2==2.5.1
|
||||
pytz==2014.10
|
||||
pyOpenSSL==16.1.0
|
||||
ndg-httpsclient==0.4.2
|
||||
pyasn1==0.1.9
|
||||
PyJWT==0.1.2
|
||||
pyOpenSSL==16.1.0
|
||||
python-dateutil==2.1
|
||||
pytz==2014.10
|
||||
requests==2.7.0
|
||||
twilio==3.4.1
|
||||
wsgiref==0.1.2
|
||||
python-dateutil==2.1
|
||||
django-auth-ldap==1.2.6
|
||||
whitenoise==3.3.0
|
||||
wsgiref==0.1.2
|
||||
|
|
Loading…
Reference in New Issue