Esempio n. 1
0
	def test_allocate_message_queue(self):
		"""Check that a message queue has been allocated for the given new connection"""

		server = Server()

		self.assertEquals(server.message_queues,{})

		server._allocate_message_queue("socket")
		self.assertIsInstance(server.message_queues["socket"],Queue.Queue)
Esempio n. 2
0
	def test_message_maker(self):
		"""Check whether the output is a string and whether it matches the message format"""
		server = Server()

		result = server._message_maker("message","username") 

		#Checks to see if the function does what it's supposed to
		self.assertIsInstance(result,str)
		self.assertEquals("username: message",result)
Esempio n. 3
0
	def test_client_accept(self):
		"""Checks whether the attempt to a accept a new client was successful by returning the new socket object and address created on the server side"""

		#Creates a new server and makes its server_socket a fake socket
		server = Server()
		server.server_socket = FakeSocket()

		#Tests the method using that new fake server_socket - but how do we do this 
		self.assertEquals(server._client_accept(), "Socket")
Esempio n. 4
0
	def test_addto_writelist(self):
		""" Checks whether addto_writelist actually adds the input to the writelist"""
		
		#Creates the trial server instance
		server = Server() # Note: because socket setup is done elsewhere, you don't actually need to worry about that. The init just has a bunhc of empty lists and dictionaries

		#Tries the actual addto_writelist method
		server._addto_writelist("Socket")

		self.assertIn("Socket",server.write_try)
Esempio n. 5
0
	def test_socket_setup(self):
		"""Checks to see whether the socket is now listening"""

		#Create a new instance of a test_server
		server = Server()
		server.server_socket = FakeSocket()

		#Executes the function to be tested
	
		#Checks whether the server_socket is listening
		self.assertTrue(server._socket_setup(host,port))
Esempio n. 6
0
	def test_addto_readlist(self):
		"""Checks whether the input socket has been added to readlist after the method is called"""

		#Creates a test server and assigns a fake socket to its socket value
		server = Server()
		sock = "Socket"

		#Tries the method
		server._addto_readlist(sock)

		#Checks whether the socket appears in the readlist 
		self.assertIn(sock,server.read_try)
Esempio n. 7
0
	def test_initialize_readlist(self):
		""" Checks whether the server is in the read list"""

		#Creates a new instance of the test_server
		server = Server()
		server.server_socket = "Socket"

		#Executes the function to be tested
		server._initialize_readlist()

		#Checks that the socket is in the readtry list
		self.assertIn("Socket",server.read_try)
Esempio n. 8
0
	def test_store_username(self):
		"""Check that the client has a username in the dictionary only after method call"""

		server = Server()
		new_socket = "Socket"
		username = "******"

		self.assertTrue(new_socket not in server.username_dictionary)

		server._store_username(new_socket,username)

		self.assertEquals(server.username_dictionary[new_socket],username)
Esempio n. 9
0
	def test_add_message(self):
		"""Checks whether a new message actually appears in the Queue after message_accept has been called on it"""
		#server = Server(host,port)
		#client = Client() / doesn't actually need a new client because all you care about is the message queue
		#client.add_username() # n
		server = Server() # Sets up the queue for usage
		socket = 'Socket' # Does not actually need to have socket qualities
		server.message_queues[socket]=Queue.Queue()
		message = 'Test'

		#Executes the function being tested
		server._add_message(socket,message) # Calls message_accept method on the test message

		#Checks whether the message now appears in the Queue
		result = server.message_queues[socket].get() # Gets the first element in the queue. 
		self.assertEquals(message,result) # Checks if it's equal to the other one
Esempio n. 10
0
	def test_create_serversocket(self):		
		"""Checks that a new server socket has been created"""
		server = Server()
		server._create_serversocket()

		self.assertIsInstance(server.server_socket,socket.socket)
Esempio n. 11
0
	def test_setto_nonblocking(self):
		"""Check that the nonblocking option has been set"""
		server = Server()
		socket = FakeSocket()

		self.assertTrue(server._setto_nonblocking(socket))