コード例 #1
0
    def test_commands_response(self):
        """
        This test will check whether ClientResponse responds commands.
        """

        test_class = ClientResponse()

        output = test_class.commands()

        test_class.quit()
        reset_login()

        self.assertTrue(output)
コード例 #2
0
    def test_commands_quit(self):
        """
        This test will check quit response.
        """
        expected_results = ["\nSigned out"]
        results = []

        test_class = ClientResponse()

        results.append(test_class.quit())
        reset_login()

        self.assertListEqual(results, expected_results)
コード例 #3
0
 def acceptConnections(self):
     """
         Accept the client connections.
     """
     while True:
         try:
             conn, address = self.socket.accept()
             self.socket.setblocking(1)
             self.clientConnections.append(conn)
             self.clientip.append(address)
             self.clientthreads[address] = 0
             self.clienthandler[address] = ClientResponse()
             log.info("Client connected from ip :" + address[0])
         except Exception as e:
             log.info("Error : %s", e)
コード例 #4
0
    def test_ClientResponse_list(self):
        """
        This test will check list command.
        Test1 : Listing without login.
        Test2 : Listing folder for user test
        """
        results = []
        expected_results = ["\nCan you login first?"]
        test_class = ClientResponse()
        test_class.login_session_data = init_login()
        results.append(test_class.list())
        test_class.login("test", "123")
        results.append(test_class.list())
        test_class.quit()
        reset_login()

        self.assertListEqual([results[0]], expected_results)
        self.assertIn("testfolder1", results[1])
コード例 #5
0
     def test_ClientResponse_write_file(self):
        """
        This test will check write file.
        Test1 : Write on non existing file.
        Test2 : Proper write file.
        """
        results = []
        expected_results = ["\nSuccess.", "\nSuccess."]
        test_class = ClientResponse()
        test_class.login_session_data = init_login()
        test_class.login("test", "123")
        test_class.change_folder("testfolder1")
        results.append(test_class.write_file(random_folder() + ".txt", "content"))
        results.append(test_class.write_file("test_write.txt", "content"))
        test_class.quit()
        reset_login()

        self.assertListEqual(results, expected_results)
コード例 #6
0
    def test_ClientResponse_read_file(self):
        """
        This test will check read file.
        Test1 : Read the non existing file.
        Test2 : Proper read file.
        """
        results = []
        expected_results = ["\nFile not found.", "\nCommand - read_file from 0 to 100 are - \nDontChangeThisContent"]
        test_class = ClientResponse()
        test_class.login_session_data = init_login()
        test_class.login("test", "123")
        test_class.change_folder("testfolder1")
        results.append(test_class.read_file("test_read2.txt"))
        results.append(test_class.read_file("test_read.txt"))
        test_class.quit()
        reset_login()

        self.assertListEqual(results, expected_results)
コード例 #7
0
    def test_ClientResponse_change_folder(self):
        """
        This test will check response for change folder.
        Test1 : Change folder without login.
        Test2 : Wrong directory change.
        Test3 : Proper directory change.
        """
        results = []
        expected_results = ["\nCan you login first?", "\nWrong directory name.", "\nChanged directory to testfolder1 successfully"]
        test_class = ClientResponse()
        test_class.login_session_data = init_login()
        results.append(test_class.change_folder("testfolder1"))
        test_class.login("test", "123")
        results.append(test_class.change_folder("testfolder2"))
        results.append(test_class.change_folder("testfolder1"))
        test_class.quit()
        reset_login()

        self.assertListEqual(results, expected_results)
コード例 #8
0
    def test_ClientResponse_create_folder(self):
        """
        This test will check response for create folder.
        Test1 : Create already present directory.
        Test2 : Proper directory with random name.
        """
        results = []
        expected_results = ["\nDirectory Already Present", "\nSuccess."]
        test_class = ClientResponse()
        test_class.login_session_data = init_login()
        test_class.login("test", "123")
        results.append(test_class.create_folder("testfolder1"))
        test_class.change_folder("testfolder1")
        results.append(test_class.create_folder("test" + random_folder()))
        test_class.quit()
        reset_login()

        self.assertListEqual(results, expected_results)
        
        
        class ClientResponseClassTestingStepFour(unittest.TestCase):
コード例 #9
0
    def test_ClientResponse_login(self):
        """
        This test will check login.
        Test1 : Wrong password
        Test2 : Wrong username
        Test3 : Proper login
        """
        test_class = ClientResponse()
        test_class.login_session_data = init_login()
        expected_results = ["\nWrong password!", "\nUsername not registered", "\nLogin completed."]
        results = []
        tests = [
            ["test", "1234"],
            ["test2", "123"],
            ["test", "123"]
        ]

        for test in tests:
            results.append(test_class.login(
                test[0], test[1]))
        test_class.quit()
        reset_login()

        self.assertListEqual(results, expected_results)