def test_post_import_checks(self):
        args = CliArgs()
        pipelinewise = PipelineWise(args, CONFIG_DIR, VIRTUALENVS_DIR)
        test_files_dir = "{}/resources/test_post_import_checks".format(os.path.dirname(__file__))

        target_pk_required = cli.utils.load_json("{}/target_config_pk_required.json".format(test_files_dir))
        target_pk_not_required = cli.utils.load_json("{}/target_config_pk_not_required.json".format(test_files_dir))
        tap_with_pk = cli.utils.load_json("{}//tap_properties_with_pk.json".format(test_files_dir))
        tap_with_no_pk_full_table = cli.utils.load_json("{}//tap_properties_with_no_pk_full_table.json".format(test_files_dir))
        tap_with_no_pk_incremental = cli.utils.load_json("{}//tap_properties_with_no_pk_incremental.json".format(test_files_dir))
        tap_with_no_pk_log_based = cli.utils.load_json("{}//tap_properties_with_no_pk_log_based.json".format(test_files_dir))
        tap_with_no_pk_not_selected = cli.utils.load_json("{}//tap_properties_with_no_pk_not_selected.json".format(test_files_dir))

        # Test scenarios when post import checks should pass
        assert pipelinewise._run_post_import_tap_checks(tap_with_pk, target_pk_required) == []
        assert pipelinewise._run_post_import_tap_checks(tap_with_pk, target_pk_not_required) == []
        assert pipelinewise._run_post_import_tap_checks(tap_with_no_pk_full_table, target_pk_required) == []
        assert pipelinewise._run_post_import_tap_checks(tap_with_no_pk_incremental, target_pk_not_required) == []
        assert pipelinewise._run_post_import_tap_checks(tap_with_no_pk_log_based, target_pk_not_required) == []
        assert pipelinewise._run_post_import_tap_checks(tap_with_no_pk_not_selected, target_pk_required) == []

        # Test scenarios when post import checks should fail due to primary keys not exists
        assert len(pipelinewise._run_post_import_tap_checks(tap_with_no_pk_incremental, target_pk_required)) == 1
        assert len(pipelinewise._run_post_import_tap_checks(tap_with_no_pk_log_based, target_pk_required)) == 1
示例#2
0
    def test_post_import_checks(self):
        """Test post import checks"""
        args = CliArgs()
        pipelinewise = PipelineWise(args, CONFIG_DIR, VIRTUALENVS_DIR)
        test_files_dir = '{}/resources/test_post_import_checks'.format(
            os.path.dirname(__file__))

        tap_pk_required = cli.utils.load_json(
            '{}/tap_config_pk_required.json'.format(test_files_dir))
        tap_pk_not_required = cli.utils.load_json(
            '{}/tap_config_pk_not_required.json'.format(test_files_dir))
        tap_pk_not_defined = cli.utils.load_json(
            '{}/tap_config_pk_not_defined.json'.format(test_files_dir))
        tap_with_pk = cli.utils.load_json(
            '{}//tap_properties_with_pk.json'.format(test_files_dir))
        tap_with_no_pk_full_table = cli.utils.load_json(
            '{}//tap_properties_with_no_pk_full_table.json'.format(
                test_files_dir))
        tap_with_no_pk_incremental = cli.utils.load_json(
            '{}//tap_properties_with_no_pk_incremental.json'.format(
                test_files_dir))
        tap_with_no_pk_log_based = cli.utils.load_json(
            '{}//tap_properties_with_no_pk_log_based.json'.format(
                test_files_dir))
        tap_with_no_pk_not_selected = cli.utils.load_json(
            '{}//tap_properties_with_no_pk_not_selected.json'.format(
                test_files_dir))

        with patch('pipelinewise.cli.pipelinewise.commands.run_command'
                   ) as run_command_mock:
            # Test scenarios when post import checks should pass
            assert pipelinewise._run_post_import_tap_checks(
                tap_pk_required, tap_with_pk, 'snowflake') == []
            assert pipelinewise._run_post_import_tap_checks(
                tap_pk_not_required, tap_with_pk, 'snowflake') == []
            assert pipelinewise._run_post_import_tap_checks(tap_pk_required, tap_with_no_pk_full_table, 'snowflake') \
                   == []
            assert pipelinewise._run_post_import_tap_checks(
                tap_pk_not_required, tap_with_no_pk_incremental,
                'snowflake') == []
            assert pipelinewise._run_post_import_tap_checks(
                tap_pk_not_required, tap_with_no_pk_log_based,
                'snowflake') == []
            assert pipelinewise._run_post_import_tap_checks(
                tap_pk_required, tap_with_no_pk_not_selected,
                'snowflake') == []
            assert pipelinewise._run_post_import_tap_checks(
                tap_pk_not_defined, tap_with_no_pk_full_table,
                'snowflake') == []

            # Test scenarios when post import checks should fail due to primary keys not exists
            assert len(
                pipelinewise._run_post_import_tap_checks(
                    tap_pk_required, tap_with_no_pk_incremental,
                    'snowflake')) == 1
            assert len(
                pipelinewise._run_post_import_tap_checks(
                    tap_pk_required, tap_with_no_pk_log_based,
                    'snowflake')) == 1
            assert len(
                pipelinewise._run_post_import_tap_checks(
                    tap_pk_not_defined, tap_with_no_pk_incremental,
                    'snowflake')) == 1
            assert len(
                pipelinewise._run_post_import_tap_checks(
                    tap_pk_not_defined, tap_with_no_pk_log_based,
                    'snowflake')) == 1

            # Test scenarios when post import checks should fail due to transformations validation command fails
            tap_with_trans = cli.utils.\
                load_json('{}/tap_config_with_transformations.json'.format(test_files_dir))

            run_command_mock.return_value = (
                1, None, 'transformation `HASH` cannot be applied')

            assert len(
                pipelinewise._run_post_import_tap_checks(
                    tap_with_trans, tap_with_no_pk_not_selected,
                    'snowflake')) == 1

            assert len(
                pipelinewise._run_post_import_tap_checks(
                    tap_with_trans, tap_with_no_pk_incremental,
                    'snowflake')) == 2

            # mock successfull transformation validation command
            run_command_mock.return_value = (0, None, None)

            assert len(
                pipelinewise._run_post_import_tap_checks(
                    tap_with_trans, tap_with_no_pk_not_selected,
                    'snowflake')) == 0

            assert len(
                pipelinewise._run_post_import_tap_checks(
                    tap_with_trans, tap_with_no_pk_incremental,
                    'snowflake')) == 1

            assert run_command_mock.call_count == 4