Exemplo n.º 1
0
def test_fes20_examples_212_filter04():
    filter_ = """
        <?xml version="1.0"?>
        <fes:Filter
             xmlns:fes="http://www.opengis.net/fes/2.0"
             xmlns:gml="http://www.opengis.net/gml"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.opengis.net/fes/2.0 
                 http://schemas.opengis.net/filter/2.0/filterAll.xsd
                 http://www.opengis.net/gml http://schemas.opengis.net/gml/2.1.2/geometry.xsd"
        >
            <fes:And>
                <fes:PropertyIsLessThan>
                    <fes:ValueReference>DEPTH</fes:ValueReference>
                    <fes:Literal>30</fes:Literal>
                </fes:PropertyIsLessThan>
                <fes:Not>
                    <fes:Disjoint>
                        <fes:ValueReference>Geometry</fes:ValueReference>
                        <gml:Box srsName="urn:fes:def:crs:EPSG::4326">
                            <gml:coordinates>
                                13.0983,31.5899 35.5472,42.8143
                            </gml:coordinates>
                        </gml:Box>
                    </fes:Disjoint>
                </fes:Not>
            </fes:And>
        </fes:Filter>
    """.strip(),
    expected = operators.BinaryLogicOperator(
        operator_type=operators.BinaryLogicType.AND,
        first_expression=operators.BinaryComparisonOperator(
            operator_type=operators.BinaryComparisonName.PROPERTY_IS_LESS_THAN,
            first_expression=expressions.ValueReference("DEPTH"),
            second_expression=expressions.Literal("30")),
        second_expression=operators.UnaryLogicOperator(
            operator_type=operators.UnaryLogicType.NOT,
            operand=operators.BinarySpatialOperator(
                operator_type=operators.SpatialOperatorName.DISJOINT,
                first_operand=expressions.ValueReference("Geometry"),
                second_operand=None,
            )))
    result = parsers.parse_filter(filter_)
    assert result == expected
Exemplo n.º 2
0
def test_fes20_examples_212_filter02():
    filter_ = """
        <?xml version="1.0"?>
        <fes:Filter
             xmlns:fes="http://www.opengis.net/fes/2.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.opengis.net/fes/2.0 
                 http://schemas.opengis.net/filter/2.0/filterAll.xsd"
        >
            <fes:PropertyIsLessThan>
                <fes:ValueReference>DEPTH</fes:ValueReference>
                <fes:Literal>30</fes:Literal>
            </fes:PropertyIsLessThan>
        </fes:Filter>
    """.strip()
    expected = operators.BinaryComparisonOperator(
        operators.BinaryComparisonName.PROPERTY_IS_LESS_THAN,
        first_expression=expressions.ValueReference("DEPTH"),
        second_expression=expressions.Literal("30"))
    result = parsers.parse_filter(filter_)
    assert result == expected
Exemplo n.º 3
0
"""Tests for the custom pyfes types"""

import pytest

from pyfes.fes20 import expressions
from pyfes.fes20 import operators

from pyfes import errors

pytestmark = pytest.mark.unit


@pytest.mark.parametrize("operand", [
    expressions.ValueReference("first"),
    expressions.Literal("second"),
    expressions.Function("third"),
])
def test_validate_operand(operand):
    operators.validate_operand(operand)


@pytest.mark.parametrize("operand, allowed", [
    (expressions.ValueReference("first"),
     (expressions.Literal, expressions.Function)),
    (expressions.Literal("second"),
     (expressions.ValueReference, expressions.Function)),
    (expressions.Function("third"),
     (expressions.ValueReference, expressions.Literal)),
])
def test_validate_operand_invalid(operand, allowed):
    with pytest.raises(errors.InvalidExpressionError):
             <fes:Filter
               xmlns:fes="http://www.opengis.net/fes/2.0"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://www.opengis.net/fes/2.0
                 http://schemas.opengis.net/filter/2.0/filterAll.xsd"
             >
                 <fes:PropertyIsEqualTo>
                     <fes:ValueReference>SomeProperty</fes:ValueReference>
                     <fes:Literal>100</fes:Literal>
                 </fes:PropertyIsEqualTo>
             </fes:Filter>
         ''',
         BinaryComparisonOperator(
             operator_type=BinaryComparisonName.PROPERTY_IS_EQUAL_TO,
             first_expression=expressions.ValueReference("SomeProperty"),
             second_expression=expressions.Literal("100")
         )
 ),
 (
         '''
             <fes:Filter
               xmlns:fes="http://www.opengis.net/fes/2.0"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://www.opengis.net/fes/2.0
                 http://schemas.opengis.net/filter/2.0/filterAll.xsd"
             >
                 <fes:PropertyIsLessThan>
                     <fes:ValueReference>DEPTH</fes:ValueReference>
                     <fes:Literal>30</fes:Literal>
               </fes:PropertyIsLessThan>
             </fes:Filter>