mirror of
https://github.com/status-im/cabot.git
synced 2025-02-24 02:18:08 +00:00
Updated and fixed unit tests
This commit is contained in:
parent
9d88e5d846
commit
ee1952c812
@ -12,8 +12,10 @@ from rest_framework.test import APITestCase
|
||||
from rest_framework.reverse import reverse as api_reverse
|
||||
from cabot.cabotapp.models import (
|
||||
GraphiteStatusCheck, JenkinsStatusCheck,
|
||||
HttpStatusCheck, ICMPStatusCheck, Service, Instance, StatusCheckResult)
|
||||
HttpStatusCheck, ICMPStatusCheck, Service, Instance, StatusCheckResult,
|
||||
UserProfile)
|
||||
from cabot.cabotapp.views import StatusCheckReportForm
|
||||
from cabot.cabotapp.alert import (send_hipchat_alert, send_alert)
|
||||
from mock import Mock, patch
|
||||
from twilio import rest
|
||||
from django.utils import timezone
|
||||
@ -411,7 +413,8 @@ class TestAPI(LocalTestCase):
|
||||
'sms_alert': False,
|
||||
'telephone_alert': False,
|
||||
'hackpad_id': None,
|
||||
'id': 1
|
||||
'id': 1,
|
||||
'url': u''
|
||||
},
|
||||
],
|
||||
'instance': [
|
||||
@ -528,7 +531,8 @@ class TestAPI(LocalTestCase):
|
||||
'sms_alert': False,
|
||||
'telephone_alert': False,
|
||||
'hackpad_id': None,
|
||||
'id': 2
|
||||
'id': 2,
|
||||
'url': u'',
|
||||
},
|
||||
],
|
||||
'instance': [
|
||||
@ -744,3 +748,59 @@ class TestAPIFiltering(LocalTestCase):
|
||||
[item['name'] for item in response.data],
|
||||
self.expected_sort_names[::-1]
|
||||
)
|
||||
|
||||
|
||||
class TestAlerts(LocalTestCase):
|
||||
def setUp(self):
|
||||
super(TestAlerts, self).setUp()
|
||||
|
||||
self.user_profile = UserProfile.objects.create(
|
||||
user = self.user,
|
||||
hipchat_alias = "test_user_hipchat_alias",)
|
||||
self.user_profile.save()
|
||||
|
||||
self.service.users_to_notify.add(self.user)
|
||||
self.service.update_status()
|
||||
|
||||
def test_users_to_notify(self):
|
||||
self.assertEqual(self.service.users_to_notify.all().count(), 1)
|
||||
self.assertEqual(self.service.users_to_notify.get(pk=1).username, self.user.username)
|
||||
|
||||
@patch('cabot.cabotapp.models.send_alert')
|
||||
def test_alert(self, fake_send_alert):
|
||||
self.service.alert()
|
||||
self.assertEqual(fake_send_alert.call_count, 1)
|
||||
fake_send_alert.assert_called_with(self.service, duty_officers=[])
|
||||
|
||||
@patch('cabot.cabotapp.alert._send_hipchat_alert')
|
||||
def test_inactive_users(self, fake_hipchat_alert):
|
||||
self.user.is_active = True
|
||||
self.user.save()
|
||||
self.service.alert()
|
||||
fake_hipchat_alert.assert_called_with(u'Service Service is back to normal: http://localhost/service/1/. @test_user_hipchat_alias', color='green', sender='Cabot/Service')
|
||||
|
||||
self.user.is_active = False
|
||||
self.user.save()
|
||||
self.service.alert()
|
||||
fake_hipchat_alert.assert_called_with(u'Service Service is back to normal: http://localhost/service/1/. ', color='green', sender='Cabot/Service')
|
||||
|
||||
|
||||
@patch('cabot.cabotapp.alert._send_hipchat_alert')
|
||||
def test_normal_alert(self, fake_hipchat_alert):
|
||||
|
||||
self.service.overall_status = Service.PASSING_STATUS
|
||||
self.service.old_overall_status = Service.ERROR_STATUS
|
||||
self.service.save()
|
||||
|
||||
self.service.alert()
|
||||
fake_hipchat_alert.assert_called_with(u'Service Service is back to normal: http://localhost/service/1/. @test_user_hipchat_alias', color='green', sender='Cabot/Service')
|
||||
|
||||
@patch('cabot.cabotapp.alert._send_hipchat_alert')
|
||||
def test_failure_alert(self, fake_hipchat_alert):
|
||||
# Most recent failed
|
||||
self.service.overall_status = Service.CALCULATED_FAILING_STATUS
|
||||
self.service.old_overall_status = Service.PASSING_STATUS
|
||||
self.service.save()
|
||||
|
||||
self.service.alert()
|
||||
fake_hipchat_alert.assert_called_with(u'Service Service reporting failing status: http://localhost/service/1/. Checks failing: @test_user_hipchat_alias', color='red', sender='Cabot/Service')
|
Loading…
x
Reference in New Issue
Block a user