Browse Source

improved testing

pull/272/head
Chris Caron 5 years ago
parent
commit
86ad70f6d5
2 changed files with 41 additions and 2 deletions
  1. +1
    -1
      .travis.yml
  2. +40
    -1
      hc/api/tests/test_notify.py

+ 1
- 1
.travis.yml View File

@ -6,7 +6,7 @@ python:
- "3.7" - "3.7"
install: install:
- pip install -r requirements.txt - pip install -r requirements.txt
- pip install braintree coveralls mock mysqlclient reportlab
- pip install braintree coveralls mock mysqlclient reportlab apprise
env: env:
- DB=sqlite - DB=sqlite
- DB=mysql - DB=mysql


+ 40
- 1
hc/api/tests/test_notify.py View File

@ -7,8 +7,9 @@ from django.core import mail
from django.utils.timezone import now from django.utils.timezone import now
from hc.api.models import Channel, Check, Notification from hc.api.models import Channel, Check, Notification
from hc.test import BaseTestCase from hc.test import BaseTestCase
from mock import patch
from mock import patch, Mock
from requests.exceptions import ConnectionError, Timeout from requests.exceptions import ConnectionError, Timeout
from django.test.utils import override_settings
class NotifyTestCase(BaseTestCase): class NotifyTestCase(BaseTestCase):
@ -636,3 +637,41 @@ class NotifyTestCase(BaseTestCase):
n = Notification.objects.get() n = Notification.objects.get()
self.assertTrue("Monthly message limit exceeded" in n.error) self.assertTrue("Monthly message limit exceeded" in n.error)
@patch("apprise.Apprise")
@override_settings(APPRISE_ENABLED=True)
def test_apprise_enabled(self, mock_apprise):
self._setup_data("apprise", "123")
mock_aobj = Mock()
mock_aobj.add.return_value = True
mock_aobj.notify.return_value = True
mock_apprise.return_value = mock_aobj
self.channel.notify(self.check)
self.assertEqual(Notification.objects.count(), 1)
self.check.status = "up"
self.assertEqual(Notification.objects.count(), 1)
@patch("apprise.Apprise")
@override_settings(APPRISE_ENABLED=False)
def test_apprise_disabled(self, mock_apprise):
self._setup_data("apprise", "123")
mock_aobj = Mock()
mock_aobj.add.return_value = True
mock_aobj.notify.return_value = True
mock_apprise.return_value = mock_aobj
self.channel.notify(self.check)
self.assertEqual(Notification.objects.count(), 1)
def test_not_implimented(self):
self._setup_data("webhook", "http://example")
self.channel.kind = "invalid"
try:
self.channel.notify(self.check)
# Code should not reach here
assert False
except NotImplementedError:
# We expect to be here
assert True

Loading…
Cancel
Save