Commit fe71a2b1a96024b11b2c46146f226094daedca95

Authored by Sergio Oliveira
1 parent 2f08f0d5

Using custom exception

colab/exceptions.py 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +
  2 +class ColabException(Exception):
  3 + """Base class for all exceptions raised by Colab"""
... ...
colab/signals/exceptions.py 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +
  2 +from ..exceptions import ColabException
  3 +
  4 +
  5 +class SignalDoesNotExist(ColabException):
  6 + """Expcetion raised when signal does not exist"""
... ...
colab/signals/signals.py
1 1 from django.dispatch import Signal
2 2 from colab.signals.celery import app
3 3  
  4 +from .exceptions import SignalDoesNotExist
  5 +
4 6  
5 7 registered_signals = {}
6 8 signal_instances = {}
... ... @@ -28,11 +30,11 @@ def connect_signal(signal_name, sender, handling_method):
28 30 signal_instances[signal_name].connect(handling_method.delay,
29 31 sender=sender)
30 32 else:
31   - raise Exception("Signal does not exist!")
  33 + raise SignalDoesNotExist
32 34  
33 35  
34 36 def send(signal_name, sender, **kwargs):
35 37 if signal_name in signal_instances:
36 38 signal_instances[signal_name].send(sender=sender, **kwargs)
37 39 else:
38   - raise Exception("Signal does not exist!")
  40 + raise SignalDoesNotExist
... ...
colab/signals/tests/test_signals.py
... ... @@ -9,8 +9,8 @@ from django.test import TestCase
9 9  
10 10 from mock import patch, MagicMock, PropertyMock
11 11  
12   -from colab.signals.signals import (registered_signals, register_signal,
13   - connect_signal, send)
  12 +from ..signals import registered_signals, register_signal, connect_signal, send
  13 +from ..exceptions import SignalDoesNotExist
14 14  
15 15  
16 16 class SignalsTest(TestCase):
... ... @@ -43,7 +43,7 @@ class SignalsTest(TestCase):
43 43 handling_method = 'Test'
44 44 signal_name = 'Test'
45 45  
46   - self.assertRaises(Exception, connect_signal, signal_name,
  46 + self.assertRaises(SignalDoesNotExist, connect_signal, signal_name,
47 47 sender, handling_method)
48 48  
49 49 @patch('colab.signals.signals.Signal.connect')
... ... @@ -76,4 +76,4 @@ class SignalsTest(TestCase):
76 76 self.assertTrue(mock.is_called)
77 77  
78 78 def test_send_signal_not_registered(self):
79   - self.assertRaises(Exception, send, 'test_signal', 'test')
  79 + self.assertRaises(SignalDoesNotExist, send, 'test_signal', 'test')
... ...