Ejemplo n.º 1
0
    def test_default_value(self):
        """Test we can affect default value according to keywords."""
        layer = load_local_vector_layer(
            'issue-3325-default-value.geojson',
            clone_to_memory=True
        )

        # This layer do not have keywords, we need to monkey patch them.
        layer.keywords = {
            'layer_purpose': 'exposure',
            'inasafe_fields': {
            },
            'inasafe_default_values': {
                female_ratio_field['key']: 0.5
            }
        }
        add_default_values(layer)
        # These keywords should add a new column female_ratio with 0.5 inside.
        index = layer.fieldNameIndex(female_ratio_field['field_name'])
        self.assertNotEqual(-1, index)
        self.assertListEqual(
            layer.uniqueValues(index),
            [0.5]
        )

        layer = load_local_vector_layer(
            'issue-3325-default-value.geojson',
            clone_to_memory=True
        )
        # This layer do not have keywords, we need to monkey patch them.
        layer.keywords = {
            'layer_purpose': 'exposure',
            'inasafe_fields': {
                female_ratio_field['key']: 'value_1'
            },
            'inasafe_default_values': {
                female_ratio_field['key']: 0.5
            }
        }
        add_default_values(layer)
        # These keywords should not add a new column female_ratio.
        index = layer.fieldNameIndex(female_ratio_field['field_name'])
        self.assertEqual(-1, index)

        index = layer.fieldNameIndex('value_1')
        self.assertListEqual(
            sorted(layer.uniqueValues(index)),
            [0.5, 1]
        )
Ejemplo n.º 2
0
    def test_default_value(self):
        """Test we can affect default value according to keywords."""
        layer = load_local_vector_layer(
            'issue-3325-default-value.geojson',
            clone_to_memory=True
        )

        # This layer do not have keywords, we need to monkey patch them.
        layer.keywords = {
            'layer_purpose': 'exposure',
            'inasafe_fields': {
            },
            'inasafe_default_values': {
                female_ratio_field['key']: 0.5
            }
        }
        add_default_values(layer)
        # These keywords should add a new column female_ratio with 0.5 inside.
        index = layer.fieldNameIndex(female_ratio_field['field_name'])
        self.assertNotEqual(-1, index)
        self.assertListEqual(
            layer.uniqueValues(index),
            [0.5]
        )

        layer = load_local_vector_layer(
            'issue-3325-default-value.geojson',
            clone_to_memory=True
        )
        # This layer do not have keywords, we need to monkey patch them.
        layer.keywords = {
            'layer_purpose': 'exposure',
            'inasafe_fields': {
                female_ratio_field['key']: 'value_1'
            },
            'inasafe_default_values': {
                female_ratio_field['key']: 0.5
            }
        }
        add_default_values(layer)
        # These keywords should not add a new column female_ratio.
        index = layer.fieldNameIndex(female_ratio_field['field_name'])
        self.assertEqual(-1, index)

        index = layer.fieldNameIndex('value_1')
        self.assertListEqual(
            sorted(layer.uniqueValues(index)),
            [0.5, 1]
        )