Exemplo n.º 1
0
    def test_get_target_schema(self):
        """Test target schema extractor from target config"""
        # No default_target_schema and schema_mapping should raise exception
        with pytest.raises(Exception):
            invalid_target_config = {}
            utils.get_target_schema(invalid_target_config, 'foo.foo')

        # Empty default_target_schema should raise exception
        with pytest.raises(Exception):
            target_config_with_default = {'default_target_schema': ''}
            utils.get_target_schema(target_config_with_default, 'foo.foo')

        # Default_target_schema should define the target_schema
        target_config_with_default = {'default_target_schema': 'target_schema'}
        assert utils.get_target_schema(target_config_with_default,
                                       'foo.foo') == 'target_schema'

        # Empty schema_mapping should raise exception
        with pytest.raises(Exception):
            target_config_with_empty_schema_mapping = {'schema_mapping': {}}
            utils.get_target_schema(target_config_with_empty_schema_mapping,
                                    'foo.foo')

        # Missing schema in schema_mapping should raise exception
        with pytest.raises(Exception):
            target_config_with_missing_schema_mapping = {
                'schema_mapping': {
                    'foo2': {
                        'target_schema': 'foo2'
                    }
                }
            }
            utils.get_target_schema(target_config_with_missing_schema_mapping,
                                    'foo.foo')

        # Target schema should be extracted from schema_mapping
        target_config_with_schema_mapping = {
            'schema_mapping': {
                'foo': {
                    'target_schema': 'foo'
                }
            }
        }
        assert utils.get_target_schema(target_config_with_schema_mapping,
                                       'foo.foo') == 'foo'

        # If target schema exist in schema_mapping then should not use the default_target_schema
        target_config = {
            'default_target_schema': 'target_schema',
            'schema_mapping': {
                'foo': {
                    'target_schema': 'foo'
                }
            }
        }
        assert utils.get_target_schema(target_config, 'foo.foo') == 'foo'

        # If target schema not exist in schema_mapping then should return the default_target_schema
        target_config = {
            'default_target_schema': 'target_schema',
            'schema_mapping': {
                'foo2': {
                    'target_schema': 'foo2'
                }
            }
        }
        assert utils.get_target_schema(target_config,
                                       'foo.foo') == 'target_schema'
Exemplo n.º 2
0
    def test_get_target_schema(self):
        """Test target schema extractor from target config"""
        # No default_target_schema and schema_mapping should raise exception
        with pytest.raises(Exception):
            invalid_target_config = {}
            utils.get_target_schema(invalid_target_config, "foo.foo")

        # Empty default_target_schema should raise exception
        with pytest.raises(Exception):
            target_config_with_default = {"default_target_schema": ""}
            utils.get_target_schema(target_config_with_default, "foo.foo")

        # Default_target_schema should define the target_schema
        target_config_with_default = {"default_target_schema": "target_schema"}
        assert utils.get_target_schema(target_config_with_default,
                                       "foo.foo") == "target_schema"

        # Empty schema_mapping should raise exception
        with pytest.raises(Exception):
            target_config_with_empty_schema_mapping = {"schema_mapping": {}}
            utils.get_target_schema(target_config_with_empty_schema_mapping,
                                    "foo.foo")

        # Missing schema in schema_mapping should raise exception
        with pytest.raises(Exception):
            target_config_with_missing_schema_mapping = {
                "schema_mapping": {
                    "foo2": {
                        "target_schema": "foo2"
                    }
                }
            }
            utils.get_target_schema(target_config_with_missing_schema_mapping,
                                    "foo.foo")

        # Target schema should be extracted from schema_mapping
        target_config_with_schema_mapping = {
            "schema_mapping": {
                "foo": {
                    "target_schema": "foo"
                }
            }
        }
        assert utils.get_target_schema(target_config_with_schema_mapping,
                                       "foo.foo") == "foo"

        # If target schema exist in schema_mapping then should not use the default_target_schema
        target_config = {
            "default_target_schema": "target_schema",
            "schema_mapping": {
                "foo": {
                    "target_schema": "foo"
                }
            }
        }
        assert utils.get_target_schema(target_config, "foo.foo") == "foo"

        # If target schema not exist in schema_mapping then should return the default_target_schema
        target_config = {
            "default_target_schema": "target_schema",
            "schema_mapping": {
                "foo2": {
                    "target_schema": "foo2"
                }
            }
        }
        assert utils.get_target_schema(target_config,
                                       "foo.foo") == "target_schema"