Created
August 5, 2013 22:35
-
-
Save thomwiggers/6160226 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
import socket | |
import mox | |
from aeolus.irclib.server import Connection | |
class Server(unittest.TestCase): | |
def setUp(self): | |
"""Initialises mocking objects""" | |
self.mox = mox.Mox() | |
#Mock sockets | |
self.mock_socket = self.mox.CreateMockAnything(socket.socket) | |
# hide socket.socket() | |
self.mox.StubOutWithMock(socket, 'socket') | |
#records the response, reply with our mock socket. | |
socket.socket(socket.AF_INET, socket.SOCK_STREAM).AndReturn(self.mock_socket) | |
self.connection = Connection() | |
pass | |
def testConnectEasy(self): | |
"""Tests connecting to a server""" | |
testnick = "thom" | |
testname = "wiggers" | |
testrealname = "je moeder" | |
testselfhost = "localhost" | |
testhost = "testserver" | |
self.mock_socket.create_connection((testhost, 6667)) | |
self.mock_socket.sendall("NICK %s\n" % testnick).AndReturn(None) | |
self.mock_socket.sendall("USER %s %s %s :%s\n" | |
% (testname, testselfhost, testhost, testrealname)).AndReturn(None) | |
#ok, en dan nu testen: | |
self.mox.ReplayAll() | |
self.connection.connect(testnick, testhost) | |
self.mox.VerifyAll() | |
self.assertEquals(testnick, self.connection.nick) | |
if __name__ == "__main__": | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment