Exemplo n.º 1
0
    def test_logs_updated_chunks_data_with_meta_chunks(
            self, background_job_manager: BackgroundJobManager) -> None:
        """Test logs updated chunks data when meta chunks is not empty."""
        fake_not_empty_data_frame = DataFrame({"col1": [42]})

        mocked_sql_to_data_frame: MagicMock = MagicMock()
        mocked_sql_to_data_frame.return_value = fake_not_empty_data_frame

        background_job_manager._sql_to_data_frame = (  # type: ignore
            mocked_sql_to_data_frame)
        background_job_manager._create_chunks_dictionary = MagicMock(
        )  # type: ignore
        background_job_manager._calculate_chunks_difference = MagicMock(
        )  # type: ignore
        background_job_manager._calculate_chunks_difference.return_value = {
            "new": 55
        }  # type: ignore

        background_job_manager._update_chunks_data()

        global mocked_storage_cursor

        background_job_manager._create_chunks_dictionary.assert_called_once_with(  # type: ignore
            fake_not_empty_data_frame)
        background_job_manager._calculate_chunks_difference.assert_called_once(
        )  # type: ignore
        mocked_storage_cursor.log_meta_information.assert_called_once_with(
            "chunks_data", {"chunks_data_meta_information": '{"new": 55}'}, 42)

        mocked_storage_cursor = MagicMock()
        mocked_storage_cursor.log_meta_information.return_value = None
Exemplo n.º 2
0
    def test_successfully_calculates_chunk_differences(
            self, background_job_manager: BackgroundJobManager) -> None:
        """Test successfully calculates chunks differences."""
        fake_base_dict: Dict[str, Dict[str, List[int]]] = {
            "customer": {
                "c_custkey": [15000],
                "c_name": [15000]
            },
            "supplier": {
                "s_address": [1000],
                "s_comment": [600]
            },
        }
        fake_substractor_dict: Dict[str, Dict[str, List[int]]] = {
            "customer": {
                "c_custkey": [1000],
                "c_name": [5000]
            },
            "supplier": {
                "s_address": [1000],
                "s_comment": [555]
            },
        }
        expected_dict: Dict[str, Dict[str, List[int]]] = {
            "customer": {
                "c_custkey": [14000],
                "c_name": [10000]
            },
            "supplier": {
                "s_address": [0],
                "s_comment": [45]
            },
        }

        received_dict: Dict = background_job_manager._calculate_chunks_difference(
            fake_base_dict, fake_substractor_dict)

        assert expected_dict == received_dict