Commits

Jason R. Coombs committed 8a2c842

Added a couple of tests for privmsg, one of which fails due to issue #4.

Comments (0)

Files changed (1)

irc/tests/test_client.py

 import datetime
 import random
 
+import pytest
+import mock
+
 import irc.client
 
 def test_version():
 		)
 	assert fd.due() == True
 	assert fd.next().due() == False
+
+@mock.patch('irc.client.socket')
+def test_privmsg_sends_msg(socket_mod):
+	server = irc.client.IRC().server()
+	server.connect('foo', 6667, 'bestnick')
+	server.privmsg('#best-channel', 'You are great')
+	socket_mod.socket.return_value.send.assert_called_with(
+		'PRIVMSG #best-channel :You are great\r\n')
+
+@mock.patch('irc.client.socket')
+def test_privmsg_fails_on_embedded_carriage_returns(socket_mod):
+	server = irc.client.IRC().server()
+	server.connect('foo', 6667, 'bestnick')
+	with pytest.raises(ValueError):
+		server.privmsg('#best-channel', 'You are great\nSo are you')