def test_dummy(self): backend = get_backend(_backend('dummy')) self.assertIsNotNone(backend) djhipchat.sent_messages = [] djhipchat.send_message('1234', 'dummy') self.assertEqual([], djhipchat.sent_messages)
def test_default_sender(self): djhipchat.sent_messages = [] with override_settings(HIPCHAT_DEFAULT_SENDER='TestSender'): djhipchat.send_message('1234', 'test sender') self.assertEqual('TestSender', djhipchat.sent_messages[0]['from']) djhipchat.sent_messages = [] with override_settings(HIPCHAT_DEFAULT_SENDER=None): djhipchat.send_message('1234', 'test sender') self.assertEqual('Django', djhipchat.sent_messages[0]['from'])
def emit(self, record): """ Sends the record info to HipChat """ kwargs = { 'room_id': self.room_id, 'message': record.getMessage(), 'message_format': 'text' } kwargs.update(self.kwargs) if record.levelname in self.colors: kwargs['color'] = self.colors[record.levelname] send_message(**kwargs)
def test_backend(self): backend = get_backend(_backend('celery')) self.assertIsNotNone(backend) djhipchat.sent_messages = [] djhipchat.send_message('1234', 'dummy', sender='TestFrom') expected = { 'room_id': '1234', 'message': 'dummy', 'from': 'TestFrom', 'format': 'json', 'message_format': 'html', 'notify': 0, 'color': 'yellow' } self.assertEqual([expected], djhipchat.sent_messages)
def test_locmem(self): backend = get_backend(_backend('locmem')) self.assertIsNotNone(backend) djhipchat.sent_messages = [] djhipchat.send_message('1234', 'locmem test', sender='TestFrom') # (room_id, message, sender, message_format, notify, color) expected = { 'room_id': '1234', 'message': 'locmem test', 'from': 'TestFrom', 'format': 'json', 'message_format': 'html', 'notify': 0, 'color': 'yellow' } self.assertEqual([expected], djhipchat.sent_messages)
def handle(self, *args, **options): if len(args) != 2: raise CommandError('Incorrect number of arguments: hipchat ' + self.args) kwargs = { 'sender': options['sender'], 'message_format': options['message_format'], 'notify': options['notify'], 'color': options['color'] } from djhipchat import send_message result = send_message(*args, **kwargs) if 'error' in result: raise CommandError(result['error']['message'])