Ejemplo n.º 1
0
class RemoteFileViewTest(default_code.DefaultCode):

    @patch(
        'src.algorithm.tree_builder.get_tree_from_node_id',
        return_value=default_code.create_folder_with_files(
            ["default_test1", "default_test2", "default_test3"]))
    def setUp(self, mock) -> None:
        super().setUp()

        self.main_model = MainModel()
        self.main_model.remote_file_model
        self.file_view_test = RemoteFileView(self.main_model)

    def tearDown(self) -> None:
        super().tearDown()

    @patch(
        'src.algorithm.tree_builder.get_tree_from_node_id',
        return_value=default_code.create_folder_with_files(
            ["test1", "test2", "test3"]))
    def test_model_changed_files(self, mock):
        self.file_view_test.Sl_model_changed()
        test_list = self.file_view_test.fileLayout._item_list
        self.assertEqual(test_list[0].wid.name == "test1", True)
        self.assertEqual(test_list[1].wid.name == "test2", True)
        self.assertEqual(test_list[2].wid.name == "test3", True)

    @patch(
        'src.algorithm.tree_builder.get_tree_from_node_id',
        return_value=default_code.create_folder_with_folders(
            ["test1", "test2", "test3"]))
    def test_model_changed_dirs(self, mock):
        self.file_view_test.Sl_model_changed()
        test_list = self.file_view_test.fileLayout._item_list
        self.assertEqual(test_list[0].wid.name == "test1", True)
        self.assertEqual(test_list[1].wid.name == "test2", True)
        self.assertEqual(test_list[2].wid.name == "test3", True)

    @patch(
        'src.algorithm.tree_builder.get_tree_from_node_id',
        return_value=default_code.create_folder_with_files(
            ["test1", "test2", "test3"]))
    def test_refresh_button(self, mock):
        result = self.file_view_test._model.folder_queue = ["NOT_LOCAL_ROOT"]
        self.file_view_test.Sl_refresh_button_clicked()
        result = self.file_view_test._model.folder_queue == ["LOCAL_ROOT"]
        self.assertEqual(result, True)

    def test_add_sync_file_exists(self):
        self.file_view_test.Sl_add_sync_file("test")

    def test_remove_sync_file_exists(self):
        self.file_view_test.Sl_remove_sync_file("test")

    def test_file_status_changed_exists(self):
        self.file_view_test.Sl_file_status_changed()
 def setUp(self, mocked) -> None:
     super().setUp()
     node = default_code.create_folder_with_files(["testFile"])
     base_dir = RemoteDirectory(node)
     self.test_model = MainModel()
     self.test_view = RemoteFileView(self.test_model)
     self.test_dir = RemoteDirectoryWidget(base_dir, self.test_view)
    def test_compare_files_client_new_file(self):
        # Imposto cartella server
        server_node = default_code.create_folder_with_files(self.FILE_NAME)
        # imposto cartella client
        client_node = default_code.create_folder_with_files(self.FILE_NAME)
        # Imposto file mancante
        missing_file = default_code._get_file_test_node()
        # Aggiungo file mancante
        client_node.add_node(missing_file)
        result = tree_comparator._compareFiles(client_node, server_node)
        # expected result
        exp_result = [{
            'node': missing_file,
            'id': 'CLIENT_NODE',
            'action': Actions.CLIENT_NEW_FILE}]

        self.assertEqual(result, exp_result)
    def test_compare_files_update_client(self):
        client_node = default_code.create_folder_with_files(self.FILE_NAME, 150)
        server_node = default_code.create_folder_with_files(self.FILE_NAME)

        result = tree_comparator._compareFiles(client_node, server_node)
        # expected result
        x = client_node.get_children()
        exp_result = [
            {
                'node': x[0],
                'id': 'CLIENT_NODE',
                'action': Actions.CLIENT_UPDATE_FILE,
            },
            {
                'node': x[1],
                'id': 'CLIENT_NODE',
                'action': Actions.CLIENT_UPDATE_FILE,
            }
        ]
        self.assertEqual(result, exp_result)
    def test_compare_files_update_server(self):
        client_node = default_code.create_folder_with_files(self.FILE_NAME)
        server_node = default_code.create_folder_with_files(self.FILE_NAME, 150)

        result = tree_comparator._compareFiles(client_node, server_node)
        # expected result
        x = server_node.get_children()
        exp_result = [
            {
                'node': x[0],
                'path': 'test',
                'action': Actions.SERVER_UPDATE_FILE,
                'snap_last_update': 100
            },
            {
                'node': x[1],
                'path': 'test',
                'action': Actions.SERVER_UPDATE_FILE,
                'snap_last_update': 100
            }
        ]
        self.assertEqual(result, exp_result)
Ejemplo n.º 6
0
class RemoteFileModelTest(default_code.DefaultCode):
    def setUp(self):
        """Metodo che viene chiamato prima di ogni metodo"""
        super().setUp()
        self.main_model = MainModel()
        self.model_test = self.main_model.remote_file_model

    def tearDown(self):
        """Metodo che viene chiamato dopo ogni metodo"""
        super().tearDown()
        self.model_test.folder_queue.clear()
        self.model_test.folder_queue.append("LOCAL_ROOT")

    def test_set_network_model(self):
        network_model = self.main_model.network_model
        self.model_test.set_network_model(network_model)
        self.assertEqual(tree_builder.networkmodel, network_model)

    @patch('src.algorithm.tree_builder.get_tree_from_node_id',
           return_value=True)
    def test_get_current_tree(self, mocked_get_tree_from_node):
        result = self.model_test.get_current_tree()
        mocked_get_tree_from_node.assert_called_once()
        self.assertEqual(result, True)

    @patch('src.model.remote_file_model.RemoteFileModel.get_current_tree',
           return_value=default_code.create_folder_with_files(["TestFile"]))
    def test_get_data_file(self, mocked_get_tree_from_node):
        file_result, dir_result = self.model_test.get_data()
        self.assertEqual(file_result[-1].get_name(), "TestFile")

    @patch('src.model.remote_file_model.RemoteFileModel.get_current_tree',
           return_value=default_code.create_folder_with_folders(["TestFolder"])
           )
    def test_get_data_folder(self, mocked_get_tree_from_node):
        file_result, dir_result = self.model_test.get_data()
        self.assertEqual(dir_result[-1].get_name(), "TestFolder")

    @patch('src.model.remote_file_model.RemoteFileModel.get_current_tree',
           return_value=default_code.create_folder_with_files(["TestFile"]))
    def test_get_data_not_prev_dir(self, mocked_get_tree_from_node):
        self.model_test.folder_queue.append("NonRoot")
        file_result, dir_result = self.model_test.get_data()
        self.assertEqual(dir_result[0].get_name(), "..")

    @patch('src.model.remote_file_model.RemoteFileModel.get_current_tree',
           return_value=default_code.create_folder_with_files(["TestFile"]))
    def test_get_data_exception(self, mocked_get_tree_from_node):
        mocked_get_tree_from_node.side_effect = APIException
        test_result = self.model_test.get_data()
        self.assertEqual(test_result, None)

    def test_set_current_node_descend(self):
        self.model_test.set_current_node("TestNode")
        self.assertEqual(self.model_test.folder_queue[-1], "TestNode")

    def test_set_current_node_ascend(self):
        self.model_test.folder_queue.append("TestNode")
        self.model_test.folder_queue.append("SecondNode")
        self.model_test.set_current_node("SecondNode")
        self.assertEqual(self.model_test.folder_queue[-1], "TestNode")
 def test_compare_files_equals(self):
     node = default_code.create_folder_with_files(self.FILE_NAME)
     result = tree_comparator._compareFiles(node, node)
     # Empty list, nothing to do
     self.assertEqual(result, [])