def test_emit_to_channel_event_is_publised_correctly(self): self.assertFalse(self.mock_redis_object.publish.called) user = '******' event = Event(event_type='MyEvent', resource='http://storyhost/PAM-1', project='http://projecthost/project/PAM', data='{}', created_on=datetime(2013, 1, 31), created_by=user) emit_to_channel('http://projecthost/project/PAM', 'new_event', event.created_by, event.serialize()) self.assertEqual(self.mock_redis.call_args[1]['host'], 'localhost') self.assertEqual(self.mock_redis.call_args[1]['port'], 6379) self.assertEqual(self.mock_redis.call_args[1]['db'], 0) self.assertEqual(self.mock_redis_object.publish.call_args[0][0], 'socketio_http://projecthost/project/PAM') publish_msg = self.mock_redis_object.publish.call_args[0][1] self.assertIn('{"args": ["http://projecthost/project/PAM", "http://authhost/user/testuser", ', publish_msg) self.assertIn('"project": "http://projecthost/project/PAM"', publish_msg) self.assertIn('"resource": "http://storyhost/PAM-1"', publish_msg) self.assertIn('"event_type": "MyEvent"', publish_msg) self.assertIn('"data": "{}"', publish_msg) self.assertIn('"name": "new_event"', publish_msg)
def test_emit_to_channel_publish_connection_error(self, mock_logger_error): self.assertFalse(self.mock_redis_object.publish.called) self.mock_redis_object.publish.side_effect = ConnectionError event = Event(event_type='MyEvent', resource='http://storyhost/PAM-1', project='http://projecthost/project/PAM', data='{}', created_on=datetime(2013, 1, 31), created_by='http://authhost/user/testuser') emit_to_channel('http://projecthost/project/PAM', 'new_event', event.created_by, event.serialize()) self.assertEqual(self.mock_redis.call_args[1]['host'], 'localhost') self.assertEqual(self.mock_redis.call_args[1]['port'], 6379) self.assertEqual(self.mock_redis.call_args[1]['db'], 0) self.assertEqual(self.mock_redis_object.publish.call_args[0][0], 'socketio_http://projecthost/project/PAM') publish_msg = self.mock_redis_object.publish.call_args[0][1] self.assertIn('{"args": ["http://projecthost/project/PAM", "http://authhost/user/testuser", ', publish_msg) self.assertIn('"project": "http://projecthost/project/PAM"', publish_msg) self.assertIn('"resource": "http://storyhost/PAM-1"', publish_msg) self.assertIn('"event_type": "MyEvent"', publish_msg) self.assertIn('"data": "{}"', publish_msg) self.assertIn('"name": "new_event"', publish_msg) mock_logger_error.assert_called_once_with('Redis does not seem to be running')