def setUp(self): """Creates an instance of the client so that tests can be run""" self.client = Client() #This intialization doesn't actually do anything.. self.client.socket = FakeSocket()
class MKServer_Client_Tests(unittest.TestCase): def setUp(self): """Creates an instance of the client so that tests can be run""" self.client = Client() #This intialization doesn't actually do anything.. self.client.socket = FakeSocket() #Do we need to do the fake_client_setup here? We definitely need a socket by the time we get to store_address def test_create_socket(self): """Tests whether the socket attribute now contains a socket object""" self.client._create_socket() self.assertIsInstance(self.client.socket, socket.socket) def test_connect_client(self): """Check that the socket is connected.""" confirmation = self.client._connect_client(host,port) self.assertTrue(confirmation) #Calls the setup method (this is the init, so no other init is needed): def test_store_address(self): """Check that address value is not null.""" #Needs: a faux client to operate on (done in the setup..?) # Runs the function #self.assertFalse(hasattr(self.client, 'address') # Interesting - this field doesn't exit until now, so this is an error? self.client._store_address() self.assertIsNotNone(self.client.address) #Decided not to test this because it would just be testing whether raw_input works - but maybe whether it's blocking # def test_prompt_username(self): # """Checks whether the function outputs what came in from raw input""" # #Needs: faux raw input # #Calls the function # result = self.client._prompt_username() # self.assertEquals(self.faux_rawinput,result) # NEeed to define faux_raw input somewhere and make that the input for the function #How do I fix this?! def test_send_username(self): """Checks whether the username from raw input has been received by the server socket""" #Needs: Server Socket (or replica), something for raw input & a client to call the method self.client.username = "******" self.assertTrue(self.client._send_username()) ####BOTH OF THE BELOW ARE DIFFICULT TO TEST BECAUSE OF THE THREADS - SHOULD I TEST THE WHILES OR WHAT pass def test_receive_messages(self): """""" pass def test_initiate_communication(self): pass def test_user_exit(self): pass